/// <summary>
		/// Loads table of contents from server and populates the list box.
		/// PS: Not running in UI thread (Invoke when updating UI)
		/// </summary>
		private void RefreshCapabilitiesFromUrl() 
		{
			try 
			{
				// Read capabilities from server
				updateStatusBar("Downloading updated table of contents...");
			
				string wmsQueryString = AnimatedEarthManager.ServerUrl + "?service=" + this.serviceName + "&version=" + WmsVersion + "&request=GetCapabilities";
				using( WebDownload download = new WebDownload(wmsQueryString) )
				{
					download.ProgressCallback += new DownloadProgressHandler( this.updateCurrentProgressBar );
					download.DownloadMemory();

					try
					{
						// Save the downloaded capabilities for future (off-line) use
						download.SaveMemoryDownloadToFile(CapabilitiesFilePath);
					}
					catch(Exception)
					{
						//For read-only cache support etc.
						// UnauthorizedException, IOException etc. 
					}

					RefreshCapabilities( download.ContentStream );
				}

				isRefreshed = true;
			}
			catch
			{
				updateStatusBar("Connection Error.  Please try again later.");
			}
			this.updateCurrentProgressBar(0,0);
		}
		/// <summary>
		/// Returns an array of satellite Tles from the input URL
		/// </summary>
		/// <param name="url"></param>
		/// <returns></returns>
		public ArrayList GetFromWeb(string url )
		{
			string line1=null,line2=null;
			bool useLocalFile = false;
			ArrayList satTles = new ArrayList();
			string saveto =Path.Combine( this.Plugin.PluginDirectory,this.Name +".txt");
			//Get the TLE data
			using( WebDownload dl = new WebDownload(url) )
			{
				try
				{
					dl.DownloadMemory();
					dl.SaveMemoryDownloadToFile(saveto);
				}
				catch(System.Net.WebException)
				{
					useLocalFile = true;
				}
				if(useLocalFile)
					using(TextReader tr = new StreamReader( saveto ))
					{
						string[] line = tr.ReadToEnd().Split('\n');
						string NumFormat = GetNumberFormat(line);
						for(int i=0;i<line.Length-1-2;i = i + 3)
						{
							if(line[i].Trim().Length == 0)
								break;
							line1 = line[i+1].Trim();
							line2 = line[i+2].Trim();
							Tle tle = new Tle(FormatTrailingNumber(line[i].Trim(), NumFormat), line1, line2);
							satTles.Add(tle);
						}
					}
				else
					using(TextReader tr = new StreamReader( dl.ContentStream ))
					{
						string[] line = tr.ReadToEnd().Split('\n');
						string NumFormat = GetNumberFormat(line);
						for(int i=0;i<line.Length-1-2;i = i + 3)
						{
							if(line[i].Trim().Length == 0)
								break;
							line1 = line[i+1].Trim();
							line2 = line[i+2].Trim();
							Tle tle = new Tle(FormatTrailingNumber(line[i].Trim(), NumFormat), line1, line2);
							satTles.Add(tle);
						}
					}
			}
			return satTles;
		}
Example #3
0
        private void UpdateDownloadComplete(WebDownload downloadInfo)
        {
            // First compare the file to the one we have
            bool bUpdate = false;
            string strVersion;
            string strTemp = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
            try
            {
                string[] tokens;
                int iHaveVer1, iHaveVer2, iHaveVer3;
                int iCurVer1, iCurVer2, iCurVer3;
                downloadInfo.Verify();
                downloadInfo.SaveMemoryDownloadToFile(strTemp);

                using (StreamReader sr = new StreamReader(Path.Combine(DirectoryPath, VersionFile)))
                {
                    strVersion = sr.ReadLine();
                    tokens = strVersion.Split('.');
                    iHaveVer1 = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture);
                    iHaveVer2 = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
                    iHaveVer3 = Convert.ToInt32(tokens[2], CultureInfo.InvariantCulture);
                }

                using (StreamReader sr = new StreamReader(strTemp))
                {
                    strVersion = sr.ReadLine();
                    tokens = strVersion.Split('.');
                    iCurVer1 = Convert.ToInt32(tokens[0], CultureInfo.InvariantCulture);
                    iCurVer2 = Convert.ToInt32(tokens[1], CultureInfo.InvariantCulture);
                    iCurVer3 = Convert.ToInt32(tokens[2], CultureInfo.InvariantCulture);
                }

                if (iCurVer1 > iHaveVer1 || (iCurVer1 == iHaveVer1 && iCurVer2 > iHaveVer2) ||
                    (iCurVer1 == iHaveVer1 && iCurVer2 == iHaveVer2 && iCurVer3 > iHaveVer3))
                {
                    this.BeginInvoke(new NotifyUpdateDelegate(NotifyUpdate), new object[] { strVersion });
                    bUpdate = true;
                }

                File.Delete(strTemp);
            }
            catch (System.Net.WebException)
            {
            }
            catch
            {
            }
            finally
            {
                if (!bUpdate && m_bUpdateFromMenu)
                    this.BeginInvoke(new MethodInvoker(NotifyUpdateNotAvailable));
            }
        }