//  public static Mutex mut = new Mutex();
        public static void LoadTexture( object objEntry)
        {
            IconCacheEntry entry = objEntry as IconCacheEntry;
            entry.Requested = true;
               // mut.WaitOne();
            try
            {
                String dir = Properties.Settings.Default.CahceDirectory + "Data\\KmlCache\\";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                // This is a expanded timeout version of WebClient
                MyWebClient Client = new MyWebClient();

                string filename = dir + ((uint)entry.Href.GetHashCode32()).ToString() + ".png";

                //if (File.Exists(filename))
                //{
                //    FileInfo fi = new FileInfo(filename);

                //    if (fi.Length != 8 && fi.Length < 100)
                //    {
                //        try
                //        {
                //            File.Delete(filename);
                //        }
                //        catch
                //        {
                //        }
                //    }
                //}

                //Client.DownloadFile(CacheProxy.GetCacheUrl(url), filename);

                Stream stream = null;
                if (entry.Owner == null)
                {

                    if (Uri.IsWellFormedUriString(entry.Href, UriKind.Absolute))
                    {
                        byte[] data = Client.DownloadData(entry.Href);
                        stream = new MemoryStream(data);
                    }
                    else
                    {
                        stream = File.Open(entry.Href, FileMode.Open);
                    }
                }
                else
                {
                    stream = entry.Owner.GetFileStream(entry.Href);
                }

                FileStream fileStream = File.OpenWrite(filename);
                byte[] buffer = new byte[32768];
                while (true)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                        break;
                    fileStream.Write(buffer, 0, read);
                }
                stream.Close();
                fileStream.Close();
                //todo this was loaded from the kmlicon API. Any Problems with that?
                entry.texture = Texture11.FromFile(filename);

                entry.Loaded = true;

            }
            catch
            {

                entry.ErrorCount++;

                // retry until sucsess or MaxError Count exceeded
                if (entry.ErrorCount < MaxErrorCount)
                {
                    entry.Requested = false;
                    entry.Loaded = false;

                }
                else
                {
                    entry.Loaded = true;
                }
            }
            finally
            {
            //    mut.ReleaseMutex();
            }
        }
Beispiel #2
0
        public static void LoadTexture(object objEntry)
        {
            WmsCahceEntry entry = objEntry as WmsCahceEntry;

            entry.Requested = true;
            try
            {
                String dir = Properties.Settings.Default.CahceDirectory + "Data\\KmlCache\\";
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }
                // This is a expanded timeout version of WebClient
                MyWebClient Client = new MyWebClient();


                string filename = dir + ((uint)entry.URL.GetHashCode32()).ToString() + ".png";


                Stream stream = null;

                if (Uri.IsWellFormedUriString(entry.URL, UriKind.Absolute))
                {
                    byte[] data = Client.DownloadData(entry.URL);
                    stream = new MemoryStream(data);
                }
                else
                {
                    stream = File.Open(entry.URL, FileMode.Open);
                }


                FileStream fileStream = File.OpenWrite(filename);
                byte[]     buffer     = new byte[32768];
                while (true)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                    {
                        break;
                    }
                    fileStream.Write(buffer, 0, read);
                }
                stream.Close();
                fileStream.Close();
                //todo this was loaded from the kmlicon API. Any Problems with that?
                entry.Texture = Texture11.FromFile(filename);

                entry.Loaded = true;
            }
            catch
            {
                entry.ErrorCount++;

                // retry until sucsess or MaxError Count exceeded
                if (entry.ErrorCount < MaxErrorCount)
                {
                    entry.Requested = false;
                    entry.Loaded    = false;
                }
                else
                {
                    entry.Loaded = true;
                }
            }
            finally
            {
                //    mut.ReleaseMutex();
            }
        }