Esempio n. 1
0
        public void LoadHardwareSettings()
        {
            try
            {
                XPathDocument  xPathDoc  = new XPathDocument(Settings.HWSettingsFilePath);
                XPathNavigator navigator = xPathDoc.CreateNavigator();

                XPathNodeIterator xPathIterator = navigator.Select("/ScanevaHardwareSettings/IHWCompo");
                foreach (XPathNavigator compoNav in xPathIterator)
                {
                    string name      = compoNav.GetAttribute("Name", "");
                    string className = compoNav.GetAttribute("Class", "");
                    string isEnabled = compoNav.GetAttribute("IsEnabled", "");

                    try
                    {
                        // Create instance if not in HW store already (first load)
                        if (!hwStore.ContainsKey(name))
                        {
                            Type t = availableHWTypes.Values.FirstOrDefault(x => x.Name == className);

                            IHWManager hwInstance = (IHWManager)Activator.CreateInstance(t, log);
                            hwStore.Add(name, hwInstance);
                        }

                        // Load Settings
                        if (hwStore.ContainsKey(name))
                        {
                            // set enabled state
                            hwStore[name].IsEnabled = (isEnabled.ToLower() == "true");

                            ParametrizableObject compo = hwStore[name] as ParametrizableObject;
                            if (compo.GetType().Name == className)
                            {
                                compo.DeserializeParameterValues(compoNav, null);
                                compo.ParameterChanged("Settings Loaded");
                            }
                            else
                            {
                                log.Add("Found settings with name '" + name + "' and class '" + className + "' but no matching component in hwStore. Settings are ignored.", "Warning");
                            }
                        }
                        else
                        {
                            log.Add("Found settings with name '" + name + "' and class '" + className + "' but no matching component in hwStore. Settings are ignored.", "Warning");
                        }
                    }
                    catch (Exception e)
                    {
                        log.Add("Error loading HW Settings for " + name + " - " + e.ToString());
                    }
                }
                XPathNavigator objectNode = navigator.SelectSingleNode("/ScanevaHardwareSettings");
            }
            catch (Exception e)
            {
                log.Add("Error loading HW Settings - " + e.ToString());
            }
        }
Esempio n. 2
0
        public void LoadScanMethod(string Filename)
        {
            try
            {
                XPathDocument  xPathDoc  = new XPathDocument(Filename);
                XPathNavigator navigator = xPathDoc.CreateNavigator();

                XPathNodeIterator xPathIterator = navigator.Select("/ScanevaScanMethod/IExperiment");

                // clear scanMethod
                scanMethod.Clear();

                foreach (XPathNavigator compoNav in xPathIterator)
                {
                    string name      = compoNav.GetAttribute("Name", "");
                    string className = compoNav.GetAttribute("Class", "");

                    try
                    {
                        // Create instance
                        Type t = availableExperiments.Values.FirstOrDefault(x => x.Name == className);

                        IExperiment          expInstance = (IExperiment)Activator.CreateInstance(t, log);
                        ParametrizableObject compo       = expInstance as ParametrizableObject;
                        expInstance.HWStore       = hwStore;
                        expInstance.PositionStore = positionStore;
                        compo.Name = name;
                        scanMethod.Add(expInstance);

                        if (compo.GetType().Name == className)
                        {
                            compo.DeserializeParameterValues(compoNav, availableExperiments);
                            expInstance.HWStore       = hwStore;
                            expInstance.PositionStore = positionStore;
                            compo.ParameterChanged("Settings Loaded");
                        }
                        else
                        {
                            log.Add("Found settings with name '" + name + "' and class '" + className + "' but no matching Experiment. Settings are ignored.", "Warning");
                        }
                    }
                    catch (Exception e)
                    {
                        log.Add("Error loading Experiment Settings for " + name + " - " + e.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                log.Add("Error loading Method Settings - " + e.ToString());
            }
        }