public void Run() { foreach (PipelineStepDescription stepDescription in _stepsDescriptions) { var workflowExecutionStep = new WorkflowExecutionStep { WorkflowId = _workflowId, PluginActionSetItemId = stepDescription.PlaginActionSetItemId, StatusCode = (int)PipelineStatusCodes.New, MessageId = (Guid?)_messageId }; _dbContext.WorkflowExecutionSteps.Add(workflowExecutionStep); _dbContext.SaveChanges(); try { workflowExecutionStep.StatusCode = (int)PipelineStatusCodes.InProgress; _dbContext.SaveChanges(); if (!string.IsNullOrEmpty(stepDescription.ConfigurationString)) { log.Debug($"Загрузка конфигурации для {stepDescription.Class}\r\n" + $"Строка конфигурации - {stepDescription.ConfigurationString}"); _pipelineExecutionContext.PluginStepSettings = JsonConvert.DeserializeObject <Dictionary <string, object> >( stepDescription.ConfigurationString); } else { _pipelineExecutionContext.PluginStepSettings = null; } string assemblyName = AssembliesPreLoader.WarmupAssembly(stepDescription); Assembly assembly = Assembly.LoadFrom(assemblyName); Type type = assembly.GetType(stepDescription.Class); ExecutePlugin(type); workflowExecutionStep.RequestBody = _pipelineExecutionContext.RequestBody; workflowExecutionStep.ResponseBody = _pipelineExecutionContext.ResponseBody; workflowExecutionStep.PipelineValues = JsonConvert.SerializeObject(_pipelineExecutionContext.PipelineValues); workflowExecutionStep.StatusCode = (int)PipelineStatusCodes.Finished; _dbContext.SaveChanges(); } catch (Exception ex) { log.Fatal("Во время выполнения работы PipelineProcessor произошла ошибка", ex); workflowExecutionStep.StatusCode = (int)PipelineStatusCodes.Error; _dbContext.SaveChanges(); throw; } } }
public ProcessHostManager(string hostname, string username, string password) { _hostname = hostname; _username = username; _password = password; AssembliesPreLoader.Reload(); var token = _shutdown.Token; Task.Run( () => { while (!token.IsCancellationRequested) { lock (_locker) { foreach (ManagedPlugin managedPlugin in _managedPlugins) { if (!_hostsDictionary.TryGetValue(managedPlugin.QueueCode, out IProcessHost host)) { host = ProcessHostFactory.GetPluginHost(_hostname, _username, _password, managedPlugin.RequestCode, managedPlugin.IsSynchronous); host.Run(); _hostsDictionary.GetOrAdd(managedPlugin.QueueCode, host); continue; } if (string.IsNullOrEmpty(host.CloseReason)) { continue; } _hostsDictionary.TryRemove(host.QueueCode, out host); } } lock (_locker) { foreach (string key in _hostsDictionary.Keys) { if (!_managedPlugins.Any(m => m.QueueCode == key)) { IProcessHost host; _hostsDictionary.TryRemove(key, out host); } } } _ping.WaitOne(_pingInterval); } }, token ); }