Beispiel #1
0
 public void StopWebServer()
 {
     try {
         KeepListening = false;
         HttpListener.Stop();
         HttpListener   = null;
         ListenerThread = null;
     }
     catch { }
 }
Beispiel #2
0
 public void Stop()
 {
     if (listener.IsListening)
     {
         listener.Stop();
     }
 }
Beispiel #3
0
 public void Dispose()
 {
     try
     {
         _running = false;
         _listener.Stop();
         _thread.Abort();
     }
     catch
     {
     }
 }
Beispiel #4
0
        static void Main(string[] args)
        {
            http.Prefixes.Add("http://*:80/");
            http.Start();
            Listen();
            string typedMessage;

            do
            {
                typedMessage = Console.ReadLine();
            } while (typedMessage != "EXIT");
            http.Stop();
        }
        public void ReadData(string path, string componentName, IDbProcessor dbProcessor)
        {
            System.Net.HttpListener web = null;
            try
            {
                web = new System.Net.HttpListener();
                web.Prefixes.Add(path);
                web.Start();

                do
                {
                    var ctx  = web.GetContext();
                    var req  = ctx.Request;
                    var data = new StreamReader(req.InputStream, req.ContentEncoding).ReadToEnd();

                    if (ProcessorMonitorContainer.ComponentStopper[componentName])
                    {
                        ProcessorMonitorContainer.ComponentStopper[componentName] = false;
                        break;
                    }

                    // parse json into an Entry array
                    var entries = JsonConvert.DeserializeObject <IEntry[]>(data);

                    foreach (var entry in entries)
                    {
                        var lvlType = LevelTypesHelper.GetLevelTypeFromString(entry.Level);

                        IEntry newEntry = EntryFactory.CreateNewEntry
                                          (
                            entry.Timestamp,
                            $"{entry.RenderedMessage}",
                            (int)lvlType,
                            componentName,
                            entry.Exception
                                          );
                        dbProcessor.WriteOne(componentName, newEntry);
                    }
                } while (!ProcessorMonitorContainer.ComponentStopper[componentName]);
            }
            finally
            {
                if (web != null && web.IsListening)
                {
                    web.Stop();
                }
            }
        }
Beispiel #6
0
 private void fluxListener()
 {
     using (var httpListener = new System.Net.HttpListener())
     {
         httpListener.Prefixes.Add("http://localhost:8811/");
         httpListener.Prefixes.Add("http://127.0.0.1:8811/");
         try
         {
             httpListener.Start();
         }
         catch (Exception ex)
         {
             Logger.QueueException("Flux Error", ex);
             return;
         }
         while (!fluxListenerTerminate && Thread.CurrentThread.ThreadState == ThreadState.Background)
         {
             //var ctx = httpListener.GetContext();
             var tsk = httpListener.GetContextAsync();
             if (!tsk.Wait(500))
             {
                 continue;
             }
             var ctx = tsk.Result;
             if (ctx.Request.HttpMethod == "POST")
             {
                 var ct = ctx.Request.QueryString.Get("ct");
                 if (!string.IsNullOrWhiteSpace(ct))
                 {
                     ctx.Response.StatusCode = 200;
                     System.Windows.Threading.Dispatcher.CurrentDispatcher.Invoke(
                         () => setColorTemp(colorTemp = int.Parse(ct)));
                     Logger.QueueLine("Color Temp Updated: {0}K", colorTemp);
                 }
                 else
                 {
                     ctx.Response.StatusCode = 404;
                 }
                 using (var strean = ctx.Response.OutputStream)
                 {
                 }
             }
         }
         Logger.QueueLine("Stopping f.lux listener");
         Task.WaitAll(Logger.FlushQueueAsync());
         httpListener.Stop();
     }
 }
Beispiel #7
0
        private static void IsHttpSysLocked(int port, bool https = false)
        {
            var urlPrefixTemplate = https ? "https://+:{0}/" : "http://+:{0}/";
            var Prefix            = string.Format(urlPrefixTemplate, port);

            var Listener = new System.Net.HttpListener
            {
                IgnoreWriteExceptions = true,
                Prefixes = { Prefix }
            };

            Listener.Start();

            Thread.SpinWait(1);
            Listener.Stop();
        }
Beispiel #8
0
        private void _Server()
        {
            Trace.TraceInformation("Enter.");

            System.Net.HttpListener _Listener = null;
            string sResponse = string.Empty;

            try
            {
                _Listener = new System.Net.HttpListener();
                _Listener.Prefixes.Add("http://" + _WebServerIP + ":" + _WebServerPort + "/" + _WebServerURIPrefix + "/");
                _Listener.Start();

                Trace.TraceInformation("Listener started for prefix " + "http://" + _WebServerIP + ":" + _WebServerPort + "/" + _WebServerURIPrefix + "/");

                if (Started != null)
                {
                    Started(this, new EventArgs());
                }

                do
                {
                    Trace.TraceInformation("Listening for request to be processed asyncronously.");

                    IAsyncResult result = _Listener.BeginGetContext(_Callback, _Listener);

                    Trace.TraceInformation("Waiting for request to be processed asyncronously.");

                    result.AsyncWaitHandle.WaitOne();

                    Trace.TraceInformation("Request processed asyncronously.");
                } while (true);
            }
            catch (System.Threading.ThreadAbortException abortEx)
            {
                Trace.TraceError("ThreadAbortException:" + abortEx.Message + Environment.NewLine + "StackTrace:" + abortEx.StackTrace);

                System.Threading.Thread.ResetAbort();

                _Abort.Set();

                if (Aborted != null)
                {
                    Aborted(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                Trace.TraceError("Exception:" + ex.Message + Environment.NewLine + "StackTrace:" + ex.StackTrace);

                _Abort.Set();

                if (Error != null)
                {
                    Error(this, new WebServerEventArgs("Exception:" + ex.Message + Environment.NewLine + "StackTrace:" + ex.StackTrace));
                }
            }
            finally
            {
                if (_Listener != null)
                {
                    if (_Listener.IsListening)
                    {
                        _Listener.Stop();
                    }
                }

                _Listener = null;
            }

            if (Stopped != null)
            {
                Stopped(this, new EventArgs());
            }
        }
 /// <summary>
 /// Stop listener
 /// </summary>
 public void Stop()
 {
     _listener.Stop();
 }
Beispiel #10
0
 public void Dispose()
 {
     _listener.Stop();
     _listener.Close();
     _handlers.Clear();
 }