Exemplo n.º 1
0
        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);
            }
        }