Exemplo n.º 1
0
        /// <summary>
        /// Adds the specified node.
        /// </summary>
        /// <param name="node">The node.</param>
        public override void Add(Node node)
        {
            if (_deviceManager == null)
                _deviceManager = CoreSystem.Managers.Find(m => m.Name.Contains("DeviceManager")) as DeviceManager;
            if (_displayManager == null)
                _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager;

            if (!Nodes.Contains(node)) {
                if (node is DeviceProperty) {
                    List<Node> devices = new List<Node>();
                    foreach (Plugin plugin in _deviceManager.Plugins) {
                        if (plugin is Device)
                            devices.Add(plugin as Device);
                    }

                    DeviceProperty deviceProperty = node as DeviceProperty;
                    deviceProperty.AddDeviceList(devices.DeepClone(), _deviceManager);
                }

                if (node is Property) {
                    Property property = node as Property;
                    property.PropertyChanged += PropertyPropertyChanged;
                    if (property.IsMonitored) {
                        if (_dataStorageManager == null)
                            _dataStorageManager = CoreSystem.Managers.Find(m => m.Name.Contains("DataStorageManager")) as DataStorageManager;
                        _dataStorageManager.Add(property);
                    }
                }

                _displayManager.Add(node);
                Nodes.Add(node);
                Trace.WriteLine("Property added: " + node.ToString(), LogCategory.Debug);
                OnNodeAdded(node);
            }
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        /// <summary>
        /// Initialize the instance of the manager.
        /// </summary>
        /// <returns></returns>
        /// <exception cref="System.Exception">
        /// Could not initialize ToolManager!
        /// or
        /// Could not initialize DeviceManager!
        /// or
        /// Could not initialize ExtensionManager!
        /// or
        /// Could not get any plugins!
        /// </exception>
        public override bool Initialize()
        {
            try {
                Trace.WriteLine("Initialize PluginManager ...", LogCategory.Info);
                ToolManager toolManager = new ToolManager();
                DeviceManager deviceManager = new DeviceManager();
                ExtensionManager extensionManager = new ExtensionManager();

                if (toolManager.Initialize() == false)
                    throw new Exception("Could not initialize ToolManager!");

                if(deviceManager.Initialize() == false)
                    throw new Exception("Could not initialize DeviceManager!");

                if(extensionManager.Initialize() == false)
                    throw new Exception("Could not initialize ExtensionManager!");

                CoreSystem.Managers.Add(toolManager);
                CoreSystem.Managers.Add(deviceManager);
                CoreSystem.Managers.Add(extensionManager);

                if (UpdatePlugins() == false)
                    throw new Exception("Could not get any plugins!");

                return true;
            } catch (Exception ex) {
                Trace.WriteLine(ex.Message, ex.StackTrace, LogCategory.Error);
                return false;
            }
        }