/// <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); } }
/// <summary> /// Removes the specified node. /// </summary> /// <param name="node">The node.</param> public override void Remove(Node node) { if(_displayManager == null) _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager; if (node is Operation) { Operation operation = node as Operation; if (_configuration.Operations.Contains(operation)) { _configuration.Operations.Remove(operation); OnOperationCollectionChanged(new List<Node> { node }, true); } } else if (node is Tool) { bool enableProcessor = false; if (CoreSystem.Processor.IsRunning) { Trace.WriteLine("Stopping processor while removing a tool ...", LogCategory.Info); CoreSystem.Processor.Stop(); enableProcessor = true; } foreach (Node child in node.Childs) { if (child is Property) _propertyManager.Remove(child); } Node parentNode = node.Parent; if (parentNode != null) parentNode.RemoveChild(node); if (enableProcessor) { CoreSystem.Processor.Start(); Trace.WriteLine("... processor started again!", LogCategory.Info); } } _displayManager.Remove(node); base.Remove(node); }
/// <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; }
/// <summary> /// Adds the specified node. /// </summary> /// <param name="node">The node.</param> public override void Add(Node node) { if (_displayManager == null) _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager; if (node is Operation) { Operation operation = node as Operation; if (!_configuration.Operations.Contains(operation)) { _configuration.Operations.Add(operation); _displayManager.Add(operation); OnOperationCollectionChanged(new List<Node> { node }, false); } } }
/// <summary> /// Initializes the specified is webservice. /// </summary> /// <param name="isWebservice">if set to <c>true</c> [is webservice].</param> /// <returns></returns> /// <exception cref="System.Exception"> /// Could not initialize ConfigurationManager! /// or /// Could not initialize PropertyManager! /// or /// Could not initialize PluginManager! /// or /// Could not initialize DisplayManager! /// or /// Could not initialize DataStorageManager! /// </exception> public static bool Initialize(bool isWebservice) { bool result = false; try { BaseManager.IsWebservice = isWebservice; //Environment.SetEnvironmentVariable("PATH", Environment.GetEnvironmentVariable("PATH") + ";" + BaseManager.AssemblyPath + Path.DirectorySeparatorChar + "Libs"); AppDomain.CurrentDomain.AssemblyResolve += delegate(object sender, ResolveEventArgs args) { // Find name (first argument) string assemblyName = args.Name.Substring(0, args.Name.IndexOf(',')); try { // Build the path to DLL and load it // WARNING: The path has to be absolute otherwise it will raise an ArgumentException (security) string libsPath = BaseManager.AssemblyPath + Path.DirectorySeparatorChar + "Libs" + Path.DirectorySeparatorChar + assemblyName + ".dll"; string basePath = BaseManager.AssemblyPath + Path.DirectorySeparatorChar + assemblyName + ".dll"; if (File.Exists(libsPath)) return Assembly.LoadFile(libsPath); else if (File.Exists(basePath)) return Assembly.LoadFile(basePath); else return null; } catch (Exception ex) { Trace.WriteLine(ex.Message, ex.StackTrace, LogCategory.Error); throw ex; } }; _traceListener = new TraceListener(BaseManager.LogPath, BaseManager.DaysToKeepLogFiles); _traceListener.SetLoggingCategoties(new List<string> { #if DEBUG LogCategory.Debug.GetDescription(), #endif LogCategory.Info.GetDescription(), LogCategory.Warning.GetDescription(), LogCategory.Error.GetDescription() }); System.Diagnostics.Trace.Listeners.Add(_traceListener); Trace.WriteLine("Initialize CoreSystem ...", LogCategory.Info); _managers.Clear(); // Default managers must be added to the CoreSystem. ProjectManager projectManager = new ProjectManager(); PropertyManager propertyManager = new PropertyManager(); PluginManager pluginManager = new PluginManager(); DisplayManager displayManager = new DisplayManager(); DataStorageManager dataStorageManager = new DataStorageManager(); _managers.Add(projectManager); _managers.Add(propertyManager); _managers.Add(pluginManager); _managers.Add(displayManager); _managers.Add(dataStorageManager); AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(CurrentDomain_AssemblyResolve); if (pluginManager.Initialize() == false) throw new Exception("Could not initialize PluginManager!"); if (propertyManager.Initialize() == false) throw new Exception("Could not initialize PropertyManager!"); if (projectManager.Initialize() == false) throw new Exception("Could not initialize ConfigurationManager!"); _traceListener.SetLoggingCategoties(projectManager.Configuration.LogConfiguration.Categories); if (displayManager.Initialize() == false) throw new Exception("Could not initialize DisplayManager!"); if (dataStorageManager.Initialize() == false) throw new Exception("Could not initialize DataStorageManager!"); ExtensionManager extensionManager = CoreSystem.Managers.Find(m => m.Name.Contains("ExtensionManager")) as ExtensionManager; if (extensionManager.Initialize() == false) throw new Exception("Could not initialize ExtensionManager!"); _processor = new Core.Processor(); _shell = new Core.Shell(); _shell.Initialize(); result = true; } catch (Exception ex) { Trace.WriteLine(ex.Message, ex.StackTrace, LogCategory.Error); throw ex; } return result; }
private void LoadedHandle(object sender, RoutedEventArgs e) { if (DesignerProperties.GetIsInDesignMode(this)) return; _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager; _guiManager = CoreSystem.Managers.Find(m => m.Name.Contains("GuiManager")) as GuiManager; _projectManager = CoreSystem.Managers.Find(m => m.Name.Contains("ProjectManager")) as ProjectManager; _projectManager.Loading += ProjectManagerLoading; foreach (Operation operation in _displayManager.Nodes.Where(o => o is Operation)) { AddTabParent(operation); } foreach(ImageProperty imageProperty in _displayManager.Nodes.Where(i => i is ImageProperty)) { AddTabItem(imageProperty); } if (this.DisplayTabControl.Items.Count > 0) this.DisplayTabControl.SelectedIndex = 0; _displayManager.NodeAddedEvent += NodeAddedEvent; _displayManager.ImageChangedEvent += ImageChangedEvent; _displayManager.NodeRemovedEvent += DisplayManagerNodeRemovedEvent; _displayManager.ClearEvent += ClearEvent; _guiManager.SelectedItemChanged += GuiManagerSelectedItemChanged; }
/// <summary> /// Removes the specified node. /// </summary> /// <param name="node">The node.</param> public override void Remove(Node node) { if (_displayManager == null) _displayManager = CoreSystem.Managers.Find(m => m.Name.Contains("DisplayManager")) as DisplayManager; if (node is Property) { foreach (Property child in node.Childs.Where(p => p is Property)) Remove(child); _displayManager.Remove(node); base.Remove(node); } }