private void HandleClient(HttpListenerContext client) { try { byte[] data; if (client.Request.RawUrl != "/api/dump-report" || client.Request.HttpMethod != "POST") { var msg = "The requested resource could not be found."; client.SendResponseAndClose(msg, 404); return; } else { var sc = 200; var reqBytes = new byte[client.Request.ContentLength64]; using (var ms = new MemoryStream()) { client.Request.InputStream.CopyTo(ms); reqBytes = ms.ToArray(); } var isZipped = client.Request.Headers["Content-Encoding"]?.Contains("gzip") ?? false; var strData = RequestHandler.HandleReportRequest(reqBytes, isZipped, out sc); client.Response.StatusCode = sc; data = Encoding.UTF8.GetBytes(strData); if (sc == 200) { NewReport?.Invoke(strData); } } WriteData(ref client, data); } // Ignore not being able to send the response if the client left. catch (HttpListenerException ex) // Mono throws error code ???, .NET throws error code 64. when(/*(onMono && ex.NativeErrorCode == 0) || */ (!onMono && (ex.NativeErrorCode == 64 || ex.NativeErrorCode == 1229))) { } catch (Exception ex) { OnException?.Invoke(ex); try { var msg = "An error occurred while processing your request."; client.SendResponseAndClose(msg, 500); } catch { client.Response.Abort(); } } }
public void Push(MustAssertionReport report) { var _observers = _Observers.ToArray(); var _observerTasks = new Task[_observers.Length]; for (var _i = 0; _i < _observers.Length; _i++) { var _observer = _observers[_i].Value; _observerTasks[_i] = Task.Run(() => _observer.OnNext(report)); } Task.WaitAll(_observerTasks); NewReport?.Invoke(report); }
public void FireNewReport(string rptdVarQualityLog, string rptdVarTimestampLog, string rptdVarPathLog, string rptdVarDescriptionLog, string rptdVarValueLog) { NewReport?.Invoke(rptdVarQualityLog, rptdVarTimestampLog, rptdVarPathLog, rptdVarDescriptionLog, rptdVarValueLog); }