Sharing knowledge is like lighting a candle from another's flame, it does not cause that flame to burn any less brightly.
Tuesday, 17 August 2010
Vodafone, HTC Desire fiasco
But after a day or 2 I found it was broken :-( if you used it for any length of time it would just quit, turn off, then not turn on for a while whilst it cooled down, oh and there was the strange squeeze thing I mentioned in another blog post.
I complained only 2 or 3 days after I received the original, I thought it would be straight forward, new for new, but unfortunately no stock, the desire is very desirable and there were supply problems.
So I waited and waited, I rang back twice a week to check on progress, I was not using my desire at this point as it was unusable, switching itself off randomly. Back to my trusty old nokia (7 years and still going strong)
And I waited.
Finally, finally after ringing twice a week for 2 months i got a replacement phone :-) yay at last, but I was told to keep my batery, sim and memory card from my other phone, strange, oh well, got my new phone now. :-)
But no, still broken, still with exactly the same problems as before.... ARRRRG, it was the battery all this time, i told them i thought it was, dam it.
And wait what's this, there is as small scuff mark on the base of the phone, its brand new isn't it?
So rang Vodafone back and said it still doesn't work, and also is this phone I have new? there is a scuff mark on it? after much a to-do I got the answer that its a reconditioned phone, and we will send you a battery (which they did but I suspect its not a new one as it came in a jiffy bag).
Anyway after some challenging discussions I got agreement that it was an error to send me a reconditioned phone, apparently an error in the system (problems with phones over 1 month into the contract get refurbished replacements), since I was 2 months into my contract I get a reconditioned one... even though id reported the problem on day 3... But the supervisor on the other end was reasonable in the end and agreed I should have had a new phone sent not a reconditioned one, and so I'm waiting, again.
And waiting and waiting, I ring back twice a week again, try to get a date but again they are out of stock, out of stock, out of stock.
Do Vodafone ever sell the HTC Desire? I know its a popular phone, that there are supply problems but in effect its been over 3 months now, you cant tell me you have not had any stock in 3 months? really?
I suspect its far more profitable to sell that new handset to a new customer than to sort out your existing ones?
I'm a bit disappointed really, as you can imagine, cause I've been using Vodafone for all my mobile life, years and years, even whilst abroad, and always had excellent service. I've had friends with orange who had trouble and problems with the provider and I've always said come to Vodafone, they are great, but seams like things change, or just maybe I've just got really unlucky.
Thursday, 13 May 2010
HTC Desire shut down problems
So ive got a brand new HTC Desire, and instantly loved it, but its not right...
If you talk on the phone for 5-10 minutes the phone will just switch off? if you use the internet or any other functionality the phone will soon enough just switch off. sometimes if you just gently squeeze it will just shut down.
Once it has shut down the status light flashes green and orange, sometimes it wont even shitch back on for ages...
So ive got in touch with vodafone, and they have been really good about sorting it out. they have quickly agreed to replace it :-) but there are none in stock at the moment, and none due in till the 23rd i think... boo
video of the squeeze
As you can see it works pretty well, quick navigation, just dont squeeze it.
Wednesday, 27 January 2010
Spring.net and asp.mvc, Getting started with dependency injection
Download Prerequesits
First get asp.mvc, download and install from here (im assuming you have vs2008 or like wise for this tutorial)
http://www.asp.net/mvc/download/
At the time of writing im using vs2008, xp and mvc 1
downloaded here
http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=53289097-73ce-43bf-b6a6-35e00103cb4b
but im sure mvc 2.0 would be much the same to set up DI
right click on your existing solution (or alternativly create a new one)
then add, new project, web, pick 'asp.net mvc web appication' from the list of templates contained
this will make a brand new mvc web app, all configured and ready to go, build and run it you should see the default mvc site out of the box.
now to get spring running and injecting goodness into it.
first download spring.net
http://www.springframework.net/download.html
im going for the latest production release 1.3.0
then download MVCContrib from
http://mvccontrib.codeplex.com/
im using the latest stable release for mvc 1.0 here
http://mvccontrib.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=33401
get both the main download and the extras package (the spring IOC assembalies are contained in the extras package)
reference the following assemblies from the solution: spring.core, mvcContrib and MCVContrib.spring
Substitute the default controller factory for the spring factory provided by mvcContrib
Add the following to the head of global.ascx
using Spring.Context.Support;
using MvcContrib.Spring;
add IOC to your global.ascx so that application_start creates a spring context
protected void Application_Start()
{
ConfigureIoC();
RegisterRoutes(RouteTable.Routes);
}
private static void ConfigureIoC()
{
ContextRegistry.RegisterContext(new XmlApplicationContext(false, "assembly://MvcApplication1/MvcApplication1/objects.xml"));
var ctx = ContextRegistry.GetContext();
SpringControllerFactory.Configure(ctx);
ControllerBuilder.Current.SetControllerFactory(typeof(SpringControllerFactory));
}
add an objects.xml file that will hold all the spring configuration
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net
http://www.springframework.net/xsd/spring-objects.xsd">
</objects>
This objects.xml must be an embedded resource into the assembly, right click the file, properties, and change it to an embedded resource. If you miss this step you will get an error stating 'Could not load file or assembly Spring.Core.....' basically stating that the assembly didn't contain the objects.xml, which is the dependency spring is looking for.
at this point if you ran the code you would get the error
No object named 'HomeController' is defined : Cannot find definition for object [HomeController]
This is good, it means that spring is looking for a definition of your home controller but cant find one.
so letes tell it about it
add this to your objects xml
<object id="HomeController" type="MvcApplication1.Controllers.HomeController, MvcApplication1">
</object>
now when you run the app you should get the same boring default mvc home page again, brilliant, looks like its working, now to test the dependency injection, this is what we have been waiting for.
Inject a custom object into the homeController
So the easiest way to demo this is to echo some text out onto the screen that comes from a dummy data
add 2 objects to the model folder
using System;
namespace MvcApplication1.Models
{
public interface IHelloDAO
{
String Hi();
}
}
namespace MvcApplication1.Models
{
public class HelloDAO : IHelloDAO
{
public string Hi()
{
return "This is data straight from HelloDAO";
}
}
}
now we are going to use this DAO (Data Access Object) in the controller to get some data from the model by using the Hi method on the IHello interface.
the class should now look like this
public class HomeController : Controller
{
public IHelloDAO HelloDAO { get; private set; }
public HomeController(IHelloDAO helloDAO)
{
HelloDAO = helloDAO;
}
public ActionResult Index()
{
//ViewData["Message"] = "Welcome to ASP.NET MVC!";
ViewData["Message"] = HelloDAO.Hi();
return View();
}
public ActionResult About()
{
return View();
}
}
We added a new constructor which takes an instance of IHelllo (this is the think that is being injected in), and we have used the instance to get the message by using HelloDAO.Hi()
finally import the relevent model namespace at the top of the file.
again if you were to run the app at this point you would get the following error:
Cannot instantiate a class that does not have a no-argument constructor [MvcApplication1.Controllers.HomeController].
which indicates quite clearly that the controller is not configured correctly. Basically spring is expecting a no argument constructor, but the real class dosent have one.
Configure Spring
Now all that remains is to wire the dependencies in the objects.xml which should now look like this
<?xml version="1.0" encoding="utf-8"?>
<objects xmlns="http://www.springframework.net"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.net
http://www.springframework.net/xsd/spring-objects.xsd">
<object id="HomeController" type="MvcApplication1.Controllers.HomeController, MvcApplication1">
<constructor-arg ref="HelloDAO" />
</object>
<object id="HelloDAO" type="MvcApplication1.Models.HelloDAO, MvcApplication1">
</object>
</objects>
you can see we have added a parameterised constructor to the controller through wich we are injecting in an implementation of the HelloDAO interface.
The index remains the same as it was out of the box and should display our message instead of the default 'Welcome to ASP.NET MVC!'
lets run it.
magic, you have configured your first and hopefully not last controller through spring.net and asp.mvc
now your ready for part 2 (Spring.net and asp.mvc, even more dependency injection)
Tuesday, 7 July 2009
Death and life of a netbook (Acer Aspire One)
This isn't really a review but ever since i've got it, its been great. Small, light, perfect for travelling and storing photos on, its been round the world with us.
I really don't have a bad word to say about it, the Intel atom 1.6 GHz processor is great and the 1 gig of ram perfect for running xp home (yes sorry i had to get the Microsoft XP version, i did really want the linux one, but it wasn't just me using it and everyone else knows xp so xp it was), and the 160gig HD is perfect for storing the photos on.
small, fast, strong, light, good looking
all good praise
so why the post?
well it broke, i didn't do anything to it, didn't install anything nasty, didn't mess with its innards (i know better than to do that to a perfectly good working laptop) but it broke. i shut it down one day, proper full shut down (not hibernation or sleep) and that was it, next time i pressed the power button nothing happened, no splash screen, no BIOS info, just a black screen :-/ eek.
Well after searching the interweb it appears it happens now and again to this perfect specimen of a nettop laptop. luckily there were some instructions on how to fix it too :-) thank god for google...
I wont go into details here, see the link below, i just thought id better let other unfortunates know that sometimes a dead laptop isn't really dead. i was dreading sending it back to the manufactures though...
Detailed instructions here
http://www.qrpcw.com/2009/01/acer-aspire-one-bios-recovery.html
Download BIOS update from here
http://support.acer-euro.com/drivers/notebook/as_one_150.html
happy days
now don't do that again. Speaking of which, if anyone knows why this happens could you let us know, im worried it might happen again, proper backups from now on then...
Wednesday, 17 June 2009
JQuery and ASP.Net
i know sometimes .net developers get, i dont know scared about trying new things that arnt born of microsoft, but JQuery is now being actively endorsed by microsoft and is actually shipped with the latest versions of the framework, so how do you use it.
1. If you dont have it get a copy of jquery.js its quite small (im currently using 'jquery-.3.2.min.js' which is 56Kb)
2. Include it in your web app
3. There are 2 ways to use it in a page
3a Add a script reference into your head section of the aspx page
<script src="Js cript/jquery -1.3.2.min.js" type="text/javascript"></script>
3b If you are using asp.net AJAX you can let the script manager handle it by:
3b.1 Adding a script manager to the form in the body of the aspx page
3b.2 Adding a scripts element
3b.3 Adding a script reference to the jquery file
3b.4 The result would look like this (remember it needs to go in side the pages form element
<asp:scriptmanager runat="server">
<scripts>
<asp:scriptreference path="~/Jscript/jquery-1.3.2.min.js">
</asp:scriptreference>
</scripts>
You are all set to use Jquery on the page
4. The most common way to initialise things is through the body onload, but this executes when the page is fully loaded, images and all, JQuery uses a special piece of script that executes when the page DOM is ready.
$(document).ready(function()
{
// do stuff when DOM is ready
});
This is where you can set styles, set up events to occur on different user actions all sorts of good stuff.
1st a couple of notes on the above code block:
1 it needs to be inside a sscript element
2 it needs to be located AFTER the scrip ref we declared in step 3 so if using the script manager it needs to be located inside the form after the script manager elements.
You can search the net for all the things you can do with JQuery, i wont repeat them all here, google is most definatly your friend.
say you want to set up a click event to a group of radio buttons so that when clicked a javascript event is fired off to show or hide related DIV elements
<script type="text/javascript">
$(document).ready(function(){
$(":radio").click(function(event){RBEvent(this)});
$(".radioClass").hide();
});
function RBEvent(obj)
{
$(".radioClass").hide("slow");
$("#Div" + obj.id).show("slow");
}
</script>
And here is the aspx elements that go along with it
< asp:RadioButton ID="RBBus" runat="server" Text="Bus" GroupName="RB" />
Bus details
Tube details
The neat thing that JQuery gives us, as in this example, is the ability to put all your page script into one place, and to have JQuery attach the events dynamically at run time making your javascript much easier to maintain. You could of course put all your script into a separate file as well which can be cached on the browser making the pages even quicker to load up.
Tuesday, 28 April 2009
Log4Net inside code run with MSTest unit testing
I could not get logging using log4net to output to the configured logger inside my unit tests
i tried
[assembly: log4net.Config. XmlConfigurator()]
in the unittest projects assembalyinfo but still log4net would not pick up the config
i found that the answer is to place an assembly initialise inside the unit test project, only one mind in the whole project. In fact if you do add 2 its an error
[AssemblyInitialize]
public static void AssemblyInitialize(TestContext testContext)
{
log4net.Config.XmlConfigurator.Configure();
}
Friday, 3 April 2009
Brief intro to LINQ
As with Generics, LINQ is a large subject that i cant write up properly without spending quite a lareg amount of time on, so i'll give a breif overview with an example of a common usage in the context of a generic list.
Overview
LINQ is a technology (or language construct) that allows you to process data using functional programming logic to perform an operation. The LINQ API is an attempt to provide a consistent programming model that allows you to manipulate data. Using LINQ we are able to create directly within the C# programming language entities called query expressions, these query expressions are created from numerous query operators that have been intentionally designed to look and feel similar (but not identical) like SQL. Using LINQ you can interact with many sources of data, listed below:
LINQ implementations
LINQ to objects
Linq to SQL
Linq to entities
Linq to XML
There are other LINQ enabled technologies but these are the most common, for a grater list look online.
All of this means that you can interact with an XML dom in the same manner as you would with a list of objects or an ADO record set without having to learn different syntax for either.
LINQ Example
List
IEnumerable
where n.Length >= 4
order by n
select n;
foreach(string name in subSetNames)
{
Console.Write(name);
}
The code above firstly creates a list of strings and places then in the names variable
Then it takes that collection filters it where the length is greater than or equal to 4
Sorts it based on the string
Puts the resulting collection in the variable subSetNames?
Finally it loops through all the strings in subSetNames? and prints them out
The resulting string is "Fred George William Smith" In this example the collection being acted on was a simple list of strings but it could be a collection of any type of object, or indeed an ADO record set, or an XML document, its a very powerful technique and allows for very clear functional logic (no complex nested loops and temporary collections for ordering etc).
This topic is massive and so im not going to go into it in any more depth, but in the most part ive not used any LINQ that is anymore complex than the example listed above. more advanced features such as lambdas and extension methods start to make things complex and ive so far managed to keep clear of using these techniques, for more info search google for the answer.
LINQ Grouping
By way of an example this code below demonstrates the power of LINQ used with a simple grouping command
string[] names = {"Albert", "Burke", "Connor", "David", "Everett", "Frank", "George", "Harris"};
//Defining the GroupBy logic (here it is lengthwise)
var groups = names.GroupBy(s => s.Length);
//Iterate through the collection created by the Grouping
foreach(IGrouping
{
//Branch on the condition decided
Console.WriteLine("Strings of Length {0}", group.Key);
//Actual results
foreach(string value in group)
Console.WriteLine(" {0}", value);
}
Produces this output
Strings of Length 6
Albert
Connor
George
Harris
Strings of Length 5
Burke
David
Frank
Strings of Length 7
Everett
LINQ Resources
MSDN 101 LINQ samples
Wednesday, 1 April 2009
Quick intro to generics
So tell me about them then!
Generics came in at .net 2.0 and are used extensively through out the .net framework internally, if you do much .net dev work you will come across then at some point.
What are generics
Generics allow you to define a type (class or structure) while leaving some of the details unspecified.
Quick Tip
When you see the following in code you know you are looking at code that uses generics
//C#
List
List
'VB.Net
Dim myArray As New List(Of integer)();
Dim my2ndArray As New List(Of myClass)();
The main benefits for using generics are:
Type safety (you can only put ints in a collection of ints for example)
Performance (boxing and unboxing of primitive types is eliminated)
Clarity (you can see in visual studio what type of class is allowed in a generic collection, and intellisence will also help you out)
The most common (and simple) usage is in the new (as of 2.0) generic collection classes.
Previous to .net 2.0 you had ArrayList, HashTable, Queue and stack (to name just a few) these classes allow you to store collections of objects, and since every class in .net derives from object you can store any object in these classes.
So if you can store any object in a collection what the point of limiting a collection to allow it to only store objects of a certain type? The main reason is for type safety and clarity. This is best discussed by example:
ArrayList myArray = new ArrayList();
myArray.Add(1);
myArray.Add(2);
myArray.Add("3");
int counter = 0;
foreach(Object o in myArray)
{
int myInt = (int) o;
counter += myInt;
}
This code will compile fine, but will throw a runtime exception when trying to cast "3" (a string) to an int. you have to be careful when adding things to your collection and you have to make sure you handle exceptions that may arise from incorrect use. I often see code testing for the type of an object before doing a cast and if it is not of the correct type ignoring it, its bad practice, error prone, and is just unnecessary when using generics.
So if we rewrite the above example using generics:
List
myArray.Add(1);
myArray.Add(2);
//myArray.Add("3"); //if uncommented will not compile
int counter = 0;
foreach(int myInt in myArray)
{
counter += myInt;
}
The change to use generic list of type int has made the code type safe (you cant add anything other than an int to myArray, if you do you will get a compile time error. Also the foreach loop is much simpler, you know that all the objects in myArray are ints, so no need for explicit type casting. All in all generic collections make the code more robust and just plain easier to read and hence maintain.
Now generics goes much deeper than just generic collections but in general you wont need to know how to create your own generic types and generic methods, but i would recommend every .net developer should know, its used all over the place. But i have not created any in any of my professional work projects.
Resources
Generics on MSDN
Use MSDN documentation on your machine
Google for Generics and .net
Friday, 27 March 2009
Introduction to Log4Net
Log4net (http://logging.apache.org/log4net/) is a tool to help the programmer output log statements to a variety of output targets, i have used it handling all the logging requirements of the applications that i have developed recently. And have found it integrates very well with spring.net and NHibernate.
In most cases i have set up the apps to log everything to a file and also log errors/warnings to an SMTP logger (which effectively sends an email out to me).
There are loads of examples and manuals etc on the website http://logging.apache.org/log4net/ it gives loads of good config examples too.
In order to get log4net working all you need is the log4net dll, configuration, and a small amount of code to get it started and logging. (this page is a good read http://logging.apache.org/log4net/release/manual/configuration.html)
But the minimum to take away is:
1. Reference the log4net dll
2. Import the log4net classes
2.1. using log4net;
2.2. using log4net.Config;
3. Add a config file (usually just a section to your web.config or app.config)
4. Add a call to the configurator
4.1. log4net.Config.XmlConfigurator?.Configure();
4.2. Or [assembly: log4net.Config.XmlConfigurator?(Watch=true)]
5. Create a logger
5.1. private static readonly ILog log = LogManager?.GetLogger?(typeof(MyClassName?));
5.2. each class should have its own logger, which should be private and static (log4net is thread safe)
6. Use the logger to log
6.1. log.Info("my info message.");
TIP
If you find you are getting double entries for log records it is probably due to you having duplicated entries in the log config. For example you might have the root set to debug logging and a named logger also set to debug, which will mean that 2 log entries get inserted for all debug messages from that named logger.
Tuesday, 24 March 2009
How to expand a virtual machines disk space
I use virtual machines for my dev environment, which means i can mess around with them, install things to test them out safe in the knowledge that you can always get back to a previous state, or even back to the start with out any pain at all.
ive got a VM for VS2003 one for VS2008, i used to have one for VS2005 (but i don't use that any more) and dare i say it one for VB6 (which thankfully ive not used for quite a while)
But recently i ran out of space on the VS2008 install, id also got office installed, and i wanted the 3.5 framework sp1 installing, which is surprisingly large.
well, this is what i did:
open up a command line
vmware-vdiskmanager.exe -x 16Gb "C:\VMWare\WinXPPro5\Windows XP Professional.vmdk"
boot up from an ubuntu 8.04 live cd
bring up command console
type sudo gparted
select your main partition
right click partition to be expanded and hit resize
move slider to the right for the whole of the disk
apply
exit ubuntu
restart xp
enjoy your new many gigs of space