Documentation Coverage Report
Current view: top level - Ninject/Azure/Cqrs.Ninject.Azure.WebJobs - CqrsNinjectJobHost.cs Hit Total Coverage
Version: 2.2 Artefacts: 2 2 100.0 %
Date: 2018-08-07 15:04:50

          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.Authentication;
      11             : using Cqrs.Hosts;
      12             : using Cqrs.Ninject.Azure.Wcf;
      13             : using Cqrs.Ninject.Azure.WebJobs.Configuration;
      14             : using Microsoft.Azure.WebJobs;
      15             : 
      16             : namespace Cqrs.Ninject.Azure.WebJobs
      17             : {
      18             :         /// <summary>
      19             :         /// Execute command and event handlers in an Azure WebJob using Ninject
      20             :         /// </summary>
      21             :         public class CqrsNinjectJobHost<TAuthenticationToken, TAuthenticationTokenHelper> : CqrsWebHost<TAuthenticationToken, TAuthenticationTokenHelper, WebJobHostModule>
      22             :                 where TAuthenticationTokenHelper : class, IAuthenticationTokenHelper<TAuthenticationToken>
      23           1 :         {
      24             :                 /// <summary>
      25             :                 /// The <see cref="CoreHost"/> to run, WebJobs are console apps and console apps start via a static method, this is the instance
      26             :                 /// that static method will actually run.
      27             :                 /// </summary>
      28             :                 protected static CoreHost<TAuthenticationToken> CoreHost { get; set; }
      29             : 
      30             :                 /// <summary>
      31             :                 /// An <see cref="Action"/> to run just before <see cref="JobHost.RunAndBlock"/>.
      32             :                 /// </summary>
      33             :                 protected static Action PreRunAndBlockAction { get; set; }
      34             : 
      35             :                 /// <remarks>
      36             :                 /// Please set the following connection strings in app.config for this WebJob to run:
      37             :                 /// AzureWebJobsDashboard and AzureWebJobsStorage
      38             :                 /// Better yet, add them to your Azure portal so they can be changed at runtime without re-deploying or re-compiling.
      39             :                 /// </remarks>
      40           1 :                 protected static void StartHost()
      41             :                 {
      42             :                         // 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.
      43             :                         // This actually does all the work... Just sit back and relax... but also stay in memory and don't shutdown.
      44             :                         CoreHost.Run();
      45             : 
      46             :                         JobHost host;
      47             :                         bool disableHostControl;
      48             :                         // I set this to true ... just because.
      49             :                         if (!bool.TryParse(_configurationManager.GetSetting("Cqrs.Azure.WebJobs.DisableWebJobHostControl"), out disableHostControl))
      50             :                                 disableHostControl = false;
      51             :                         if (disableHostControl)
      52             :                         {
      53             :                                 var jobHostConfig = new JobHostConfiguration
      54             :                                 {
      55             :                                         // https://github.com/Azure/azure-webjobs-sdk/issues/741
      56             :                                         DashboardConnectionString = null
      57             :                                 };
      58             :                                 host = new JobHost(jobHostConfig);
      59             :                         }
      60             :                         else
      61             :                                 host = new JobHost();
      62             : 
      63             :                         if (PreRunAndBlockAction != null)
      64             :                                 PreRunAndBlockAction();
      65             : 
      66             :                         // The following code ensures that the WebJob will be running continuously
      67             :                         host.RunAndBlock();
      68             :                 }
      69             :         }
      70             : }

Generated by: LCOV version 1.12