/// <summary> /// Used to send a task back to the core. /// </summary> private void SendResultToCore() { _loggerService.LogMessage(SERVICE_NAME, _taskToProcess.ToString(), LogLevel.Info); _pipeServer = new PipeServer(); _pipeServer.CreatePipe(); _pipeServer.WriteString(_taskToProcess.ToString()); _pipeServer.WaitForDrain(); }
/// <summary> /// SendTasks(): Sends Task(s) to their Where-Tos /// </summary> public void SendTasks() { var tempQueue = (TaskQueue)_memoryCache.Get("taskQueue"); var tempBag = new TaskQueue(); try { // Loop through all Priorities in Sorted Dictionary foreach (var task in _priorities.ToList()) { // Created new Pipe Server to send Task to Where-To using (_pipeServer = new PipeServer(task.Value.WhereTo)) { try { _pipeServer.CreatePipe(); _loggerService.LogMessage(SERVICE_NAME, task.Value.Name + " moving to " + task.Value.WhereTo, LogLevel.Info); } catch (ArgumentNullException ane) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); throw new TaskServiceException(ane.Message); } catch (ArgumentOutOfRangeException aoore) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, aoore.Message, LogLevel.Error); throw new TaskServiceException(aoore.Message); } catch (ArgumentException ae) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, ae.Message, LogLevel.Error); throw new TaskServiceException(ae.Message); } catch (PlatformNotSupportedException pnse) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, pnse.Message, LogLevel.Error); throw new TaskServiceException(pnse.Message); } catch (NotSupportedException nse) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error); throw new TaskServiceException(nse.Message); } catch (IOException ioe) { _memoryCache.Set("taskServiceStarted", false); _loggerService.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); throw new TaskServiceException(ioe.Message); } try { // Send Task to Where-To as a request _pipeServer.WriteString(task.Value.ToString()); } catch (NotSupportedException nse) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error); throw new TaskServiceException(nse.Message); } catch (ObjectDisposedException ode) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ode.Message, LogLevel.Error); throw new TaskServiceException(ode.Message); } catch (ArgumentNullException ane) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); throw new TaskServiceException(ane.Message); } catch (ArgumentOutOfRangeException aoofre) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, aoofre.Message, LogLevel.Error); throw new TaskServiceException(aoofre.Message); } catch (IOException ioe) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); throw new TaskServiceException(ioe.Message); } catch (EncoderFallbackException efe) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, efe.Message, LogLevel.Error); throw new TaskServiceException(efe.Message); } catch (ArgumentException ae) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ae.Message, LogLevel.Error); throw new TaskServiceException(ae.Message); } catch (OverflowException oe) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, oe.Message, LogLevel.Error); throw new TaskServiceException(oe.Message); } try { // Wait for Pipe to Drain _pipeServer.WaitForDrain(); // Disconnects the pipeserver _pipeServer.Disconnect(); } catch (ObjectDisposedException ode) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ode.Message, LogLevel.Error); throw new TaskServiceException(ode.Message); } catch (NotSupportedException nse) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error); throw new TaskServiceException(nse.Message); } catch (IOException ioe) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); throw new TaskServiceException(ioe.Message); } catch (InvalidOperationException ioe) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); throw new TaskServiceException(ioe.Message); } // Close Pipe that send this Task to Where-To _pipeServer.ClosePipe(); try { // Remove Task from Priorities _priorities.Remove(task.Key); } catch (ArgumentNullException ane) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); throw new TaskServiceException(ane.Message); } // Since Concurrent Bag does not have a remove function, // Shadow copy all Task(s) that were NOT sent and copy // that Concurrent Bag back into memory foreach (var temp in tempQueue.Queue) { if (temp.Name != task.Value.Name) { tempBag.Queue.Add(temp); } } tempQueue = tempBag; tempBag = new TaskQueue(); } } } catch (ArgumentNullException ane) { _memoryCache.Set(SERVICE_MEMORY, false); _loggerService.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); throw new TaskServiceException(ane.Message); } _memoryCache.Set("taskQueue", tempQueue); }
/// <inheritdoc /> /// <summary> /// Starts a Pipe Server in this Pipe Service /// </summary> public void Start() { using (_pipeServer = new PipeServer()) { try { _memoryCache.Set(SERVICE_MEMORY, true); _logger.LogMessage(SERVICE_NAME, "Started", LogLevel.Info); while ((bool)_memoryCache.Get(SERVICE_MEMORY)) { // Potential request from client try { // Create a new Pipe for connection to this Pipe Server. Waits // for a client connection _pipeServer.CreatePipe(); _logger.LogMessage(SERVICE_NAME, "New Pipe Created", LogLevel.Info); // Request from client received var request = _pipeServer.ReadString(); // Process request from client ProcessRequest(request); // Sent response to client _pipeServer.WriteString("Accepted Task"); // Wait for all Pipe communication to stop _pipeServer.WaitForDrain(); } catch (NotSupportedException nse) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error); } catch (ObjectDisposedException ode) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, ode.Message, LogLevel.Error); } catch (ArgumentNullException ane) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); } catch (ArgumentOutOfRangeException aoore) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, aoore.Message, LogLevel.Error); } catch (IOException ioe) { _memoryCache.Set(SERVICE_MEMORY, false); Start(); _logger.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); } catch (DecoderFallbackException dfe) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, dfe.Message, LogLevel.Error); // _logger.LogError(dfe.Message); } catch (ArgumentException ae) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, ae.Message, LogLevel.Error); // _logger.LogError(ae.Message); } catch (OverflowException oe) { _memoryCache.Set(SERVICE_MEMORY, false); _logger.LogMessage(SERVICE_NAME, oe.Message, LogLevel.Error); // _logger.LogError(oe.Message); } _pipeServer.Disconnect(); _pipeServer = new PipeServer(); } } catch (ArgumentNullException ane) { //_logger.LogError(ane.Message); _logger.LogMessage(SERVICE_NAME, ane.Message, LogLevel.Error); throw new PipeServiceException(ane.Message); } catch (ArgumentOutOfRangeException aoore) { //_logger.LogError(aoore.Message); _logger.LogMessage(SERVICE_NAME, aoore.Message, LogLevel.Error); throw new PipeServiceException(aoore.Message); } catch (ArgumentException ae) { //_logger.LogError(ae.Message); _logger.LogMessage(SERVICE_NAME, ae.Message, LogLevel.Error); throw new PipeServiceException(ae.Message); } catch (PlatformNotSupportedException pnse) { _logger.LogMessage(SERVICE_NAME, pnse.Message, LogLevel.Error); throw new PipeServiceException(pnse.Message); } catch (NotSupportedException nse) { _logger.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error); throw new PipeServiceException(nse.Message); } catch (IOException ioe) { _logger.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error); throw new PipeServiceException(ioe.Message); } } }