public override void ExecuteResult(ActionContext context) { EntityTag = GenerateEntityTag(context); FillRanges(context.HttpContext.Request); if (!(IsRangesValid(context.HttpContext.Response) && IsModificationDateValid(context.HttpContext.Request, context.HttpContext.Response) && IsEntityTagValid(context.HttpContext.Request, context.HttpContext.Response))) { return; } context.HttpContext.Response.Headers.Add("Last-Modified", FileModificationDate.ToString("r")); context.HttpContext.Response.Headers.Add("ETag", string.Format("\"{0}\"", EntityTag)); context.HttpContext.Response.Headers.Add("Accept-Ranges", "bytes"); if (!RangeRequest) { context.HttpContext.Response.Headers.Add("Content-Length", FileLength.ToString()); context.HttpContext.Response.ContentType = ContentType; context.HttpContext.Response.StatusCode = HTTP_STATUS_CODE_OK; if (context.HttpContext.Request.Method != "HEAD") { WriteEntireEntity(context.HttpContext.Response); } } else { var boundary = "---------------------------" + LocalTime.Now.Ticks.ToString("x"); context.HttpContext.Response.Headers.Add("Content-Length", GetContentLength(boundary).ToString()); if (!MultipartRequest) { context.HttpContext.Response.Headers.Add("Content-Range", string.Format("bytes {0}-{1}/{2}", RangesStartIndexes[0], RangesEndIndexes[0], FileLength)); context.HttpContext.Response.ContentType = ContentType; } else { context.HttpContext.Response.ContentType = string.Format("multipart/byteranges; boundary={0}", boundary); } context.HttpContext.Response.StatusCode = HTTP_STATUS_CODE_PARTIAL_CONTENT; if (context.HttpContext.Request.Method != "HEAD") { for (var i = 0; i < RangesStartIndexes.Length; i++) { if (MultipartRequest) { context.HttpContext.Response.Write(string.Format("--{0}\r\n", boundary)); context.HttpContext.Response.Write(string.Format("Content-Type: {0}\r\n", ContentType)); context.HttpContext.Response.Write(string.Format("Content-Range: bytes {0}-{1}/{2}\r\n\r\n", RangesStartIndexes[i], RangesEndIndexes[i], FileLength)); } if (!context.HttpContext.RequestAborted.IsCancellationRequested) { WriteEntityRange(context.HttpContext.Response, RangesStartIndexes[i], RangesEndIndexes[i]); if (MultipartRequest) { context.HttpContext.Response.Write("\r\n"); } } else { return; } } if (MultipartRequest) { context.HttpContext.Response.Write(string.Format("--{0}--", boundary)); } } } }
private void startScan() { dataGridView1.Rows.Clear(); dataGridView1.ClearSelection(); try { //setting variables DateTime FileModificationDate; DateTime lastRunTime; DateTime nextRunTime; TimeSpan duration; string sTreshold; string sDateDiff; string sDateDiff2; int iDays; int iHours; int iMinutes; int iMaxTime; int iElapsedTime; Boolean bToMuch = false; using (StreamReader sr = new StreamReader("Data.dat")) { String line = sr.ReadToEnd(); string sStatus; string[] lines = line.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); for (int i = 1; i < lines.Length; i++) { string[] tabs = lines[i].Split('\t'); if (string.IsNullOrEmpty(tabs[0]) == false) { FileModificationDate = File.GetLastWriteTime(tabs[2]); Boolean bFileExist = File.Exists(tabs[2]) ? true : false; if (bFileExist) { dateDifference(FileModificationDate); Int32.TryParse(tabs[3], out iDays); Int32.TryParse(tabs[4], out iHours); Int32.TryParse(tabs[5], out iMinutes); duration = new TimeSpan(iDays, iHours, iMinutes, 0); lastRunTime = FileModificationDate; nextRunTime = FileModificationDate.Add(duration); sTreshold = iDays.ToString() + ":" + iHours.ToString() + ":" + iMinutes.ToString(); sDateDiff = daysDiff.ToString() + ":" + hoursDiff.ToString() + ":" + minutesDiff.ToString(); sDateDiff2 = daysDiff.ToString() + " Days " + hoursDiff.ToString() + " Hours " + minutesDiff.ToString() + " Minutes"; bToMuch = false; iMaxTime = iDays * 24 * 60 + iHours * 60 + iMinutes; iElapsedTime = daysDiff * 24 * 60 + hoursDiff * 60 + minutesDiff; if (iMaxTime >= iElapsedTime) { bToMuch = false; } else { bToMuch = true; } if (bToMuch) { sStatus = "Warning"; this.dataGridView1.Rows.Add(tabs[1], lastRunTime.ToString(), nextRunTime.ToString(), sDateDiff2, sStatus); this.dataGridView1.Rows[i - 1].DefaultCellStyle.BackColor = Color.Yellow; //this.dataGridView1.Rows[i - 1].DefaultCellStyle.ForeColor = Color.White; this.dataGridView1.Rows[i - 1].Cells[4].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.ClearSelection(); } else { sStatus = "OK"; this.dataGridView1.Rows.Add(tabs[1], lastRunTime.ToString(), nextRunTime.ToString(), sDateDiff2, sStatus); this.dataGridView1.Rows[i - 1].Cells[4].Style.BackColor = Color.Green; this.dataGridView1.Rows[i - 1].Cells[4].Style.ForeColor = Color.White; this.dataGridView1.Rows[i - 1].Cells[4].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.ClearSelection(); } } else { this.dataGridView1.Rows.Add(tabs[1], "- File not found -", "- File not found -", "- File not found -", "Error"); this.dataGridView1.Rows[i - 1].DefaultCellStyle.BackColor = Color.Red; this.dataGridView1.Rows[i - 1].DefaultCellStyle.ForeColor = Color.White; this.dataGridView1.Rows[i - 1].Cells[1].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.Rows[i - 1].Cells[2].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.Rows[i - 1].Cells[3].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; this.dataGridView1.Rows[i - 1].Cells[4].Style.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.ClearSelection(); } } } } } catch (Exception sel) { this.dataGridView1.Rows.Add(sel.Message, "Error", "Error", "Error", "Error"); this.dataGridView1.RowsDefaultCellStyle.BackColor = Color.Red; this.dataGridView1.RowsDefaultCellStyle.ForeColor = Color.White; this.dataGridView1.RowsDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; } }
public void ManageMultipartDownload(/*Byte[] content, String name, HttpRequest request, HttpResponse response*/) { //Request = request; //Response = response; //FileName = name; ////if (FileContent == null) //// FileContent = File.ReadAllBytes(FilePath); //FileLength = content.Length; //FileContent = content; //ContentType = "application/pdf"; //Generate entity tag EntityTag = GenerateEntityTag(); //Get ranges from request GetRanges(Request); //If all validations are successful if (ChangeSignature || Validate(Request, Response)) { //Set common headers //Response.Buffer = false; Response.AddHeader("Last-Modified", FileModificationDate.ToString("r")); Response.AddHeader("ETag", String.Format("\"{0}\"", EntityTag)); //Response.Cache.SetCacheability(HttpCacheability.Public); //required for etag output //Response.Cache.SetETag(EntityTag); Response.AddHeader("Accept-Ranges", "bytes"); Response.ContentType = "application/pdf"; Response.AddHeader("Content-Disposition", "inline;filename=" + FileName); //If this is not range Request if (!RangeRequest) { //Set standard headers Response.AddHeader("Content-Length", FileLength.ToString()); //Response.AddHeader("Content-Type", "application/pdf"); //Set status code Response.StatusCode = 200; //If this is not HEAD Request if (!Request.HttpMethod.Equals("HEAD")) { //Write entire file to Response Console.WriteLine("Request.HttpMethod : " + Request.HttpMethod); Console.WriteLine("Write entire file to Response"); WriteEntireEntity(Response); } } //If this is range Request else { string boundary = "---------------------------" + DateTime.Now.Ticks.ToString("x"); //Compute and set content length Response.AddHeader("Content-Length", GetContentLength(boundary).ToString()); //If this is not multipart Request if (!MultipartRequest) { //Set content range and type Response.AddHeader("Content-Range", String.Format("bytes {0}-{1}/{2}", RangesStartIndexes[0], RangesEndIndexes[0], FileLength)); Response.ContentType = ContentType; } //Otherwise else { //Set proper content type Response.ContentType = String.Format("multipart/byteranges; boundary={0}", boundary); } //Set status code Response.StatusCode = 206; //If this not HEAD Request if (!Request.HttpMethod.Equals("HEAD")) { //For each Requested range for (int i = 0; i < RangesStartIndexes.Length; i++) { //If this is multipart Request if (MultipartRequest) { //Write additional multipart info Response.Write(String.Format("--{0}\r\n", boundary)); Response.Write(String.Format("Content-Type: {0}\r\n", ContentType)); Response.Write(String.Format("Content-Range: bytes {0}-{1}/{2}\r\n\r\n", RangesStartIndexes[i], RangesEndIndexes[i], FileLength)); } //Write range (with multipart separator if required) if (Response.IsClientConnected) { Console.Write("WriteEntityRange"); WriteEntityRange(Response, RangesStartIndexes[i], RangesEndIndexes[i]); if (MultipartRequest) { Response.Write("\r\n"); } Response.Flush(); } else { return; } } //If this is multipart Request if (MultipartRequest) { Response.Write(String.Format("--{0}--", boundary)); } } } } }