/// <summary> /// Sets the context for which this control will be embedded /// </summary> /// <param name="parentControl">The interface instance from the parent</param> /// <param name="parentContext">The context provided by the parent</param> /// <param name="btnStartContent">Button text override string</param> /// <param name="btnStopContent">Button text override string</param> /// <param name="btnPauseContent">Button text override string</param> /// <param name="btnResumeContent">Button text override string</param> /// <param name="btnStatusContent">Button text override string</param> public void SetContext(IProcessControl parentControl , object parentContext = null , string btnStartContent = null , string btnStopContent = null , string btnPauseContent = null , string btnResumeContent = null , string btnStatusContent = null) { _parentControl = parentControl; _parentContext = parentContext; if (!string.IsNullOrEmpty(btnStartContent)) { btnStart.Content = btnStartContent; } if (!string.IsNullOrEmpty(btnStopContent)) { btnStop.Content = btnStopContent; } if (!string.IsNullOrEmpty(btnPauseContent)) { btnPause.Content = btnPauseContent; } if (!string.IsNullOrEmpty(btnResumeContent)) { btnResume.Content = btnResumeContent; } if (!string.IsNullOrEmpty(btnStatusContent)) { btnStatus.Content = btnStatusContent; } }
public AutoQCBackgroundWorker(IAppControl appControl, IProcessControl processControl, IAutoQCLogger logger) { _appControl = appControl; _processControl = processControl; _logger = logger; _fileWatcher = new AutoQCFileSystemWatcher(logger); }
/// <inheritdoc/> public Task <IClient> CreateAsync(string product, IProcessControl ctrl) { var client = new IoTHubClient(ctrl); var connection = _hub.Connect(DeviceId, ModuleId, client); client.Connection = connection ?? throw new CommunicationException("Failed to connect to fake hub"); return(Task.FromResult <IClient>(client)); }
/// <summary> /// Create supervisor creating and managing twin instances /// </summary> /// <param name="factory"></param> /// <param name="config"></param> /// <param name="events"></param> /// <param name="process"></param> /// <param name="logger"></param> public SupervisorServices(IContainerFactory factory, IModuleConfig config, IEventEmitter events, IProcessControl process, ILogger logger) { _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _config = config ?? throw new ArgumentNullException(nameof(config)); _events = events ?? throw new ArgumentNullException(nameof(events)); _process = process ?? throw new ArgumentNullException(nameof(process)); _factory = factory ?? throw new ArgumentNullException(nameof(factory)); }
public bool ReadLastAcquiredFileDate(IAutoQCLogger logger, IProcessControl processControl) { logger.Log("Getting the acquisition date on the newest file imported into the Skyline document.", 1, 0); var exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (exeDir == null) { logger.LogError("Cound not get path to the Skyline report file"); return(false); } var skyrFile = Path.Combine(exeDir, "FileAcquisitionTime.skyr"); var reportFile = Path.Combine(SkylineFileDir, "AcquisitionTimes.csv"); // Export a report from the given Skyline file var args = string.Format( @" --in=""{0}"" --report-conflict-resolution=overwrite --report-add=""{1}"" --report-name=""{2}"" --report-file=""{3}""", SkylineFilePath, skyrFile, "AcquisitionTimes", reportFile); var procInfo = new ProcessInfo(AutoQCForm.SkylineRunnerPath, AutoQCForm.SKYLINE_RUNNER, args, args); if (!processControl.RunProcess(procInfo)) { logger.LogError("Error getting the last acquired file date from the Skyline document."); return(false); } // Read the exported report to get the last AcquiredTime for imported results in the Skyline doucment. if (!File.Exists(reportFile)) { logger.LogError("Could not find report outout {0}", reportFile); return(false); } try { LastAcquiredFileDate = GetLastAcquiredFileDate(reportFile, logger); if (!LastAcquiredFileDate.Equals(DateTime.MinValue)) { logger.Log("The most recent acquisition date in the Skyline document is {0}", LastAcquiredFileDate); } else { logger.Log("The Skyline document does not have any imported results."); } } catch (IOException e) { logger.LogError("Exception reading file {0}. Exception details are: ", reportFile); logger.LogException(e); return(false); } return(true); }
/// <inheritdoc/> public async Task<IClient> CreateAsync(string product, IProcessControl ctrl) { if (_bypassCertValidation) { _logger.Warning("Bypassing certificate validation for client."); } // Configure transport settings var transportSettings = new List<ITransportSettings>(); if ((_transport & TransportOption.MqttOverTcp) != 0) { var setting = new MqttTransportSettings( TransportType.Mqtt_Tcp_Only); if (_bypassCertValidation) { setting.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; } transportSettings.Add(setting); } if ((_transport & TransportOption.MqttOverWebsocket) != 0) { var setting = new MqttTransportSettings( TransportType.Mqtt_WebSocket_Only); if (_bypassCertValidation) { setting.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; } transportSettings.Add(setting); } if ((_transport & TransportOption.AmqpOverTcp) != 0) { var setting = new AmqpTransportSettings( TransportType.Amqp_Tcp_Only); if (_bypassCertValidation) { setting.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; } transportSettings.Add(setting); } if ((_transport & TransportOption.AmqpOverWebsocket) != 0) { var setting = new AmqpTransportSettings( TransportType.Amqp_WebSocket_Only); if (_bypassCertValidation) { setting.RemoteCertificateValidationCallback = (sender, certificate, chain, sslPolicyErrors) => true; } transportSettings.Add(setting); } if (transportSettings.Count != 0) { return await Try.Options(transportSettings .Select<ITransportSettings, Func<Task<IClient>>>(t => () => CreateAdapterAsync(product, () => ctrl?.Reset(), t)) .ToArray()); } return await CreateAdapterAsync(product, () => ctrl?.Reset()); }
/// <summary> /// Allows consumer of the control provide an interface to handle the button click events. /// <para>It also allows consumer to store a context object that will be returned on the click events.</para> /// </summary> /// <param name="parentControl">IProcessControl for parent</param> /// <param name="parentContext">Optional context to return with every event</param> /// <param name="maxTasksHdlr">Optional handler for the max tasks change event</param> /// <param name="btnStartContent">Optional caption for the start button</param> /// <param name="btnStopContent">Optional caption for the stop button</param> /// <param name="btnPauseContent">Optional caption for the pause button</param> /// <param name="btnResumeContent">Optional caption for the resume button</param> /// <param name="btnStatusContent">Optional caption for the status button</param> public void SetContext(IProcessControl parentControl , object parentContext = null , NumericPlusMinus.ClickHandler maxTasksHdlr = null , string btnStartContent = null , string btnStopContent = null , string btnPauseContent = null , string btnResumeContent = null , string btnStatusContent = null) { _parent = parentControl; _parentContext = parentContext; _maxTasksClickHdlr = maxTasksHdlr; // set the context on the tpe control a=hanldr tpeControl.SetContext(_parent , _parentContext , btnStartContent , btnStopContent , btnPauseContent , btnResumeContent , btnStatusContent); }
/// <summary> /// Create client /// </summary> /// <param name="ctrl"></param> internal IoTHubClient(IProcessControl ctrl) { _ctrl = ctrl; }
/// <inheritdoc/> public async Task StartAsync(string type, string siteId, string serviceInfo, IProcessControl reset) { if (_client == null) { try { await _lock.WaitAsync(); if (_client == null) { // Create client _logger.Debug("Starting Module Host..."); _client = await _factory.CreateAsync(serviceInfo, reset); DeviceId = _factory.DeviceId; ModuleId = _factory.ModuleId; // Register callback to be called when a method request is received await _client.SetMethodDefaultHandlerAsync((request, _) => _router.InvokeMethodAsync(request), null); await InitializeTwinAsync(); // Register callback to be called when settings change ... await _client.SetDesiredPropertyUpdateCallbackAsync( (settings, _) => ProcessSettingsAsync(settings), null); // Report type of service, chosen site, and connection state var twinSettings = new TwinCollection { [TwinProperty.kType] = type, [TwinProperty.kConnected] = true }; // Set site if provided if (string.IsNullOrEmpty(SiteId)) { SiteId = siteId; twinSettings[TwinProperty.kSiteId] = SiteId; } await _client.UpdateReportedPropertiesAsync(twinSettings); // Done... _logger.Information("Module Host started."); return; } } catch (Exception ex) { _client?.Dispose(); _client = null; _reported?.Clear(); DeviceId = null; ModuleId = null; SiteId = null; throw ex; } finally { _lock.Release(); } } throw new InvalidOperationException("Already started"); }
/// <inheritdoc/> public async Task StartAsync(string type, string siteId, string productInfo, string version, IProcessControl reset) { if (Client == null) { try { await _lock.WaitAsync(); if (Client == null) { // Create client _logger.Debug("Starting Module Host..."); Client = await _factory.CreateAsync(productInfo + "_" + version, reset); DeviceId = _factory.DeviceId; ModuleId = _factory.ModuleId; Gateway = _factory.Gateway; // Register callback to be called when a method request is received await Client.SetMethodDefaultHandlerAsync((request, _) => _router.InvokeMethodAsync(request), null); await InitializeTwinAsync(); // Register callback to be called when settings change ... await Client.SetDesiredPropertyUpdateCallbackAsync( (settings, _) => ProcessSettingsAsync(settings), null); // Report type of service, chosen site, and connection state var twinSettings = new TwinCollection { [TwinProperty.Type] = type }; // Set site if provided if (string.IsNullOrEmpty(SiteId)) { SiteId = siteId; twinSettings[TwinProperty.SiteId] = SiteId; } // Set version information twinSettings[TwinProperty.Version] = version; await Client.UpdateReportedPropertiesAsync(twinSettings); // Done... kModuleStart.WithLabels(DeviceId ?? "", ModuleId ?? "", _moduleGuid, version, DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", CultureInfo.InvariantCulture)).Set(1); _logger.Information("Module Host started."); return; } } catch (Exception) { kModuleStart.WithLabels(DeviceId ?? "", ModuleId ?? "", _moduleGuid, version, DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.FFFFFFFK", CultureInfo.InvariantCulture)).Set(0); _logger.Error("Module Host failed to start."); Client?.Dispose(); Client = null; _reported?.Clear(); DeviceId = null; ModuleId = null; SiteId = null; Gateway = null; throw; } finally { _lock.Release(); } } throw new InvalidOperationException("Already started"); }
/// <summary> /// This method copy's each database field which is in the <paramref name="includedColumns"/> /// from the <paramref name="source"/> interface to this data row. /// </summary> public void Copy_From_But_TakeOnly(IProcessControl source, params string[] includedColumns) { if (includedColumns.Contains(ProcessControlsTable.IdCol)) this.Id = source.Id; if (includedColumns.Contains(ProcessControlsTable.ConnectionStringNameCol)) this.ConnectionStringName = source.ConnectionStringName; if (includedColumns.Contains(ProcessControlsTable.StatusCol)) this.Status = source.Status; if (includedColumns.Contains(ProcessControlsTable.TypeCol)) this.Type = source.Type; if (includedColumns.Contains(ProcessControlsTable.SubTypeCol)) this.SubType = source.SubType; if (includedColumns.Contains(ProcessControlsTable.SubParameterCol)) this.SubParameter = source.SubParameter; if (includedColumns.Contains(ProcessControlsTable.WriteTimeCol)) this.WriteTime = source.WriteTime; if (includedColumns.Contains(ProcessControlsTable.ProcessedUpToCol)) this.ProcessedUpTo = source.ProcessedUpTo; if (includedColumns.Contains(ProcessControlsTable.ProcessedUpToDateTimeCol)) this.ProcessedUpToDateTime = source.ProcessedUpToDateTime; if (includedColumns.Contains(ProcessControlsTable.LastUpdateTokenCol)) this.LastUpdateToken = source.LastUpdateToken; }
/// <summary> This method copy's each database field from the <paramref name="source"/> interface to this data row.</summary> public void Copy_From(IProcessControl source, bool includePrimaryKey = false) { if (includePrimaryKey) this.Id = source.Id; this.ConnectionStringName = source.ConnectionStringName; this.Status = source.Status; this.Type = source.Type; this.SubType = source.SubType; this.SubParameter = source.SubParameter; this.WriteTime = source.WriteTime; this.ProcessedUpTo = source.ProcessedUpTo; this.ProcessedUpToDateTime = source.ProcessedUpToDateTime; this.LastUpdateToken = source.LastUpdateToken; }
/// <summary> This method copy's each database field into the <paramref name="target"/> interface. </summary> public void Copy_To(IProcessControl target, bool includePrimaryKey = false) { if (includePrimaryKey) target.Id = this.Id; target.ConnectionStringName = this.ConnectionStringName; target.Status = this.Status; target.Type = this.Type; target.SubType = this.SubType; target.SubParameter = this.SubParameter; target.WriteTime = this.WriteTime; target.ProcessedUpTo = this.ProcessedUpTo; target.ProcessedUpToDateTime = this.ProcessedUpToDateTime; target.LastUpdateToken = this.LastUpdateToken; }
public bool ReadLastAcquiredFileDate(IAutoQCLogger logger, IProcessControl processControl) { logger.Log("Getting the acquisition date on the newest file imported into the Skyline document.", 1, 0); var exeDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); if (exeDir == null) { logger.LogError("Cound not get path to the Skyline report file"); return false; } var skyrFile = Path.Combine(exeDir, "FileAcquisitionTime.skyr"); var reportFile = Path.Combine(SkylineFileDir, "AcquisitionTimes.csv"); // Export a report from the given Skyline file var args = string.Format( @" --in=""{0}"" --report-conflict-resolution=overwrite --report-add=""{1}"" --report-name=""{2}"" --report-file=""{3}""", SkylineFilePath, skyrFile, "AcquisitionTimes", reportFile); var procInfo = new ProcessInfo(AutoQCForm.SkylineRunnerPath, AutoQCForm.SKYLINE_RUNNER, args, args); if (!processControl.RunProcess(procInfo)) { logger.LogError("Error getting the last acquired file date from the Skyline document."); return false; } // Read the exported report to get the last AcquiredTime for imported results in the Skyline doucment. if (!File.Exists(reportFile)) { logger.LogError("Could not find report outout {0}", reportFile); return false; } try { LastAcquiredFileDate = GetLastAcquiredFileDate(reportFile, logger); if (!LastAcquiredFileDate.Equals(DateTime.MinValue)) { logger.Log("The most recent acquisition date in the Skyline document is {0}", LastAcquiredFileDate); } else { logger.Log("The Skyline document does not have any imported results."); } } catch (IOException e) { logger.LogError("Exception reading file {0}. Exception details are: ", reportFile); logger.LogException(e); return false; } return true; }
/// <summary> /// This method copy's each database field which is not in the <paramref name="excludedColumns"/> /// from the <paramref name="source"/> interface to this data row. /// </summary> public void Copy_From_But_Ignore(IProcessControl source, params string[] excludedColumns) { if (!excludedColumns.Contains(ProcessControlsTable.IdCol)) this.Id = source.Id; if (!excludedColumns.Contains(ProcessControlsTable.ConnectionStringNameCol)) this.ConnectionStringName = source.ConnectionStringName; if (!excludedColumns.Contains(ProcessControlsTable.TypeCol)) this.Type = source.Type; if (!excludedColumns.Contains(ProcessControlsTable.SubTypeCol)) this.SubType = source.SubType; if (!excludedColumns.Contains(ProcessControlsTable.WriteTimeCol)) this.WriteTime = source.WriteTime; if (!excludedColumns.Contains(ProcessControlsTable.ProcessedUpToCol)) this.ProcessedUpTo = source.ProcessedUpTo; if (!excludedColumns.Contains(ProcessControlsTable.ProcessedUpToDateTimeCol)) this.ProcessedUpToDateTime = source.ProcessedUpToDateTime; if (!excludedColumns.Contains(ProcessControlsTable.LastUpdateTokenCol)) this.LastUpdateToken = source.LastUpdateToken; }