Esempio n. 1
0
        private void InitTask(HttpListenerContext context)
        {
            try
            {
                var task = this.ProcessRequestAsync(context);
                task.ContinueWith(x => HandleError(x.Exception, context), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.AttachedToParent);

                //if (task.Status == TaskStatus.Created)
                //{
                //    task.RunSynchronously();
                //}
            }
            catch (Exception ex)
            {
                HandleError(ex, context);
            }
        }
Esempio n. 2
0
        public FeatureContext(HttpListenerContext context)
        {
            _context            = context;
            _onCompletedActions = new List <Tuple <Func <object, Task>, object> >();
            _onStartingActions  = new List <Tuple <Func <object, Task>, object> >();

            Features = new FeatureCollection();
            Features.Set <IHttpRequestFeature>(this);
            Features.Set <IHttpResponseFeature>(this);
            Features.Set <IHttpConnectionFeature>(this);
            Features.Set <IHttpSendFileFeature>(this);
            Features.Set <IHttpBufferingFeature>(this);

            _requestScheme = context.Request.Url.Scheme;
            _requestPath   = Uri.UnescapeDataString(context.Request.Url.AbsolutePath);

            _requestHeaders = new Http.HeaderDictionary(context.Request.Headers.Count);
            foreach (string key in context.Request.Headers)
            {
                _requestHeaders.Add(key, context.Request.Headers.Get(key));
            }
            _responseHeaders = new HeaderDictionary(context.Response.Headers);

            var buffer = new MemoryStream();

            _requestStream  = context.Request.InputStream;
            _responseStream = new ResponseStream(buffer, OnStart);

            _onFinished = async() =>
            {
                _context.Response.ContentLength64 = buffer.Length;

                buffer.Seek(0, SeekOrigin.Begin);
                await buffer.CopyToAsync(_context.Response.OutputStream);

                _context.Response.OutputStream.Flush();
            };
        }
Esempio n. 3
0
 private void HandleError(Exception ex, HttpListenerContext context)
 {
 }
Esempio n. 4
0
        private async Task ProcessRequestAsync(HttpListenerContext context)
        {
            var request  = context.Request;
            var response = context.Response;

            var localPath = request.Url.LocalPath.Trim('/');

            _logger.Info("Http {0} {1}", request.HttpMethod, localPath);

            try
            {
                if (string.Equals(localPath, "windowstate-maximized", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("maximized");
                }
                else if (string.Equals(localPath, "windowstate-normal", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("normal");
                }
                else if (string.Equals(localPath, "windowstate-minimized", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("minimized");
                }
                else if (string.Equals(localPath, "windowstate-fullscreen", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("fullscreen");
                }
                else if (string.Equals(localPath, "windowsize", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowSizeChanged();
                }
                else if (localPath.StartsWith("directshowplayer", StringComparison.OrdinalIgnoreCase))
                {
                    await _dsPlayerBridge.ProcessRequest(context, localPath).ConfigureAwait(false);
                }
                else if (localPath.StartsWith("fileexists", StringComparison.OrdinalIgnoreCase))
                {
                    using (var reader = new StreamReader(context.Request.InputStream))
                    {
                        var path   = reader.ReadToEnd();
                        var exists = File.Exists(path);
                        exists = false;
                        var bytes = Encoding.UTF8.GetBytes(exists.ToString().ToLower());
                        context.Response.ContentLength64 = bytes.Length;
                        context.Response.OutputStream.Write(bytes, 0, bytes.Length);
                    }
                }
                else if (localPath.StartsWith("directoryexists", StringComparison.OrdinalIgnoreCase))
                {
                    using (var reader = new StreamReader(context.Request.InputStream))
                    {
                        var path   = reader.ReadToEnd();
                        var exists = Directory.Exists(path);
                        var bytes  = Encoding.UTF8.GetBytes(exists.ToString().ToLower());
                        context.Response.ContentLength64 = bytes.Length;
                        context.Response.OutputStream.Write(bytes, 0, bytes.Length);
                    }
                }
            }
            finally
            {
                response.Close();
            }
        }
Esempio n. 5
0
 private void ProcessContext(HttpListenerContext context)
 {
     Task.Factory.StartNew(() => InitTask(context));
 }
 private void HandleError(Exception ex, HttpListenerContext context)
 {
 }
        private async Task ProcessRequestAsync(HttpListenerContext context)
        {
            var request = context.Request;
            var response = context.Response;

            var localPath = request.Url.LocalPath.Trim('/');
            _logger.Info("Http {0} {1}", request.HttpMethod, localPath);

            try
            {
                if (string.Equals(localPath, "windowstate-maximized", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("maximized");
                }
                else if (string.Equals(localPath, "windowstate-normal", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("normal");
                }
                else if (string.Equals(localPath, "windowstate-minimized", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("minimized");
                }
                else if (string.Equals(localPath, "windowstate-fullscreen", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowStateChanged("fullscreen");
                }
                else if (string.Equals(localPath, "windowsize", StringComparison.OrdinalIgnoreCase))
                {
                    _windowSync.OnElectronWindowSizeChanged();
                }
                else if (localPath.StartsWith("directshowplayer", StringComparison.OrdinalIgnoreCase))
                {
                    await _dsPlayerBridge.ProcessRequest(context, localPath).ConfigureAwait(false);
                }
            }
            finally
            {
                response.Close();
            }
        }
        private void InitTask(HttpListenerContext context)
        {
            try
            {
                var task = this.ProcessRequestAsync(context);
                task.ContinueWith(x => HandleError(x.Exception, context), TaskContinuationOptions.OnlyOnFaulted | TaskContinuationOptions.AttachedToParent);

                //if (task.Status == TaskStatus.Created)
                //{
                //    task.RunSynchronously();
                //}
            }
            catch (Exception ex)
            {
                HandleError(ex, context);
            }
        }
 private void ProcessContext(HttpListenerContext context)
 {
     Task.Factory.StartNew(() => InitTask(context));
 }