Tuesday 31 July 2012

Deploy TimerJobs to SharePoint 2007 farm

Working with SharePoint 2007 is full with excitement, don't you agree? I am lucky enough to be an advanced SharePoint developer + admin. Today, I am going to share one trick on deploying TimerJobs to MOSS 3.0.

After executing a list of "stsadm" commands, please be sure to recycle the MOSS Timer service, and do a recycle of your IIS app pools.

It took me a day for figure out why the newly deployed timerjob wasn't running, as there is no any system trace available to you. Hope it help.

show your appreciation by clicking on those Google ads

Friday 23 March 2012

MVC 4 Web API access Session

It's not recommended to use Session  in Web API for various of good reasons. However, in case you're still so interested to access Session for any business needs, here is a quick solution to allow accessing Session in Web API.

 
// In global.asax
public class MvcApp : System.Web.HttpApplication
{
 public static void RegisterRoutes(RouteCollection routes)
 {
  var route = routes.MapHttpRoute(
   name: "DefaultApi",
   routeTemplate: "api/{controller}/{id}",
   defaults: new { id = RouteParameter.Optional }
  );
  route.RouteHandler = new MyHttpControllerRouteHandler();
 }
}

// Create two new classes
public class MyHttpControllerHandler : HttpControllerHandler, IRequiresSessionState
{
 public MyHttpControllerHandler(RouteData routeData): base(routeData)
 {
 }
}
public class MyHttpControllerRouteHandler : HttpControllerRouteHandler
{
 protected override IHttpHandler GetHttpHandler(RequestContext requestContext)
 {
  return new MyHttpControllerHandler(requestContext.RouteData);
 }
}

// Now Session is visible in your Web API
public class ValuesController : ApiController
{
 public string GET(string input)
 {
  var session = HttpContext.Current.Session;
  if (session != null)
  {
   if (session["Time"] == null)
    session["Time"] = DateTime.Now;
   return "Session Time: " + session["Time"] + input;
  }
  return "Session is not availabe" + input;
 }
}
 



Source is here.

Thursday 22 March 2012

First Cloud OS - Solaris 11

Oracle has released Solaris 11 and claimed it as the first Cloud OS in the market. Looking forward to having my hands on it.

Details of Oracle Solaris 11 can be found on here

Monday 13 February 2012

Best IDE tools/plug-ins for eclipse Java development

Looking for best IDE integrated tools/plug-ins for eclipse Java development just like Resharper or CodeRush for Visual Studio .Net platform. Anyone has few suggestions?

Monday 30 January 2012

javascript: base64 encoding

It's quite easy to implement. See the code snippets below


<script>
    base64Keys = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=";
    base64Encode = function(input) {
      var chr1, chr2, chr3, enc1, enc2, enc3, enc4, i, output;
      output = "";
      i = 0;
      input = utf8Encode(input);
      while (i < input.length) {
        chr1 = input.charCodeAt(i++);
        chr2 = input.charCodeAt(i++);
        chr3 = input.charCodeAt(i++);
        enc1 = chr1 >> 2;
        enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
        enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
        enc4 = chr3 & 63;
        if (isNaN(chr2)) {
          enc3 = enc4 = 64;
        } else if (isNaN(chr3)) {
          enc4 = 64;
        }
        output = "" + output + (base64Keys.charAt(enc1)) + (base64Keys.charAt(enc2)) + (enc3 < 64 ? base64Keys.charAt(enc3) : '') + (enc4 < 64 ? base64Keys.charAt(enc4) : '');
      }
      return output;
    };

    utf8Encode = function(string) {
      var c, s, utftext, _i, _len, _ref;
      string = string.replace(/\r\n/g, "\n");
      utftext = "";
      _ref = string.split('');
      for (_i = 0, _len = _ref.length; _i < _len; _i++) {
        s = _ref[_i];
        c = s.charCodeAt(0);
        if (c < 128) {
          utftext += String.fromCharCode(c);
        } else if (c > 127 && c < 2048) {
          utftext += String.fromCharCode((c >> 6) | 192);
          utftext += String.fromCharCode((c & 63) | 128);
        } else {
          utftext += String.fromCharCode((c >> 12) | 224);
          utftext += String.fromCharCode(((c >> 6) & 63) | 128);
          utftext += String.fromCharCode((c & 63) | 128);
        }
      }
      return utftext;
    };
</script>
 

Friday 27 January 2012

Command-line to launch Android emulator.

Assuming Android SDK has been successfully installed and AVD of your target android version was created. For Window 7 user, the install path is likely at "c:\Program Files\Android\android-sdk\tools\". If you have problems on above step, please refer to Android developer site or email me. The command line to launch your emulator, for example IceCream.

c:\>"C:\Program Files\Android\android-sdk\tools\emulator.exe" -avd IceCream

Javascript to request GPS location from web page

There is no direct method natively built in Javascript stack. Don't give up though. I am giving your few lines of code to provide the result you look for. The code runs well on IE9, Chrome, FireFox, Safari on both PC and mobile device platforms.

 
function requestGeoLocation() {
 if (navigator.geolocation) {
 navigator.geolocation.getCurrentPosition(function(loc){
 // do nothing
 //document.getElementById('myloc').innerHTML = 'Location: ' + 
 //    loc.coords.latitude + ', ' +
 //    loc.coords.longitude;
    
        }, function() { alert('request denied or something went wrong.');});
} else { 
 alert('GPS is supported.'); 
}