private void btnGetAllResource_Click(object sender, EventArgs e) { this.ResourcescheckedListBox.Items.Clear(); IAGSServerConnectionFactory factory = new AGSServerConnectionFactoryClass(); IPropertySet pConnectionProperties = this.method_5(); IAGSServerConnection connection = null; try { connection = factory.Open(pConnectionProperties, 0); } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } IAGSEnumServerObjectName serverObjectNames = connection.ServerObjectNames; serverObjectNames.Reset(); for (IAGSServerObjectName name2 = serverObjectNames.Next(); name2 != null; name2 = serverObjectNames.Next()) { this.ilist_0.Add(name2); this.ResourcescheckedListBox.Items.Add(new Class7(name2)); } connection = null; factory = null; }
protected override void OnClick() { IMxDocument pmxdoc = (IMxDocument)ArcMap.Application.Document; IMap pmap = pmxdoc.FocusMap; IGxDialog pGxDialog = new GxDialog(); pGxDialog.Title = "Browse Data"; //pGxDialog.set_StartingLocation("C:\\Temp"); pGxDialog.set_StartingLocation("GIS Servers"); IEnumGxObject pEnumGx; if (!pGxDialog.DoModalOpen(0, out pEnumGx)) { return; // Exit if user press Cancel } IGxObject pgxobject = pEnumGx.Next(); IGxAGSObject gxAGSObject = pgxobject as IGxAGSObject; IAGSServerObjectName agsServerObjectName = gxAGSObject.AGSServerObjectName; IAGSServerConnectionName agsServerConnectionName = agsServerObjectName.AGSServerConnectionName; IPropertySet propertySet = agsServerConnectionName.ConnectionProperties; //create a new ArcGIS Server connection factory IAGSServerConnectionFactory2 agsServerConnectionFactory2 = (IAGSServerConnectionFactory2) new AGSServerConnectionFactory(); IAGSServerConnection agsServerConnection = agsServerConnectionFactory2.Open(propertySet, 0); //get an enum of all server object names from the server (GIS services, i.e.) IAGSEnumServerObjectName soNames = agsServerConnection.ServerObjectNames; IAGSServerObjectName3 soName = (IAGSServerObjectName3)soNames.Next(); ILayerFactory msLayerFactory = new MapServerLayerFactory(); IEnumLayer enumLyrs = msLayerFactory.Create(soName); IMapServerLayer mapServerLayer = (IMapServerLayer)enumLyrs.Next(); pmap.AddLayer((ILayer)mapServerLayer); ArcMap.Application.CurrentTool = null; }
/// <summary> /// 连接地图服务,获取IAGSServerObjectName对象 /// </summary> /// <param name="hostOrUrl">服务地址,例:http://services.arcgisonline.com/ArcGIS/services</param> /// <param name="serviceName">服务名称,例:ESRI_Imagery_World_2D</param> /// <param name="isLAN">是否局域网(Local Area Network)</param> /// <returns></returns> private IAGSServerObjectName GetServerObjectName(string hostOrUrl, string serviceName, bool isLAN = false) { //设置连接属性 IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty(isLAN ? "machine" : "url", hostOrUrl); //打开连接 IAGSServerConnectionFactory factory = new AGSServerConnectionFactory(); IAGSServerConnection connection = factory.Open(propertySet, 0); IAGSEnumServerObjectName serverObjectNames = connection.ServerObjectNames; serverObjectNames.Reset(); IAGSServerObjectName serverObjectName; while ((serverObjectName = serverObjectNames.Next()) != null) { if (serverObjectName.Name.ToLower() == serviceName.ToLower() && serverObjectName.Type == "MapServer") { break; } } return(serverObjectName); }
private void btnOK_Click(object sender, EventArgs e) { if ((this.rdoResourceUse.SelectedIndex == 1) && (this.ResourcescheckedListBox.CheckedItems.Count == 0)) { MessageBox.Show("请选择所用资源!"); } else { new AGSServerConnectionFactoryClass(); IPropertySet set = this.method_5(); IAGSServerConnectionName name = new AGSServerConnectionNameClass { ConnectionProperties = set }; try { IAGSServerConnection connection = (name as IName).Open() as IAGSServerConnection; if (connection == null) { return; } } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } string path = Environment.SystemDirectory.Substring(0, 2) + @"\Documents and Settings\Administrator\Application Data\ESRI\ArcCatalog\"; if (Directory.Exists(path)) { string str2 = path + this.txtServer.Text + ".ags"; str2 = this.method_4(str2); IGxAGSConnection connection2 = new GxAGSConnection(); object obj2 = null; if ((this.rdoResourceUse.SelectedIndex == 1) && (this.ResourcescheckedListBox.CheckedItems.Count > 0)) { string[] strArray = new string[this.ResourcescheckedListBox.CheckedItems.Count]; for (int i = 0; i < this.ResourcescheckedListBox.CheckedItems.Count; i++) { strArray[i] = this.ResourcescheckedListBox.CheckedItems[i].ToString(); } obj2 = strArray; } connection2.AGSServerConnectionName = name; connection2.SelectedServerObjects = obj2; connection2.SaveToFile(str2); this.igxObject_0 = connection2 as IGxObject; } base.DialogResult = DialogResult.OK; base.Close(); } }
private void btnOK_Click(object sender, EventArgs e) { if (this.txtTempFolder.Text.Trim().Length == 0) { MessageBox.Show("请输入过渡文件夹"); } else { string path = Environment.SystemDirectory.Substring(0, 2) + @"\Users\Administrator\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string text = this.txtMUrl.Text; if (text.IndexOf("http://") == 0) { text = text.Substring(7); } else { this.txtMUrl.Text = "http://" + this.txtMUrl.Text; } string[] strArray = text.Split(new char[] { '/' }); IAGSServerConnectionFactory factory = new AGSServerConnectionFactoryClass(); IPropertySet pConnectionProperties = this.method_2(this.ConnectionFile, strArray[0]); IAGSServerConnection connection = null; try { connection = factory.Open(pConnectionProperties, 0); if (connection == null) { return; } } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } if (Directory.Exists(path)) { IGxAGSConnection connection2 = new GxAGSConnection { AGSServerConnectionName = connection.FullName as IAGSServerConnectionName }; connection2.SaveToFile(this.ConnectionFile); this.igxObject_0 = connection2 as IGxObject; } base.DialogResult = DialogResult.OK; } }
private void method_7() { this.ResourcescheckedListBox.Items.Clear(); IAGSServerConnection connection = (this.iagsserverConnectionName_0 as IName).Open() as IAGSServerConnection; IAGSEnumServerObjectName serverObjectNames = connection.ServerObjectNames; serverObjectNames.Reset(); for (IAGSServerObjectName name2 = serverObjectNames.Next(); name2 != null; name2 = serverObjectNames.Next()) { string name = name2.Name; this.ResourcescheckedListBox.Items.Add(name, this.method_6(name)); } connection = null; }
private static IAGSServerObjectName3 FindServerObjectname(IAGSServerConnection gisServer, string svcName) { var soNames = gisServer.ServerObjectNames; IAGSServerObjectName3 soName; while ((soName = (IAGSServerObjectName3)soNames.Next()) != null) { Debug.Print("soName: " + soName.Name); if ((soName.Type == "MapServer") && (soName.Name.ToUpper() == svcName.ToUpper())) { return(soName); } } return(null); }
public IAGSServerObjectName GetMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN) { //设置连接属性 IPropertySet pPropertySet = new PropertySetClass(); if (pIsLAN) { pPropertySet.SetProperty("machine", pHostOrUrl); } else { pPropertySet.SetProperty("url", pHostOrUrl); } //打开连接 IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory(); //Type factoryType = Type.GetTypeFromProgID( // "esriGISClient.AGSServerConnectionFactory"); //IAGSServerConnectionFactory agsFactory = (IAGSServerConnectionFactory) // Activator.CreateInstance(factoryType); IAGSServerConnection pConnection = pFactory.Open(pPropertySet, 0); //Get the image server. IAGSEnumServerObjectName pServerObjectNames = pConnection.ServerObjectNames; pServerObjectNames.Reset(); IAGSServerObjectName ServerObjectName = pServerObjectNames.Next(); while (ServerObjectName != null) { if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) && (ServerObjectName.Type == "MapServer")) { break; } ServerObjectName = pServerObjectNames.Next(); } //返回对象 return(ServerObjectName); }
private void method_0(object sender, EventArgs e) { this.Cursor = Cursors.WaitCursor; this.imapServer_0 = null; try { IAGSServerConnectionFactory factory = new AGSServerConnectionFactoryClass(); IPropertySet pConnectionProperties = new PropertySetClass(); this.iagsserverConnection_0 = factory.Open(pConnectionProperties, 0); IAGSEnumServerObjectName serverObjectNames = this.iagsserverConnection_0.ServerObjectNames; while (serverObjectNames.Next() != null) { this.Cursor = Cursors.Default; } } catch (Exception exception) { this.Cursor = Cursors.Default; MessageBox.Show(exception.Message, "An error has occurred"); } }
/// <summary> /// 获取ArcGisServer地图服务标识,连接服务器 /// </summary> /// <param name="pHostOrUrl"></param>服务器主机URL /// <param name="pServiceName"></param>服务名称 /// <param name="pIsLAN"></param>主机是否是在局域网或者是互联网 /// <returns></returns> private IAGSServerObjectName GetAGSMapServer(string pHostOrUrl, string pServiceName, bool pIsLAN) { //设置连接属性 IPropertySet pPropertySet = new PropertySet(); if (pIsLAN) { pPropertySet.SetProperty("machine", pHostOrUrl); } else { pPropertySet.SetProperty("url", pHostOrUrl); } IAGSServerConnectionFactory pFactory = new AGSServerConnectionFactory(); IAGSServerConnection agsConn = pFactory.Open(pPropertySet, 0); //打开获取服务器 IAGSEnumServerObjectName pServerObjectNames = agsConn.ServerObjectNames; //获取服务器上所有服务的标识属性,即服务标识集合 pServerObjectNames.Reset(); //使指针指向服务开头 IAGSServerObjectName ServerObjectName = null; //获取服务标识 while ((ServerObjectName = pServerObjectNames.Next()) != null) { if ((ServerObjectName.Name.ToLower() == pServiceName.ToLower()) && (ServerObjectName.Type == "MapServer")) {//判断获取所需服务 break; } } //返回对象 return(ServerObjectName);//返回服务标识 }
/// <summary> /// Add AGS Map Layer /// </summary> /// <param name="inUserName"></param> /// <param name="inPassword"></param> /// <param name="inName"></param> /// <param name="inMapUrl"></param> internal void AddAGSLayer(string inUserName, string inPassword, string inName, string inMapUrl) { IAGSServerConnectionName2 agsServerConnectionName = (IAGSServerConnectionName2) new AGSServerConnectionName(); // http://localhost/ArcGIS/rest/services/Map1/MapServer // Convert to http://localhost/ArcGis/Services // and http://localgsot/ArcGIS/Map1/MapServer string servicecatalog = inMapUrl.Substring(0, inMapUrl.IndexOf("/REST/SERVICES", StringComparison.CurrentCultureIgnoreCase)) + "/Services"; string mapserviceurl = ReplaceEx(inMapUrl, "/REST/", "/", StringComparison.InvariantCultureIgnoreCase); string mapservice = ""; Regex rMapServerRest = new Regex("^(?i:.*/REST/SERVICES/(?<mapname>.*)/MAPSERVER.*)$"); Match m = rMapServerRest.Match(inMapUrl); if (m.Success) { mapservice = m.Groups["mapname"].Value; } //Create a property set of connection details IPropertySet props = new PropertySet(); props.SetProperty("url", servicecatalog); if (inUserName != null) { props.SetProperty("user", inUserName); props.SetProperty("password", inPassword); props.SetProperty("hideuserproperty", false); props.SetProperty("anonymous", false); } IAGSServerObjectName2 agsServerObjectName = (IAGSServerObjectName2) new AGSServerObjectName(); IAGSServerConnectionFactory AGSConnectionFactory = new AGSServerConnectionFactory(); IAGSServerConnection AGSConnection = AGSConnectionFactory.Open(props, 0); IAGSEnumServerObjectName enumSOName = null; enumSOName = AGSConnection.ServerObjectNames; IAGSServerObjectName SOName = null; SOName = enumSOName.Next(); while (SOName != null) { System.Diagnostics.Debug.WriteLine(SOName.Name + ": " + SOName.Type); if (SOName.Name.Equals(mapservice, StringComparison.InvariantCultureIgnoreCase) && SOName.Type == "MapServer") { //create the layer object IMapServerGroupLayer mapServerLayer = new MapServerLayerClass(); IName mapServerConnectionName = (IName)SOName; IDataLayer dataLayer = (IDataLayer)mapServerLayer; //try to connect try { dataLayer.Connect(mapServerConnectionName); } catch (Exception ex) { throw new Exception("Could not connect to URL", ex); } //create the layer name ILayer layer; layer = (ILayer)mapServerLayer; layer.Visible = true; layer.Name = inName; //return the layer ArcMap.Document.AddLayer(layer); break; } SOName = enumSOName.Next(); } }
/// <summary> /// Parse ArcGIS MapServer Service /// </summary> /// <param name="urlAGS"></param> public void OpenAGS(string urlAGS) { try { ///Parse the url for MapServer -- get the service url and the service name string strUrl = urlAGS; string[] strUrlParts = strUrl.Split('/'); string strUrlSvr = null; string strSvrName = null; for (int i = 0; i < strUrlParts.Length; i++) { if (strUrlParts[i] == "services") { strUrlSvr = string.Join("/", strUrlParts.Take(i + 1).ToArray()); for (int j = i + 1; j < strUrlParts.Length - 1; j++) { if (strSvrName != null) { strSvrName += "/"; } strSvrName += strUrlParts[j]; } break; } } ///Set up ArcGIS Service connection factory, which includes the list of services IAGSServerConnectionFactory pAGSSvrConnFactory = new AGSServerConnectionFactoryClass(); IPropertySet pPropSet = new PropertySetClass(); pPropSet.SetProperty("URL", strUrlSvr); IAGSServerConnection pAGSSvrConn = pAGSSvrConnFactory.Open(pPropSet, 0); ///Get the list of services IAGSEnumServerObjectName pEnumSOName = pAGSSvrConn.ServerObjectNames; IAGSServerObjectName pAGSSOName = pEnumSOName.Next(); ///Get the specific service with the service name while (pAGSSOName != null) { //Debug.WriteLine(pAGSSOName.Name + ":" + pAGSSOName.Type); if (pAGSSOName.Name == strSvrName && pAGSSOName.Type == "MapServer") { break; } pAGSSOName = pEnumSOName.Next(); } ///Open the specific service IName pName = pAGSSOName as IName; IMapServer pMapServer = pName.Open() as IMapServer; IMapServerLayer pMapSvrLayer = new MapServerLayerClass(); pMapSvrLayer.ServerConnect(pAGSSOName, pMapServer.DefaultMapName); ///Configure the layer before adding it to the map ILayer pLayer = pMapSvrLayer as ILayer; AddLayer(pLayer); } catch (Exception ex) { MessageBox.Show(ex.StackTrace); } }
private void btnOK_Click(object sender, EventArgs e) { if (((this.radioGroup1.SelectedIndex >= 1) && !this.chkUseDefaultFolder.Checked) && (this.txtTempFolder.Text.Trim().Length == 0)) { MessageBox.Show("请输入过渡文件夹"); } else { IPropertySet set; object obj2; object obj3; string path = Environment.SystemDirectory.Substring(0, 2) + @"\Users\Administrator\AppData\Roaming\ESRI\Desktop10.2\ArcCatalog\"; if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string str2 = ""; string text = ""; if (this.radioGroup1.SelectedIndex == 0) { text = this.txtServer.Text; } else { text = this.txtMUrl.Text; } string str4 = ""; if (this.radioGroup1.SelectedIndex == 0) { str4 = "(用户)"; } else if (this.radioGroup1.SelectedIndex == 1) { str4 = "(系统管理员)"; } else if (this.radioGroup1.SelectedIndex == 2) { str4 = "(发布者)"; } if (text.IndexOf("http://") == 0) { text = text.Substring(7); } else { this.txtServer.Text = "http://" + this.txtServer.Text; } string[] strArray = text.Split(new char[] { '/' }); string str5 = strArray[0]; if (strArray.Length > 0) { str2 = path + "arcgis on" + strArray[0].Replace(":", "_") + str4 + ".ags"; } else { str2 = path + "arcgis on" + str4 + ".ags"; } str2 = this.method_1(str2); IAGSServerConnectionFactory factory = new AGSServerConnectionFactoryClass(); if (this.radioGroup1.SelectedIndex == 0) { set = this.method_2(str2, str5); } else { set = this.method_3(str2, str5); } set.GetAllProperties(out obj2, out obj3); IAGSServerConnection connection = null; try { connection = factory.Open(set, 0); if (connection == null) { return; } } catch (Exception exception) { MessageBox.Show(exception.ToString()); return; } if (Directory.Exists(path)) { IGxAGSConnection connection2 = new GxAGSConnection { AGSServerConnectionName = connection.FullName as IAGSServerConnectionName }; connection2.SaveToFile(str2); this.igxObject_0 = connection2 as IGxObject; } base.DialogResult = DialogResult.OK; } }
/// <summary> /// Adds ArcGIS layer to map /// </summary> /// <param name="ipMxDoc"></param> /// <param name="strServer"></param> /// <param name="strLayerName"></param> /// <param name="strSecretName"></param> /// <returns></returns> private bool addLayerAGS(IMxDocument ipMxDoc, string strServer, string strLayerName, string strSecretName) { IPropertySet2 pProps = null; string pServerUrl; string strServerObj; pServerUrl = GetAGSServiceUrl(strServer); // connect to the GIS server IAGSServerConnectionFactory pAGSServerConnectionFactory = new AGSServerConnectionFactory(); pProps = (IPropertySet2) new PropertySet(); pProps.SetProperty("URL", pServerUrl); IAGSServerConnection pAGSConnection = pAGSServerConnectionFactory.Open(pProps, 0); //get server objectname from url strServerObj = GetServerObjectName(strServer); // enumerate over server objects IAGSEnumServerObjectName pAGSSObjs = pAGSConnection.ServerObjectNames; IAGSServerObjectName pAGSSObj = pAGSSObjs.Next(); while (pAGSSObj != null) { if (pAGSSObj.Type == "MapServer" && pAGSSObj.Name == strServerObj) { break; } pAGSSObj = pAGSSObjs.Next(); } IName pName = (IName)pAGSSObj; IAGSServerObject pAGSO = (IAGSServerObject)pName.Open(); IMapServer mapServer = (IMapServer)pAGSO; IPropertySet prop = new PropertySetClass(); prop.SetProperty("URL", pServerUrl); prop.SetProperty("Name", pAGSSObj.Name); //Create new layer IMapServerLayer pMSLayer = (IMapServerLayer) new MapServerLayer(); pMSLayer.ServerConnect(pAGSSObj, mapServer.DefaultMapName); if (!isMapServerAdded(strServer)) { setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName); IMap ipMap = ipMxDoc.FocusMap; ipMap.AddLayer((ILayer)pMSLayer); logger.writeLog(StringResources.AddAGSLayer + strSecretName); } else { // set visibility setAGSLayerVisiblity((MapServerLayer)pMSLayer, strSecretName); } //add to the service list string strItem = EncodeServiceList(strServer, strLayerName, strSecretName); // m_pLogger.Msg "adding to service list : " & strItem colServiceList.Add(strItem); //set flag logger.writeLog("strServer = " + strServer + " strServer & strLayerName = " + strServer + strLayerName); return(true); }