July 20, 2011

Word documents and merging two branches

Filed under: ms office — Tags: , Himanshu @ 11:46 pm

Do you create word documents? Do you send them for review to your boss? I think, answers of both of these questions will be “yes” for most people, and I’m not exception! MS Word have a good feature – Track Changes. As it’s name suggests, it  tracks the changes while document is being edited, and can show final (edited version) of the document or can show final document with highlighting changes . While changes are highlighted, they are easy to notice and can also navigation across changes easily.

But, if your boss forgot to start the change tracking, then? Well, not to worry, word can do merging of two different branches like a version control. Steps:

  1. Very important! Make sure you are having extra copy (backup) of both the documents (your copy and boss’s copy). Just in case we create mess in the process, you don’t loose your valuable information in these documents.
  2. After making sure both documents (e.g. “My Copy” and “Boss’s Copy”) are closed, open “Boss’s Copy” document in MS Word.
  3. Invoke “Save as“ operation and try and save it over “My Copy” of the document. (Notice already open document name and Save as name in the image)
  4. Word should prompt you for different available option, having one of them to be “Merge changes into existing files” (for example, as  depicted in image), select it and continue with “Save as” operation.

In the result of above, “My Copy” document will be updated as if Boss have changed the document while having “Change Track” on.

SaveAs-And-Overwrite-Me

July 5, 2011

WaitHandles’ Switch

Filed under: .net,multi-threading Himanshu @ 3:57 pm

I will say it again: “I like extension methods”. They provide great way of increase readability of the code in languages like C#.

Anyway this post is not about extension method. Have you ever needed to write code that will wait on different wait handles (WaitHandle) and execute different piece of code depending up on which handle is signaled. Here is one way to implement that:

public static void WaitSwitch(this WaitHandle[] waitHandles, params Action[] actions)
  
{
  
    waitHandles.DoEmptyOrNullArgCheck("waitHandles");
  
    actions.DoEmptyOrNullArgCheck("waitHandles");
  
    if (waitHandles.Length != actions.Length)
  
        throw new ArgumentException("length of wait handles and actions has to be same");
  
    var triggerIndex = WaitHandle.WaitAny(waitHandles);
  
    actions[triggerIndex]();
  
}
  

And then client code will become as:

(new[] { shutdownTriggeredEvent, updateAvailableEvent }).WaitSwitch(
  
    () => isShutdownRequested = true,
  
    DownloadNextUpdate
  
);
  

July 1, 2011

HTTP 404 while asp.net web forms and spring.net project

Filed under: asp.net,spring.net Himanshu @ 3:32 pm

While doing some refactoring with the project, I suddenly start getting HTTP 404, and that to for all pages that exists and was working few minutes back. I was amused to get the error, with the fact that pages existed, I could see them and feel them! After a while, I noticed that I have deleted a existing .aspx file from project which I forgot to remove from spring.net configuration file.

If you add any .aspx in Spring.Net config that do not exists, Spring.NET brings you to yellow screen with appropriate message. But not when you delete one from project and forget to remove from config file! At least not all the time.

Powered by WordPress