Beispiel #1
0
 public void AddResource(Resource resource)
 {
     string key = string.Format("{0}.{1}", resource.DeviceClass, resource.StateCode);
     if (!states.ContainsKey(key))
         states.Add(key, resource);
     else
         states[key] = resource;
 }
        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);
            }
        }