private void ProcessRequestHandler(Task <HttpListenerContext> result) { var context = result.Result; if (!listener.IsListening) { return; } // Start new listener which replace this listener.GetContextAsync().ContinueWith(ProcessRequestHandler); // Read request string request = new StreamReader(context.Request.InputStream).ReadToEnd(); // Prepare response var responseBytes = handler.Invoke(request); context.Response.ContentLength64 = responseBytes.Length; var output = context.Response.OutputStream; output.WriteAsync(responseBytes, 0, responseBytes.Length); output.Close(); }
public TViewModel Update(Guid Id, TViewModel data, ProcessDataDelegate <TModel> processDelegate = null) { var _store = Store; if (!ReadMode && _store != null) { TModel item = (TModel)Activator.CreateInstance(typeof(TModel), new object[] { }); item.LoadFrom(data); _store.Save(item, (x) => { x = processDelegate?.Invoke(x) ?? x; if (CheckHashChange(x)) { return(x); } return(null); }); StoreChanges(); data.LoadFrom(item); } else if (ReadMode) { throw new AccessViolationException("Repository is in Read Mode"); } return(data); }