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 static bool ConnectAGS(string host, string sAgsAdminUser, string sAgsAdminPwd) { try { IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("url", host); propertySet.SetProperty("user", sAgsAdminUser); propertySet.SetProperty("password", sAgsAdminPwd); propertySet.SetProperty("ConnectionMode", esriAGSConnectionMode.esriAGSConnectionModePublisher); propertySet.SetProperty("ServerType", esriAGSServerType.esriAGSServerTypeDiscovery); IAGSServerConnectionName3 connectName = new AGSServerConnectionNameClass() as IAGSServerConnectionName3; connectName.ConnectionProperties = propertySet; IAGSServerConnectionAdmin agsAdmin = ((IName)connectName).Open() as IAGSServerConnectionAdmin; soAdmin = agsAdmin.ServerObjectAdmin as IServerObjectAdmin; return(true); } catch (Exception exc) { Console.WriteLine("Error: Couldn't connect to AGSServer: {0}. Message: {1}", host, exc.Message); return(false); } }
/// <summary> /// connect to ags server /// </summary> /// <param name="host">host</param> /// <returns>true if connected</returns> private static bool ConnectAGS(string host) { try { IPropertySet propertySet = new PropertySetClass(); propertySet.SetProperty("url", host); propertySet.SetProperty("ConnectionMode", esriAGSConnectionMode.esriAGSConnectionModePublisher); propertySet.SetProperty("ServerType", esriAGSServerType.esriAGSServerTypeDiscovery); propertySet.SetProperty("user", username); propertySet.SetProperty("password", password); propertySet.SetProperty("ALLOWINSECURETOKENURL", true); IAGSServerConnectionName3 connectName = new AGSServerConnectionNameClass() as IAGSServerConnectionName3; connectName.ConnectionProperties = propertySet; IAGSServerConnectionAdmin agsAdmin = ((IName)connectName).Open() as IAGSServerConnectionAdmin; soAdmin = agsAdmin.ServerObjectAdmin; return true; } catch (Exception exc) { Console.WriteLine("Error: Couldn't connect to AGSServer: {0}. Message: {1}", host, exc.Message); return false; } }