Exemplo n.º 1
0
        public void SaveSettings()
        {
            using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
            {
                if (ms.Length != 0)
                {
                    ms.SetLength(0);
                    ms.Seek(0, System.IO.SeekOrigin.Begin);
                }

                XmlDocument doc       = new System.Xml.XmlDocument();
                XmlElement  root_elem = doc.CreateElement("root");
                foreach (IModbusStation stat in stations)
                {
                    XmlElement elem = doc.CreateElement("station");
                    StationFactory.SaveStation(elem, stat);
                    root_elem.AppendChild(elem);
                }

                foreach (IChannel ch in channels)
                {
                    XmlElement elem = doc.CreateElement("channel");
                    ChannelFactory.SaveChannel(elem, ch);
                    root_elem.AppendChild(elem);
                }
                doc.AppendChild(root_elem);
                doc.Save(ms);
                environment.Project.SetData("settings/" + StringConstants.PluginId + "_channels", ms);
            }
        }
Exemplo n.º 2
0
        void LoadSettings()
        {
            channels.Clear();
            stations.Clear();
            using (System.IO.Stream ms = environment.Project["settings/" + StringConstants.PluginId + "_channels"])
            {
                if (ms == null || ms.Length == 0)
                {
                    return;
                }
                XmlDocument doc = new System.Xml.XmlDocument();
                try
                {
                    doc.Load(ms);
                }
                catch
                {
                    return;
                }
                XmlNodeList snodes = doc.GetElementsByTagName("station");
                foreach (XmlElement snode in snodes)
                {
                    stations.Add(StationFactory.CreateStation(snode, this));
                }
                XmlNodeList nodes = doc.GetElementsByTagName("channel");
                foreach (XmlElement node in nodes)
                {
                    channels.Add(ChannelFactory.CreateChannel(node, this));
                }

                foreach (IModbusStation stat in stations)
                {
                    stat.ClearChannels();
                    foreach (ModbusChannelImp chan in channels)
                    {
                        if (chan.ModbusStation == stat.Name)
                        {
                            stat.AddChannel(chan);
                            chan.MyStation = (ModbusBaseClientStation)stat;
                        }
                    }
                }
            }
            FireChannelChangedEvent();
        }