WinDbg Preview

/ 1:59 PM
WinDbg has a new version and I loved this. The UX is better. It makes it easier to debug.
WinDbg has a new version and I loved this. The UX is better. It makes it easier to debug.
Continue Reading

Instead of using like

$("#mask").inputmask ("d/m/y" , {autoUnmask : true});


it is better to use knockout custom binding.

Define the custom binding in html or make an AMD module.

ko.bindingHandlers.inputmask = {
  init: function (element, valueAccessor, allBindingsAccessor) {
    var obj = valueAccessor(),
              allBindings = allBindingsAccessor(),
              format = allBindings.format;
    $(element).inputmask(format , obj);

    ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
      $(element).inputmask('destroy');
    });
  },
  update: function (element) {
    $(element).trigger('change');
  }
};
or define this in main module.
define(['durandal/system', 'durandal/app', 'durandal/viewLocator' , 'durandal/composition'],  function (system, app, viewLocator , composition) { composition.addBindingHandler('inputmask', {
        init: function (element, valueAccessor, allBindingsAccessor ) {
              var obj = valueAccessor(),
                  allBindings = allBindingsAccessor(),
                  format = allBindings.format;
              $(element).inputmask(format , obj);


               ko.utils.domNodeDisposal.addDisposeCallback(element, function () {
                 $(element).inputmask('destroy');
               });          
        },
        update: function (element) {
            $(element).trigger('change');
        }
    });
......
}
And you can use in view as:
<input data-bind="inputmask :  {autoUnmask: true} , format : 'd/m/y'" id="mask" type="text" />
By using shim, jquery libraries can be used in Durandal.

In the main js, configure shim. I have written a module UIInitialize to intialize the interface. This is dependant on jQuery, jQueryGritter and jQueryPulsate.

requirejs.config({
    urlArgs: "bust=" + (new Date()).getTime(),
    paths: {
        'text': '../Scripts/text',
        'durandal': '../Scripts/durandal',
        'plugins': '../Scripts/durandal/plugins',
        'transitions': '../Scripts/durandal/transitions',
        'jQueryGritter': '../Scripts/gritter/js/jquery.gritter',
        'jQueryPulsate': '../Scripts/jquery.pulsate.min',
        'UIInitialize': '../Scripts/UIGeneral',
    },
    shim: {
        'UIInitialize': {
            deps: ['jquery', 'jQueryGritter', 'jQueryPulsate'],
            exports: 'UIInitialize'
        }
    }
});

The UIInitialize.js is as below:

var UIInitialize = function () {
    return {
          init: function () { 
               // Initialize gritter and pulsate
          }
    };
}();

The router configuratin is in the shell.js file. I need to make this router dynamically managable. To do so, I have used ajax.

The change is in the active method in shell.js file.

activate: function () {
   var routes = [];
 
   $.ajax({
       url: "/Route/Get",
       async: false,
       dataType  : 'json'
       }).done(function (response) {
       routes = response;
   });
 
   router.map(routes).buildNavigationModel();
   return router.activate();
}

The server code is as below.
public JsonResult Get()
  {
     List route = new List()
     {
        new Route(){ route = "" ,title = "Welcome", moduleId = "viewmodels/welcome", nav= true },
        new Route(){ route = "flickr" , moduleId = "viewmodels/flickr" , nav= true }
     };

     return Json(route , JsonRequestBehavior.AllowGet);
}

Durandal does not have a mechanism to manage css file for each view. So I have created a plugin to manage css files.

The plugin is as below. I have placed this plugin under durandal/plugins folder


define(['jquery'], function ($) {
 return {
    loadCss : function (fileName) {
	var cssTag = document.createElement("link")
	cssTag.setAttribute("rel", "stylesheet")
	cssTag.setAttribute("type", "text/css")
	cssTag.setAttribute("href", fileName)
	cssTag.setAttribute("class", "__dynamicCss")

	document.getElementsByTagName("head")[0].appendChild(cssTag)
	},
	removeModuleCss: function () {
	$(".__dynamicCss").remove();

	}
  };
});

In the viewmodel, I have used is as below.


define(['plugins/cssLoader'], function (cssLoader) {
  var ctor = function () {
	this.compositionComplete = function () {
	  cssLoader.loadCss("sample.css");
      cssLoader.loadCss("sample2.css");
 	};
    this.deactivate =  function () {
    cssLoader.removeModuleCss();
    }
  };

  return ctor;
});
I am using the code below to download file.


WebClient myWebClient = new WebClient();
myWebClient.DownloadFile(myStringWebResource, fileName);
But suddenly I have started to get 504 error. After adding header, the error has gone.
myWebClient.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)";
When I try to create a new appointment using EWS Managed API, I get the following error.


The request failed schema validation: The element 'OptionalAttendees' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types' has incomplete content. List of possible elements expected: 'Attendee' in namespace 'http://schemas.microsoft.com/exchange/services/2006/types'.

When I add an optional attendee it works but I do not need any optional attendee.
I tried
appointment.OptionalAttendees.Clear();
but no help. But removing it by using

public readonly static ExtendedPropertyDefinition PidLidOptionalAttendees = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.Meeting, 0x00000007, MapiPropertyType.String);
appointment.RemoveExtendedProperty(PidLidOptionalAttendees);
solved my problem.
Using Count (Over Partition by) decreases the performance. Be careful before using this. I had to change these statements because of the performance problem.
I have an application using Ms Word for spell checking. The application impersonates an admin account. The application runs when the specified account is logged on the server. But when the account is not logged on I receive " (Exception from HRESULT: 0x8001010A (RPC_E_SERVERCALL_RETRYLATER))" error.

I solved the problem as following:

Created a new pool for the application.
Set the identity specified in the web config.
Set load profile true.

Notes:
I could not set the security because the MS Word is not listed in the dcom config. I could add it to there but I did not want to modify the registry.So I had to do as above.

Word Automation

by on 2:30 PM
I have an application using Ms Word for spell checking. The application impersonates an admin account. The application runs when the specif...
When adding a CustomControl dynamically, you receive "Unable to find control id referenced by the 'ControlToCompare' property" error.

I search for the Internet and found no solution. I achieved this bu using JavaScript and jQuery.

In page add a startup script. (I don't like Page.RegisterStartupScript)

$(document).ready(function() {
<%= this.StartUpScript %>
});
In code behind

CompareValidator cv = new CompareValidator();
cv.ID = "customvalidatorid";
cv.ValueToCompare ="Whatever"; // You must set a value. Else, you get an error.
this.StartUpScript += String.Format("document.getElementById(\"{0}\").controltovalidate=\"{1}\";", cv.ClientID, YourControlToCompareId);
this.StartUpScript += String.Format("document.getElementById(\"{0}\").removeAttribute(\"valuetocompare\");", cv.ClientID);
That's it!