private void dataGridView1_DataSourceChanged(object sender, EventArgs e) { var lastchanged = cfiles.OrderByDescending(f => f.LastModified).Take(10).ToList <CoordFile>(); Font font = new Font("Arial", 9); for (int i = 0; i < lastchanged.Count; i++) { CoordFile cf = lastchanged[i]; int ic = (lastchanged.Count * 2) - (i + 5); Color color = Color.FromArgb(ic * 7, ic * 15, ic * 15); if (IsToday(cf.LastModified)) { color = Color.DarkGreen; } dataGridView1.Rows[i].DefaultCellStyle = new DataGridViewCellStyle() { Font = font, BackColor = color, ForeColor = Color.FromArgb((255 - color.R), (255 - color.G), (255 - color.B)) }; } dataGridView1.Columns["FullName"].Visible = false; dataGridView1.Columns["Url"].Visible = false; dataGridView1.AutoResizeColumns(); }
private void DownIfChanged(object state) { string strFile = state.ToString(); CoordFile cf = cfiles.FirstOrDefault(f => f.Url.Equals(strFile)); HttpWebRequest wrq = WebRequest.Create(strFile) as HttpWebRequest; wrq.Method = "GET"; wrq.IfModifiedSince = (cf != null ? cf.LastModified : DateTime.MinValue); try { using (WebResponse wr = wrq.GetResponse()) { using (StreamReader sr = new StreamReader(wr.GetResponseStream())) { string[] parts = strFile.Replace("http://", "").Split('/'); string strFilePath = strDownloadPath + "\\" + (parts.Length >= 3 ? parts[2] : parts[1]); if (cf != null) { strFilePath = cf.FullName; } if (File.Exists(strFilePath)) { File.Delete(strFilePath); } using (FileStream fs = new FileStream(strFilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { byte[] buffer = Encoding.Default.GetBytes(sr.ReadToEnd()); fs.Write(buffer, 0, buffer.Length); fs.Close(); } if (cf == null) { cfiles.AddCf(new CoordFile(new FileInfo(strFilePath))); } cf = cfiles.FirstOrDefault(f => f.FullName.Equals(strFilePath)); cf.LastModified = DateTime.Parse(wr.Headers["Last-Modified"]); cf.LastRefreshed = DateTime.Now; sr.Close(); } wr.Close(); } } catch (WebException we) { } finally { if (cf != null) { cf.LastRefreshed = DateTime.Now; } lock (added) { added.Add(strFile); } if (icntDone >= cfiles.Count()) { this.UseWaitCursor = false; //Cursor = Cursors.Default; } } }