Documentation Coverage Report
Current view: top level - Azure/Cqrs.Azure.WebJobs - CqrsJobHost.cs Hit Total Coverage
Version: 2.2 Artefacts: 2 2 100.0 %
Date: 2017-09-22

          Line data    Source code
       1             : #region Copyright
       2             : // // -----------------------------------------------------------------------
       3             : // // <copyright company="Chinchilla Software Limited">
       4             : // //   Copyright Chinchilla Software Limited. All rights reserved.
       5             : // // </copyright>
       6             : // // -----------------------------------------------------------------------
       7             : #endregion
       8             : 
       9             : using System;
      10             : using Cqrs.Azure.ConfigurationManager;
      11             : using Cqrs.Hosts;
      12             : using Microsoft.Azure.WebJobs;
      13             : 
      14             : namespace Cqrs.Azure.WebJobs
      15             : {
      16             :         /// <summary>
      17             :         /// Execute command and event handlers in an Azure WebJob
      18             :         /// </summary>
      19             :         public abstract class CqrsJobHost<TAuthenticationToken> : TelemetryCoreHost<TAuthenticationToken>
      20           1 :         {
      21             :                 /// <summary>
      22             :                 /// The <see cref="CoreHost"/> that gets executed by the Azure WebJob.
      23             :                 /// </summary>
      24             :                 protected static CoreHost<TAuthenticationToken> CoreHost { get; set; }
      25             : 
      26             :                 /// <summary>
      27             :                 /// An <see cref="Action"/> that is execute pre <see cref="JobHost.RunAndBlock"/>.
      28             :                 /// </summary>
      29             :                 protected static Action PreRunAndBlockAction { get; set; }
      30             : 
      31             :                 /// <remarks>
      32             :                 /// Please set the following connection strings in app.config for this WebJob to run:
      33             :                 /// AzureWebJobsDashboard and AzureWebJobsStorage
      34             :                 /// Better yet, add them to your Azure portal so they can be changed at runtime without re-deploying or re-compiling.
      35             :                 /// </remarks>
      36           1 :                 protected static void StartHost()
      37             :                 {
      38             :                         // We use console state as, even though a webjob runs in an azure website, it's technically loaded via something call the 'WindowsScriptHost', which is not web and IIS based so it's threading model is very different and more console based.
      39             :                         // This actually does all the work... Just sit back and relax... but also stay in memory and don't shutdown.
      40             :                         CoreHost.Run();
      41             : 
      42             :                         JobHost host;
      43             :                         bool disableHostControl;
      44             :                         // I set this to true ... just because.
      45             :                         if (!bool.TryParse(_configurationManager.GetSetting("Cqrs.Azure.WebJobs.DisableWebJobHostControl"), out disableHostControl))
      46             :                                 disableHostControl = false;
      47             :                         if (disableHostControl)
      48             :                         {
      49             :                                 var jobHostConfig = new JobHostConfiguration
      50             :                                 {
      51             :                                         // https://github.com/Azure/azure-webjobs-sdk/issues/741
      52             :                                         DashboardConnectionString = null
      53             :                                 };
      54             :                                 host = new JobHost(jobHostConfig);
      55             :                         }
      56             :                         else
      57             :                                 host = new JobHost();
      58             : 
      59             :                         if (PreRunAndBlockAction != null)
      60             :                                 PreRunAndBlockAction();
      61             : 
      62             :                         // The following code ensures that the WebJob will be running continuously
      63             :                         host.RunAndBlock();
      64             :                 }
      65             :         }
      66             : }

Generated by: LCOV version 1.10