async private Task <bool> AddMap2Connection(List <string> serviceNames, List <IMap> maps) { try { if (serviceNames.Count != maps.Count) { return(false); } for (int i = 0; i < serviceNames.Count; i++) { XmlStream stream = new XmlStream("MapDocument"); stream.Save("IMap", maps[i]); stream.ReduceDocument("//IMap"); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); stream.WriteStream(sw); //XmlDocument doc = new XmlDocument(); //doc.LoadXml(sb.ToString()); ServerConnection service = new ServerConnection(ConfigTextStream.ExtractValue(_connectionString, "server")); if (!service.AddMap(serviceNames[i], sb.ToString(), ConfigTextStream.ExtractValue(_connectionString, "user"), ConfigTextStream.ExtractValue(_connectionString, "pwd"))) { System.Windows.Forms.MessageBox.Show("Can't add map", "ERROR"); } } await Refresh(); if (Refreshed != null) { Refreshed(this); } return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "ERROR"); return(false); } }
async private Task <bool> AddService2Connection(XmlStream stream) { try { StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); stream.WriteStream(sw); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); FormAddServiceableDataset dlg = new FormAddServiceableDataset(); if (dlg.ShowDialog() != DialogResult.OK) { return(false); } ServerConnection service = new ServerConnection(ConfigTextStream.ExtractValue(_connectionString, "server")); if (!service.AddMap(dlg.ServiceName, doc.SelectSingleNode("//IServiceableDataset").OuterXml, ConfigTextStream.ExtractValue(_connectionString, "user"), ConfigTextStream.ExtractValue(_connectionString, "pwd"))) { System.Windows.Forms.MessageBox.Show("Can't add map", "ERROR"); } //Refresh(); if (!await Refresh()) { return(false); } if (Refreshed != null) { Refreshed(this); } return(true); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message, "ERROR"); return(false); } }
private void AddServiceCollection2Connection(string collectionName, string[] services) { XmlStream stream = new XmlStream("ServiceCollection"); stream.Save("Services", new XmlStreamStringArray(services)); StringBuilder sb = new StringBuilder(); StringWriter sw = new StringWriter(sb); stream.WriteStream(sw); XmlDocument doc = new XmlDocument(); doc.LoadXml(sb.ToString()); ServerConnection service = new ServerConnection(ConfigTextStream.ExtractValue(_connectionString, "server")); if (!service.AddMap(collectionName, doc.SelectSingleNode("//ServiceCollection").OuterXml, ConfigTextStream.ExtractValue(_connectionString, "user"), ConfigTextStream.ExtractValue(_connectionString, "pwd"))) { System.Windows.Forms.MessageBox.Show("Can't add map", "ERROR"); } }