public OwlDatabaseInfo(DeviceManagerSettings owlSettings, SystemServices systemServices)
 {
     Settings = owlSettings;
     SystemServices = systemServices;
     OwlDb = null;
     ApplianceListInternal = null;
 }
        private bool CheckSunnyExplorer(DeviceManagerSettings dmSettings, out String log)
        {
            log = "";

            try
            {
                FileInfo info = new FileInfo(dmSettings.ExecutablePath);
                if (info.Exists)
                {
                    log += "Sunny Explorer located";
                    return true;
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception e)
            {
                log += "Error checking Sunny Explorer at: " + dmSettings.ExecutablePath + " - Exception: " + e.Message;
            }

            String newPath = @"C:\Program Files (x86)\SMA\Sunny Explorer\SunnyExplorer.exe";

            try
            {
                FileInfo info = new FileInfo(newPath);
                if (info.Exists)
                {
                    dmSettings.ExecutablePath = newPath;
                    log += "Sunny Explorer located at '" + newPath + "'";
                    return true;
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception e)
            {
                log += "Error checking Sunny Explorer at: " + newPath + " - Exception: " + e.Message;
            }

            newPath = @"C:\Program Files\SMA\Sunny Explorer\SunnyExplorer.exe";

            try
            {
                FileInfo info = new FileInfo(newPath);
                if (info.Exists)
                {
                    dmSettings.ExecutablePath = newPath;
                    log += "Sunny Explorer located at '" + newPath + "'";
                    return true;
                }
            }
            catch (FileNotFoundException)
            {
            }
            catch (Exception e)
            {
                log += "Error checking Sunny Explorer at: " + newPath + " - Exception: " + e.Message;
            }

            log += NewLine + "Sunny Explorer not located - Please install Sunny Explorer";

            return false;
        }
        private void LoadDeviceManagers()
        {
            ObservableCollection<DeviceManagerSettings> deviceManagerList = new ObservableCollection<DeviceManagerSettings>();

            XmlElement managers = GetElement("devicemanagerlist");
            if (managers == null)
            {
                managers = GetElement("modbusmanagerlist");  // locate node to be replaced
                if (managers != null)
                {
                    XmlElement managersNew = AddElement(settings, "devicemanagerlist"); // create replacement
                    while(managers.HasChildNodes)  // locate old device manager nodes
                    {
                        XmlElement managerNew = AddElement(managersNew, "devicemanager"); // create new device manager node
                        XmlElement manager = (XmlElement)managers.FirstChild; // select old device manager
                        while (manager.HasChildNodes)
                            managerNew.AppendChild(manager.FirstChild);  // reparent old manager children to new manager
                        managers.RemoveChild(manager); // remove old device manager from old managers list
                    }
                    settings.RemoveChild(managers); // remove old device managers list
                    managers = managersNew; // install new device managers list
                }
            }
            if (managers == null)
                managers = AddElement(settings, "devicemanagerlist");
            else
                foreach(XmlElement manager in managers.ChildNodes)
                    RemoveExtraElements(manager, "serialport", 1);

            foreach (XmlNode e in managers.ChildNodes)
            {
                if (e.NodeType == XmlNodeType.Element && e.Name == "devicemanager")
                {
                    DeviceManagerSettings manager = new DeviceManagerSettings(this, (XmlElement)e);
                    deviceManagerList.Add(manager);
                }
            }

            IEnumerable<DeviceManagerSettings> sorted = deviceManagerList.OrderBy(mms => ((mms.Enabled ? "0" : "1") + mms.Description));

            _DeviceManagerList = new ObservableCollection<DeviceManagerSettings>();
            foreach (DeviceManagerSettings im in sorted)
                _DeviceManagerList.Add(im);

            _AllDevicesList = new ObservableCollection<DeviceManagerDeviceSettings>();
            _AllConsolidationDevicesList = new ObservableCollection<DeviceManagerDeviceSettings>();
            RefreshAllDevices();
            // consolidations must be registered after all devices from all managers are in the list
            foreach (DeviceManagerDeviceSettings dev in _AllDevicesList)
                dev.RegisterConsolidations();
        }
        public void DeleteDeviceManager(DeviceManagerSettings manager)
        {
            XmlElement managers = GetElement("devicemanagerlist");
            if (managers == null)
                return;

            DeviceManagerList.Remove(manager);

            foreach (XmlNode child in managers.ChildNodes)
            {
                if (child.NodeType == XmlNodeType.Element && child.Name == "devicemanager")
                {
                    if (ElementHasChild(child, "name", manager.Name))
                    {
                        managers.RemoveChild(child);
                        SettingChangedEventHandler("");
                        RefreshAllDevices();
                        return;
                    }
                }
            }
        }
        public DeviceManagerSettings AddDeviceManager()
        {
            XmlElement managers = GetElement("devicemanagerlist");
            if (managers == null)
                managers = AddElement(settings, "devicemanagerlist");

            XmlElement e = AddElement(managers, "devicemanager");
            DeviceManagerSettings manager = new DeviceManagerSettings(this, e);
            // This was producing extra serial port element
            //XmlElement e2 = AddElement(e, "serialport");
            //manager.SerialPort = new SerialPortSettings(this, e2);
            manager.Enabled = false;

            DeviceManagerList.Add(manager);

            return manager;
        }
 public DeviceManagerDeviceSettings(ApplicationSettings root, XmlElement element, DeviceManagerSettings deviceManagerSettings)
     : base(root, element)
 {
     ApplicationSettings = root;
     _DeviceManagerSettings = deviceManagerSettings;
     RemoveOldElements();
     LoadDetails();
 }