コード例 #1
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);
        }
コード例 #2
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);
        }