/// ----------------------------------------------------------------------------- /// <summary> /// ProcessModule processes the module which is attached to this container /// </summary> /// <history> /// [cnurse] 12/05/2007 Created /// </history> /// ----------------------------------------------------------------------------- private void ProcessModule() { if (ContentPane != null) { //Process Content Pane Attributes ProcessContentPane(); // always add the actions menu as the first item in the content pane. if (InjectActionMenu && ModulePermissionController.HasModuleAccess(SecurityAccessLevel.Edit, string.Empty, ModuleConfiguration) && Request.QueryString["dnnprintmode"] != "true") { ContentPane.Controls.Add(LoadControl("~/admin/Menus/DNNActions/DDRActionsMenu.ascx")); jQuery.RequestHoverIntentRegistration(); } //Process Module Header ProcessHeader(); //Try to load the module control _moduleHost = new ModuleHost(ModuleConfiguration, ParentSkin, this); ContentPane.Controls.Add(ModuleHost); //Process Module Footer ProcessFooter(); //Process the Action Controls if (ModuleHost != null && ModuleControl != null) { ProcessChildControls(this); } //Add Module Stylesheets ProcessStylesheets(ModuleHost != null); } }
public override void Unregister() { Log.Source.TraceInformation("Unregister module {0}", ModuleName); if (_ModuleHost == null) { ModuleLoader.RemoveModuleManager(this); return; } try { Log.Source.TraceInformation("Disconnect {0}", _ModuleHost); _ModuleHost.Disconnect(); } catch (Exception ex) { Far.Api.ShowError("ERROR: module " + _ModuleHost, ex); } finally { _ModuleHost = null; ModuleLoader.RemoveModuleManager(this); } }
/// <summary> /// Tries to serialize the state object and save it using SCOM Agent API. /// </summary> /// <param name="state">Module state object to save.</param> /// <returns>Returns true if success, false otherwise.</returns> protected bool SavePreviousState() { if (ModuleState == null) { return(false); } lock (shutdownLock) { using (MemoryStream memoryStream = new MemoryStream()) { BinaryFormatter binaryFormatter = new BinaryFormatter(); try { binaryFormatter.Serialize(memoryStream, ModuleState); ModuleHost.SaveState(memoryStream.GetBuffer(), (int)memoryStream.Length); return(true); } catch (Exception e) { Global.logWriteException(e, this); return(false); } } } }
public QueryServiceListPA(ModuleHost <ServiceListDataItem> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost, configuration, previousState) { if (Environment.OSVersion.Version.Major >= 6) // >= Windows Vista / 2008 { supportDelayedStart = true; supportClusteredService = true; } }
void ConnectModuleHost() { _ModuleHost = (ModuleHost)CreateEntry(_ModuleHostClassType); _ModuleHostClassType = null; Log.Source.TraceInformation("Connect {0}", _ModuleHost); _ModuleHost.Connect(); }
void ConnectModuleHost() { _ModuleHost = (ModuleHost)Activator.CreateInstance(_ModuleHostClassType, false); _ModuleHostClassType = null; Log.Source.TraceInformation("Connect {0}", _ModuleHost); _ModuleHost.Connect(); }
public override void Start() { lock (shutdownLock) { if (shutdown) { return; } ModuleHost.RequestNextDataItem(); } }
public ModuleBaseExtension(ModuleHost <TOutputDataType> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { LoadConfiguration(configuration); //Move this _logger = new TraceLogger(this.GetType().Name, "Operations Manager"); //QUESTION: Not sure if we need to work with states... //LoadPreviousState(previousState); }
public SimpleProbeAction(ModuleHost <PropertyBagDataItem> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { // don't need to check moduleHost != null => the base constructor does this // check configuration != null only if the module has configuration shutdownLock = new object(); // load configuration here if any Log($"SimpleProbeAction class instance is created. Host process PID: {Process.GetCurrentProcess().Id}; Managed thread: {Thread.CurrentThread.ManagedThreadId}\r\n"); }
public void ModuleHost_ShouldLoad_ASingleModuleLoader() { // Given var loader = new Mock <ILoader <TestAppEvents> >(); var events = new TestAppEvents(); // When var moduleHost = new ModuleHost <TestAppEvents>(loader.Object, events); // Then loader.Verify(m => m.Load(events)); }
/// <summary> /// /// </summary> /// <param name="configuration">Instance of <see cref="configuration"/> /// </param> /// <param name="environment">Instance of /// <see cref="IHostingEnvironment"/></param> /// <param name="logger">Instance of <see cref="ILogger{Startup}"/> /// <param name="sharedHandler">Instance of /// <see cref="HttpMessageHandler"/>. It will be used to make outgoing /// HTTP requests.</param> /// </param> public Startup( IConfiguration configuration, IHostingEnvironment environment, ILogger <Startup> logger, HttpMessageHandler httpMessageHandler = null) { this._logger = logger; this._environment = environment; this._configuration = configuration; this._httpMessageHandler = httpMessageHandler; this._moduleHost = new ModuleHost(configuration); }
/// ----------------------------------------------------------------------------- /// <summary> /// ProcessModule processes the module which is attached to this container. /// </summary> private void ProcessModule() { if (this._tracelLogger.IsDebugEnabled) { this._tracelLogger.Debug($"Container.ProcessModule Start (TabId:{this.PortalSettings.ActiveTab.TabID},ModuleID: {this.ModuleConfiguration.ModuleDefinition.DesktopModuleID}): Module FriendlyName: '{this.ModuleConfiguration.ModuleDefinition.FriendlyName}')"); } if (this.ContentPane != null) { // Process Content Pane Attributes this.ProcessContentPane(); // always add the actions menu as the first item in the content pane. if (this.InjectActionMenu && !ModuleHost.IsViewMode(this.ModuleConfiguration, this.PortalSettings) && this.Request.QueryString["dnnprintmode"] != "true") { JavaScript.RequestRegistration(CommonJs.DnnPlugins); this.ContentPane.Controls.Add(this.LoadControl(this.PortalSettings.DefaultModuleActionMenu)); // register admin.css ClientResourceManager.RegisterAdminStylesheet(this.Page, Globals.HostPath + "admin.css"); } // Process Module Header this.ProcessHeader(); // Try to load the module control this._moduleHost = new ModuleHost(this.ModuleConfiguration, this.ParentSkin, this); if (this._tracelLogger.IsDebugEnabled) { this._tracelLogger.Debug($"Container.ProcessModule Info (TabId:{this.PortalSettings.ActiveTab.TabID},ModuleID: {this.ModuleConfiguration.ModuleDefinition.DesktopModuleID}): ControlPane.Controls.Add(ModuleHost:{this._moduleHost.ID})"); } this.ContentPane.Controls.Add(this.ModuleHost); // Process Module Footer this.ProcessFooter(); // Process the Action Controls if (this.ModuleHost != null && this.ModuleControl != null) { this.ProcessChildControls(this); } // Add Module Stylesheets this.ProcessStylesheets(this.ModuleHost != null); } if (this._tracelLogger.IsDebugEnabled) { this._tracelLogger.Debug($"Container.ProcessModule End (TabId:{this.PortalSettings.ActiveTab.TabID},ModuleID: {this.ModuleConfiguration.ModuleDefinition.DesktopModuleID}): Module FriendlyName: '{this.ModuleConfiguration.ModuleDefinition.FriendlyName}')"); } }
public void OnNewDataItems(DataItemBase[] dataItems, bool isLogicalllyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgeState, DataItemProcessingCompleteCallback completionCallback, object completionState) { if ((acknowledgeCallback == null && completionCallback != null) || (acknowledgeCallback != null && completionCallback == null)) { throw new ArgumentOutOfRangeException(nameof(acknowledgeCallback), nameof(completionCallback)); } lock (_shutdownLock) { if (_shutdown) { return; } _logger.WriteLog(TraceEventType.Information, 450, $"Executing probe OnNewDataItems action"); TOutputDataType[] results = null; try { results = GetOutputData(dataItems); } catch (Exception ex) { _logger.WriteLog(TraceEventType.Critical, 500, $"Critical exception while trying to retrieve output data \n\n {ex}"); acknowledgeCallback?.Invoke(acknowledgeState); completionCallback?.Invoke(completionState); //QUESTION: Not sure if we need to request next dataItem ModuleHost.RequestNextDataItem(); throw new ModuleException(ex.Message, ex.InnerException); } acknowledgeCallback?.Invoke(acknowledgeState); completionCallback?.Invoke(completionState); //QUESTION: Should the state always be null? if (results.Length > 0) { ModuleHost.PostOutputDataItems(results, isLogicalllyGrouped, GetAcknowledgementCallback(), null); } _logger.WriteLog(TraceEventType.Information, 451, $"Requesting next data item"); ModuleHost.RequestNextDataItem(); } }
static async Task Main(string[] args) { await ModuleHost.Run <TestModule>(args, (services, configuration) => { services.AddSingleton <IModuleClient, MockModuleClientProxy>(); services.AddHostedService(x => new MockMessageInjector(x.GetRequiredService <IConfiguration>(), x.GetRequiredService <IModuleClient>(), async(config, client) => await client.SendEventAsync("input", new Message(Encoding.UTF8.GetBytes("Sample Message"))))); }); }
/// <inheritdoc/> public VisionViewModel Assemble(Dispatcher dispatcher) { var viewModel = new VisionViewModel(); var modules = PluginHost.Load <IVisionModule>(); foreach (var module in modules) { var moduleHost = new ModuleHost(module); viewModel.Bind(moduleHost); } return(viewModel); }
public override void Start() { Log($"Entering {nameof(Start)}; Managed thread: {Thread.CurrentThread.ManagedThreadId}.\r\n"); lock (shutdownLock) { if (shutdown) { return; } // Request the very first data item ModuleHost.RequestNextDataItem(); Log($"First data item requested.\r\n"); } }
static async Task Main(string[] args) { await ModuleHost.Run <SimulatorModule>(args, (services, configuration) => { if (configuration["Environment"] == "Debug") { services.AddSingleton <IModuleClient, MockModuleClientProxy>(); } else { services.AddSingleton <IModuleClient, ModuleClientProxy>(); } }); }
public ModuleBaseCoreWorkflow(ModuleHost <TOutputDataType> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { if (moduleHost == null) { throw new ArgumentNullException("moduleHost"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } shutdownLock = new object(); PreInitialize(moduleHost, configuration, previousState); LoadConfiguration(configuration); LoadPreviousState(previousState); }
private void ProcessModule() { if (ContentPane != null) { ProcessContentPane(); ProcessHeader(); _ModuleHost = new ModuleHost(ModuleConfiguration, ParentSkin); ContentPane.Controls.Add(ModuleHost); ProcessFooter(); if (ModuleHost != null && ModuleControl != null) { ProcessChildControls(this); } ProcessStylesheets(ModuleHost != null); } }
public void OnNewDataItems(DataItemBase[] dataitems, bool logicallyGrouped, DataItemAcknowledgementCallback acknowledgeCallback, object acknowledgedState, DataItemProcessingCompleteCallback completionCallback, object completionState) { Log($"Entering {nameof(OnNewDataItems)}; Managed thread: {Thread.CurrentThread.ManagedThreadId}\r\n"); Log($"Received {(dataitems == null ? 0 : dataitems.Length)} inbound data items of {(dataitems == null && dataitems.Length >=1 ? "<unknown>" : dataitems[0].DataItemTypeName)} type.\r\n"); lock (shutdownLock) { // don't start if shutdown is in progress if (shutdown) { return; } Log($"No shutdown in progress.\r\n"); PropertyBagDataItem[] ReturningResults = null; try { // put the actual monitoring code here: ReturningResults = <get result code> Log($"Competed output data item.\r\n"); } catch (Exception e) { Log($"Error while getting output data: {e.Message}.\r\n"); } if (ReturningResults != null && ReturningResults.Length != 0) { // send data back to SCOM Agent, if any if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, logicallyGrouped); } Log($"Output data item(s) posted.\r\n"); } // completed the current run, ask for next ModuleHost.RequestNextDataItem(); Log($"Next data item requested.\r\n"); } }
public DiskProbeAction(ModuleHost <PropertyBagDataItem> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { // don't need to check moduleHost != null => the base constructor does this // check configuration != null only if the module has configuration shutdownLock = new object(); // load configuration here if any Log($"{nameof(DiskProbeAction)} class instance is created. Host process PID: {Process.GetCurrentProcess().Id}; Managed thread: {Thread.CurrentThread.ManagedThreadId}\r\n"); if (configuration != null) { LoadConfiguration(configuration); } else { throw new ArgumentNullException(nameof(configuration)); } Log($"Configuration is loaded.\r\n"); }
protected void PostOutputData(TOutputDataType[] ReturningResults, DataItemAcknowledgementCallback AcknowledgementCallback, bool LogicallyGrouped) { lock (shutdownLock) { if (shutdown) { return; } } try { if (ReturningResults != null || ReturningResults.Length > 0) { if (AcknowledgementCallback == null) { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0]); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped); } } else { if (ReturningResults.Length == 1) { ModuleHost.PostOutputDataItem(ReturningResults[0], AcknowledgementCallback, null); } else { ModuleHost.PostOutputDataItems(ReturningResults, LogicallyGrouped, AcknowledgementCallback, null); } } } } catch (Exception e) { ModuleHost.NotifyError(ModuleErrorSeverity.DataLoss, e); } }
public void ModuleHost_ShouldLoad_MultipleModuleLoaders() { // Given var loader1 = new Mock <ILoader <TestAppEvents> >(); var loader2 = new Mock <ILoader <TestAppEvents> >(); var loaders = new List <ILoader <TestAppEvents> >() { loader1.Object, loader2.Object }; var events = new TestAppEvents(); // When var moduleHost = new ModuleHost <TestAppEvents>(loaders, events); // Then loader1.Verify(m => m.Load(events)); loader2.Verify(m => m.Load(events)); }
static async Task Main(string[] args) { await ModuleHost.Run <OrchestratorModule>(args, (services, configuration) => { if (configuration["Environment"] == "Debug") { services.AddSingleton <IModuleClient, MockModuleClientProxy>(); services.AddHostedService(x => new MockMessageInjector(x.GetRequiredService <IConfiguration>(), x.GetRequiredService <IModuleClient>(), async(config, client) => await client.SendEventAsync("telemetry", new Message(File.ReadAllBytes("Mock/TelemetryMessageSample.json"))))); services.AddSingleton <IHttpHandler, MockHttpClientHandler>(); services.AddSingleton <ITimeSeriesRecorder, InfluxDBRecorder>(); services.AddSingleton <IInfluxDBClient, InfluxDBClient>((e) => new InfluxDBClient( configuration.GetValue("INFLUX_URL", "http://localhost:8897"), configuration.GetValue("INFLUX_USERNAME", ""), configuration.GetValue("INFLUX_PASSWORD", ""))); services.AddSingleton <IHttpHandler, Service.HttpClientHandler>((e) => new Service.HttpClientHandler("http://localhost:8000/")); } else { services.AddSingleton <IModuleClient, ModuleClientProxy>(); // services.AddSingleton<IHttpHandler, Service.HttpClientHandler>((e) => new Service.HttpClientHandler(configuration.GetValue("ML_BASE_URI", "http://ml:5001/"))); services.AddSingleton <IHttpHandler, MockHttpClientHandler>(); services.AddSingleton <IInfluxDBClient, InfluxDBClient>((e) => new InfluxDBClient( configuration.GetValue("INFLUX_URL", "http://influxdb:8086"), configuration.GetValue("INFLUX_USERNAME", ""), configuration.GetValue("INFLUX_PASSWORD", ""))); services.AddSingleton <ITimeSeriesRecorder, InfluxDBRecorder>(); } }); }
public PropertyBagMultiplePerformanceDataMapper(ModuleHost <MOMPerfDataItem> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost) { if (moduleHost == null) { throw new ArgumentNullException("moduleHost"); } if (configuration == null) { throw new ArgumentNullException("configuration"); } if (previousState != null) { // Since this module never calls SaveState this value should be null. throw new ArgumentOutOfRangeException("previousState"); } shutdownLock = new object(); LoadConfiguration(configuration); }
/// ----------------------------------------------------------------------------- /// <summary> /// ProcessModule processes the module which is attached to this container /// </summary> /// <history> /// [cnurse] 12/05/2007 Created /// </history> /// ----------------------------------------------------------------------------- private void ProcessModule() { if (ContentPane != null) { //Process Content Pane Attributes ProcessContentPane(); // always add the actions menu as the first item in the content pane. if (InjectActionMenu && !ModuleHost.IsViewMode(ModuleConfiguration, PortalSettings) && Request.QueryString["dnnprintmode"] != "true") { ContentPane.Controls.Add(LoadControl("~/admin/Menus/ModuleActions/ModuleActions.ascx")); //register admin.css ClientResourceManager.RegisterAdminStylesheet(Page, Globals.HostPath + "admin.css"); } //Process Module Header ProcessHeader(); //Try to load the module control _moduleHost = new ModuleHost(ModuleConfiguration, ParentSkin, this); ContentPane.Controls.Add(ModuleHost); //Process Module Footer ProcessFooter(); //Process the Action Controls if (ModuleHost != null && ModuleControl != null) { ProcessChildControls(this); } //Add Module Stylesheets ProcessStylesheets(ModuleHost != null); } }
/// ----------------------------------------------------------------------------- /// <summary> /// Recursive function to add module's actions to the DNNNodeCollection based off of passed in ModuleActions /// </summary> /// <param name="parentAction">Parent action</param> /// <param name="parentNode">Parent node</param> /// <param name="rootNode">Root Node.</param> /// <param name="actionControl">ActionControl to base actions off of</param> /// <param name="intDepth">How many levels deep should be populated</param> /// <remarks> /// </remarks> /// <history> /// [Jon Henning] 5/15/2006 Created /// </history> /// ----------------------------------------------------------------------------- private static void AddChildActions(ModuleAction parentAction, DNNNode parentNode, DNNNode rootNode, IActionControl actionControl, int intDepth) { //Add Menu Items foreach (ModuleAction action in parentAction.Actions) { bool isActionPending = IsActionPending(parentNode, rootNode, intDepth); if (action.Title == "~") { if (isActionPending == false) { //A title (text) of ~ denotes a break parentNode.DNNNodes.AddBreak(); } } else { //if action is visible and user has permission if (action.Visible && (action.Secure != SecurityAccessLevel.Anonymous || (!ModuleHost.IsViewMode(actionControl.ModuleControl.ModuleContext.Configuration, PortalSettings.Current)) && ModulePermissionController.HasModuleAccess(action.Secure, Null.NullString, actionControl.ModuleControl.ModuleContext.Configuration))) { if (isActionPending) { parentNode.HasNodes = true; } else { int i = parentNode.DNNNodes.Add(); DNNNode node = parentNode.DNNNodes[i]; node.ID = action.ID.ToString(); node.Key = action.ID.ToString(); node.Text = action.Title; //no longer including SPACE in generic node collection, each control must handle how they want to display if (string.IsNullOrEmpty(action.ClientScript) && string.IsNullOrEmpty(action.Url) && string.IsNullOrEmpty(action.CommandArgument)) { node.Enabled = false; } else if (!string.IsNullOrEmpty(action.ClientScript)) { node.JSFunction = action.ClientScript; node.ClickAction = eClickAction.None; } else { node.NavigateURL = action.Url; if (action.UseActionEvent == false && !String.IsNullOrEmpty(node.NavigateURL)) { node.ClickAction = eClickAction.Navigate; if (action.NewWindow) { node.Target = "_blank"; } } else { node.ClickAction = eClickAction.PostBack; } } node.Image = action.Icon; if (action.HasChildren()) //if action has children then call function recursively { AddChildActions(action, node, rootNode, actionControl, intDepth); } } } } } }
protected override void PreInitialize(ModuleHost <QuadrupleListDataItem> moduleHost, XmlReader configuration, byte[] previousState) { ModInit.Logger.AddLoggingSource(GetType(), ModInit.evtId_WriteRegistryElementWA); base.PreInitialize(moduleHost, configuration, previousState); }
public WriteRegistryElementWA(ModuleHost <QuadrupleListDataItem> moduleHost, XmlReader configuration, byte[] previousState) : base(moduleHost, configuration, previousState) { }