public DloadNoForm(string dloadUrl, string dloadFileName, int msToWait) { // load file: DownloadThread dt = new DownloadThread(); dt.DownloadUrl = dloadUrl; dt.tile = this; dt.baseName = "dld-quiet"; dt.fileName = dloadFileName; dt.CompleteCallback += new DownloadCompleteHandler(completeCallback); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dloadUrl); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), dloadUrl); #if DEBUG LibSys.StatusBar.Trace("OK: DloadNoForm:DloadNoForm() - loading remote from " + dloadUrl); #endif // wait no more than specified time for delivery: if (msToWait > 0) { DateTime started = DateTime.Now; while (!m_completed && (DateTime.Now - started).Milliseconds < msToWait) { Thread.Sleep(100); } } }
public DloadNoForm(string dloadUrl, string dloadFileName, int msToWait) { // load file: DownloadThread dt = new DownloadThread(); dt.DownloadUrl = dloadUrl; dt.tile = this; dt.baseName = "dld-quiet"; dt.fileName = dloadFileName; dt.CompleteCallback += new DownloadCompleteHandler( completeCallback ); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dloadUrl); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), dloadUrl); #if DEBUG LibSys.StatusBar.Trace("OK: DloadNoForm:DloadNoForm() - loading remote from " + dloadUrl); #endif // wait no more than specified time for delivery: if(msToWait > 0) { DateTime started = DateTime.Now; while(!m_completed && (DateTime.Now - started).Milliseconds < msToWait) { Thread.Sleep(100); } } }
public DloadProgressForm(string dloadUrl, string dloadFileName, bool doRun, bool closeIfFailed) { m_doRun = doRun; // for help file only m_closeIfFailed = closeIfFailed; // for unimportant files - don't hold failed dload form open InitializeComponent(); downloadUrlTextBox.Text = dloadUrl; downloadFileTextBox.Text = dloadFileName; this.outputGroupBox.Enabled = true; this.bytesDownloadedTextBox.Text = ""; this.totalBytesTextBox.Text = ""; this.progressBar.Minimum = 0; this.progressBar.Maximum = 0; this.progressBar.Value = 0; // load Dld file and run it: DownloadThread dt = new DownloadThread(); dt.DownloadUrl = dloadUrl; dt.tile = this; dt.baseName = "dld"; dt.fileName = dloadFileName; dt.CompleteCallback += new DownloadCompleteHandler(completeCallback); dt.ProgressCallback += new DownloadProgressHandler(progressCallback); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dloadUrl); ThreadPool2.QueueUserWorkItem(new WaitCallback(dt.Download), dloadUrl); #if DEBUG LibSys.StatusBar.Trace("OK: DloadProgressForm:DloadProgressForm() - loading remote from " + dloadUrl); #endif this.Text = Project.PROGRAM_NAME_HUMAN + " - downloading file"; Project.setDlgIcon(this); }
public DloadProgressForm(string dloadUrl, string dloadFileName, bool doRun, bool closeIfFailed) { m_doRun = doRun; // for help file only m_closeIfFailed = closeIfFailed; // for unimportant files - don't hold failed dload form open InitializeComponent(); downloadUrlTextBox.Text = dloadUrl; downloadFileTextBox.Text = dloadFileName; this.outputGroupBox.Enabled = true; this.bytesDownloadedTextBox.Text = ""; this.totalBytesTextBox.Text = ""; this.progressBar.Minimum = 0; this.progressBar.Maximum = 0; this.progressBar.Value = 0; // load Dld file and run it: DownloadThread dt = new DownloadThread(); dt.DownloadUrl = dloadUrl; dt.tile = this; dt.baseName = "dld"; dt.fileName = dloadFileName; dt.CompleteCallback += new DownloadCompleteHandler( completeCallback ); dt.ProgressCallback += new DownloadProgressHandler( progressCallback ); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dloadUrl); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), dloadUrl); #if DEBUG LibSys.StatusBar.Trace("OK: DloadProgressForm:DloadProgressForm() - loading remote from " + dloadUrl); #endif this.Text = Project.PROGRAM_NAME_HUMAN + " - downloading file"; Project.setDlgIcon(this); }
/// <summary> /// helps when image file was corrupted, arranges reload. /// </summary> /// <param name="tile"></param> /// <param name="baseName"></param> public static void resetBackdrop(Tile tile, string baseName) { string imageFileName = Path.Combine(m_mapsPath, baseName + imageExt); try { if(Project.serverAvailable) { string imageUrl = getFileUrl(tile, baseName, imageFileName); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler( imageDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( imageDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), baseName); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:resetBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load on reset: " + e.Message); } }
public static Features getFeatures(Tile tile, string baseName) { string featuresFileName = Path.Combine(m_mapsPath, baseName + featuresExt); Features ret = null; try { if(m_featuresCache.ContainsKey(baseName)) { ret = (Features)m_featuresCache[baseName]; // may be still downloading if(ret != null) { ret.MarkUsed(); } #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - found in cache - " + ret); #endif return ret; } bool loadedFromFile = false; if(!Project.reloadRefresh && File.Exists(featuresFileName)) { try { ret = new Features(featuresFileName, baseName, true); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - loaded local"); #endif AddFeatures(baseName, ret); loadedFromFile = true; } catch {} } if(!loadedFromFile && m_mappingServers.Count > 0) { string featuresUrl = getFileUrl(tile, baseName, featuresFileName); if(featuresUrl == null) { ret = new Features(null, baseName, true); // doFill with null name makes it Empty AddFeatures(baseName, ret); return ret; } if(!m_featuresCache.ContainsKey(baseName)) { ret = new Features(featuresFileName, baseName, false); // fill later AddFeatures(baseName, ret); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = featuresUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = featuresFileName; dt.CompleteCallback += new DownloadCompleteHandler( featuresDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( featuresDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add this to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download)); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getFeatures() - tile '" + baseName + "' - loading remote from " + featuresUrl); #endif } } } catch (Exception e) { LibSys.StatusBar.Error("file '" + featuresFileName + "' failed to load: " + e.Message); } // whatever happened before, returning null is not an option. if(ret == null) { ret = new Features(null, baseName, true); // doFill with null name makes it Empty AddFeatures(baseName, ret); } return ret; }
public static Backdrop getBackdrop(Tile tile, string baseName) { string imageFileName = Path.Combine(m_mapsPath, baseName + imageExt); Backdrop ret = null; try { if(m_backdropCache.ContainsKey(baseName)) { ret = (Backdrop)m_backdropCache[baseName]; // may be IsEmpty, if proven that can't download ret.MarkUsed(); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - found in cache - " + ret); #endif return ret; } bool loadedFromFile = false; if(!Project.reloadRefresh && File.Exists(imageFileName)) { try { ret = new Backdrop(imageFileName, baseName, true); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loaded from file"); #endif AddBackdrop(baseName, ret); loadedFromFile = true; } catch {} } if(!loadedFromFile && m_mappingServers.Count > 0) { string imageUrl = getFileUrl(tile, baseName, imageFileName); if(imageUrl == null) { ret = new Backdrop(null, baseName, true); // doFill with null name makes it Empty AddBackdrop(baseName, ret); return ret; } if(!m_backdropCache.ContainsKey(baseName)) { ret = new Backdrop(imageFileName, baseName, false); // fill later AddBackdrop(baseName, ret); DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = tile; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler( imageDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( imageDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download)); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } #if DEBUG else { LibSys.StatusBar.Trace("OK: TileCache:getBackdrop() - tile '" + baseName + "' - already in cache"); } #endif } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load: " + e.Message); } // whatever happened before, returning null is not an option. if(ret == null) { ret = new Backdrop(null, baseName, true); // doFill with null name makes it Empty AddBackdrop(baseName, ret); } return ret; }
//private void Run(object state, DateTime requestEnqueueTime) private void Run(object state) { string emailText = importTextBox.Text; string lineToSearch = "http://www.geocaching.com/seek/cache_details.asp"; m_errorCount = 0; //ArrayList links = new ArrayList(); int nCaches; int gcCount = 0; int lineno = 0; string line; StringReader stream = new StringReader(emailText); // first, count the links to make sure there are some, and to set progress bar maximum: try { while((line = stream.ReadLine()) != null) { lineno++; if(line.IndexOf(lineToSearch) != -1) { gcCount++; //links.Add(line.Trim()); } } } catch {} nCaches = gcCount; if(nCaches == 0) { statusLabel.Text = "Error: pasted text does not contain links to geocache pages."; } else { statusLabel.Text = "OK: email contains " + nCaches + " caches"; progressBar.Maximum = nCaches; progressBar.Minimum = 0; // bring up Progress monitor form, first sleep in the loop will give it some time to initialize: //Project.threadPool.PostRequest (new WorkRequestDelegate (RunPM), "import geocache"); ThreadPool2.QueueUserWorkItem (new WaitCallback (RunPM), "import geocache"); lineno = 0; gcCount = 0; try { stream = new StringReader(emailText); while((line = stream.ReadLine()) != null && gcCount < m_maxLinks && !m_stop) { lineno++; try { if(line.IndexOf(lineToSearch) != -1) { // try not to overload the server: Thread.Sleep(gcCount == 0 ? 1000 : m_processingDelaySec * 1000); gcCount++; progressBar.Value = gcCount; string link = line.Trim(); statusLabel.Text = "IP: processing " + link + " - " + gcCount + " of " + nCaches; DownloadThread dt = new DownloadThread(); dt.DownloadUrl = link; dt.tile = null; int pos = link.IndexOf("ID="); dt.baseName = pos < 0 ? link : link.Substring(pos); dt.fileName = ""; dt.CompleteCallback += new DownloadCompleteHandler( gcDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( gcDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), dt.baseName); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), dt.baseName); } } catch (Exception ee) { LibSys.StatusBar.Error(" line=" + lineno + " " + ee.Message); } } } catch {} statusLabel.Text = "OK: finished processing, " + gcCount + " links processed, " + m_errorCount + " errors"; if(gcCount >= m_maxLinks) { statusLabel.Text += " [limit " + m_maxLinks + " reached]"; } WaypointsCache.RefreshWaypointsDisplayed(); m_pictureManager.Refresh(); } importButton.Enabled = true; }
/// <summary> /// serves silent preload /// </summary> public static void downloadIfMissing(string baseName) { string imageFileName = tileImagePath(baseName); try { if(m_backdropCache.ContainsKey(baseName) || File.Exists(imageFileName) || !Project.serverAvailable) { return; } string imageUrl = getImageUrl(baseName); if(!m_backdropCache.ContainsKey(baseName)) { DownloadThread dt = new DownloadThread(); dt.DownloadUrl = imageUrl; dt.tile = null; dt.baseName = baseName; dt.fileName = imageFileName; dt.CompleteCallback += new DownloadCompleteHandler( imageDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( imageDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); // tilesBeingLoadedCount++; //add dt worker method to the thread pool / queue a task //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), baseName); ThreadPool2.QueueUserWorkItem (new WaitCallback (dt.Download), baseName); #if DEBUG LibSys.StatusBar.Trace("OK: TerraserverCache:getBackdrop() - tile '" + baseName + "' - loading remote from " + imageUrl); #endif } else { //LibSys.StatusBar.Trace("OK: TerraserverCache:getBackdrop() - tile '" + baseName + "' - already in cache"); } } catch (Exception e) { LibSys.StatusBar.Error("file '" + imageFileName + "' failed to load: " + e.Message); } }
private static void FetchEarthquakes() { if(!Project.drawEarthquakes) { return; } ArrayList UrlList = new ArrayList(); /* http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs7day-M1.txt http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs1day-M1.txt http://earthquake.usgs.gov/eqcenter/recenteqsww/catalogs/eqs1hour-M1.txt */ // See http://earthquake.usgs.gov/eqcenter/recenteqsww/Quakes/quakes_all.php for data feeds UrlList.Add(new UrlListStruct("http://earthquake.usgs.gov/eqcenter/catalogs/eqs1hour-M1.txt", "neic-lasthour-csv", new FormatProcessor(processBulletinCsv))); // current UrlList.Add(new UrlListStruct("http://earthquake.usgs.gov/eqcenter/catalogs/eqs1day-M1.txt", "neic-lastday-csv", new FormatProcessor(processBulletinCsv))); // current UrlList.Add(new UrlListStruct("http://earthquake.usgs.gov/eqcenter/catalogs/eqs7day-M1.txt", "neic-sevendays-csv", new FormatProcessor(processBulletinCsv))); // current // UrlList.Add(new UrlListStruct("http://earthquake.usgs.gov/recenteqsww/Quakes/quakes_all.html", // "neic-bulletin", new FormatProcessor(processBulletin))); // current UrlList.Add(new UrlListStruct("http://neic.usgs.gov/neis/qed/", "neic-qed", new FormatProcessor(processQed))); // last 30 days // UrlList.Add(new UrlListStruct("http://www.data.scec.org/recenteqs/Quakes/quakes0.html", // "scec-quakes0", new FormatProcessor(processQuakes0))); // Southern CA // // UrlList.Add(new UrlListStruct("http://tux.wr.usgs.gov/Quakes/quakes0.html", // "hawaii-quakes0", new FormatProcessor(processQuakes0))); // Hawaii // // UrlList.Add(new UrlListStruct("http://www.ess.washington.edu/recenteqs/Quakes/quakes0.htm", // "wa-quakes0", new FormatProcessor(processQuakes0))); // NortWest US // the 7-days list seems to be obsolete, contains June 2004 data: // UrlList.Add(new UrlListStruct("http://neic.usgs.gov/neis/qed/last_seven_days.html", // "neic-last_seven_days", new FormatProcessor(process7Days))); // last 7 days /* // this just hangs waiting. doesn't look like finger is supoported. UrlList.Add(new UrlListStruct("finger://gldfs.cr.usgs.gov/quake", "gldfs", new FormatProcessor(processQuakes0))); // Gldfs */ m_threadCount = 0; foreach(UrlListStruct uls in UrlList) { string filename = Project.GetMiscPath(uls.source + ".html"); if(Project.doFetchEqHtml) { DownloadThread dt = new DownloadThread(); dt.DownloadUrl = uls.url; dt.tile = uls; dt.baseName = uls.url; dt.fileName = filename; dt.CompleteCallback += new DownloadCompleteHandler( eqDownloadCompleteCallback ); dt.ProgressCallback += new DownloadProgressHandler( eqDownloadProgressCallback ); dt.addMonitoredMethod = new AddMonitoredMethod(ProgressMonitor.addMonitored); //add dt worker method to the thread pool / queue a task m_threadCount++; //Project.threadPool.PostRequest (new WorkRequestDelegate (dt.Download), uls.url); ThreadPool2.QueueUserWorkItem(new WaitCallback (dt.Download), uls.url); LibSys.StatusBar.Trace("IP: - loading remote from " + uls.url); } else { uls.processor(uls.url, filename, uls.source); } } if(m_threadCount <= 0 && m_pictureManager != null) // too quick if fetching { RefreshEarthquakesDisplayed(); m_pictureManager.Refresh(); } }