public async Task <string> Listen(string id, CancellationToken cancel)
        {
            if (httpListener.IsListening)
            {
                httpListener.Stop();
            }
            httpListener.Start();

            try
            {
                using (cancel.Register(httpListener.Stop))
                {
                    while (true)
                    {
                        var context = await httpListener.GetContextAsync().ConfigureAwait(false);

                        var foo        = context.Request;
                        var queryParts = HttpUtility.ParseQueryString(context.Request.Url.Query);

                        if (queryParts["state"] == id)
                        {
                            context.Response.Close();
                            return(queryParts["code"]);
                        }
                    }
                }
            }
            finally
            {
                httpListener.Stop();
            }
        }
Example #2
0
        public async Task <string> Listen(string id, CancellationToken cancel)
        {
            if (httpListener.IsListening)
            {
                httpListener.Stop();
            }
            httpListener.Start();

            try
            {
                using (cancel.Register(httpListener.Stop))
                {
                    while (true)
                    {
                        lastContext = await httpListener.GetContextAsync().ConfigureAwait(false);

                        var queryParts = HttpUtility.ParseQueryString(lastContext.Request.Url.Query);

                        if (queryParts["state"] == id)
                        {
                            return(queryParts["code"]);
                        }
                    }
                }
            }
            catch (Exception)
            {
                httpListener.Stop();
                throw;
            }
        }
Example #3
0
        /// <summary>
        /// Shut down the Web Service
        /// </summary>
        public void Stop()
        {
            List <IWebSocketConnection> connections;

            lock (_webSocketConnections)
            {
                connections = _webSocketConnections.ToList();
                _webSocketConnections.Clear();
            }

            foreach (var connection in connections)
            {
                try
                {
                    connection.Dispose();
                }
                catch
                {
                }
            }

            if (_listener != null)
            {
                _logger.Info("Stopping HttpListener...");
                var task = _listener.Stop();
                Task.WaitAll(task);
                _logger.Info("HttpListener stopped");
            }
        }
 /// <summary>
 /// Shut down the Web Service
 /// </summary>
 public void Stop()
 {
     if (_listener != null)
     {
         _listener.Stop();
     }
 }
Example #5
0
        /// <summary>
        /// The background thread method.
        /// </summary>
        private void BackgroundThreadMethod()
        {
            _log.Info("WebDAVServer background thread has started");
            try
            {
                _listener.Start();
                while (true)
                {
                    if (_stopEvent.WaitOne(0))
                    {
                        return;
                    }

                    var context = Listener.GetContext(_stopEvent);
                    if (context == null)
                    {
                        _log.Debug("Exiting thread");
                        return;
                    }

                    ThreadPool.QueueUserWorkItem(ProcessRequest, context);
                }
            }
            finally
            {
                _listener.Stop();
                _log.Info("WebDAVServer background thread has terminated");
            }
        }
Example #6
0
        private void BackgroundThreadMethod()
        {
            _Logger.Log(LogLevel.Informational, "WebDAVServer background thread has started");
            try
            {
                _Listener.Start();
                while (true)
                {
                    if (_StopEvent.WaitOne(0))
                    {
                        return;
                    }

                    IHttpListenerContext context = Listener.GetContext(_StopEvent);
                    if (context == null)
                    {
                        _Logger.Log(LogLevel.Debug, "Exiting thread");
                        return;
                    }

                    ThreadPool.QueueUserWorkItem(ProcessRequest, context);
                }
            }
            finally
            {
                _Listener.Stop();
                _Logger.Log(LogLevel.Informational, "WebDAVServer background thread has terminated");
            }
        }
Example #7
0
 /// <summary>
 /// Shut down the Web Service
 /// </summary>
 public void Stop()
 {
     if (_listener != null)
     {
         _logger.Info("Stopping HttpListener...");
         _listener.Stop();
         _logger.Info("HttpListener stopped");
     }
 }
Example #8
0
 /// <summary>
 /// Shut down the Web Service
 /// </summary>
 public void Stop()
 {
     if (_listener != null)
     {
         _logger.Info("Stopping HttpListener...");
         var task = _listener.Stop();
         Task.WaitAll(task);
         _logger.Info("HttpListener stopped");
     }
 }
Example #9
0
        private void Stop()
        {
            _stop.Set();
            _listenerThread.Join();

            lock (_lock)
            {
                _listener.Stop();
                _listener.Close();
                _stoped = true;
            }
        }
Example #10
0
        /// <summary>
        /// Dispose DionysosFX App
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                try
                {
                    if (_listener != null)
                    {
                        _listener.Stop();
                        _listener.Dispose();
                    }
                }
                catch
                {
                }
            }

            base.Dispose(disposing);
        }
Example #11
0
        public void Stop()
        {
            if (!IsListening || IsStopping)
            {
                return;
            }
            if (IsStarting)
            {
                throw new UnableToStopHostException("Cannot stop server until server has finished starting");
            }
            IsStopping = true;

            try
            {
                OnBeforeStop?.Invoke();

                StopEvent.Set();
                if (!TestingMode)
                {
                    Listening.Join();
                    foreach (var worker in Workers)
                    {
                        worker.Join();
                    }
                }
                Listener.Stop();

                if (!IsListening)
                {
                    OnAfterStop?.Invoke();
                }
            }
            catch (Exception e)
            {
                throw new UnableToStopHostException($"An error occured while trying to stop {GetType().FullName}", e);
            }
            finally
            {
                IsStopping = false;
            }
        }
        /// <summary>
        /// The background thread method.
        /// </summary>
        private void BackgroundThreadMethod()
        {
            _log.Info("WebDAVServer background thread has started");
            try
            {
                _listener.Start();
                Stopwatch sw = new Stopwatch();
                sw.Start();
                while (true)
                {
                    _log.DebugFormat("BackgroundThreadMethod poll ms: {0}", sw.ElapsedMilliseconds);
                    if (_stopEvent.WaitOne(0))
                    {
                        return;
                    }

                    sw.Reset();
                    IHttpListenerContext context = Listener.GetContext(_stopEvent);
                    if (context == null)
                    {
                        _log.Debug("Exiting thread");
                        return;
                    }
                    _log.DebugFormat("Queued Context request: {0}", context.Request.HttpMethod);

                    ThreadPool.QueueUserWorkItem(ProcessRequest, context);
                }
            }
            catch (Exception ex)
            {
                //This error occours if we are not able to queue a request, the whole webdav server
                //is terminating.
                _log.Error(String.Format("Web dav ended unexpectedly with error {0}", ex.Message), ex);
            }
            finally
            {
                _listener.Stop();
                _log.Info("WebDAVServer background thread has terminated");
            }
        }
Example #13
0
 /// <summary>
 /// Causes this instance to stop receiving incoming requests
 /// </summary>
 public void Stop()
 {
     _listener.Stop();
 }