public void Dispose()
        {
            PipeServer.Disconnect();
            PipeServer.Dispose();
            PipeServer   = null;
            StreamWriter = null;

            Log.Debug($"Stopped log server {{{Identifier}}}");
        }
示例#2
0
        public void Dispose()
        {
            JsonWriter.WriteEndArray();
            PipeServer.Disconnect();
            PipeServer.Dispose();
            PipeServer = null;

            Log.Debug("Daemon", $"Stopped device debugger server {{{Identifier}}}");
        }
示例#3
0
        public void Dispose()
        {
            JsonWriter.WriteEndArray();
            PipeServer.Disconnect();
            PipeServer.Dispose();
            PipeServer = null;

            Log.Debug($"Stopped tablet debugger server {{{Identifier}}}");
        }
        /// <inheritdoc />
        /// <summary>
        ///     Stops a Pipe Server with this Pipe Service. Waits for all
        ///     Pipe Communication to halt, then closes all Pipe(s)
        /// </summary>
        public void Stop()
        {
            try
            {
                // Wait for Pipe communication to stop
                _pipeServer.WaitForDrain();

                _pipeServer.Disconnect();

                // Close Pipe
                _pipeServer.Dispose();

                _memoryCache.Set(SERVICE_MEMORY, false);
            }

            catch (ObjectDisposedException ode)
            {
                _logger.LogMessage(SERVICE_NAME, ode.Message, LogLevel.Error);


                _memoryCache.Set(SERVICE_MEMORY, false);

                throw new PipeServiceException(ode.Message);
            }

            catch (NotSupportedException nse)
            {
                _logger.LogMessage(SERVICE_NAME, nse.Message, LogLevel.Error);


                _memoryCache.Set(SERVICE_MEMORY, false);

                throw new PipeServiceException(nse.Message);
            }

            catch (IOException ioe)
            {
                _logger.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error);


                _memoryCache.Set(SERVICE_MEMORY, false);

                throw new PipeServiceException(ioe.Message);
            }

            catch (InvalidOperationException ioe)
            {
                _logger.LogMessage(SERVICE_NAME, ioe.Message, LogLevel.Error);


                _memoryCache.Set(SERVICE_MEMORY, false);

                throw new PipeServiceException(ioe.Message);
            }
        }
        /// <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);
                }
            }
        }