public void ProcessRequest(HttpContext context) { HttpResponse response = HttpContext.Current.Response; HttpResponseCancellationToken cancellationToken = new HttpResponseCancellationToken(response); NameValueCollection requestParameters = context.Request.QueryString; try { Filename = requestParameters["Meter"] + "_" + requestParameters["EventType"] + "_Event_" + requestParameters["eventID"] + ".zip"; response.ClearContent(); response.Clear(); response.AddHeader("Content-Type", ContentType); response.AddHeader("Content-Disposition", "attachment;filename=" + Filename); response.BufferOutput = true; using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { int eventID = int.Parse(requestParameters["eventID"]); Event evt = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", eventID); DateTime startDate = requestParameters.AllKeys.ToList().IndexOf("startDate") >= 0 ? DateTime.Parse(requestParameters["startDate"]) : evt.StartTime; DateTime endDate = requestParameters.AllKeys.ToList().IndexOf("endDate") >= 0 ? DateTime.Parse(requestParameters["endDate"]) : evt.EndTime; COMTRADEWriter.WriteResults(evt.MeterID, evt.LineID, startDate, endDate, response.OutputStream); } } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { response.End(); } }
public void ProcessRequest(HttpContext context) { HttpResponse response = HttpContext.Current.Response; HttpResponseCancellationToken cancellationToken = new HttpResponseCancellationToken(response); NameValueCollection requestParameters = context.Request.QueryString; try { Filename = requestParameters["Meter"] + "_" + requestParameters["EventType"] + "_Event_" + requestParameters["eventID"] + ".csv"; response.ClearContent(); response.Clear(); response.AddHeader("Content-Type", CsvContentType); response.AddHeader("Content-Disposition", "attachment;filename=" + Filename); response.BufferOutput = true; WriteTableToStream(requestParameters, response.OutputStream, response.Flush, cancellationToken); } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { response.End(); } }
/// <summary> /// Enables processing of HTTP web requests by a custom handler that implements the <see cref="IHostedHttpHandler"/> interface. /// </summary> /// <param name="request">HTTP request message.</param> /// <param name="response">HTTP response message.</param> /// <param name="cancellationToken">Propagates notification from client that operations should be canceled.</param> public Task ProcessRequestAsync(HttpRequestMessage request, HttpResponseMessage response, CancellationToken cancellationToken) { NameValueCollection requestParameters = request.RequestUri.ParseQueryString(); response.Content = new PushStreamContent((stream, content, context) => { try { SecurityPrincipal securityPrincipal = request.GetRequestContext().Principal as SecurityPrincipal; CopyModelAsCsvToStream(securityPrincipal, requestParameters, stream, null, cancellationToken); } catch (Exception ex) { LogExceptionHandler?.Invoke(ex); throw; } finally { stream.Close(); } }, new MediaTypeHeaderValue(CsvContentType)); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = GetModelFileName(requestParameters["ModelName"]) }; #if MONO return(Task.FromResult(false)); #else return(Task.CompletedTask); #endif }
public Task ProcessRequestAsync(HttpRequestMessage request, HttpResponseMessage response, CancellationToken cancellationToken) { NameValueCollection requestParameters = request.RequestUri.ParseQueryString(); string breaker = requestParameters["breaker"]; DateTime fromDate = DateTime.Parse(requestParameters["fromDate"]); DateTime toDate = DateTime.Parse(requestParameters["toDate"]); response.Content = new PushStreamContent((stream, content, context) => { try { Filename = (breaker == "0" ? "AllBreakers" : breaker) + "_" + fromDate.ToString("MM/dd/yyyy") + "_" + toDate.ToString("MM/dd/yyyy") + ".csv"; WriteTableToStream(breaker, fromDate, toDate, stream, null, cancellationToken); } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { stream.Close(); } }, new MediaTypeHeaderValue(CsvContentType)); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = Filename }; return(Task.CompletedTask); }
/// <summary> /// Enables processing of HTTP Web requests by a custom HttpHandler that implements the <see cref="IHttpHandler" /> interface. /// </summary> /// <param name="context">An <see cref="HttpContext" /> object that provides references to the intrinsic server objects (for example, Request, Response, Session, and Server) used to service HTTP requests.</param> public void ProcessRequest(HttpContext context) { HttpResponse response = context.Response; HttpResponseCancellationToken cancellationToken = new HttpResponseCancellationToken(response); NameValueCollection requestParameters = context.Request.QueryString; SecurityPrincipal securityPrincipal = context.User as SecurityPrincipal; response.ClearContent(); response.Clear(); response.AddHeader("Content-Type", CsvContentType); response.AddHeader("Content-Disposition", "attachment;filename=" + GetModelFileName(requestParameters["ModelName"])); response.BufferOutput = true; try { CopyModelAsCsvToStream(securityPrincipal, requestParameters, response.OutputStream, response.Flush, cancellationToken); } catch (Exception ex) { LogExceptionHandler?.Invoke(ex); throw; } finally { response.End(); } }
public void ProcessRequest(HttpContext context) { HttpResponse response = HttpContext.Current.Response; HttpResponseCancellationToken cancellationToken = new HttpResponseCancellationToken(response); NameValueCollection requestParameters = context.Request.QueryString; string breaker = requestParameters["breaker"]; DateTime fromDate = DateTime.Parse(requestParameters["fromDate"]); DateTime toDate = DateTime.Parse(requestParameters["toDate"]); try { Filename = (breaker == "0"? "AllBreakers": breaker) + "_" + fromDate.ToString("MM/dd/yyyy") + "_" + toDate.ToString("MM/dd/yyyy") + ".csv"; response.ClearContent(); response.Clear(); response.AddHeader("Content-Type", CsvContentType); response.AddHeader("Content-Disposition", "attachment;filename=" + Filename); response.BufferOutput = true; WriteTableToStream(breaker, fromDate, toDate, response.OutputStream, response.Flush, cancellationToken); } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { response.End(); } }
public Task ProcessRequestAsync(HttpRequestMessage request, HttpResponseMessage response, CancellationToken cancellationToken) { NameValueCollection requestParameters = request.RequestUri.ParseQueryString(); response.Content = new PushStreamContent((stream, content, context) => { try { Filename = requestParameters["Meter"] + "_" + requestParameters["EventType"] + "_Event_" + requestParameters["eventID"] + ".csv"; WriteTableToStream(requestParameters, stream, null, cancellationToken); } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { stream.Close(); } }, new MediaTypeHeaderValue(CsvContentType)); response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = Filename }; return(Task.CompletedTask); }
private async Task ProcessFileAsync(HttpContent file) { string csvFileData = await file.ReadAsStringAsync(); try { string[] csvRows = csvFileData.Split('\n'); string[] tableFields = csvRows[0].Split(','); for (int i = 0; i < tableFields.Length; i++) { tableFields[i] = tableFields[i].Trim(); tableFields[i] = tableFields[i].Trim(new char[] { '[', ']' }); } int[] fieldIndexes = new int[8]; fieldIndexes[0] = Array.IndexOf(tableFields, "AlarmID"); fieldIndexes[1] = Array.IndexOf(tableFields, "AlarmChannelID"); fieldIndexes[2] = Array.IndexOf(tableFields, "AlarmAlarmTypeID"); fieldIndexes[3] = Array.IndexOf(tableFields, "AlarmHourOfWeek"); fieldIndexes[4] = Array.IndexOf(tableFields, "AlarmSeverity"); fieldIndexes[5] = Array.IndexOf(tableFields, "AlarmHigh"); fieldIndexes[6] = Array.IndexOf(tableFields, "AlarmLow"); fieldIndexes[7] = Array.IndexOf(tableFields, "AlarmEnabled"); if (!fieldIndexes.Any(n => n < 0)) // Check if any indexes are negative (missing) { using (DataContext dataContext = new DataContext()) { TableOperations <HourOfWeekLimit> table = dataContext.Table <HourOfWeekLimit>(); for (int i = 1; i < csvRows.Length; ++i) { string[] row = csvRows[i].Split(','); HourOfWeekLimit newRecord = new HourOfWeekLimit() { ID = int.Parse(row[fieldIndexes[0]]), ChannelID = int.Parse(row[fieldIndexes[1]]), AlarmTypeID = int.Parse(row[fieldIndexes[2]]), HourOfWeek = int.Parse(row[fieldIndexes[3]]), Severity = int.Parse(row[fieldIndexes[4]]), High = double.Parse(row[fieldIndexes[5]]), Low = double.Parse(row[fieldIndexes[6]]), Enabled = int.Parse(row[fieldIndexes[7]]) }; table.UpdateRecord(newRecord); } } } } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } }
public Task ProcessRequestAsync(HttpRequestMessage request, HttpResponseMessage response, CancellationToken cancellationToken) { NameValueCollection requestParameters = request.RequestUri.ParseQueryString(); response.Content = new PushStreamContent((stream, content, context) => { try { using (AdoDataConnection connection = new AdoDataConnection("systemSettings")) { int eventID = int.Parse(requestParameters["eventID"]); Event evt = (new TableOperations <Event>(connection)).QueryRecordWhere("ID = {0}", eventID); DateTime startDate = requestParameters.AllKeys.ToList().IndexOf("startDate") >= 0 ? DateTime.Parse(requestParameters["startDate"]) : evt.StartTime; DateTime endDate = requestParameters.AllKeys.ToList().IndexOf("endDate") >= 0 ? DateTime.Parse(requestParameters["endDate"]) : evt.EndTime; COMTRADEWriter.WriteResults(evt.MeterID, evt.LineID, startDate, endDate, stream); } } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } finally { stream.Close(); } }, new MediaTypeHeaderValue(ContentType)); try { Filename = requestParameters["Meter"] + "_" + requestParameters["EventType"] + "_Event_" + requestParameters["eventID"] + ".zip"; response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment") { FileName = Filename }; } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } return(Task.CompletedTask); }
private async Task ProcessFileAsync(HttpContent file, string referrer) { string csvFileData = await file.ReadAsStringAsync(); try { string[] csvRows = csvFileData.Split('\n'); string[] tableFields = csvRows[0].Split(','); for (int i = 0; i < tableFields.Length; i++) { tableFields[i] = tableFields[i].Trim(); tableFields[i] = tableFields[i].Trim(new char[] { '[', ']' }); } if (referrer.Contains("ChannelsWithHourlyLimits.cshtml") || referrer.Contains("MetersWithHourlyLimits.cshtml") || referrer.Contains("HourOfWeekLimits.cshtml")) { int[] fieldIndexes = new int[8]; fieldIndexes[0] = Array.IndexOf(tableFields, "AlarmID"); fieldIndexes[1] = Array.IndexOf(tableFields, "AlarmChannelID"); fieldIndexes[2] = Array.IndexOf(tableFields, "AlarmAlarmTypeID"); fieldIndexes[3] = Array.IndexOf(tableFields, "AlarmHourOfWeek"); fieldIndexes[4] = Array.IndexOf(tableFields, "AlarmSeverity"); fieldIndexes[5] = Array.IndexOf(tableFields, "AlarmHigh"); fieldIndexes[6] = Array.IndexOf(tableFields, "AlarmLow"); fieldIndexes[7] = Array.IndexOf(tableFields, "AlarmEnabled"); if (!fieldIndexes.Any(n => n < 0)) // Check if any indexes are negative (missing) { using (DataContext dataContext = new DataContext()) { TableOperations <HourOfWeekLimit> table = dataContext.Table <HourOfWeekLimit>(); for (int i = 1; i < csvRows.Length; ++i) { string[] row = csvRows[i].Split(','); HourOfWeekLimit newRecord = new HourOfWeekLimit() { ID = int.Parse(row[fieldIndexes[0]]), ChannelID = int.Parse(row[fieldIndexes[1]]), AlarmTypeID = int.Parse(row[fieldIndexes[2]]), HourOfWeek = int.Parse(row[fieldIndexes[3]]), Severity = int.Parse(row[fieldIndexes[4]]), High = float.Parse(row[fieldIndexes[5]]), Low = float.Parse(row[fieldIndexes[6]]), Enabled = int.Parse(row[fieldIndexes[7]]) }; table.UpdateRecord(newRecord); } } } } else if (referrer.Contains("ChannelsWithNormalLimits.cshtml") || referrer.Contains("MetersWithNormalLimits.cshtml")) { int channelIdIndex = Array.IndexOf(tableFields, "ChannelID"); int highIndex = Array.IndexOf(tableFields, "ChannelHigh"); int lowIndex = Array.IndexOf(tableFields, "ChannelLow"); using (DataContext dataContext = new DataContext()) { TableOperations <AlarmRangeLimit> table = dataContext.Table <AlarmRangeLimit>(); for (int i = 1; i < csvRows.Length; ++i) { string[] row = csvRows[i].Split(','); AlarmRangeLimit record = table.QueryRecordWhere("ChannelID = {0}", int.Parse(row[channelIdIndex])); if (record == null) { continue; } record.High = float.Parse(row[highIndex]); record.Low = float.Parse(row[lowIndex]); table.UpdateRecord(record); } } } } catch (Exception e) { LogExceptionHandler?.Invoke(e); throw; } }
private void HandleException(Exception e) { if (!ExceptionHandling.IsNull()) { ExceptionHandling(this, EventArgs.Empty); } var logExceptionHandler = new LogExceptionHandler(LogException); logExceptionHandler.BeginInvoke(e, LogCallback, null); }