Shawn Cicoria - CedarLogic

Perspectives and Observations on Technology

Recent Posts

Sponsors

Tags

General





Community

Email Notifications

Blogs I Read

Archives

Other

Use OpenDNS

September 2011 - Posts

Faking SPContext–for testing only…

Keith Dahlby has a good post on creating a fake SPContext.  Here’s the link and the code

NOTE: This is not production safe code – use at own risk…

http://solutionizing.net/2009/02/16/faking-spcontext/

public static SPContext FakeSPContext(SPWeb contextWeb)
{
  // Ensure HttpContext.Current
  if (HttpContext.Current == null)
  {
    HttpRequest request = new HttpRequest("", web.Url, "");
    HttpContext.Current = new HttpContext(request,
      new HttpResponse(TextWriter.Null));
  }

  // SPContext is based on SPControl.GetContextWeb(), which looks here
  if(HttpContext.Current.Items["HttpHandlerSPWeb"] == null)
    HttpContext.Current.Items["HttpHandlerSPWeb"] = web;

  return SPContext.Current;
}
Posted: 09-21-2011 2:54 PM by cicorias | with no comments
Filed under:
Use an Action delegate to time a method…

I wanted an ability to be able to simply time methods and write to a log/trace sink and a very simple approach that I ended up using was to provide a method that takes an Action delegate which would be the method that is to be timed.

The following is what I came up with (this is my reminder…)

class Program
{
    static void Main(string[] args)
    {
        TestMethod1();
    }

    private static void TestMethod1()
    {
        LoggingHelper.TimeThis("doing something", () =>
        {
            Console.WriteLine("This is the Real Method Body");
            Thread.Sleep(100);
        });
    }
}

public static class LoggingHelper
{
    public static void TimeThis(string message, Action action)
    {
        string methodUnderTimer = GetMethodCalled(1);
        Stopwatch sw = Stopwatch.StartNew();
        LogMessage( string.Format("started: {0} : {1}", methodUnderTimer, message));
        action();
        sw.Stop();
        LogMessage(string.Format("ended  : {0} : {1} : elapsed : {2}", methodUnderTimer, message, sw.Elapsed));

    }

    private static string GetMethodCalled(int stackLevel)
    {
        StackTrace stackTrace = new StackTrace();
        StackFrame stackFrame = stackTrace.GetFrame(stackLevel + 1);
        MethodBase methodBase = stackFrame.GetMethod();
        return methodBase.Name;
    }

    static void LogMessage(string message){
        Console.WriteLine("{0}", message);
    }

}
Posted: 09-21-2011 12:15 PM by cicorias | with no comments
Filed under: ,
Comparison of Windows Azure Storage Queues and Service Bus Queues « Microsoft Technologies Rocks !!!

Nice table comparing Windows Azure Queues vs. Windows Azure AppFabric Service Bus – note the comment regarding in WAZ SDK 1.5 Queue message size is now 64KB

Of course, I like the name of the blog too.

Comparison of Windows Azure Storage Queues and Service Bus Queues « Microsoft Technologies Rocks !!!

Posted: 09-20-2011 5:06 AM by cicorias | with no comments
Filed under:
MiniProfiler– A simple but effective mini-profiler for ASP.NET MVC and ASP.NET.

Once in a while a good tool that I find out about that helps me developing solutions comes in real handy.  MiniProfiler is one of those tools.

Developed by the StackOverflow folks it’s available in source or binary, and NuGet packages

Take a look

http://code.google.com/p/mvc-mini-profiler/

http://nuget.org/List/Packages/MiniProfiler

Posted: 09-18-2011 6:34 AM by cicorias | with no comments
Filed under: , , ,
Slides for BUILD conference…

On the Channel 9 site where the BUILD conference sessions are available, there are several feeds that provide the media associated with the sessions.

One that’s not listed explicitly is the PowerPoint slides – that feed is here:

http://channel9.msdn.com/Events/BUILD/BUILD2011/RSS/slides

Posted: 09-18-2011 5:44 AM by cicorias | with no comments
Filed under:
Building scalable web applications with Windows Azure (ed. and on premise too!)

Matthew Kerner’s session at BUILD covers many of the patterns and approaches that a well designed and highly scalable solution can do to make the most efficient use of the platform.

Truth is many of the areas Matthew covers should be for on Premise too – including use of Windows Azure CDN...

Smile  At about ~30:00 in Matthew references one of my posts on Windows Azure CDN and using it with your Compute role (hosted service) as an CDN origin…

Building scalable web apps with Windows Azure
http://channel9.msdn.com/events/BUILD/BUILD2011/SAC-870T

Bringing Hyper-V to “Windows 8” - Building Windows 8 - Site Home - MSDN Blogs

This is huge – and a welcomed addition.  Been waiting too long for this.

Bringing Hyper-V to “Windows 8” - Building Windows 8 - Site Home - MSDN Blogs