Beispiel #1
0
        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);
                }
            }
        }
Beispiel #2
0
        /// <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 void queryDisconnected()
        {
            if (!isValid)
            {
                return;
            }

            ThreadPool2.QueueUserWorkItem(new WaitCallback(_queryDisconnected), "preloading tiles");
        }
Beispiel #4
0
 private void DlgPdaExport_Load(object sender, System.EventArgs e)
 {
     Project.ClearPopup();
     Cursor.Current         = Cursors.WaitCursor;
     this.messageLabel.Text = "\nPlease wait, preparing data...";
     //Project.threadPool.PostRequest (new WorkRequestDelegate (prepareFiles), "ProcessRecentFileItemClick");
     ThreadPool2.QueueUserWorkItem(new WaitCallback(prepareFiles), "DlgPdaExport");
     this.saveButton.Focus();
     this.Enabled = false;
 }
Beispiel #5
0
        /// <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);
            }
        }
Beispiel #6
0
        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);
        }
Beispiel #7
0
        private void btnThreadPool_Click(object sender, EventArgs e)
        {
            ThreadPool2 threadPool = new ThreadPool2();

            threadPool.Do();
        }
Beispiel #8
0
        //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;
        }
Beispiel #9
0
 private void importButton_Click(object sender, System.EventArgs e)
 {
     //Project.threadPool.PostRequest (new WorkRequestDelegate (Run), "import geocache");
     ThreadPool2.QueueUserWorkItem(new WaitCallback(Run), "import geocache");
     importButton.Enabled = false;
 }
Beispiel #10
0
        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);
        }
Beispiel #11
0
        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);
        }
Beispiel #12
0
 private void previewButton_Click(object sender, System.EventArgs e)
 {
     ThreadPool2.EmptyQueue();
     action(true);
 }