Archive

Posts Tagged ‘RemoteX’

Working at the right level of abstraction

May 25th, 2010 2 comments

At RemoteX we have been a bit unhappy with the code produced to create our REST-service using WCF.

The problem is that you have these contracts that you specify. These contracts then build up a web-service end-point using the WebGet and similar attributes, to create a REST-style endpoint. The contracts however often look like a SOAP contract, or an interface wrapping behavior. A typical contract often includes the following operations for a specific type of document:

  • Get Single (web get on href entity-type/id)
  • Get List (web get on href: entity-type)
  • Get List with modified since (entity-type with query-string)
  • and so on

The trouble is the URI’s. A single contract often specifies several endpoint’s and several behaviors. There is no Single-responsibility principal at work, or rather the single responsibility might be that a contract handles a specific entity. End result, a lot of code for simple things and a REST-service that is unnecessary hard to extend.

This setup also makes it tricky to see the structure of the REST-service, the URI’s are spread out in the code contracts, forcing you to look at each method to figure out the different URIs.

After working with Grails and Django, and finally when I read the documentation for the Kayak web server. I realized what we were doing wrong. A reference in the Kayak documentation was the wakeup call:

The server component is an intuitive, unobtrusive, no-gimmicks implementation of HTTP, and the framework simply maps HTTP transactions to C# method invocations with minimal syntax and configuration.

We’re not working on entities as an abstraction, we’re building a REST-based service. Our level of abstraction needs to be HTTP.

So I discussed this with a colleague Johan, the day after. After a while Johan set to work on a piece of the REST-server that needed rewriting and after a week of TDDing. He came back with this wonderful piece of infrastructure, that worked along side the “old style” infrastructure.

The idea is that we have one contract. This contract has 4 methods:

  • Get
  • Put
  • Post
  • Delete

Essentially all the methods we want to implement. We then have a route configuration, similar to that of Grails or Django. That routes requests to Controllers that will take care of them.

Johan set things up so there is a single server, that looks at the route-configuration when a request arrives and executes a command on the controller object. The controller object doesn’t have to add methods for the operations doesn’t support. In fact, the controller object is a plain POCO with no inheritance or interface on it. As long as it has a method that matches the operation it will be called.

Serialization is handled in the framework and by following conventions when writing the controller you can take different input automatically processed by the infrastructure.

Lets see an example:

public class LogController
{ 

    readonly DataContextFactory<RMXAppsDataContext> _contextFactory;  

    public LogController(DataContextFactory<RMXAppsDataContext> contextFactory)        {
        _contextFactory = contextFactory;   

    }

    public void Post(LogEntry entry, IIdentity user)
    {  

        PostMessage( user, entry.Message );
    }

        public void PostMessage( IIdentity user, string href, string entry )
    {            using (var context = _contextFactory.CreateContext())
        {                var dbUser = context.GetTable<User>().Where(u => u.UserName == user.Name).FirstOrDefault();
            var dbEntry = new Applications.Data.LogEntry                    {
                    Message = entry,                        Date = DateTime.UtcNow,
                    User1 = dbUser                    };
            context.GetTable<Applications.Data.LogEntry>().InsertOnSubmit(dbEntry);                context.SubmitChanges();
        }        }         [return: Xml]
    public Log Get()        {
        Collection<LogEntry> entries;
        using (var context = _contextFactory.CreateContext())

        {                var e = (from l in context.GetTable<Applications.Data.LogEntry>()

                    orderby l.Date descending
                    select Mapper.Map<Applications.Data.LogEntry, LogEntry>( l )).Take( 50 );

                      entries = new Collection<LogEntry>(new List<LogEntry>(e));
        }            return new Log { Href = "log/", LogEntries = entries };
    }}

It’s not the prettiest of examples (and I apologize if the code doesn’t look that great).

What your looking at is a simple log controller. It handles the log/ endpoint. The endpoint has a Get and a Post operation. Post is used to add LogEntries, and Get gives the latest 50 entries.

You will notice that the Get operation is marked with [return: Xml] this means that the operation will serialize the return value using XML.

The Post operation takes two inputs. LogEntry and a IIdentity. Both these parameters are set by conventions.

IIdentity is the user, as authenticated by the login-module, the infrastructue simply gives the user to any IIdentity parameter in a web-method.

The LogEntry is the deserialized body of the request. The infrastructure looks at any parameter that doesn’t fit a convention, checks if its serializeable and if the body of the request can be deserialized into such an object.

Now a route configuration is another object, that specifies which urls which controllers are registered too. These structures are set up using Castle, and loaded from any assembly in the web directory. Allowing us to extend the REST-service by dropping in assemblies that implement our structure.

Since this was added the development of the REST-service has really taken off. We add roughly one-two endpoints per week, designed to solve specific pains and give views of the domain specific to the task at hand.

By working at the HTTP level of abstraction instead of the contract abstraction, we have reduced the cost for extending the rest-service tremendously. Even better is that the controllers are easy to test, the code displays its intent clearly, and you can see what each specific Uri in the REST-service does.

Special thanks to Johan, great work!

Tags: ,

Measuring defects

May 3rd, 2010 2 comments

I was working on performance tuning for the mobile client of RemoteX Applications when I found a tool called EQATEC Analytics. Six month later I added it to our clients for the first time.

EQATEC Analytics is quite interesting, for RemoteX it solves an interesting issue. Error reports are hard to collect from Compact Framework devices, especially since all error messages state that “we’re missing the translation pack to translate these errors, thus you get this crappy errors message instead”.

EQATEC Analytics captures all unhandled exceptions and report them back to a server application for analysis. This means that all crashes are reported so they can be analyzed by us, without involving the user in the information collection process. (no personal information is sent to the server)

The benefits of this enormous. We can see the quality trends of our applications (at least when it comes to crashes), and fix the errors that occur the most.

Traditionally the errors are fixed based on the information received by customers, manual error reports and what not. Relying on this type of information means that you fix the errors that most people report, or the errors you can reproduce. With EQATEC Analytics you, you can get an exact stack trace indicating the problem area, and depending on how you configure it to work you can also request information regarding what was happening during the crash.,

It also provides an excellent way to see if our efforts of improving the quality of the product is helping or not.

Now it also has features to collect information about what kind of system our applications are run on, and also collect statistics of which features are used in the applications.

We’ve used EQATEC Analytics in production since January 2010 and so far we are very happy with the results.

An interesting note here is that the next version of Shuffle will use a similar tool for Android, called Flurry.

Inheritance of features

January 14th, 2010 2 comments

Given my recent combining of Tracks and Shuffle. An interesting thing happened. Something that happens when you combine two products so that they inherit features from each other.

On Shuffle’s issue list there are a few items currently regarding repeating tasks, and the ability to hide a task for a period of time. Tracks has these features, since Shuffle can synchronize with Tracks, Shuffle now also have these features. That is if you choose to synchronize with Tracks.

I’ve done a few integration projects thus far. And the ones that are truly successful are when they take the aspects and features of both applications into consideration, to create a win-win scenario between the two applications.

Here is another recent example. At RemoteX, we recently integrated a system that handles the ordering of materials, goods, equipment etc. In essence this integration feature means that you can go to a retailer, order goods, specify the order they should tag the invoice with. End result, RemoteX automatically adds the goods to the application and if possible attaches a copy of the invoice to the case. Ready to be billed to the customer. Since the other system has integrated with almost all resellers of service equipment in Sweden, the daring customers running this set-up can, at least in theory, eliminates the need for keeping stocks of equipment or goods in house.

If you understand where these synergy effects can show up you can also align the integration so that both applications maximizes the gain of integrating with the other system. This is important to think of when designing an integration, how do we achieve the maximum win-win?

Testing level + 1

November 30th, 2009 No comments

I learned a new way to test objects the other day.

We had a consultant over to talk about a TDD course he will be holding for RemoteX internally. During the discussion the suggestion to test an object by mocking the object itself came up.

What you do is, you use Rhino mocks (or similar) to create a partial mock of the object under test. What you override is the methods that will result in external communication.

This requires you to put all communication code in a single method, which you then override using the partial mock. The test then becomes, is the method for external communication called.

This reduces the amount of mocking code needed for more coupled objects, and also reduces the “IoC container for testability” need. Allowing the IoC focus to be focused on interchangeable parts.

Tags: ,

Functional TagEditor

November 29th, 2009 No comments

I notice now that I cannot use the tag editor I’ve created from RemoteX Applications on my personal laptop. In requires a larger screen than what I have.

Anyway, this is a working version of the design I showed to mock-up earlier

image

Each row has a sub-class handling each option in the drop down (Strategy pattern). Selecting an option changes the available controls for editing the tag.

Tags: ,

Target acquired

November 26th, 2009 No comments

I ran into a designers block while working on a new feature for the online configuration editor for RemoteX Applications. (notice the name change?)

An interesting observation was that the risk for the design has shifted. In previous features I started with QUnit and the highest risk part, isolated it, TDD:ed it and got it working. I work with the same tactic now, but the issues have moved to different parts of the view.

Now the complexity is in the editing fields all of a sudden. Forcing me to start my testing on those components.

To unblock my designers block I used Balsamiq Mocks to draw up a UI. I hade a vague idea to begin with, and Balsamiq helped me finalize my thoughts into the following UI.

myImage (1) (Looking at it now I notice that I forgot the “Add” button)

Tags: ,

RemoteX Localization Editor final touches

November 19th, 2009 1 comment

I’ve been working on a JavaScript client for our REST-service. So far it’s an editor for Localization and pick list options. But I was on a roll!

imageSo we charge by the amount of users each installation, lets add an easy way to calculate the amount of users. Download the list of users, and just count them. Pretty easy when then REST server is already in place.  To the right here you can see the end result of the view of the users. I did a similar one to calculate what we call resources.

While I was on that I figured I could add some graphs. I have a small thing for visual data. I found the JQuery Flot plugin, which suited my needs quite well.

I combined the flot plugin with our REST based search API and created some graphs. All cooked together I could produce a statistics view like this:

image

To finish things up I added the style used on RemoteX website, to get a consistent feel. This took some sweat, as the style sheet is generated HTML and CSS from dotNetNuke, and not exactly the same as my carefully handcrafted HTML. In the end I got it in and here is the end result.

image

RemoteX Applications Localization Editor next step

November 17th, 2009 No comments

In a previous post I mentioned that I started working on a localization editor for RemoteX Applications. This last week I started change a few things on the server side.

In RemoteX Applications there are certain combobox’es where you can change the content to customer specific lists. Previously they have been stored as XML files on the server, but this caused long process round trips for changing them. It also added cost to our Operations department at RemoteX. Currently were trying to reduce process costs and delays for our Operations to free up resources for tasks with higher value.

The list configurations are now stored in the database of the system, and is accessible through the REST service. Allowing me to create yet another web based editor.

This one was very similar to the first. Pick a list to edit, add or remove some keyword; then save.

image

The work was straight forward as it was so similar to the precious editor. The separation of concerns between the classes allowed me to just implement a few classes to get a first prototype up and running. The whole solution was completed in a couple of hours.

I added both editors to the same page, and quickly noticed one thing. If you changed editor you needed to enter your password and username again. This couldn’t do.

So I used the technique outlined in my other post about AJAX and Basic Auth, to add a single login dialog forcing the user to login when the page loads.

image

With some JQuery UI I got the above login dialog. Now the login state is available the entire duration of the “visit”.

Localization editor for Applications

November 7th, 2009 No comments

I don’t realy know what to do right now, so I thought I’d share some of the latest work on RemoteX Applications.

RemoteX Applications has support for multiple languages being used in the same hosted installation. Basically we install a set of languages for each installation. Now most of our customers want to make some changes to the standard localization. These changes were made by our operations team, who would verify the installed language on each system installation.

While this is all fine and good, the problem is when we update the localizations. All of a sudden there is a lot of different customer specific language packs which needs to be updated with new keywords and translations. Others might need to be removed.

What we have done now is to separate out customer specific changes from the standard language packs. The operations teams can handle the standard language packs and the customer specific details are separated out and can be managed independently, thus not slowing down upgrade scenarios.

But it doesn’t end here, I finally got some use for my JQuery work for RemoteX Applications. I just completed a minor web application to handle the customer specific changes in an AJAX interface, talking with our REST-service.

RemoteX Applications Localiztion Editor

RemoteX Applications Localization Editor

The screenshot above shows the interface. The editor allows the user to make changes to different languages on different applications. The interface displays the keyword, and the standard translation, allowing the user to enter his or her own translations in the text box.

Changing Localization details

Changing Localization details

The text box saves the override to the server. There are also options for adding new keywords, updating specific keywords without finding the specific text box to edit.

What is fun about this application is that the idea just popped into my head a few days ago. The implementation time is around 2 days of TDD work. There are roughly 84 tests checking the Javascript using QUnit.

There are two things I especially like with the implementation. One is that the separation of concerns was separated out quite nicely, this was greatly beneficial for the testing. I also noticed that there are some quirks in the interface which wouldn’t have been there if I hadn’t used TDD.

I had an idea of how I wanted to make the interface from the start. But my initial plan was to write it using WPF and host it in the Windows Client. However since I made this in JavaScript using JQuery the approach was a bit different. I’ll walk you through roughly how my plans evolved during the development process.

  1. The greatest risk I was was with the XML generation which was to create the messages I sent to the server. To mitigate this I started by isolating this functionality in a “class”.
  2. Once I saw that the tests were achieving the behaviour I needed from the XML Writer I started with the interface. I knew roughly how I wanted it, so I focused mainly on the behaviour. I work heavily with DIV’s, if I know I need to display something I add a DIV for it. This allows my to do formatting later as a separate step.
  3. The third class was the controls for selecting languages and buttons for loading. I knew from the start that I didn’t want any logic in these classes, instead I wanted to create a Controller pattern to handle all logic. This turned out great.
  4. The fourth class is where I started to notice some interesting synergies popping out from the code. The isolation level of the components allows me to reuse previous components to solve business needs through composition.
  5. Lastly, the controller logic is tied in to complete the application. The controller mainly ties all the UI together using AJAX. Interesting to note here is that I tested the AJAX by mocking the AJAX calls. Previously I’ve tested AJAX for doing GETs by having a static XML document to fetch. Testing it with mocking was quite easy and allowed for different kinds of testing.

The editor is now tested to be working in IE8, Chrome and FireFox.

Tags: , ,

Microsoft + RemoteX = Software + Services

September 8th, 2009 No comments

This August Microsoft wrote a piece on RemoteX Applications. The article highlights the benefits of Software + Services, and using Microsoft technologies to develop it. Being a central player behind the solution for RemoteX Applications, it’s always great to get the kind acknowledgement of the resulting product. Event if it is somewhat sales oriented.

The article is available here. If you want to read it yourself.

Tags: