/// <summary> /// Updates the DataMode.Elements. /// </summary> /// <param name="newElements">ExtendedObservableCollection<TileableElement></param> private void UpdateDataModelElements(ExtendedObservableCollection <TileableElement> newElements) { #region OUs // Add and update new OUs. foreach (OrganizationalUnit newOU in newElements.GetOrganizationalUnits()) { bool ouFound = false; foreach (OrganizationalUnit oldOU in DataModel.Instance.Elements.GetOrganizationalUnits()) { if (newOU.ID == oldOU.ID) { ouFound = true; oldOU.Name = newOU.Name; oldOU.ParentID = newOU.ParentID; oldOU.LastUpdate = newOU.LastUpdate; oldOU.FQDN = newOU.FQDN; oldOU.SortingProperty = newOU.SortingProperty; break; } } if (!ouFound) { new OrganizationalUnit(newOU.ID, newOU.Name, newOU.FQDN, newOU.ParentID, newOU.Elements, newOU.LastUpdate); } } // Remove old Ous. foreach (OrganizationalUnit oldOU in DataModel.Instance.Elements.GetOrganizationalUnits()) { bool ouFound = false; foreach (OrganizationalUnit newOU in newElements.GetOrganizationalUnits()) { if (newOU.ID == oldOU.ID) { ouFound = true; break; } } if (!ouFound) { if (oldOU.ParentID == null) { DataModel.Instance.Elements.RemoveOnUI(oldOU); } else { OrganizationalUnit parentOU = DataModel.Instance.GetOu((int)oldOU.ParentID); parentOU.Elements.RemoveOnUI(oldOU); } } } #endregion #region MS // Add and update new MonitoredSystems. foreach (MonitoredSystem newMS in newElements.GetMonitoredSystems()) { bool msFound = false; foreach (MonitoredSystem oldMS in DataModel.Instance.Elements.GetMonitoredSystems()) { if (oldMS.ID == newMS.ID) { msFound = true; oldMS.LastUpdate = newMS.LastUpdate; oldMS.MAC = newMS.MAC; oldMS.Name = newMS.Name; oldMS.OuID = newMS.OuID; oldMS.ResetDate = newMS.ResetDate; oldMS.State = newMS.State; oldMS.Sequence = newMS.Sequence; oldMS.SortingProperty = newMS.SortingProperty; oldMS.CurrentPlatform = newMS.CurrentPlatform; oldMS.FQDN = newMS.FQDN; oldMS.IsAvailable = newMS.IsAvailable; oldMS.CustomUIValuesLoaded = newMS.CustomUIValuesLoaded; #region Plugins //Add and update new Plugins. foreach (Plugin newPlugin in newMS.Plugins) { bool pluginFound = false; foreach (Plugin oldPlugin in oldMS.Plugins) { if (oldPlugin.Name == newPlugin.Name) { pluginFound = true; oldPlugin.MainValue = newPlugin.MainValue; oldPlugin.Product = newPlugin.Product; oldPlugin.Platform = newPlugin.Platform; oldPlugin.Version = newPlugin.Version; oldPlugin.CurrentMapping = newPlugin.CurrentMapping; #region Indicators // Add and update new Indicators foreach (Indicator newIndi in newPlugin.Indicators) { bool indiFound = false; foreach (Indicator oldIndi in oldPlugin.Indicators) { if (oldIndi.Name == newIndi.Name) { indiFound = true; oldIndi.CurrentValue = newIndi.CurrentValue; oldIndi.DataType = newIndi.DataType; oldIndi.FilterStatement = newIndi.FilterStatement; oldIndi.IndicatorMapping = newIndi.IndicatorMapping; oldIndi.MappingDuration = newIndi.MappingDuration; oldIndi.MonitoredSystemMAC = newIndi.MonitoredSystemMAC; oldIndi.PluginName = newIndi.PluginName; oldIndi.StatementCritical = newIndi.StatementCritical; oldIndi.StatementWarning = newIndi.StatementWarning; oldIndi.StorageDuration = newIndi.StorageDuration; oldIndi.UpdateInterval = newIndi.UpdateInterval; oldIndi.IndicatorValues = newIndi.IndicatorValues; break; } } if (!indiFound) { oldPlugin.Indicators.AddOnUI(newIndi); } } // Remove old indicators var indisToRemove = new List <Indicator>(); foreach (Indicator oldIndi in oldPlugin.Indicators) { bool indiFound = false; foreach (Indicator newIndi in newPlugin.Indicators) { if (newIndi.Name == oldIndi.Name) { indiFound = true; break; } } if (!indiFound) { indisToRemove.Add(oldIndi); } } foreach (Indicator indiToRemove in indisToRemove) { oldPlugin.Indicators.RemoveOnUI(indiToRemove); } #endregion break; } } if (!pluginFound) { oldMS.Plugins.AddOnUI(newPlugin); } } //Remove old plugins. var pluginsToRemove = new List <Plugin>(); foreach (Plugin oldPlugin in oldMS.Plugins) { bool pluginFound = false; foreach (Plugin newPlugin in newMS.Plugins) { if (newPlugin.Name == oldPlugin.Name) { pluginFound = true; break; } } if (!pluginFound) { pluginsToRemove.Add(oldPlugin); } } foreach (Plugin pluginToRemove in pluginsToRemove) { oldMS.Plugins.RemoveOnUI(pluginToRemove); } #endregion break; } } if (!msFound) { new MonitoredSystem(newMS.Name, newMS.ID, newMS.MAC, newMS.FQDN, newMS.State, newMS.ResetDate, newMS.Plugins, newMS.CurrentPlatform, newMS.IsAvailable, newMS.OuID, newMS.LastUpdate); } } // Remove old MonitoredSystems. foreach (MonitoredSystem oldMS in DataModel.Instance.Elements.GetMonitoredSystems()) { bool msFound = false; foreach (MonitoredSystem newMS in newElements.GetMonitoredSystems()) { if (newMS.ID == oldMS.ID) { msFound = true; break; } } if (!msFound) { OrganizationalUnit parentOU = DataModel.Instance.GetOu(oldMS.OuID); parentOU.Elements.RemoveOnUI(oldMS); } } #endregion }