Example #1
0
 public override void Dispose()
 {
     try {
         if (download != null)
         {
             download.Dispose();
             download = null;
         }
     }
     finally {
         base.Dispose();
     }
 }
Example #2
0
		/// <summary>
		/// Web download callback for Files relative to a xml
		/// used by loadXMLFileFromURL
		/// </summary>
		private void xmlRelatedFileDownloadComplete(WebDownload dl)
		{	
			for(int i=0; i<xmlDownloads.Count; i++)
			{	
				for(int u=1; u<((ArrayList)(xmlDownloads[i])).Count; u++)//xmlDownloads[0] is the xml path
				{					
					if(((string)((ArrayList)(xmlDownloads[i]))[u]) ==
						dl.Url)
					{						
						((ArrayList)(xmlDownloads[i])).RemoveAt(u);
						if(((ArrayList)(xmlDownloads[i])).Count <= 1)
						{								
							//load xml (all files have been downloaded)
							loadShapeFileWithAlreadyExistingXML(
								((string)((ArrayList)(xmlDownloads[i]))[0]),false);
							xmlDownloads.RemoveAt(i);
						}
					}
				}
				
			}

			dl.Dispose();
		}
Example #3
0
		/// <summary>
		/// Web download callback for Zips
		/// </summary>
		private void ZipDownloadComplete(WebDownload dl)
		{
			createXmlLoadShape(dl.SavedFilePath);			
			dl.Dispose();
		}
Example #4
0
		/// <summary>
		/// Web download callback for shp+shx+dbf
		/// </summary>
		private void ShpDownloadComplete(WebDownload dl)
		{
			if(dl.SavedFilePath.ToLower().EndsWith(".shp"))
			{
				for(int i=0; i<actualDownloads.Count; i++)
				{
					if( ((WebDownload)actualDownloads[i]).SavedFilePath==
						Path.ChangeExtension(dl.SavedFilePath,".dbf"))
					{
						if( ((WebDownload)actualDownloads[i]).IsComplete )
						{
							((WebDownload)actualDownloads[i]).Dispose();
							actualDownloads.RemoveAt(i);
							createXmlLoadShape(dl.SavedFilePath);
						}
						else
							return;
					}				
				}
			}
			else 
			{
				for(int i=0; i<actualDownloads.Count; i++)
				{
					if( ((WebDownload)actualDownloads[i]).SavedFilePath==
						Path.ChangeExtension(dl.SavedFilePath,".shp"))
					{
						if( ((WebDownload)actualDownloads[i]).IsComplete )
						{
							((WebDownload)actualDownloads[i]).Dispose();
							actualDownloads.RemoveAt(i);
							createXmlLoadShape(Path.ChangeExtension(dl.SavedFilePath,".shp"));
						}
						else
							return;
					}				
				}
			}						
			dl.Dispose();
		}
Example #5
0
 private void DownloadComplete(WebDownload oDownload)
 {
     // --- Sending it is what matters, we don't care what comes back ---
     oDownload.Dispose();
 }
Example #6
0
        public static RenderableObjectList getRenderableFromLayerFile(string layerFile, World parentWorld, Cache cache, bool enableRefresh)
        {
            try {
                XPathDocument docNav = null;
                XPathNavigator nav = null;

                try {
                    docNav = new XPathDocument(layerFile);
                    nav = docNav.CreateNavigator();
                }
                catch (Exception ex) {
                    Log.Write(ex);
                    return null;
                }

                XPathNodeIterator iter = nav.Select("/LayerSet");

                if (iter.Count > 0) {
                    iter.MoveNext();
                    string redirect = iter.Current.GetAttribute("redirect", "");
                    if (redirect != null
                        && redirect.Length > 0) {
                        FileInfo layerFileInfo = new FileInfo(layerFile);

                        try {
                            Angle[] bbox = CameraBase.getViewBoundingBox();
                            string viewBBox = string.Format(CultureInfo.InvariantCulture, "{0},{1},{2},{3}", bbox[0].ToString().TrimEnd('бу'), bbox[1].ToString().TrimEnd('бу'), bbox[2].ToString().TrimEnd('бу'), bbox[3].ToString().TrimEnd('бу'));

                            //See if there is a ? already in the URL
                            int flag = redirect.IndexOf("?");
                            if (flag == -1) {
                                redirect = redirect + "?BBOX=" + viewBBox;
                            }
                            else {
                                redirect = redirect + "&BBOX=" + viewBBox;
                            }

                            WebDownload download = new WebDownload(redirect);

                            string username = iter.Current.GetAttribute("username", "");
                            string password = iter.Current.GetAttribute("password", "");

                            if (username != null) {
                                ////	download.UserName = username;
                                ////	download.Password = password;
                            }

                            FileInfo tempDownloadFile = new FileInfo(layerFile.Replace(layerFileInfo.Extension, "_.tmp"));

                            download.DownloadFile(tempDownloadFile.FullName, DownloadType.Unspecified);

                            tempDownloadFile.Refresh();
                            if (tempDownloadFile.Exists
                                && tempDownloadFile.Length > 0) {
                                FileInfo tempStoreFile = new FileInfo(tempDownloadFile.FullName.Replace("_.tmp", ".tmp"));
                                if (tempStoreFile.Exists) {
                                    tempStoreFile.Delete();
                                }

                                tempDownloadFile.MoveTo(tempStoreFile.FullName);
                            }

                            download.Dispose();

                            using (StreamWriter writer = new StreamWriter(layerFile.Replace(layerFileInfo.Extension, ".uri"), false)) {
                                writer.WriteLine(redirect);
                            }
                        }
                        catch (Exception ex) {
                            Log.Write(ex);
                        }

                        return getRenderableFromLayerFile(layerFile.Replace(layerFileInfo.Extension, ".tmp"), parentWorld, cache);
                    }
                    else {
                        RenderableObjectList parentRenderable = null;

                        string sourceUri = null;
                        if (layerFile.EndsWith(".tmp")) {
                            //get source url
                            using (StreamReader reader = new StreamReader(layerFile.Replace(".tmp", ".uri"))) {
                                sourceUri = reader.ReadLine();
                            }
                        }
                        string refreshString = iter.Current.GetAttribute("Refresh", "");
                        if (refreshString != null
                            && refreshString.Length > 0) {
                            if (iter.Current.Select("Icon").Count > 0) {
                                parentRenderable = new Icons(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                                #region by zzm
                            else if (iter.Current.Select("MyIcon").Count > 0) {
                                // add my icon here.
                                parentRenderable = new MyIcons(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                            else if (iter.Current.Select("MyChart").Count > 0) {
                                // add chart here.
                                parentRenderable = new MyCharts(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                                #endregion

                            else {
                                parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", ""), (sourceUri != null ? sourceUri : layerFile), TimeSpan.FromSeconds(ParseDouble(refreshString)), parentWorld, cache);
                            }
                        }
                        else {
                            if (iter.Current.Select("Icon").Count > 0) {
                                parentRenderable = new Icons(iter.Current.GetAttribute("Name", ""));
                            }
                                #region by zzm
                            else if (iter.Current.Select("MyIcon").Count > 0) {
                                // add my icon here.
                                parentRenderable = new MyIcons(iter.Current.GetAttribute("Name", ""));
                            }
                            else if (iter.Current.Select("MyChart").Count > 0) {
                                // add chart here.
                                parentRenderable = new MyCharts(iter.Current.GetAttribute("Name", ""));
                            }
                                #endregion

                            else {
                                parentRenderable = new RenderableObjectList(iter.Current.GetAttribute("Name", ""));
                            }
                        }

                        parentRenderable.ParentList = parentWorld.RenderableObjects;

                        if (World.Settings.useDefaultLayerStates) {
                            parentRenderable.IsOn = ParseBool(iter.Current.GetAttribute("ShowAtStartup", ""));
                        }
                        else {
                            parentRenderable.IsOn = IsLayerOn(parentRenderable);
                        }

                        parentRenderable.ShowOnlyOneLayer = ParseBool(iter.Current.GetAttribute("ShowOnlyOneLayer", ""));

                        parentRenderable.MetaData.Add("XmlSource", (sourceUri != null ? sourceUri : layerFile));

                        parentRenderable.MetaData.Add("World", parentWorld);
                        parentRenderable.MetaData.Add("Cache", cache);
                        parentRenderable.ParentList = parentWorld.RenderableObjects;

                        string renderPriorityString = iter.Current.GetAttribute("RenderPriority", "");
                        if (renderPriorityString != null) {
                            if (String.Compare(renderPriorityString, "Icons", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.Icons;
                            }
                            else if (String.Compare(renderPriorityString, "LinePaths", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.LinePaths;
                            }
                            else if (String.Compare(renderPriorityString, "Placenames", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.Placenames;
                            }
                            else if (String.Compare(renderPriorityString, "AtmosphericImages", false) == 0) {
                                parentRenderable.RenderPriority = RenderPriority.AtmosphericImages;
                            }
                        }

                        string infoUri = iter.Current.GetAttribute("InfoUri", "");

                        if (infoUri != null
                            && infoUri.Length > 0) {
                            if (parentRenderable.MetaData.Contains("InfoUri")) {
                                parentRenderable.MetaData["InfoUri"] = infoUri;
                            }
                            else {
                                parentRenderable.MetaData.Add("InfoUri", infoUri);
                            }
                        }

                        addImageLayersFromXPathNodeIterator(iter.Current.Select("ImageLayer"), parentWorld, parentRenderable);
                        addQuadTileLayersFromXPathNodeIterator(iter.Current.Select("QuadTileSet"), parentWorld, parentRenderable, cache);
                        addPathList(iter.Current.Select("PathList"), parentWorld, parentRenderable);
                        addPolygonFeature(iter.Current.Select("PolygonFeature"), parentWorld, parentRenderable);
                        addLineFeature(iter.Current.Select("LineFeature"), parentWorld, parentRenderable);
                        addTiledPlacenameSet(iter.Current.Select("TiledPlacenameSet"), parentWorld, parentRenderable);
                        addIcon(iter.Current.Select("Icon"), parentWorld, parentRenderable, cache);
                        addScreenOverlays(iter.Current.Select("ScreenOverlay"), parentWorld, parentRenderable, cache);
                        addChildLayerSet(iter.Current.Select("ChildLayerSet"), parentWorld, parentRenderable, cache);

                        #region by zzm
                        AddMyIcon(iter.Current.Select("MyIcon"), parentWorld, parentRenderable, cache);
                        AddMyChart(iter.Current.Select("MyChart"), parentWorld, parentRenderable, cache);
                        AddMesh(iter.Current.Select("MeshLayer"), parentWorld, parentRenderable, cache);
                        #endregion

                        addExtendedInformation(iter.Current.Select("ExtendedInformation"), parentRenderable);

                        if (parentRenderable.RefreshTimer != null && enableRefresh) {
                            parentRenderable.RefreshTimer.Start();
                        }
                        return parentRenderable;
                    }
                }
            }
            catch (Exception ex) {
                Log.Write(ex);
                //Utility.Log.Write(layerFile);
            }
            return null;
        }
Example #7
0
		void DownloadComplete( WebDownload downloadInfo )
		{
			if(this.InvokeRequired)
			{
				Invoke(new DownloadCompleteHandler(DownloadComplete), new object[]{downloadInfo});
				return;
			}

			try
			{
				downloadInfo.Verify();
				Image = System.Drawing.Image.FromStream(downloadInfo.ContentStream);
			}
			catch(Exception caught)
			{
				this.Visible = false;
				MessageBox.Show(caught.Message, "Legend image download failed.",
					MessageBoxButtons.OK,MessageBoxIcon.Warning);
			}
			finally
			{
				if(downloadInfo!=null)
					downloadInfo.Dispose();
				Text = oldText;
			}
		}
Example #8
0
		/// <summary>
		/// Retrieves a bitmap from cache or the web
		/// </summary>
		/// <param name="filename">The URI to download the bitmap from</param>
		/// <returns>The downloaded bitmap</returns>
		private string GetWebImage(string filename)
		{
			// Try using a cached version
			if (bitmapCache.ContainsKey(filename))
				return filename;

			// Download the file from the web
			WebDownload myDownload = new WebDownload(filename);
			myDownload.DownloadMemory();

			// Load it into a Bitmap
			Bitmap bit = (Bitmap)System.Drawing.Bitmap.FromStream(myDownload.ContentStream);

			// Cache the downloaded bitmap
			myDownload.Dispose();
			bitmapCache.Add(filename, bit);
			return filename;
		}