Thursday, June 25, 2009

Is twitter an alternative for opinion polls?

Looking at http://fixoutlook.org/, I feel it is as another facet of twitter as a tool for collecting opinion poll. Regular radio buttons, checkboxes wont allow you to express your view. They force you to choose from what is asked for. I guess twitter approach is giving better handle to express the opinions. Any idea how to parse live twitter updates in public timeline?

Tuesday, June 23, 2009

Wonderware Hardware Offerings

Wonderware is offering range of hardware platforms to compliment their software.

Portifolio includes equipment for hazardous area, touch panels tablet PC etc.
Find range of offerings

Managed Extensibility Framework - Part2

This is in continuation with my previous post, Part1 of this series. Part1 covered the problem MEF tried to solve. I will start this part directly with example and then I will explain various sections in detail.

As of now MEF is all in one dll named System.ComponentModel.Composition. You can download this framework from codeplex.

It is currently in Preview 5. OK to get a quick grasp of this framework let us create three solutions.

  1. Console application which can consume extensible parts
  2. Class library which contains contract, rather interfaces
  3. Class library which contains one of the extensible parts that implements contract

Console application which can consume extensible parts

  1. Create a console application and call it “meflab1”
  2. Add reference to System.ComponentModel.Composition.dll (from bin directory of downloaded zip file)
  3. Replace code in Program.cs with following snippet
    using System;
    using System.IO;
    using System.Reflection;
    using System.ComponentModel.Composition;
    using System.ComponentModel.Composition.Hosting;
    using System.ComponentModel.Composition.Primitives;
    namespace meflab1
    {
    class Program
    {
    [Import]
    public IGreetings Greetings { get; set; }

    static void Main(string[] args)
    {
    Console.WriteLine("Enter 0 to quit, any other number to continue");
    while (Console.ReadLine() != "0")
    {

    Program program = new Program();
    program.Compose();
    program.Run();
    }
    }

    void Compose()
    {
    try
    {
    DirectoryCatalog catalog =
    new DirectoryCatalog(AppDomain.CurrentDomain.BaseDirectory);

    AggregateCatalog agcatalogue = new AggregateCatalog(new ComposablePartCatalog[] {catalog,
    new AssemblyCatalog(Assembly.GetExecutingAssembly())});

    CompositionContainer container = new CompositionContainer(agcatalogue);

    CompositionBatch batch = new CompositionBatch();

    batch.AddPart(this);

    container.Compose(batch);
    }
    catch (FileNotFoundException fnfex)
    {
    Console.WriteLine(fnfex.Message);
    }
    catch (CompositionException cex)
    {
    Console.WriteLine(cex.Message);
    }
    }

    void Run()
    {
    if (Greetings != null)
    {
    Console.WriteLine(Greetings.SayHello());
    }
    Console.Read();
    }
    }
    }

  4. Add a class by name SimpleGreeting and replace code in SimpleGreeting.cs with following snippet
    using System;
    using System.Collections.Generic;
    using System.ComponentModel.Composition;

    namespace meflab1
    {
    [Export(typeof(IContextInfo))]
    public class UserInfo : IContextInfo
    {
    public IDictionary<string, string> GetContextInfo()
    {
    return new Dictionary<string, string> { { "UserName",
    Environment.UserDomainName + "\\" + Environment.UserName } };
    }
    }
    }
  5. Save this solution.

Class library which contains contract, rather interfaces


  1. Create a class library and call it “meflibrary”
  2. Rename Class1.cs to Contract.cs
  3. Now replace contents of Contract.cs with following snippet. We are just defining two interfaces here
    using System.Collections.Generic;
    namespace meflab1
    {
    public interface IContextInfo
    {
    IDictionary<string, string> GetContextInfo();
    }

    public interface IGreetings
    {
    string SayHello();
    }
    }
  4. Build it and add reference of this class library to application we built in last step

Class library which contains one of the extensible parts that implements contract

  1. Create a class library and call it as “mefpart”
  2. Add reference to System.ComponentModel.Composition.dll (from bin directory of downloaded zip file)
  3. Rename Class1.cs to SimpleGreeting.cs
  4. Now replace contents of SimpleGreeting.cs with following snippet. Here we are implementing one of the extensible part
    using System.ComponentModel.Composition;

    namespace meflab1
    {
    [Export(typeof(IGreetings))]
    public class SimpleGreeting : IGreetings
    {
    [Import(typeof(IContextInfo))]
    public IContextInfo ContextInfo { get; set; }

    public string SayHello()
    {
    string userName;
    var props = ContextInfo.GetContextInfo();
    props.TryGetValue("UserName", out userName);
    return "Hello " + (userName ?? "<null>") + " from Visual Studio 2010";
    }
    }
    }
  5. Build it

Having this infrastructure let us do two exercises

  1. Run application without dependent assembly
  2. Run application without dependent assembly during start up but make it available before JIT compiling

Run application without dependent assembly

Now build first solution and try to run it.

  1. Open command prompt
  2. Navigate to output folder of first solution
  3. start mefpart.exe. Application will be waiting at “Enter 0 to quit, any other number to continue”
  4. Enter any non-zero value. We end up with following error
The composition produced a single composition error. The root cause is provided below.
Review the CompositionException.Errors property for more detailed inf
ormation.

1) No exports were found that match the constraint
'((exportDefinition.ContractName = "meflab1.IGreetings") && (exportDefinition.Metadata.ContainsKey("Expor
tTypeIdentity") && "meflab1.IGreetings".Equals(exportDefinition.Metadata.get_Item
("ExportTypeIdentity"))))'.

Resulting in: Cannot set import 'meflab1.Program.Greetings
(ContractName="meflab1.IGreetings")' on part 'meflab1.Program'.
Element: meflab1.Program.Greetings (ContractName="meflab1.IGreetings")
--> meflab1.Program

This is expected as we don’t have any library implementing IGreetings interface.

Run application without dependent assembly during start up but make it available before JIT compiling

  1. Open command prompt
  2. Navigate to output folder of first solution
  3. start mefpart.exe. Application will be waiting at “Enter 0 to quit, any other number to continue”
  4. Copy mefpart.dll from output directory of mefpart’s solution to output directory of meflab1. That is nothing but current directory of command prompt.
  5. Enter any non zero value
  6. Observe that application could seamlessly load part and execute code in it

So what didn’t work in part-1 works now. I will leave explanation of various sections of this code to next post, i.e. Part-3.

Managed Extensibility Framework - Part1

I wanted to make this post since last two weeks. For some reason it didn’t happen. Today I was asked by one of my colleagues so I couldn’t take another exception.

First let me introduce you what is officially told about this framework

“The Managed Extensibility Framework (MEF) is a new library in .NET that enables greater reuse of applications and components. Using MEF, .NET applications can make the shift from being statically compiled to dynamically composed. If you are building extensible applications, extensible frameworks and application extensions, then MEF is for you.”

So take that middle sentence “statically compiled to dynamically composed”. It is all about that.

Building reusable code into libraries and using them in applications is normal. In legacy Win32 applications if a library is linked to an application, linker used to add reference to that library in PE header. When runtime tries to load this application loader used to perform following operations

  1. resolve all dependencies
  2. load them into memory
  3. map them to respective pointers
  4. then start main routine

But with CLR, and JIT compilation in the middle, things are slightly different. Now loader tries to load those libraries which are needed to execute just the Main method. As other methods are called from Main, IL for those methods are JIT compiled on demand and loaded into memory. These things can be simplified with an example. [By the way, if you are thinking that I am going away from main subject of MEF; you are thinking correctly. But I am doing this internationally. Because I feel understanding about the problem that MEF is trying to solve makes you an informed user of MEF, so that you will be able clearly distinguish when and where MEF can be used. So I will keep this part of the series just for introduction.]

Now coming back to example. Let us start with a simple console application. Name it “WOMEF”. (without MEF.)

Replace the code in Program.cs with following snippet.

using System;
using WOMEFLib;

namespace WOMEF
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter 0 to quit, any other number to continue");
while (Console.ReadLine() != "0")
{
new Program().SayHelloToUser();
}
}

public void SayHelloToUser()
{
Console.WriteLine("In SayHelloToUser");
IWOMEFLib womeflib = new CWOMEFLib();
womeflib.SayHello(Environment.UserDomainName + Environment.UserName);
Console.ReadLine();
}
}
}
Let us define IWOMEFLib and CWOMEFLib in a library. So add a class library project to this solution by name “WOMEFLib”.

Rename Class1.cs to CWOMEFLib.cs. Then replace code with following snippet.


using System;
namespace WOMEFLib
{
public interface IWOMEFLib
{
int SayHello(string username);
}
public class CWOMEFLib : IWOMEFLib
{

#region IWOMEFLib Members

public int SayHello(string username)
{
Console.WriteLine("\"" + "Say Hello to " + username + "\"");
return 0;
}

#endregion
}
}
Now in WOMEF project add a project reference to WOMEFLib project. Change configuration to Release, build and test application.

So nothing great about this. But we are going to witness some interesting facts with these two assemblies.

  1. When loader loads CWOMEFLib.dll

  2. What happens if CWOMEFLib.dll is missing when application is starting

  3. When SayHelloToUser methods is JIT compiled

  4. What happens if CWOMEFLib.dll is copied to application directory while it is waiting for user input

In order to check these scenarios we are going to view method table and descriptors of application WOMEFLib.exe in runtime.

We are going to use Windbg here. If you don’t have it installed download it at link.

When loader loads CWOMEFLib.dll

Here we are going to check when loader loads CWOMEFLib.dll.

  1. Start Windbg.

  2. In Windbg, click on File –> Open executable

  3. Navigate to Release folder of solution and select WOMEF.exe

  4. Windbg stops with interrupt 3. Press F5 to continue.
  5. ntdll!DbgBreakPoint:
    7c90120e cc int 3


  6. Now application starts and waits for user entry with message “Enter 0 to quit, any other number to continue”

  7. In Windbg go to Debug menu and click on break. This is the ideal time to break into application as it is up and running.

  8. Now load sos.dll in windbg by entering following command in Windbg “.loadby sos.dll mscorwks”
  9. ntdll!DbgBreakPoint:
    7c90120e cc int 3
    Missing image name, possible paged-out or corrupt data.
    0:003> .loadby sos.dll mscorwks


  10. Now dumpdomains by entering command “!dumpdomain”

  11. 0:003> !dumpdomain
    *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\Microsoft.NET\... -
    PDB symbol for mscorwks.dll not loaded
    --------------------------------------
    System Domain: 7a3bd058
    LowFrequencyHeap: 7a3bd07c
    HighFrequencyHeap: 7a3bd0c8
    StubHeap: 7a3bd114
    Stage: OPEN
    Name: None
    --------------------------------------
    Shared Domain: 7a3bc9a8
    LowFrequencyHeap: 7a3bc9cc
    HighFrequencyHeap: 7a3bca18
    StubHeap: 7a3bca64
    Stage: OPEN
    Name: None
    Assembly: 001b0628
    --------------------------------------
    Domain 1: 0016d298
    LowFrequencyHeap: 0016d2bc
    HighFrequencyHeap: 0016d308
    StubHeap: 0016d354
    Stage: OPEN
    SecurityDescriptor: 0016e5c0
    Name: WOMEF.exe
    Assembly: 001b0628 [C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll]
    ClassLoader: 001b06a8
    SecurityDescriptor: 001ae190
    Module Name
    033e1000 C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll


    Assembly: 001b9800 [D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe]
    ClassLoader: 001b9e68
    SecurityDescriptor: 001b96c8
    Module Name
    00a72c5c D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe


    Assembly: 001bcb30 [D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEFLib.dll]
    ClassLoader: 001bbc98
    SecurityDescriptor: 001bcd28
    Module Name
    00a730c8 D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEFLib.dll

  12. As expected there are three app domains. In application specific appdomain three assemblies are loaded. First one (mscorlib.dll) is pretty standard one. Second one (WOMEF.exe) is application itself. And third one (WOMEFLib.dll) is referenced assembly.

  13. So loader loaded referenced assembly though we have not yet used any type from it so far. We are just at first line in Main method. Also we don’t use any type from WOMEF.dll in Main method. Still loader loaded this assembly because it is there in manifest. Now let us see what happens if this assembly is not available when we start WOMEF.exe. Kill application by pressing Control+C. If needed close Windbg and reopen.

What happens if CWOMEFLib.dll is missing when application is starting

Here we are going to check what happens if CWOMEFLib.dll is missing when application is starting. Move CWOMEFLib.dll from Release folder to some other folder outside solution directory (say to Desktop. Don’t copy cut it.)

  1. Start Windbg.

  2. In Windbg, click on File –> Open executable

  3. Navigate to Release folder of solution and select WOMEF.exe

  4. Windbg stops with interrupt 3. Press F5 to continue.
  5. ntdll!DbgBreakPoint:
    7c90120e cc int 3

  6. Now application starts and waits for user entry with message “Enter 0 to quit, any other number to continue”.

  7. Though one of the dependent assembly is not available application runs normally till this point. This makes an interesting point. Why loader didn’t complain that CWOMEFLib.dll is not available? Answer is SayHelloToUser is not yet JIT compiled. And we will verify this fact in next section. Kill application by pressing Control+C. If needed close Windbg and reopen.

When SayHelloToUser methods is JIT compiled

Here we are going to check when SayHelloToUser methods is actually JIT compiled. Move back CWOMEFLib.dll to Release folder.

  1. Start Windbg.

  2. In Windbg, click on File –> Open executable

  3. Navigate to Release folder of solution and select WOMEF.exe

  4. Windbg stops with interrupt 3. Press F5 to continue.
  5. ntdll!DbgBreakPoint:
    7c90120e cc int 3
  6. Now application starts and waits for user entry with message “Enter 0 to quit, any other number to continue”.

  7. In Windbg go to Debug menu and click on break. This is the ideal time to break into application as it is up and running.

  8. Now load sos.dll in windbg by entering following command in Windbg “.loadby sos.dll mscorwks”
  9. ntdll!DbgBreakPoint:
    7c90120e cc int 3
    Missing image name, possible paged-out or corrupt data.
    0:003> .loadby sos.dll mscorwks


  10. Now dumpdomains by entering command “!dumpdomain”

  11. 0:003> !dumpdomain
    *** ERROR: Symbol file could not be found. Defaulted to export symbols for C:\WINDOWS\Microsoft.NET\... -
    PDB symbol for mscorwks.dll not loaded
    --------------------------------------
    System Domain: 7a3bd058
    LowFrequencyHeap: 7a3bd07c
    HighFrequencyHeap: 7a3bd0c8
    StubHeap: 7a3bd114
    Stage: OPEN
    Name: None
    --------------------------------------
    Shared Domain: 7a3bc9a8
    LowFrequencyHeap: 7a3bc9cc
    HighFrequencyHeap: 7a3bca18
    StubHeap: 7a3bca64
    Stage: OPEN
    Name: None
    Assembly: 001b0628
    --------------------------------------
    Domain 1: 0016d298
    LowFrequencyHeap: 0016d2bc
    HighFrequencyHeap: 0016d308
    StubHeap: 0016d354
    Stage: OPEN
    SecurityDescriptor: 0016e5c0
    Name: WOMEF.exe
    Assembly: 001b0628 [C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll]
    ClassLoader: 001b06a8
    SecurityDescriptor: 001ae190
    Module Name
    033e1000 C:\WINDOWS\assembly\GAC_32\mscorlib\2.0.0.0__b77a5c561934e089\mscorlib.dll


    Assembly: 001b9800 [D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe]
    ClassLoader: 001b9e68
    SecurityDescriptor: 001b96c8
    Module Name
    00a72c5c D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe


    Assembly: 001bcb30 [D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEFLib.dll]
    ClassLoader: 001bbc98
    SecurityDescriptor: 001bcd28
    Module Name
    00a730c8 D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEFLib.dll

  12. Now we are just at first line of Main method. Let us get address if method table of assembly WOMEF.exe by using command !dumpmodule –mt <module address 00a72c5c>. See module address in red color.
  13. 0:003> !dumpmodule -mt 00a72c5c
    Name: D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe
    Attributes: PEFile
    Assembly: 001b9780
    LoaderHeap: 00000000
    TypeDefToMethodTableMap: 00a700c0
    TypeRefToMethodTableMap: 00a700cc
    MethodDefToDescMap: 00a70128
    FieldDefToDescMap: 00a70138
    MemberRefToDescMap: 00a7013c
    FileReferencesMap: 00a701a4
    AssemblyReferencesMap: 00a701a8
    MetaData start address: 004020c0 (1864 bytes)

    Types defined in this module

    MT TypeDef Name
    ------------------------------------------------------------------------------
    00a73010 0x02000002 WOMEF.Program

    Types referenced in this module

    MT TypeRef Name
    ------------------------------------------------------------------------------
    03650508 0x01000001 System.Object
    03654258 0x01000012 System.Console
    036508ec 0x01000013 System.String
    00a73484 0x01000016 WOMEFLib.IWOMEFLib


  14. Using method table address let us get module descriptions by using command !dumpmt –md <method table 00a73010>. See mt address in red color.
  15. 0:003> !dumpmt -md 00a73010
    EEClass: 00a712f4
    Module: 00a72c5c
    Name: WOMEF.Program
    mdToken: 02000002 (D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe)
    BaseSize: 0xc
    ComponentSize: 0x0
    Number of IFaces in IFaceMap: 0
    Slots in VTable: 7
    --------------------------------------
    MethodDesc Table
    Entry MethodDesc JIT Name
    035a6a70 03424934 PreJIT System.Object.ToString()
    035a6a90 0342493c PreJIT System.Object.Equals(System.Object)
    035a6b00 0342496c PreJIT System.Object.GetHashCode()
    036172f0 03424990 PreJIT System.Object.Finalize()
    00a7c019 00a73008 NONE WOMEF.Program..ctor()
    00de0070 00a72ff0 JIT WOMEF.Program.Main(System.String[])
    00a7c015 00a72ffc NONE WOMEF.Program.SayHelloToUser()

  16. Here observe the JIT status of SayHelloToUser method as NONE. Means that SayHelloToUser is not yet JIT compiled. Let us run the application by pressing F5 in Windbg and entering a non zero value in console. As soon as you enter a non-zero value in console CLR compiles SayHelloUser, loads it from with reference to SayHello method in WOMEFLib.dll. Now console waits for input because of ReadLine.

  17. Now let us break into debugger again by clicking on Break menu option of Debug menu in Windbg.

  18. Let us check status of method description again by using same command !dumpmt –md <method table 00a73010>. You can even use up arrow twice in windbg to get there.
  19. 0:003> !dumpmt -md 00a73010
    EEClass: 00a712f4
    Module: 00a72c5c
    Name: WOMEF.Program
    mdToken: 02000002 (D:\My Documents\Visual Studio 2008\Projects\MEF\WOMEF\WOMEF\bin\Release\WOMEF.exe)
    BaseSize: 0xc
    ComponentSize: 0x0
    Number of IFaces in IFaceMap: 0
    Slots in VTable: 7
    --------------------------------------
    MethodDesc Table
    Entry MethodDesc JIT Name
    035a6a70 03424934 PreJIT System.Object.ToString()
    035a6a90 0342493c PreJIT System.Object.Equals(System.Object)
    035a6b00 0342496c PreJIT System.Object.GetHashCode()
    036172f0 03424990 PreJIT System.Object.Finalize()
    00a7c019 00a73008 NONE WOMEF.Program..ctor()
    00de0070 00a72ff0 JIT WOMEF.Program.Main(System.String[])
    00de00d0 00a72ffc JIT WOMEF.Program.SayHelloToUser()


  20. Now observe status of SayHelloToUser method as JIT. This makes it clear that SayHelloToUser method would have never been JIT compiled if a zero is entered in console window as the first option. So when control goes inside while loop CLR started JIT compiling called method.

  21. Let us see a tricky case now. Assume that we wont make WOMEFLib.dll available to WOMEF.exe when WOMEF.exe is starting but we will copy this assembly while application is waiting for user input with message “Enter 0 to quit, any other number to continue” for the first time. Kill application by pressing Control+C. For this last case we don’t need windbg.

What happens if CWOMEFLib.dll is copied to application directory while it is waiting for user input

Here we are going to check what happens if CWOMEFLib.dll is copied to application directory while it is waiting for user input for the first time. Move CWOMEFLib.dll from Release folder to some other folder outside solution directory (say to Desktop. Don’t copy cut it.)
  1. Open command prompt

  2. Navigate to Release folder of solution and start WOMEF.exe

  3. Application starts and waits for user entry with message “Enter 0 to quit, any other number to continue”. At this point move back CWOMEFLib.dll to Release folder.

  4. Enter a non-zero value and press enter

  5. Now when application tries to compile SayHelloToUser, it tries to refer type CWOMEF in WOMEFLib.dll and fails to resolve assembly. It comes out with an exception

  6. Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'WOMEFLib, ..


  7. That means, even though the assembly is made available when it is actually being referred, loader ignores to reload.

  8. It is this particular aspect that MEF tries to solve.

Existing possibilities

OK with that background I hope you are clear on what MEF is trying to solve. But before looking at MEF let us see how we can solve this particular problem with existing technology. With CLR 2.0 we have an option of loading assembly in runtime. After loading assembly in runtime we can create objects of types defined in it and we can even invoke them using reflection techniques. This is quite straight forward. I will just provide a working sample. Do following changes to our solution
  1. In WOMEF project remove reference to WOMEFLib.dll.

  2. Then replace code in Program.cs with following snippet

  3. using System;
    using System.Reflection;
    namespace WOMEF
    {

    class Program
    {
    static void Main(string[] args)
    {
    Console.WriteLine("Enter 0 to quit, any other number to continue");
    while (Console.ReadLine() != "0")
    {
    new Program().SayHelloToUser();
    }
    }

    public void SayHelloToUser()
    {
    Console.WriteLine("In SayHelloToUser");
    InvokeMethod("WOMEFLib", "CWOMEFLib", "SayHello", new object[] { Environment.UserDomainName+Environment.UserName });
    Console.ReadLine();
    }

    public object InvokeMethod(string assemblyName, string className, string methodName, object[] parameters)
    {
    System.Type[] parametersTypes;
    int parametersCount = 0;
    object returnObject = null;
    try
    {
    Type type = System.Reflection.Assembly.LoadFrom(assemblyName + ".dll").GetType(
    assemblyName + "." + className);

    parametersTypes = new System.Type[parameters.GetUpperBound(0) + 1];

    foreach (object parameter in parameters)
    {
    if (parameter != null)
    parametersTypes[parametersCount] = parameter.GetType();
    parametersCount++;
    }

    MethodInfo mi = type.GetMethod(methodName, parametersTypes);
    ConstructorInfo ci = type.GetConstructor(Type.EmptyTypes);
    object objectinstance = ci.Invoke(null);
    //Invoke
    returnObject = mi.Invoke(objectinstance, parameters);
    }
    catch (TargetException tex)
    {
    throw tex;
    }

    return returnObject;
    }
    }
    }

  4. Here Invoke method loads assembly (WOMEFLib) in runtime, constructs class object (CWOMEFLib) and invokes a method (SayHello) in it.

In next post we will see how MEF framework not only simplifies this process but also provides many more useful options for tihis kind of scenarios.

Saturday, June 13, 2009

Integrating Real time communication tools with real time systems

There is an excellent video on how Wonderware integrated Office Communication framework around Application Server.

Kind of integration they achieved is remarkable. Watch video at link below to have glimpse on how it is done. It is quite evident from this video that social collaboration infrastructures when integrated with real-time systems bring lot of value proposition to plant floor. As dependency on various communication means (like mobile phones, messengers, micro blogging) is increasing to achieve a task, clean and neat integration among these tools brings feature richness to solution offering.

We tend to record events and alarms from the system. We even archive them for many years. Most this information is captured out of systems. But with each event, humans operating systems share and discuss lot of information. Interleaving conversations with system generated events makes up a wealth of information. Further this information can be fed to data mining systems to bring out lot of interesting facts which can be used for improvements, optimizations etc.

This video is from Channel9.

Wonderware: Synchronizing Production, Industrial Operations and Business Objectives

Participants:

Rob McGreevy, Dir. Industry Solutions, Wonderware
Paul Forney, Chief Solutions Architect, Wonderware

Charles Torre, Senior Technical Evangelist at Microsoft

Thursday, June 11, 2009

Regular expressions interleave

Today we had requirement to write regex for domain users and machines. While doing this I expected some scope for succinctness in expression. First I will start with the expression I wrote then I will to succinctness part.

=====================

Regular expression to match hostnames in intranet scenario.

Here requirements are

1) Machine names can contain letter, numbers, underscore or hyphen

2) Names should not start or end with underscore or hyphen

3) labels are tld part follow machine name with an ‘.’ in between.

4) Further on labels may follow same format as machine name.

5) Every label follows with a dot

6) tld is just com

^[A-Za-z0-9][A-Za-z0-9-_]+[A-Za-z0-9].([A-Za-z0-9][A-Za-z0-9-_]+[A-Za-z0-9].){1,3}(comCOM){1}$

Here the special requirement is have a configurable number of labels.

With a minor change similar expression can be used to match Fully Qualified Domain Name for usernames and email addresses also.

^[A-Za-z0-9][A-Za-z0-9-_]+.[A-Za-z0-9-_]+[A-Za-z0-9]@([A-Za-z0-9][A-Za-z0-9-_]+[A-Za-z0-9].){1,3}(comCOM){1}$

Now coming to little bit of explanation.

^ : start of the string; [A-Za-z0-9] : must start with a character or numeric avoid hyphen or underscore; and rest of the expression is self explanatory.

=====================

With that I am curious to know about possible ways of writing expressions with interleave characters with specifiable multiplicity.

I know that is very confusing statement. Sorry I am very poor in expressing in short and crisp sentence.

What I mean here is these expressions can be looked at as

<character set>.<character set>@<character set>.<com>. Here dot and @ are mere interleaves for character sets. They hold restrictions like they can not placed at beginning and ending of character sets. That mean they are always interleaved.

Now I am want know possible means of specifying such interleaves with a language syntax. Also I should be able to specify multiply within a definable part of expression. For example I can allow only 1 dot before @ and that must be interleaved within valid character sets.

So I wish to express this expression as ^[A-Za-z]<interleave([0-9]+[.])>@([A-Za-z]<interleave([0-9]+)>.) {1,3}(comCOM){1}$

Requesting gurus of regular expressions to help me in case such a feature is available ?

Thursday, June 04, 2009

Google Wave – waawhhh

It is just more than five years since google started email service. I using it from those early days.

But from what I understood from upcoming “Google Wave” its is going to redefine the way that we will be looking at all those online services like mail, chat, blog, album, video share, microblog, shared documents etc…

Based on federation services as defined by google as www.waveprotocol.org this is going to create a revolution.

Here are few options that I am just dying to try once I get access

a) replay options

b) model based context oriented spell check

c) collaborative document with diff marks

d) and cool picture drop down (I don’t mind using bits from gears till html 5 makes the feature default in browsers)

e) kind of live transfer letter by letter. I just can’t image how that would show up in low bandwidth networks

f) Inline reply

g) kind of editing features

what else to mention, each and every feature demonstrated there.

Just can’t wait any longer…..

Monday, June 01, 2009

Bing is up and ready

New Microsoft search engine Bing is up and running. It is decision search engine. Check it out. Performance is just like Google. Yet Yet to check on relevance of content. I searched my name and found similar results as Google search. I am going to use this as primary search engine for next few days

image

ASP.Net AjaxControl Toolkit update

This is quite late information but could be useful. ASP.Net Ajax control toolkit is updated with three new controls.

Now we don’t need to depend on FreeTextBox kind of controls for Html WYSIWYG (What-You-See-Is-What-You-Get) editors.

Then an extender on textbox can get windows like combo box with advanced options like enter and append to filter etc.

Then we get a built-in color picker. Personally I am no so impressed with this, but it is now available. Find link here

AJAX Control Toolkit (May 2009 Release)