Sunday, May 31, 2009

Gtalk Gadgets Links for iphone

For Google Accounts / Gmail users:
http://talkgadget.google.com/talkgadget/m

For Google Apps:
http://hostedtalkgadget.google.com/a/mydomain.com/talkgadget/m

Wednesday, May 27, 2009

How to create a plug-in component to a framework in C-Sharp?

I was thinking on a design where I can plug-in a component to a existing framework without making any change to framework code.

Scenario: Let’s discuss a scenario that you have created a user interface or a framework in which you need to make calls to the plugged in components. In this scenario you cannot make a call to the component methods directly. In case you need it, the component needs to be added as a reference and that namespace of the component need to be available in the framework. But if you don’t want to change even a small of the code in the framework and it is generic enough to call the methods in the components then it is not so easy at all as we discussed.


I think you are pretty confused with the scenario. Let’s take an example where we have a drawing framework. We have a component to draw circles. The framework should be designed in such a way that it can call any components which has a method draw_circle() without actually adding that component as a reference to the framework. How will design the framework?
I hope you are now almost clear about the concept, let’s go into the design part of it. We have to assume that we don’t have a component at all. I need to add two numbers. I need to design a framework which will add two numbers without actually knowing the components which actually adds those numbers.

Step 1: There should be some way that both client and server should know about the methods which they need to call. So we need to expose an interface say ICalculate. ICalculate should be available for both server and client. Its better that the interface we have is available with a separate component. So client and server can add that component to communicate each other.

using System;
using System.Collections.Generic;
using System.Text;

namespace MyInterface
{
public interface ICalculate
{
int Add(int x, int y);
}
}

Step 2: Now we need to do something for making the component be accessed by the framework. Better way is to have a configuration file. Before doing that lets have an understanding of how the component might be like.
Component should inherit from the interface so that the method which is exposed through the interface will be implemented. Since we have a separate component which have the interface add that interface component as a reference.


using System;
using System.Collections.Generic;
using System.Text;
using MyInterface;

namespace MyLib
{
public class MyLibClass: ICalculate
{
#region MyLibInterface Members

public int Add(int x, int y)
{
return x + y;
}

#endregion
}
}
In this example I am not defining any configuration file, but I am hardcoding it in the framework which is absolutely since we need to make changes in the framework code to adapt with the changes in the plug-in component. I am sorry I don’t have time to code all those things to read it from an xml file and all. Just bear with me and take this code as a proof of concept.
Ok, now coming back to our mission.

Step 3: We have a configuration file, read the assembly name and class name from it. This change need to be done by the developer who plugs in his component to the framework.

Step 4: Now we have the assembly name (dll name) and the class name. Now use reflection to get the assembly and create an instance of the class and call the methods in the runtime.
using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;

using MyInterface;

namespace MyConsole
{
class Program
{
static void Main(string[] args)
{
Assembly asm = Assembly.LoadFrom("MyLib.dll");
Type myType = asm.GetType("MyLib.MyLibClass");
ICalculate myObj = Activator.CreateInstance(myType) as ICalculate;
Console.WriteLine(myObj.Add(10, 20).ToString());
}

}
}
That is all, we are done with framework which doesn’t require any framework modification (rather component which links with another component at the runtime). Hope this will help and kindly revert back if you have any doubts.

Wednesday, May 20, 2009

Setting up linksys router for Tataindicom Connection

I am bored of getting wired to my laptop. So i decided to get a wifi router. I got a linksys router. Configuring is just so simple. It comes with a CD and you can just follow the instruction. But what I am listing out is some issues which you could find while configuring internet.

Listing out the steps in short,

i) Plug the Ethernet cable from your broadband Internet provider into the port labeled "Internet"
ii) Plug another Ethernet cable which comes with router into one of the available ports
iii) Plug the other end of that same cable into an Ethernet port on your laptop.
iv) Instead of following the cd you can directly use internet explorer and type http://192.168.1.1
v) Select Lan for Tataindicom connection and setup the security, select wireless and choose WAP. Select a password of your choice. You should be using the same password to connect it to the wireless connection.
vi) If you are getting Acquiring Network Connection indefinitely issues would be a) Your password given could be wrong while trying to connect
b) You might not have selected obtain Ip Address automatically from internet properties

Let me know if you face any issues doing this. Happy Wirefree browsing.

Thursday, May 07, 2009

Convert Int to Hex in C Sharp

int x = 8005;

Console.WriteLine(String.Format("{0:x}", x));