Beispiel #1
0
        /// <summary>
        /// Put a new request in the queue. Returns a DataRequestDescriptor matching the request. If there is
        /// already a request pending for the same source, the existing descriptor is returned.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        static public DataRequest Request(DataRequestDescriptor request)
        {
            // TODO: actually parse the request and differentiate between different DataRequest types
            DataRequestHTTP drd = new DataRequestHTTP(request);

            // before anything, try to fulfill the request from cache
#if VERBOSE
            Log.Write(Log.Levels.Verbose, "DataStore: New request for " + request.Source);
#endif

/*
 *          if (drd.TryCache())
 *          {
 #if VERBOSE
 *              Log.Write(Log.Levels.Verbose, "DataStore: Request fulfilled from cache, no queue required");
 #endif
 *              if (drd.RequestDescriptor.CompletionCallback != null)
 *              {
 #if VERBOSE
 *                  Log.Write(Log.Levels.Verbose, "DataStore: calling completion callback...");
 #endif
 *                  drd.RequestDescriptor.CompletionCallback(drd);
 *              }
 *              return drd;
 *          }
 */
            lock (m_lock)
            {
#if VERBOSE
                Log.Write(Log.Levels.Verbose, "DataStore: Request enqueued.");
#endif
                m_pendingRequests.Insert(0, drd);
            }
            return(drd);
        }
Beispiel #2
0
 public DataRequest(DataRequestDescriptor request)
 {
     m_lock          = new Object();
     m_request       = request;
     m_contentStream = null;
     m_state         = DataRequestState.Queued;
     m_cacheHit      = false;
     m_headers       = new NameValueCollection();
     m_priority      = 50;
     m_totalRequests++;
     m_nextTry = DateTime.Now;
 }
Beispiel #3
0
        static private Stream CacheCallback(DataRequestDescriptor drd)
        {
            lock (m_cacheLock)
            {
                // search for any files that could be used to fulfill the request.
                if (drd.CacheLocation == null)
                {
                    return(null);
                }

                // Try cache with default file extension
                string cacheFullPath = drd.CacheLocation;
                if (File.Exists(cacheFullPath))
                {
                    return(new FileStream(cacheFullPath, FileMode.Open));
                }

                // Try cache but accept any valid image file extension
                const string ValidExtensions = ".bmp.dds.dib.hdr.jpg.jpeg.pfm.png.ppm.tga.gif.tif";

                // if (allowCache)
                {
                    string cacheSearchPath = Path.GetDirectoryName(cacheFullPath);
                    if (Directory.Exists(cacheSearchPath))
                    {
                        foreach (string imageFile in Directory.GetFiles(
                                     cacheSearchPath,
                                     Path.GetFileNameWithoutExtension(cacheFullPath) + ".*"))
                        {
                            string extension = Path.GetExtension(imageFile).ToLower();
                            if (ValidExtensions.IndexOf(extension) > 0)
                            {
                                return(new FileStream(imageFile, FileMode.Open));
                            }
                        }
                    }
                }

                // no stream found for this data request.
                return(null);
            }
        }
Beispiel #4
0
        public TextureSource(string url, string cacheLocation, ImageStore imageStore, PriorityCallback priorityCallback)
        {
//            if (s_inQueueTexture == null)
//                InitStaticTextures();

            // convert cache location to dds
//            string ddsCache = Path.GetDirectoryName(cacheLocation)+"\\"+Path.GetFileNameWithoutExtension(cacheLocation) + ".dds";
            m_drd = new DataRequestDescriptor(url, cacheLocation, new CacheCallback(CacheCallback));
            m_drd.CompletionCallback = new CompletionCallback(CompletionCallback);
            m_drd.PriorityCallback   = priorityCallback;

            m_imageStore = imageStore;

            if (m_settings == null)
            {
                // get the World Wind Settings through reflection.
                Assembly a       = Assembly.GetEntryAssembly();
                Type     appType = a.GetType("WorldWind.MainApplication");
                System.Reflection.FieldInfo finfo = appType.GetField("Settings", BindingFlags.Static | BindingFlags.Public | BindingFlags.GetField);
                m_settings = finfo.GetValue(null) as WorldWindSettings;
            }
        }
Beispiel #5
0
 public DataRequestHTTP(DataRequestDescriptor request)
     : base(request)
 {
 }