/// <summary>
        ///     Used as the start of the service
        /// </summary>
        public void Start()
        {
            if (!(bool)_memoryCache.Get(SERVICE_MEMORY))
            {
                _memoryCache.Set(SERVICE_MEMORY, true);
                _loggerService.LogMessage(SERVICE_NAME, "Started", LogLevel.Info);
            }

            while ((bool)_memoryCache.Get(SERVICE_MEMORY))
            {
                _loggerService.LogMessage(SERVICE_NAME, "Started", LogLevel.Info);

                _pipeClient.CreatePipe();


                var incomingTask = _pipeClient.ReadString();
                _loggerService.LogMessage(SERVICE_NAME, incomingTask, LogLevel.Info);
                _taskToProcess = new TaskModel(incomingTask);
                ProcessTask();
                _pipeClient.WaitForDrain();
                _pipeClient = new PipeClient(PIPE_NAME);
                _pipeServer = new PipeServer();

                Thread.Sleep(1000);
            }
        }
        private void BringUpPipe()
        {
            _pipeClient.CreatePipe();
            var incomingTask = _pipeClient.ReadString();

            _loggerService.LogMessage(SERVICE_NAME, incomingTask, LogLevel.Info);
            _taskToProcess = new TaskModel(incomingTask);
        }
 /// <summary>
 ///     Processes the task by creating a client pipe to the core
 /// </summary>
 /// <param name="task">Requires a <see cref="string" /></param>
 private string ProcessTask(string task)
 {
     if (!IsValidJson(task))
     {
         return("");
     }
     _loggerService.LogMessage(SERVICE_NAME, "Processing Task",
                               LogLevel.Debug);
     _pipeClient = new PipeClient();
     _pipeClient.CreatePipe();
     _pipeClient.WriteString(task);
     _pipeClient.WaitForDrain();
     return(_pipeClient.ReadString());
 }
 /// <summary>
 ///     Starts up the service
 /// </summary>
 public void Start()
 {
     if (!(bool)_memoryCache.Get(SERVICE_MEMORY))
     {
         _memoryCache.Set(SERVICE_MEMORY, true);
     }
     while ((bool)_memoryCache.Get(SERVICE_MEMORY))
     {
         _pipeClient.CreatePipe();
         TaskToProcess = new TaskModel(_pipeClient.ReadString());
         ProcessTask();
         _pipeClient.WaitForDrain();
         _pipeClient = new PipeClient(PIPE_NAME);
         Thread.Sleep(1000);
     }
 }
        /// <summary>
        ///     Used as a way to start the service
        /// </summary>
        public void Start()
        {
            if (!(bool)_memoryCache.Get(SERVICE_MEMORY))
            {
                _memoryCache.Set(SERVICE_MEMORY, true);
            }

            while ((bool)_memoryCache.Get(SERVICE_MEMORY))
            {
                _pipeClient.CreatePipe();

                var taskReceived = _pipeClient.ReadString();
                _task = new TaskModel(taskReceived);
                ProcessTask();
            }
        }
        /// <summary>
        ///     Starts to run the server
        /// </summary>
        private void RunServer()
        {
            while (true)
            {
                //Find the TCP Service
                var service = _config.Components.Find(comp => comp.Name == "TCPService");
                //Create the TCP Listener to
                var server = new TcpListener(IPAddress.Parse(service.Properties.IP),
                                             service.Properties.Port);

                server.Start();


                _loggerService.LogMessage(SERVICE_NAME,
                                          $"Server has started on {service.Properties.IP}:{service.Properties.Port}.  Waiting for a connection...",
                                          LogLevel.Info);
                _loggerService.LogMessage(SERVICE_NAME, "Started", LogLevel.Debug);

                var client = server.AcceptTcpClient();

                _loggerService.LogMessage(SERVICE_NAME, "Client Connected", LogLevel.Info);

                var stream = client.GetStream();
                while (!stream.DataAvailable)
                {
                }

                var bytes = new byte[client.Available];

                stream.Read(bytes, 0, bytes.Length);

                //translate bytes of request to string
                var request = Encoding.UTF8.GetString(bytes);

                if (new Regex("^GET").IsMatch(request))
                {
                    request = request.Substring(3, request.Length - 3);
                    if (!IsValidJson(request))
                    {
                        server.Stop();
                    }

                    //TODO: Check Request to make sure it is the JSON compatible and that it is able to convert to a task
                    ProcessTask(request);
                    _loggerService.LogMessage(SERVICE_NAME, _pipeClient.ReadString(),
                                              LogLevel.Debug);

                    var response = Encoding.UTF8.GetBytes("HTTP/1.1 101 Switching Protocols"
                                                          + Environment.NewLine
                                                          + "Connection: Upgrade" + Environment.NewLine
                                                          + "Upgrade: websocket" + Environment.NewLine
                                                          + "Sec-WebSocket-Accept: " + Convert.ToBase64String(
                                                              SHA1.Create().ComputeHash(
                                                                  Encoding.UTF8.GetBytes(
                                                                      new Regex("Sec-WebSocket-Key: (.*)")
                                                                      .Match(request)
                                                                      .Groups[1]
                                                                      .Value
                                                                      .Trim()
                                                                      + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
                                                                      )
                                                                  )
                                                              ) + Environment.NewLine
                                                          + Environment.NewLine);

                    stream.Write(response, 0, response.Length);
                }
                else
                {
                    if (!IsValidJson(request))
                    {
                        server.Stop();
                    }


                    _loggerService.LogMessage(SERVICE_NAME, "REQ: " + request,
                                              LogLevel.Debug);
                    ProcessTask(request);
                    _loggerService.LogMessage(SERVICE_NAME, _pipeClient.ReadString(),
                                              LogLevel.Debug);
                    var response = Encoding.UTF8.GetBytes("Data received");
                    stream.Write(response, 0, response.Length);
                }

                client.Close();
                server.Stop();
            }
        }