Quick Intro to Protobuf

Protobuf-net is a .net adaption of Google’s Protocol Buffers and is generally considered to be a really fast serialization/deserialization library.  The target serializable classes are decorated with mainly 3 attributes.

The target class is decorated with the ProtoContract attributes, indicating that the class can be serialized.

The ProtoMember attribute indicates the field that will be serialized, while the number N denotes the order in which the property would be serialized. By default, the properties would be serialized in alphabetical order.

As the name suggests, the ProtoIgnore attributes is used to indicate the properties that needs to be ignored while serializing.

Let’s create the example class which we would be serializing.

public class Student
  public string Name { get; set; }

In order to serialize the class, you would be using the Static method Serialize.

var stOriginal = new Student() { Name = "jia" };
byte[] array;
using (var stream = new System.IO.MemoryStream())
   ProtoBuf.Serializer.Serialize(stream, stOriginal);
   array = stream.ToArray();

Similarly, the static method Deserialize can be used to deserialize the object back.

Student stDeserialized;
using (var stream = new System.IO.MemoryStream(array))
  stDeserialized = ProtoBuf.Serializer.Deserialize(stream);

Easy as that !! Happy Coding !!

Sneak Peak at Response Files (.rsp)

The Visual Studio has evolved so much that anyone hardly uses the CSC.exe tool and command line switches any longer. But there could be days when you are forced to opt for CSC.exe and the biggest woe is the huge list of switches/parameters that you need to associate each time you want to compile using csc.exe.

The response files (*.rsp) provides a cleaner way to find a solution for this problem, inevitably also taking caring of accidentally missing parameters. Response files is plain text files which contains a set of switches you would like to apply to your compilation command. Let’s consider the example.

csc.exe /out:jia.exe /t:exe program.cs

We have opted for a simple example. In real life, you could be referring to a bag full of dependencies, which you would have to include using the /r switch. But for sake of example, we will stick to simple example mentioned above. We will now write out response file to include the /out and /t switches.


We will name it as “app.rsp”. Now, to compile our cs file, we would need to specify the rsp file using the @ prefix.

csc.exe @app.rsp program.cs

The .Net framework uses a similar approach internally by employing a global response file (csc.rsp). This is the reason we could compile the source files even when skip referencing commonly used dlls in command.

Oxyplot and DateTime Axis

Anyone who has just been introduced to OxyPlot and had to deal with a graph comprising of a Time/DateTime axis might find themselves in a corner. The first thing you would notice is that the DataPoint structure accepts only double and that means trouble, especially with a not-so-exhaustive documentation the tool supports. But if you keep persisting and look around a bit, you will soon notice that the OxyPlot developers has done a fair bit of job to ensure TimeAxis (and many more) are possible. The DateTimeAxis Class enables you to add a DateTime object to your PlotModel.

But prior to jumping to your Axes, you need to find a solution to add a DateTime to your DataPoint Collection. This is again made possible by the DateTimeAxis class and the ToDouble method.

var  dataPoints = new[]
    new DataPoint(DateTimeAxis.ToDouble(new DateTime(2018,1,1,7,23,0)),12),
    new DataPoint(DateTimeAxis.ToDouble(new DateTime(2018,1,1,8,23,0)),9),
    new DataPoint(DateTimeAxis.ToDouble(new DateTime(2018,1,1,10,23,0)),13)

Now let’s add the required axes.

MainGraphModel.Axes.Add(new DateTimeAxis()
  Maximum = DateTimeAxis.ToDouble(new DateTime(2018, 1, 1, 12, 23, 0)),
  Minimum = DateTimeAxis.ToDouble(new DateTime(2018, 1, 1, 6, 23, 0)),
  Position = AxisPosition.Bottom,
  IntervalType = DateTimeIntervalType.Hours,
  MinorIntervalType = DateTimeIntervalType.Hours


Oxyplot does look pretty good, only if they had better documentation.


Git stash

Git is arguably the most versatile version control system around and one cannot resist falling in love with this awesome piece of code every time you use it.

One of the lesser known features in Git, especially for individual developers/teams who have recently migrated from other tools is the “stash” command.

You might often find yourself in situation when you aren’t yet ready to commit your code, you would like to view the last commit without trashing the existing code. You could also be in situation when you want keep your local changes without committing and then swap to do something else.

This is where the stash comes into the picture. Stash creates a backup of your current staged and unstaged changes, and returns your branch to the last commit. To stash your changes, you use the stash command.

git stash

When you are ready to go back to your stashed changes, you can use the ‘git stash apply‘ command. This would take your latest stashed changes and apply it to the branch.

git stash apply.

Finally you could delete your stashed changes by using the git stash drop command.

git stash drop.

This would remove your last set of stashed changes.

Stimulsoft – Non-Modal Designer in WPF App, Part 2

In the previous post, we explored Supervising Controller Pattern to provide a solution to the issue we faced when using Stimulsoft Designer  Controller as an embedded control in WPF application. Even while we used the Supervising Controller Pattern, we still fiddled with the MVVM pattern by making the ViewModel “aware” of the View, even though it wasn’t depended. In this section, we would be exploring another method, through which could eliminate the ‘awareness’ factor, allowing us to work along the MVVM pattern with all its purity.
As in previous section, we will begin by adding the designer control in our XAML.
So how do we do resolve the issue this time around, without breaking the MVVM pattern ? Instead of Supervising Controller Pattern, we would instead on something which is native to the WPF. The Behaviours and Attached Properties
Behavior and Attached Property
Behavior allows us to Attach a new property the StiWpfDesignerControl, which is bindable.
public class ReportBehavior : Behavior
        public static readonly DependencyProperty ReportSourceProperty = DependencyProperty.RegisterAttached("ReportSource", typeof(object), typeof(ReportBehavior), new PropertyMetadata(ReportSourceChanged));

        private static void ReportSourceChanged(DependencyObject DependencyObject, DependencyPropertyChangedEventArgs PropertyChangedEvent)
            var stidesigner = DependencyObject as StiWpfDesignerControl;

            if (stidesigner != null)
                stidesigner.Report = PropertyChangedEvent.NewValue as Stimulsoft.Report.StiReport;

        public static void SetReportSource(DependencyObject target, object value)
            target.SetValue(ReportSourceProperty, value);

        public static object GetReportSource(DependencyObject target)
            return target.GetValue(ReportSourceProperty);
As can be seen in the code above, we have defined a property called “ReportSource” which allows us to the set the Report Property of the Designer Controller.  We can now bind our property in our XAML
Putting it all together
      <wpfdesign:StiWpfDesignerControl local1:ReportBehavior.ReportSource="{Binding Path=ActiveReport}" x:Name="DesignerControl"  ></wpfdesign:StiWpfDesignerControl>
Don’t forget the namespace


Stimulsoft – Non-Modal Designer in WPF App

Stimulsoft Reports is one among the most powerful and easy to use Reporting Tools available. While this post is not focused on feature of Stimulsoft Reports, it is worth checking out the features in Stimulsoft Website.


Embedded Stimulsoft Designer Control and MVVM

The post would rather focus on displaying the powerful Stimulsoft Designer in a WPF application with Data Source being .Net Objects created at runtime. While this is pretty straightforward to do when you want to invoke the designer as a Modal Dialog, it becomes a little messier when you want the designer to be an embedded control, particularly when you want to stick to the MVVM Pattern.
Let’s first go ahead and place our designer control in the View first.

Don’t miss out adding the namespace


For sake of example, we would mock our business object rather than taking it out of Database

   public class Products
       public string Name { get; set; }
       public decimal Price { get; set; }

var   _ProductCollection = new List()
  new ProductModel() { Name = "Product 1", Price = 100 },
  new ProductModel() { Name = "Product 2", Price = 200 }

We do have a property ‘ActiveReport’ , which holds the report details and is responsible for synchronizing the dictionary. Let’s define the Property and synchronize our collection.

  private Stimulsoft.Report.StiReport _ActiveReport;

  public Stimulsoft.Report.StiReport ActiveReport
  get { return _ActiveReport; }
  _ActiveReport = value;

And the code to register the collection with StiReport.

  ActiveReport = new Stimulsoft.Report.StiReport();
  ActiveReport.RegBusinessObject("Products", _ProductCollection);

This is where our problems begin. We do not have a property (the Report Property doesn’t allow Binding) exposed by Stimulsoft Designer to which could bind the StiReport Instance. We can do it pragmatically by assigning the Report Property, but that would involve breaking the MVVM Structure. We would prefer not to do that, atleast not directly. So what would be our workaround ?

Supervising Controller Pattern

The workaround lies with having a Supervising Controlling Pattern. The Supervising Controller allows the ViewModel to be aware of the View, but not depended on it. Now this can be a tricky situation if someone questions whether this would be breaking the MVVM, considering as per MVVM, the ViewModel should be completely independent of View. Pretty much true, but when all doors are closed, there is nothing wrong in making the ViewModel ‘aware‘ of View, as long as it is not dependent on View and we do minimalist code in View. Remember, there is a significant difference in being aware and being dependent.

So how do we implement the Supervising Controlling Pattern and make the ViewModel aware of the View. We first being by creating the Contract interface through which the ViewModel would be interacting with View. Let’s call it ISupervisorController

  public interface ISupervisingController
  void UpdateReportControl(Stimulsoft.Report.StiReport Report);

As you can see, it has a single method called UpdateReportControl, accepting the StiReport instance. Let’s go ahead and implement it in the View. We will make that only minimalist work is done in the code behind class.

  public void UpdateReportControl(StiReport Report)
  ReportDesigner.Report = Report;

So with that done, we come to the most important part – how do we get an instance of View in the ViewModel ? Thanks to Caliburn.Micro, we do have a solution for that as well.

Screen and IViewAware

The Screen class in Caliburn.Micro utilizes an interface ‘IViewAware, which exposes a method called OnViewAttached which gives us reference to the attached View. All that left to do is override the method and use our Supervising Controller interface to call the method from View, which sets the Report property of Designer Control

  protected override void OnViewAttached(object view, object context)
  base.OnViewAttached(view, context);
  (view as ISupervisingController).UpdateReportControl(ActiveReport);

That’s it, you have your .Net Object Collection synchronized with the Designer. The entire source code described in this post can be found here

TFS task board exceeds limits

It was one of those days when the QA was having a joyful time in office as he filling up the Sprint Board with bugs when he encountered issue saying “You have exceeded the number of items allowed on your task board.” Developers, who were pulling their hairs out till then, had a wry smile while I sat up there searching for a solution before the QA eat my head out.
In the end, the fix doesn’t seem to be as tough as I expected, even though it did require a bit of research. All it needn’t was couple of steps.
Step 1 : Open “Developer Command Prompt” and run the following command
witadmin command witadmin exportprocessconfig /collection:CollectionURL /p:ProjectName /f:settings.xml
Step 2: Open up the created settings.xml and locate the tag which says TaskBacklog category=”Microsoft.TaskCategory” and Add following to it .
The tag would now look like following.
Step 3 : Save the file and import the settings back using the command
witadmin importprocessconfig /collection:CollectionURL /p:ProjectName /f:settings.xml
You should be all set now.  I can now see the QA smiling while the developers are back with their hands over their  head.

Configuring MediaWiki on Windows 7/10

The purpose of this post is to create a simple and straightforward guide for Windows users to install and configure  MediaWiki on a Windows Operating System.
Step 1: The first step towards configuring Mediawiki is installing Xampp. The installer of Xampp can be found in following URL.
By default Apache Server uses Port. You might want to change it by editing “httpd.conf” from the Xampp Control Panel.
Listen 8080
Now your Apache and MySql Server would be ready to run.
Step 2: The next step involves setting password for “root” in your MySQL Server.  You can do the same using the following URL and selecting http://localhost:8080/security/xamppsecurity.php” as seen in the screenshot.
Once inside the link, you can set the password for the “root”.
You might have to restart server to make the change effective.
Step 3: There is one more step you have to accomplish before you get your hands dirty with MediaWiki and that is to create the require Database. This would require you to login to the phpMyAdmin Dashboard. This can be done by accessing following link.
Use the password you had set for “root” to login to the dashboard.
You can create the Database by accessing the “Database” link in the top Menu.
Step 4: Now you are all set to start configuring your MediaWiki.  Download your copy of MediaWiki from following URL and extract the files to your “C:\xampp\htdocs” folder.
You can start your MediaWiki Configuration wizard using following link.
Step 5 : The Mediawiki Configuration Wizard provides a simple yet effective  way to configure your wiki portal. Most of the steps in the wizard is self explanatory. Only place to care for is to set your database credentials as same as “root” you had set in previous step.
Once the wizard is completed, you would need to copy the generated localsettings.php file to your “C:\xampp\htdocs\mediawiki” folder.
That’s it, and now you would have your wiki all set to run. Go ahead and access it using following url.