private void RefreshTableOfContents() { if(isRefreshing) return; isRefreshing = true; try { wms_server_list.WMS_SERVER_LISTType root = GetServerList(); updateCurrentProgressBar(0, root.ServerCount ); UpdateStatusBar( "Loading WMS servers... Please wait." ); for(int i = root.ServerMinCount; i < root.ServerCount; i++) { wms_server_list.WMS_server curServer = root.GetServerAt(i); try { string savePath = Path.Combine( this.CacheDirectory, curServer.Name.Value); string xmlPath = savePath + ".xml"; Directory.CreateDirectory( savePath ); string url = curServer.ServerUrl.Value + (curServer.ServerUrl.Value.IndexOf("?") > 0 ? "&request=GetCapabilities&service=WMS&version=" + curServer.Version.Value : "?request=GetCapabilities&service=WMS&version=" + curServer.Version.Value); using( WebDownload download = new WebDownload(url) ) download.DownloadFile(xmlPath ); this.wmsList = new WMSList(curServer.Name.Value, curServer.ServerUrl.Value, xmlPath, curServer.Version.Value); if(this.wmsList.Layers != null) { foreach(MyWMSLayer l in this.wmsList.Layers) { TreeNode tn = this.getTreeNodeFromWMSLayer(l); this.treeViewTableOfContents.BeginInvoke(new UpdateTableTreeDelegate(this.UpdateTableTree), new object[] {tn}); } } } catch(WebException) { TreeNode tn = new TreeNode(curServer.Name.Value + " (Connection Error)"); tn.ForeColor = Color.Red; this.treeViewTableOfContents.BeginInvoke(new UpdateTableTreeDelegate(this.UpdateTableTree), new object[] {tn}); } catch(Exception ex) { TreeNode tn = new TreeNode(curServer.Name.Value + " " + ex.ToString()); tn.ForeColor = Color.Red; this.treeViewTableOfContents.BeginInvoke(new UpdateTableTreeDelegate(this.UpdateTableTree), new object[] {tn}); } updateCurrentProgressBar(i+1, root.ServerCount); } // TODO: Invoke this.treeViewTableOfContents.AfterSelect += new TreeViewEventHandler(treeViewTableOfContents_AfterSelect); this.panelLower.Enabled = true; UpdateStatusBar( "" ); updateCurrentProgressBar(0,1); this.isRefreshed = true; } catch( Exception caught ) { this.worldWindow.Caption = caught.Message; } finally { this.isRefreshing = false; } }
protected override ModelNode[] Load() { WebDownload oCatalogDownload = new WebDownload(m_oUri.ToCapabilitiesUri(), true); oCatalogDownload.DownloadFile(CapabilitiesFilename); WMSList oCatalog = new WMSList(m_oUri.ToCapabilitiesUri(), CapabilitiesFilename); m_strTitle = oCatalog.Name; List<ModelNode> result = new List<ModelNode>(); foreach (WMSLayer oLayer in oCatalog.Layers[0].ChildLayers) { if (oLayer.ChildLayers == null) { result.Add(new WMSLayerModelNode(m_oModel, oLayer)); } else { result.Add(new WMSFolderModelNode(m_oModel, oLayer)); } } if (oCatalog.Layers[0].Name != null) { result.Add(new WMSLayerModelNode(m_oModel, oCatalog.Layers[0])); } result.Sort(new Comparison<ModelNode>(WMSRootModelNode.SortWMSChildNodes)); return result.ToArray(); }