Пример #1
0
 public void AddDevice(Device device)
 {
     if (devices.ContainsKey(device.DeviceClass))
     {
         if (!devices[device.DeviceClass].Contains(device))
             devices[device.DeviceClass].Add(device);
     }
     else
     {
         List<Device> deviceList = new List<Device>();
         deviceList.Add(device);
         devices.Add(device.DeviceClass, deviceList);
     }
 }
Пример #2
0
        private void InitializeResourceManager(Context context)
        {
            try
            {
                ResourceConfiguration configuration = new ResourceConfiguration();
                configuration.Load("Monitor.xml");
                DeviceManager deviceManager = new DeviceManager();

                foreach (string key in configuration.Resources.Keys)
                {
                    foreach (ResourceConfig resourceConfig in configuration.Resources[key])
                    {
                        Resource resource = new Resource();
                        resource.DeviceClass = key;
                        resource.StateCode = resourceConfig.StateCode;
                        resource.StateDesc = resourceConfig.StateDesc;
                        System.Drawing.Image image = null;
                        try
                        {
                            if (resourceConfig.ImageFile != null && resourceConfig.ImageFile.Trim().Length != 0)
                                image = System.Drawing.Bitmap.FromFile(resourceConfig.ImageFile);
                        }
                        catch (Exception e)
                        {
                            Logger.Error("ContextInitialize�����ԭ��" + e.Message);
                        }
                        resource.Image = image;

                        deviceManager.AddResource(resource);
                    }
                }

                foreach (string key in configuration.Devices.Keys)
                {
                    foreach (DeviceConfig deviceConfig in configuration.Devices[key])
                    {
                        Device device = new Device();
                        device.DeviceClass = key;
                        device.DeviceNo = deviceConfig.DeviceNo;
                        device.X = deviceConfig.X;
                        device.Y = deviceConfig.Y;
                        device.Width = deviceConfig.Width;
                        device.Height = deviceConfig.Height;
                        deviceManager.AddDevice(device);
                    }
                }

                context.DeviceManager = deviceManager;
                configuration.Release();
            }
            catch (Exception e)
            {
                Logger.Error("ContextInitialize�����ԭ��" + e.Message);
            }
        }