codingoutloud
10/3/2012 - 7:02 PM

Windows Azure Web About Box snippet

Windows Azure Web About Box snippet

<!-- 
   The beginnings of some useful context to display so one might understand some simple things about a 
   Windows Azure deployment without a lot of effort
   Source: https://gist.github.com/3829053
-->
<!-- 
   As might be included in an About page:
   Note: only useful when run within a custom assembly; if run from within default.cshtml on, say, trivial
   Windows Azure Web Sites site, it would show the About info for mscorlib, such as:
      Last compiled: Saturday, January 21, 2012 at 5:40:04 PM UTC, File version: 4.0.0.0) 
-->
<!-- 
   TODO: add System uptime (e.g., http://stackoverflow.com/questions/972105/retrieve-system-uptime-using-c-sharp 
         or msdn.microsoft.com/en-us/library/system.environment.tickcount.aspx)
         add ASP.NET uptime (e.g., http://www.codeproject.com/Articles/3311/Detecting-the-UpTime-of-Web-Server)
   TODO: add ability to identity info about local resources (e.g.,
         var logPath = RoleEnvironment.GetLocalResource("AdStreamerServiceLogs").RootPath;
         ViewData["LogPath"] = logPath;
         var partialDiagSetting = RoleEnvironment.GetConfigurationSettingValue(
                                        "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString");
         partialDiagSetting = partialDiagSetting.Substring(0, 
                                   Math.Max("UseDevelopmentStorage=true".Length, partialDiagSetting.Length / 2));
         ViewBag.diagSetting = partialDiagSetting;
         --- 
         @Html.TextBox("Log File Path", ViewData["LogPath"])
         <p>At the tone the local server time will be:</p>
         <p>@DateTime.Now.ToLongTimeString()</p>
         <p>Diagnostics Setting:</p>
         <p>@ViewBag.diagSetting</p>
-->
<article>
    @{
        string assemblyName = String.Empty;
        string assemblyCompiledUtc = String.Empty;
        string assemblyVersion = String.Empty;
        string exceptionInfo = String.Empty;
        try
        {
            assemblyName = System.Web.Compilation.BuildManager.GetGlobalAsaxType().BaseType.Assembly.GetName().Name;
            var assemblyCreatedUtc = new FileInfo(System.Web.Compilation.BuildManager.GetGlobalAsaxType().BaseType.Assembly.Location).CreationTimeUtc;
            assemblyCompiledUtc = String.Format("{0} at {1} UTC", assemblyCreatedUtc.ToLongDateString(), assemblyCreatedUtc.ToLongTimeString());
            assemblyVersion = System.Web.Compilation.BuildManager.GetGlobalAsaxType().BaseType.Assembly.GetName(false).Version.ToString();
        }
        catch (Exception ex)
        {
            exceptionInfo = ex.Message; // TODO: does razor not allow this to be called?
        }
    }
    <ul>
        <li><small>Assembly name: @assemblyName</small></li>
        <li><small>Last compiled: @assemblyCompiledUtc</small></li>
        <li><small>File version: @assemblyVersion</small></li>
    </ul>
    <small>@exceptionInfo</small>
</article>