Example #1
0
        public Device GetDevice(string name, int type, bool forceNew)
        {
            Device dev = null;

            if (dicDevice.ContainsKey(type))
            {
                List<Device> list = dicDevice[type];

                for (int i = 0; i < list.Count; i++)
                {
                    if (list[i].Name == name)
                    {
                        dev = list[i];
                        break;
                    }
                }
            }

            if (dev == null && forceNew)
            {
                if (dicDevice.ContainsKey(type))
                {
                    dev = new Device(name, type, 0);
                    dicDevice[type].Add(dev);
                }
                else
                {
                    dev = new Device(name, type, 0);
                    List<Device> list = new List<Device>();
                    list.Add(dev);
                    dicDevice.Add(type, list);
                }
            }

            return dev;
        }
Example #2
0
        private void LoadXml(string fileName)
        {
            XmlDocument doc = new XmlDocument();
            doc.Load(fileName);

            XmlNode nodeDevices = doc.SelectSingleNode("Devices");

            foreach (XmlNode nodeDevice in nodeDevices.ChildNodes)
            {

              string name=  nodeDevice.Attributes["Name"].Value;
              int type = int.Parse(nodeDevice.Attributes["Type"].Value);

              if (dicDevice.ContainsKey(type))
              {
                  int devIndex = dicDevice[type].Count;
                  Device dev = new Device(name, type, devIndex);

                  dicDevice[type].Add(dev);
              }
              else
              {
                  Device dev = new Device(name, type, 0);

                  dicDevice.Add(type, new List<Device>());
                  dicDevice[type].Add(dev);
              }

            }
        }