private static void ReadDetails( ref RapidFireModisRecord rfmr ) { using (StreamReader sr = new StreamReader(rfmr.DetailFilePath, System.Text.Encoding.UTF8)) { rfmr.Description = sr.ReadLine(); string regionString = sr.ReadLine(); if (regionString.IndexOf("region:") != -1) { rfmr.regionCode = regionString.Split(':')[1].Trim(); } string temp = sr.ReadLine(); while (temp.IndexOf("projection:") == -1 && temp.IndexOf("sat:") == -1) { rfmr.Description += " [" + temp + "]"; temp = sr.ReadLine(); } while (temp.IndexOf("sat:") != -1) { if (rfmr.satellite != null && rfmr.satellite.Length > 2) rfmr.satellite += " & " + temp.Split(':')[1].Trim(); else rfmr.satellite = temp.Split(':')[1].Trim(); temp = sr.ReadLine(); } if (temp.IndexOf("projection:") != -1) { rfmr.Projection = temp.Split(':')[1].Trim(); temp = sr.ReadLine(); } else { Log.Write(Log.Levels.Error, "RFMR", "Problem parsing record '" + rfmr.Title + "'."); } while (temp != null) { string n = (temp.Split(':')[1].Replace("+", "").Trim()); if (temp.IndexOf("UL lon:") != -1) { rfmr.west = Single.Parse(n, CultureInfo.InvariantCulture ); } else if (temp.IndexOf("UL lat:") != -1) { rfmr.north = Single.Parse(n, CultureInfo.InvariantCulture ); } else if (temp.IndexOf("LR lon:") != -1) { rfmr.east = Single.Parse(n, CultureInfo.InvariantCulture ); } else if (temp.IndexOf("LR lat:") != -1) { rfmr.south = Single.Parse(n, CultureInfo.InvariantCulture ); } temp = sr.ReadLine(); } } }
void ProcessRecord( NameValueCollection fields ) { // process the record somewhere string projection = fields["projection"]; if (projection == null) return; // We currently only support "geographic projection if (projection.IndexOf("Plate Carree") < 0) return; string worldFiles = fields["world files"]; if (worldFiles == null) return; if(worldFiles.Length <= 3) return; string images = fields["images"]; if (images==null) return; string[] parsedImages = images.Trim().Split(' '); if (parsedImages.Length <= 0) return; string title = fields["record"]; if (title == null) return; RapidFireModisRecord rfmr = new RapidFireModisRecord(); rfmr.Title = title.Trim(); rfmr.ImagePaths = parsedImages; string rawDateString = rfmr.Title.Split('.')[1].Substring(1); DateTime dt = new DateTime( Int32.Parse(rawDateString.Substring(0, 4)), 1, 1) + System.TimeSpan.FromDays(Double.Parse(rawDateString.Substring(4, 3)) - 1); // TODO: Incremental download (date range) // if (dateTimePickerBeginDate.Value > dt) // return; rfmr.dateString = String.Format(CultureInfo.InvariantCulture, "{0}/{1}/{2}", dt.Month, dt.Day, dt.Year); // We need the info file for each record.... string moreInfoUrl = "http://rapidfire.sci.gsfc.nasa.gov/gallery/" + parsedImages[0].Split('/')[0].Trim() + "/" + rfmr.Title + ".txt"; lock (this.modisList.SyncRoot) { if (this.modisList.Contains(rfmr.Title)) return; } if (!File.Exists(rfmr.DetailFilePath)) { try { this.labelStatus.Text = string.Format(CultureInfo.CurrentCulture, "Downloading {0}/{1}", progressBar.Value,progressBar.Maximum); using (WebDownload client = new WebDownload(moreInfoUrl)) client.DownloadFile(rfmr.DetailFilePath); } catch (Exception) { //Delete the file in case it was only partially saved... if (File.Exists(rfmr.DetailFilePath)) File.Delete(rfmr.DetailFilePath); return; } } if (new FileInfo(rfmr.DetailFilePath).Length<=0) return; ReadDetails( ref rfmr ); lock (this.modisList.SyncRoot) { this.modisList.Add(rfmr.Title, rfmr); } using (StreamWriter sw = new StreamWriter(CacheDirectory + "\\CachedModisListNew.txt", true, System.Text.Encoding.UTF8)) { sw.WriteLine(rfmr.Title); sw.WriteLine(rfmr.Description); sw.WriteLine(rfmr.dateString); sw.Write(rfmr.ImagePaths[0]); for (int image = 1; image < rfmr.ImagePaths.Length; image++) sw.Write("*" + rfmr.ImagePaths[image]); sw.Write(Environment.NewLine); sw.WriteLine(rfmr.west.ToString(CultureInfo.InvariantCulture)); sw.WriteLine(rfmr.south.ToString(CultureInfo.InvariantCulture)); sw.WriteLine(rfmr.east.ToString(CultureInfo.InvariantCulture)); sw.WriteLine(rfmr.north.ToString(CultureInfo.InvariantCulture)); } }
private void loadSavedFileList(string filePath) { if(!File.Exists(filePath)) return; using( StreamReader fileReader = new StreamReader(filePath, System.Text.Encoding.UTF8) ) { try { string line = fileReader.ReadLine(); while(line != null) { RapidFireModisRecord rfmr = new RapidFireModisRecord(); rfmr.Title = line.Trim(); rfmr.Description = fileReader.ReadLine().Trim().Replace("<br>", Environment.NewLine); rfmr.dateString = fileReader.ReadLine().Trim(); string imageLine = fileReader.ReadLine().Trim(); rfmr.ImagePaths = imageLine.Split('*'); rfmr.west = Single.Parse(fileReader.ReadLine().Trim(), CultureInfo.InvariantCulture); rfmr.south = Single.Parse(fileReader.ReadLine().Trim(), CultureInfo.InvariantCulture); rfmr.east = Single.Parse(fileReader.ReadLine().Trim(), CultureInfo.InvariantCulture); rfmr.north = Single.Parse(fileReader.ReadLine().Trim(), CultureInfo.InvariantCulture); lock(this.modisList.SyncRoot) { this.modisList.Add(rfmr.Title, rfmr); } line = fileReader.ReadLine(); } } catch { if(File.Exists(filePath)) File.Delete(filePath); } } }
private void UpdateIcon(RapidFireModisRecord rfmr, string iconImagePath, bool show, bool exists ) { if(!show) { if(exists) RemoveIconFromCurrentList(rfmr); return; } if(!exists) AddIconToCurrentList(rfmr, iconImagePath); }
private void AddIconToCurrentList(RapidFireModisRecord rfmr, string iconFilePath) { if(this.iconSet == null) { return; } lock(this.currentList.SyncRoot) { if(!this.currentList.Contains(rfmr.Title)) { int imageIndex = 0; if(this.radioButtonResolution1km.Checked) { for(int i = 0; i < rfmr.ImagePaths.Length; i++) { if(rfmr.ImagePaths[i].IndexOf("1km") != -1) { imageIndex = i; break; } } } else if(this.radioButtonResolution500m.Checked) { for(int i = 0; i < rfmr.ImagePaths.Length; i++) { if(rfmr.ImagePaths[i].IndexOf("500m") != -1) { imageIndex = i; break; } } } else if(this.radioButtonResolution250m.Checked) { for(int i = 0; i < rfmr.ImagePaths.Length; i++) { if(rfmr.ImagePaths[i].IndexOf("250m") != -1) { imageIndex = i; break; } } } string[] titleParts = rfmr.Title.Split('.'); string dateString = titleParts[1].Replace("A", ""); int year = Int32.Parse(dateString.Substring(0,4), CultureInfo.InvariantCulture); int dayOfYear = Int32.Parse(dateString.Substring(4,3), CultureInfo.InvariantCulture); System.DateTime dt = new DateTime(year,1,1); dt = dt.AddDays(dayOfYear - 1); dt = dt.AddHours(Double.Parse(titleParts[2].Substring(0,2), CultureInfo.InvariantCulture)); dt = dt.AddMinutes(Double.Parse(titleParts[2].Substring(2,2), CultureInfo.InvariantCulture)); string desc = String.Format(CultureInfo.CurrentCulture,"{0} ({1} @ {2})\n{3}", titleParts[0],dt.ToShortDateString(), dt.ToShortTimeString(), rfmr.Description); string iconDirectory = Path.Combine( Path.Combine( MainApplication.Settings.DataPath, "Icons" ), "Modis" ); string iconFullPath = Path.Combine( iconDirectory, iconFilePath ); iconSet.AddDownloadableIcon(rfmr.Title, 0, rfmr.west, rfmr.south, rfmr.east, rfmr.north, "http://rapidfire.sci.gsfc.nasa.gov/gallery/" + rfmr.ImagePaths[imageIndex], CacheDirectory + "\\" + rfmr.ImagePaths[imageIndex].Replace("/","\\"), iconFullPath, World.Settings.ModisIconSize, desc); this.currentList.Add(rfmr.Title, rfmr); } } }
private void RemoveIconFromCurrentList(RapidFireModisRecord rfmr) { lock(this.currentList.SyncRoot) { if(this.currentList.Contains(rfmr.Title)) { this.iconSet.RemoveDownloadableIcon(rfmr.Title); this.currentList.Remove(rfmr.Title); } } }