Welcome to EMC Consulting Blogs Sign in | Join | Help

Rory Street's EMC Consulting Blog (2004 - 2011)

This blog has now moved to http://rory.streetfamily.info - please update your subscriptions if you wish to receive new content.

  • Configuration by Convention with XAML

    Yes I know the above probably doesn’t make much sense when first read. But the truth is that in any convention based system, there is going to be some configuration, we can’t avoid it completely.

    I’ve been working with using XAML as a configuration method in a convention based application where we had the requirement to pull in some details about where the from line in emails would come from.

    Why use XAML? XAML enables us to control the structure of our configuration easily and it also gives us intellisense. If you’ve ever tried creating custom configuration sections for the web.config and and app.config files you’ll see where I am coming from here.

    As part of my investigation into the problem I came across this really cool article on The Code Project called Using XAML for Custom Application Configuration which I used as part of my solution. The article goes into detail about XAML configuration in your application all I did was slightly adapt how I used what is here so it may be worth you reading this first to familiarise yourself with XAML configuration.

    So how does it work?

    As we were using dependency injection in our application I decided to inject my configuration into my classes. In this case by configuration class is based on the interface IBaseConfiguration.

       1:  namespace TestApplication
       2:  {
       3:      public class EmailManagement : IEmailManagement
       4:      {
       5:          private readonly IBaseConfiguration _configuration;
       6:   
       7:          public MyTestClass(IBaseConfiguration configuration)
       8:          {
       9:              _configuration = configuration;
      10:          }
      11:   
      12:          public void SendEmailToCustomer()
      13:          {
      14:              var emailSettings = this._configuration.GetConfiguration<ReplyEmailSettings>();
      15:              
      16:              var message = new MailMessage();
      17:   
      18:              message.From = new MailAddress(emailSettings.EmailAddress, emailSettings.Name);
      19:              
      20:              ...
      21:              ....    
      22:          }
      23:      }
      24:  }

    The main line to pay attention to above is line 14. See how I’ve used a generic to tell my configuration method I want the settings for the XAML configuration based on ReplyEmailSettings? Now lets take a look at the actual configuration class.

       1:  namespace TestApplication.Configuration
       2:  {
       3:      public class ConfigurationBase : IBaseConfiguration
       4:      {
       5:          /// <summary>
       6:          /// Get a configuration. 
       7:          /// </summary>
       8:          /// <typeparam name="T">Type we want returned
       9:          /// </typeparam>
      10:          /// <returns>
      11:          /// A populated type 
      12:          /// </returns>
      13:          public T GetConfiguration<T>()
      14:          {
      15:              Type itemType = typeof(T);
      16:              var pathbuilder = new StringBuilder();
      17:   
      18:              pathbuilder.Append("../../configuration/");
      19:              pathbuilder.Append(itemType.Name);
      20:              pathbuilder.Append(".xaml");
      21:   
      22:              using (FileStream xamlStream = File.OpenRead(pathbuilder.ToString()))
      23:              {
      24:                  return (T)System.Windows.Markup.XamlReader.Load(xamlStream);
      25:              }
      26:          }
      27:      }
      28:  }

    As you can see in the configuration class above what I have done is incredibly simple. My configuration class assumes that all configurations are stored within a configuration folder in my application. It also assumes that I am going to name my XAML configuration files the same as the class I use to represent them (line 19). So my configuration method goes and looks for my XAML file and returns its configuration for me in line 22 and 24.

    I really like how this has worked out. It gets around the issue of having to separately store the location of your configuration files in yet another configuration file or hard coding them into your application.

    I’ve included the XAML configuration file and its accompanying class for reference below.

    The ReplyEmailSettings.XAML file

       1:  <Entities:ReplyEmailSettings xmlns="clr-namespace:XamlConfig;assembly=XamlConfig"
       2:       xmlns:col="clr-namespace:System.Collections;assembly=mscorlib"
       3:       xmlns:Entities="clr-namespace:TestApplication.Configuration.Entities;assembly=TestApplication.Configuration"
       4:                       
       5:                               EmailAddress="test@test.com"
       6:                               Name="The name of the email from"
       7:                               SubjectLine="The subject line"
       8:                               >
       9:   
      10:      
      11:      
      12:  </Entities:ReplyEmailSettings>

    The ReplyEmailSettings class the above XAML file is based on.

       1:   
       2:  namespace TestApplication.Configuration.Entities
       3:  {
       4:      public class ReplyEmailSettings
       5:      {
       6:          public string Name { get; set; }
       7:   
       8:          public string EmailAddress { get; set; }
       9:   
      10:          public string SubjectLine { get; set; }
      11:   
      12:      }
      13:  }
    * Apologies for the formatting of this blog article. The new blog styles appear to have destroyed my code view plug-in. 
    Posted 21 July 2010 09:38 by rory.street | 0 Comments
    Filed under:
  • Java and .NET talking to each other

    One thing I can say about my 10 years working at EMC Consulting (previously Conchango), its never been dull and there has always been something interesting or unusual thrown into the mix of things so you don’t do the same old tasks all the time. One such task has been coding a solution with a .NET GUI, based on Java API’s that talks to a Unix system. Now I’ve always considered myself more a C# .NET person but to be honest when it comes to the requirements of a project I am not too bothered as long as the solution is good and picking up another programming language is always a bonus! (Thanks to two of our Java guru’s Gavyn Dowst and Lee Ervine for being so patient with me when I asked them Java questions every day!)

    Anyway back to the task at hand. I had the requirement to communicate with a Java API from a .NET application and was pointed in the direction of JNBridge by my colleague James Rowland-Jones (the picture on his blog is a testament to the great Photoshop skills of the platform architect on our previous project). JNBridge enables .NET to use Java components and Java to use .NET components by the creation of proxy objects.

    The best way for me to explain it I suppose is to demonstrate how easy it is to use with a rather simple example.

    1. Lets start by creating a simple Java app that we will call from our .NET application.

    MyJavaTest.java

    package JavaTestPackage;

    public class MyJavaTest
    {
        public int AddNumbers(int firstNumber, int secondNumber)
        {
            int answer = firstNumber + secondNumber;
            return answer;
        }
    }

    2. Compile the application (you will need to install the java JDK)

    javac MyJavaTest.java

    3. Download JnBridge Pro (evaluation version) install it and start up jnbproxyGUI.exe (you will need to run this as an Administrator)

    4. When prompted select the option .NET –> Java

    5. In the GUI that appears select the project menu and select Edit Class Path
    jnbridge1

    In here click add and enter the path to where you compiled your MyJavaTest.class. After you are done click OK

    6. Once again go to the Project menu and select “Add Classes from Classpath...”
    jnbridgealt  
    Type in the name of the class you have just created “JavaTestPackage.MyJavaTest” and click Add and then click OK.

    7. Once JNBridge is finished click and select the your package in the left hand folder structure “JavaTestPackage” and click Add. 
    jnbridgealt2

    8. Go to the project menu and select Build. You will be given an option to select a name for your DLL here. I have selected MyJavaTest.DLL

    9. Fire up Visual Studio and create a new Console Application and add a references to MyJavaTest.DLL, JNBShare.DLL and JNBSharedMem.DLL
    NetJNBridge1

    You will find the JNB DLL’s in the programs file directory where JNBridge is installed.

    10. Add the MyJavaTest.class file to your project. You can add this as a JAR file or inside its JavaTestPackage folder.

    11. Add an App.Config file to your project and add the following to it.

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <configSections>

            <sectionGroup name="jnbridge">
                <!-- comment out the following sections if using .NET 1.0 or 1.1, uncomment if using .NET 2.0 -->
                <section name="dotNetToJavaConfig"
                              type="System.Configuration.SingleTagSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <section name="javaToDotNetConfig"
                              type="System.Configuration.SingleTagSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <section name="tcpNoDelay"
                              type="System.Configuration.SingleTagSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
                <section name="javaSideDeclarations"
                              type="System.Configuration.NameValueSectionHandler, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
            </sectionGroup>
        </configSections>
        <jnbridge>
            <!-- <dotNetToJavaConfig scheme="jtcp" host="localhost" port="8085"></dotNetToJavaConfig>-->
            <!-- Edit the following config sections and replace the attribute values with values germane to your system-->
            <dotNetToJavaConfig scheme="sharedmem"
                                jvm="C:\Program Files\Java\j2re1.4.2_15\bin\client\jvm.dll"
                                jnbcore="C:\Program Files\JNBridge\JNBridgePro v4.1\jnbcore\jnbcore.jar"
                                bcel="C:\Program Files\JNBridge\JNBridgePro v4.1\jnbcore\bcel-5.1-jnbridge.jar"
                                classpath="C:\Users\rory.street\Documents\Visual Studio 2008\Projects\TestFromNET\TestFromNET\JavaTestPackage"/>

        </jnbridge>
    </configuration>

    Please note that a sample of this file is available with the JNBridge install called JNBProxy_sharedmem.config. The important parts that will need changing for your machine is dotNetToJavaConfig, over here you will need to change the paths to where these items are installed on your machine. In the above case the Java Virtual Machine, JNBridge and where the Java Class is (MyJavaTest.class) we just created a proxy for.

    12. Now we can write some C# .NET code.

    namespace TestFromNET
    {
        class Program
        {
            static void Main(string[] args)
            {
                MyJavaTest test = new MyJavaTest();

                Console.WriteLine( test.AddNumbers(9, 8));

                Console.ReadLine();
            }
        }
    }

    As you can see the code is incredibly simple. We are calling our proxy class and using it to add two numbers together. The results are passed back from our Java class to our .NET C# application.

    testnetresult

    A few things to note. When dealing with more complex interop between Java and C# you will need to make use of the proxy’ed java.lang library when getting Java types back (this is where it pays to get to know a bit more Java!). When dealing with events you will need to implement what are known as “CallBacks” in your .NET code, more details on these can be found on the JNBridge blog

  • Twitter rescuing customer service

    Having recently moved home, one of the things I went to great pains to ensure was setup correctly at my new home was broadband. Being an IT consultant and my wife running a home based business has made broadband essential for both of us. Sadly on the day broadband should have gone live at my new home nothing happened and I ended up having to call BT to find what had gone wrong. Eventually getting through to a call centre in India I was told that my account had been incorrectly setup and that they would put me through to a team that could handle this. This team then put me back to another team in India who then put me back to a smaller team in the UK who seemed to know everything that was going on.  Apparently my line had a “marker” on it, a term I had only discovered on that day - basically meaning the previous broadband provider still had control of the line. I was told they would take care of it for me and to leave it a day. A day came and I heard nothing from BT so I decided to phone them in the afternoon. I was informed that the tag had been removed from my line and that I could order broadband from them now, however I would have to wait another 5 days for them to activate it! Annoyed by the whole event I vented my frustration on Twitter where I was DM’d by @BTCare asking me how they could help.  My initial reaction was surprise “BT are on on Twitter?”, I told them the issue I had and they asked for my account details they then told me they would get my account activation brought forward for me to the next day – what a result!

    This really got me thinking. BT is a large organisation with many different departments and getting them all working together from a customer satisfaction point of view must be quite a challenge. Things are bound to go wrong and people will vent their frustration when it does go wrong, the important thing I see happening here is finding out what is going wrong. Twitter is quite a good place to start to gather this information and then to try and correct the problem now that someone in the organisation has the big picture of what didn’t work for the customer. Doing some searches on Google I discovered BT isn’t the only large company using Twitter to help with customer service many others are also at it. CRM systems are now incorporating “Service cloud plug-ins” to help find disgruntled customers, correct the issues and help and hopefully learn from the mistakes made. These plug-ins don’t just cover Twitter they can encompass other networks/services such as Google and Facebook. One of the most popular systems appears to be COtweet (currently in Beta and free to use for now) who have built a business around using Twitter as a “social CRM system” and boasts some well known brands on their website. It appears even big players such as Microsoft are entering the Twitter CRM arena by tying Dynamics CRM to Twitter. I find it interesting how Twitter has started to become more than just a social communicating tool, it has also started to become a platform for companies to build their services on in the same way Facebook opened its API to the public for developers to create applications. How Twitter will make money from this is still quite unclear and if you Google that question all you find are remarks of a planned revenue model targeting businesses. We may find in future that for an organisation to not be on Twitter is considered almost as bad as not having a website.

  • Google Chrome OS cometh

    It has long been speculated that Google may have been working on their own operating system and finally the speculation is over - Google are to launch a new web based OS called Google Chrome OS. My first thoughts when seeing the headline was pretty much the same thoughts I had when people were speculating about a possible OS venture by Google “Its probably a version of Linux”. Surprisingly and much to my delight its not based on any operating system at all its going to be built from the ground up.

    Personally I full heartedly welcome the introduction of a new OS to the Operating System arena especially one by the likes of Google. I think another OS adds more options and more options can only be good for the consumer. It keeps all the other OS vendors on their toes and forces them to make their OS’s better and more reliable and by other OS vendors of course  I am referring to Microsoft, Apple and Linux. Google has the corporate muscle to push an operating system to market that will get it taken seriously.

    Now its all very well having a new Operating System but its pretty much useless without software. A brand new operating system is going to need applications pretty fast to catch up with the likes of the other OS vendors out there who have thousands (probably millions) of applications already. I would have it as a guess that Google would first push its browser which would then support its other web based applications such as Google Docs, Google Spreadsheet and Google Wave. Maybe the browser will be an integral part of the OS with heavy usage of Google Gears? Google are also going to want the likes of Adobe Flash on their OS, otherwise content from the likes of Google’s company YouTube would not work on their OS along with other popular web apps. One of my questions is, just how far will Google venture into the OS market? Will we see Google for workgroups or possibly a Google OS appliance server as we do with their search appliance?

    Posted 08 July 2009 19:28 by rory.street | 0 Comments
    Filed under:
  • The PC is dead long live the NC (in the cloud)

    Cast your mind back to 1995 when the chairman of Oracle, Larry Ellison stated “The personal computer is a ridiculous device”, later followed by “It's too hard to use, too powerful, too costly...” Larry Ellison was off course championing what he thought was the PC’s replacement the NC or Network Computer. The idea behind the NC was not a bad one, everything was stored on centrally held servers (on the Internet) where you didn’t have to worry about how it was going to be backed up and you could access your information from any NC device no matter where you were in the world. The problem was his idea was probably 14 years to early and since then the PC has become slim lined and very cheap.

    Today we store a lot of our information online (or dare I call it the cloud?). As consumers we store our photos on flikr, backup up our files using BT Digital Vault and Microsoft’s SkyDrive, we download and store our music on the Internet, we watch TV and films over the Internet and we log into our PC’s or servers at home using programs such as GoToMyPC. Without realising it PC’s started to fulfil the role of Network Computers with the advent of faster broadband connections. But it is not just PC’s that get to play in this new interactive world there are a multitude of devices that access the Internet daily such as Smart Mobile phones, games consoles, set top boxes and even common house hold appliances.

    As things are going it appears more and more of the things we do on our computers will be hosted online. The companies providing us with these services will need to scale to meet these demands and to help them meet these demands, is my favourite buzz word of the year “the cloud”. As a consumer I am not too worried about where my data is stored or where my services are provided from as long as it is secure and I can get to my data. One of the biggest problems for services and goods companies is the age old problem of anticipating demand. If I overspend on my infrastructure to supply demand I have costs I will find harder to recoup because demand was not as high as I anticipated. Demand will not always be consistent and so as a company I would like to have the resources on tap I can pay for when I need them instantly, without having to fork out for large infrastructure I will only use intermittently.

    Eventually if (and this is a big if) cloud computing takes off in a big way we may find that we no longer need the benefits of a powerful PC. Soon the very desktops we use could be stored in a “Cloud Computing Container”. No longer would we need to worry about upgrades to our operating systems, performance or the software we use - all of this would be taken care of for us. All we would need to access our desktops is a simple Internet enabled computer or dare I say Network Computer?

    Posted 03 July 2009 11:29 by rory.street | 5 Comments
    Filed under:
  • “The Authentication Service is Unknown” error after hard disk switch

    A few days ago my Dell Latitude D830 suddenly died on me and would not turn itself back on. The IT department removed my hard disk and placed it inside a new D830. All seemed to work perfectly until I rebooted and started to get the above error. I was unable to connect to the network, certain programs wouldn't work and I wasn't even able to look at the event log to see what was wrong!

    So taking out my personal laptop I Googled the error and came up with some rather interesting results. It appears that when Vista starts up, if any of the programs hang or fail it can lead to some pretty strange behaviour. The first error I received was the "People near me service has failed. A system call that should never fail has failed". It appears the culprit was the winsock service and the fastest way to solve the problem was to open a command line window as Administrator and use the following command.

    Netsh winsock reset

    Reboot your machine and like magic, the problem is solved.

    You can find more about the problem here http://social.technet.microsoft.com/Forums/en-US/itprovistasecurity/thread/f4ce24aa-ae9d-4927-8b0f-52f3ddc4fbd9

  • Beware Temporary Projects in VS2008

    Last week I happily started a project in Visual Studio 2008 and made some good progress in getting my code ready. What I hadn't realised was Visual Studio started this project in Temporary Project mode. It's a useful feature if like me you need to quickly try out a few ideas on a quick application. The only problem with Temporary Projects is what seems to happen to them when your machine crashes (a rare occurrence but it happens).

    As you guessed my machine crashed after I had tried to start it up after putting it in hibernation mode. When I went back to Visual Studio I couldn't find any trace of my projects in its history and searched my hard disk for the project which was mysteriously gone. Doing some BING-ing (yes I have started using Microsoft's new search engine) I found the location for Temporary Projects, which is:

    C:\Users\<your username>\AppData\Local\Temporary Projects

    Opening this folder I was horrified to discover it was empty, where had my project gone? My only theory on the matter was that temporary projects ask you if you want to save them when you close Visual Studio. Because Visual Studio had effectively been terminated when my machine crashed I am guessing when I started up Visual Studio again when my machine rebooted it must have deleted what was in the Temporary Projects folder. I'd love to know if this is the case, anyway to cut a long story short there is a feature in Vista I have never used until today called "Restore previous versions". To restore a previous version of a folder right click on the folder and select this option. You can then select which version of the folder you wish to recover –great! What a life saver that was!

  • Updating an MS Ajax Update Panel with JavaScript

    This entry is more for my own future reference. If you need to update an MS Ajax update panel client side, use the following syntax in your JavaScript.

    __doPostBack('myUpdatePanel', '')

    Where 'myUpdatePanel' is the ID of your update panel. You can read more on this from Dave Wards blog.

  • My first look at Google Chrome

    Finally I had the opportunity to give Google's new web browser Google Chrome a test drive. Google Chrome installs in under 3 minutes which is pretty impressive! Launching Google Chrome is also pretty fast it's pretty much instant in launching when compared to Firefox 3 which pauses for a bit. Below is a table of memory usage on first load for each browser using Google as their home page.

    Browser

    Memory Used

    IE 7

    12,276 K

    Google Chrome

    19,184 K

    Firefox 3

    44, 376 K


    Google Chromes memory usage appears similar to Internet Explorer. Loading pages is almost instant with Google Chrome while there appears to be the slightest of hiccups with Firefox, Internet Explorer appears to be the slowest (on my machine) when loading web pages. I am not sure if Google Chrome loads pages in a clever way that make them appear almost instant, whatever it does its pretty smooth.

    So what features do you get with Google Chrome? Well on first inspection Google Chrome is incredibly light weight it reminds you of the earlier versions of Firefox. Hidden away in the interface is tabbing, book marking and a developer menu. One thing I couldn't find though was the Google Toolbar! Oh well maybe its planned for a future release? Typing URL's into the search bar kicks in an intelligent Google Suggest type interface for the closest match to what you are typing. Right click on any element on the page reveals a context menu with an "Inspect element" option which opens up a new window with an HTML element and resource inspector. The inspector also enables you to view a graph of how long items took to download and their size, however I was unable to get this to work.

    Over all I really like Google Chrome I am not entirely sure what it uses under the covers they have mentioned using components from Mozilla Firefox and Apples Webkit. Whatever they have used the experience for me so far has been good.

  • Rename Outlook 2007 folders

    I recently had a strange issue with my Outlook inbox being renamed to that of a document I had just emailed from Word. I wasn't able to rename the folder and discovered the only solution was to start up Outlook with the following command line.

    "C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" /resetfoldernames

    This set all of my system folders in Outlook back to their default names.

Powered by Community Server (Personal Edition), by Telligent Systems