/// <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); }