Thursday, 19 July 2012

IP Address's

Loop back address - It is a virtual network interface implemented in software only and not connected to any hardware, but which is fully integrated into the computer system's internal network infrastructure. Any traffic that a computer program sends to the loopback interface is immediately received on the same interface. Localhost is mapped to loopback address, usually 127.0.0.1 for IPv4, although any address in the range 127.0.0.0 to 127.255.255.255 is mapped to it. IPv6 designates only a single address for this function, 0:0:0:0:0:0:0:1 (also written as ::1).

Unspecified or 0:0:0:0 or * address - represents any address, but should not be present on outgoing packets. If you bind a listening socket to 0.0.0.0, you're telling the OS to accept connections on any ip address that the host has network adapters bound to. e.g. if your host had two network adapters with two different ip addresses. You can bind a socket to either one and it will accept connections only on that adapter. Or you can bind a socket to 0.0.0.0 (INADDR_ANY in WinSock) and it will bind to both adapters.

Private address - used within organization, range from 192.168.0.0 to 192.168.255.255 and 172.16.0.0 to 172.16.255.255

Public address - can be static or dynamic(per internet session). Static IP's are used sometime for gaming or hosting website etc.

IPV6 - IPV4 is 4 part address with each part size is of 8 bits, so totally 32 bits. It allows 4,29,49,67,296 or 2^32 addresses. But IPV6 is 8 part address with each part size is of 16 bits, so totally 128 bits.

Sample code to figure out whether IP address is 32 or 128 bits

    string input = "your IP address goes here";

    IPAddress address;
    if (IPAddress.TryParse(input, out address))
    {
        switch (address.AddressFamily)
        {
            case System.Net.Sockets.AddressFamily.InterNetwork:
                // we have IPv4
                break;
            case System.Net.Sockets.AddressFamily.InterNetworkV6:
                // we have IPv6
                break;
            default:
                // umm... yeah... I'm going to need to take your red packet and...
                break;
        }
    }

Wednesday, 4 July 2012

Split unity configuration file

For maintenance reasons, it is better to split a 'BIG' unity configuration into multiple files. One such way to do this is

1. Let us imagine we need to split into two files, so your root config file will look like below

<configSections>
    <section name="unitySection1
          type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, 
          Microsoft.Practices.Unity.Configuration"/>
    <section name="unitySection2
          type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, 
          Microsoft.Practices.Unity.Configuration"/>
</configSections>

<unitySection1 configSource="unity1.config" />
<unitySection2 configSource="unity2.config" /> 
 
2. And your individual unity files will look like below(see the highlighted section that 'unity' tag becomes 'unitySection1')
 
   <unitySection1>
       <container /> 
   </unitySection1>
 
   <unitySection2
       <container />
   </unitySection2>
 
3. Load the separate configuration files into Container


    UnityContainer.LoadConfiguration - will adds up the container details, so we just need to call it twice


 private void Initialise()
 {
   string[] unitySections = new string[] {"unitySection1", "unitySection2"};
  
   IUnityContainer container = new UnityContainer(); 
 
   foreach(var section in unitySections)
   {
      var configuration = ConfigurationManager.OpenExeConfiguration(path);
 
      var unitySection = (UnityConfigurationSection)configuration.
                          GetSection(section);
        
      container.LoadConfiguration(unitySection);
    }
 }
 
reference link 

CmdLet.ShouldContinue

Please refer this

Below example code

protected override void ProcessRecord()
{
    if (this.ShouldContinue("Are you sure you want to uninstall""Confirm Uninstall"))
    {
        //your script here
    }
}