示例#1
0
        /// <summary>
        /// Loads a new instance of ProjectManager.
        /// Will also override the old values of the currently loaded ProjectManager.
        /// </summary>
        /// <param name="path">Path to the configuration file.</param>
        /// <returns>Returns the instance of the ProjectManager if successful, else null.</returns>
        public override object Load(string path)
        {
            if (this.Loading != null)
                this.Loading();

            ProjectManager manager = base.Load(path) as ProjectManager;
            this.Configuration.Name = manager.Configuration.Name;

            _pluginManager = CoreSystem.Managers.Find(m => m.Name.Contains("PluginManager")) as PluginManager;
            _deviceManager = CoreSystem.Managers.Find(m => m.Name.Contains("DeviceManager")) as DeviceManager;
            _propertyManager = CoreSystem.Managers.Find(m => m.Name.Contains("PropertyManager")) as PropertyManager;
            _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;

            _displayManager.Clear();

            this.Configuration.Operations.Clear();
            _propertyManager.Nodes.Clear();

            List<Node> configuratedDevices = new List<Node>();

            foreach (Device d in manager.Configuration.Devices) {
                Device device = _deviceManager.Plugins.Find(p => p.Fullname == d.Fullname && p.AssemblyFile == d.AssemblyFile) as Device;
                Device deviceClone = device.Clone() as Device;
                deviceClone.Name = d.Name;
                deviceClone.UID = d.UID;
                deviceClone.Cache = d.Cache;

                foreach (Property p in deviceClone.Childs) {
                    if (p is ListProperty) {
                        ListProperty lp = p as ListProperty;
                        Property childProperty = d.Cache.Childs.Find(c => ((Node)c).Name == lp.Name) as Property;
                        lp.Value = childProperty.Value;
                    }
                }

                configuratedDevices.Add(deviceClone);
            }
            List<Device> devices = new List<Device>();
            foreach (Device d in configuratedDevices)
                devices.Add(d);

            this.Configuration.Devices.AddRange(devices);
            _deviceManager.AddRange(configuratedDevices);

            foreach (Operation o in manager.Configuration.Operations) {
                Operation operation = _pluginManager.Plugins.Find(p => p.Fullname == o.Fullname && p.AssemblyFile == o.AssemblyFile) as Operation;
                Operation operationClone = operation.Clone() as Operation;
                operationClone.Name = o.Name;
                operationClone.UID = o.UID;
                operationClone.Cache = o.Cache;

                _displayManager.Add(operationClone);

                CloneProperties(o, operationClone);

                Trace.WriteLine("Loading opeartion: " + operationClone.Name + " (" + operationClone.UID + ")...", LogCategory.Debug);

                LoadToolChilds(o, operationClone);

                this.Configuration.Operations.Add(operationClone);
                _propertyManager.ConnectPropertiesByNode(operationClone);
            }

            if (this.Loaded != null)
                this.Loaded();

            FileName = path;
            HasSavedProject = true;

            return this;
        }