Пример #1
0
 //Ищем связанные NA. в случае нахождения модуля - проверяем связь с локацией и сохраняем Location_Id
 EnterpriseManagementRelationshipObject <EnterpriseManagementObject> SubChild(Guid G)
 {
     try
     {
         EnterpriseManagementObject EMO = null;
         EnterpriseManagementRelationshipObject <EnterpriseManagementObject> rel = null; //new EnterpriseManagementRelationshipObject<EnterpriseManagementObject>();
         var T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(G, relNetworkAdapterHasChildNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
         foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
         {
             rel = relobj;
             EMO = relobj.TargetObject;
         }
         if (EMO.IsInstanceOf(classModule))
         {
             var G_objects = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(EMO.Id, relLocationContainsConfigItem, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
             foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> confobj in G_objects)
             {
                 Location_Id = confobj.SourceObject.Id;
             }
         }
         return(rel);
     }
     catch (Exception ex)
     {
         System.Windows.MessageBox.Show("SubChild procedure error : " + ex.Message, "Service Manager", MessageBoxButton.OK, MessageBoxImage.Error);
         return(null);
     }
 }
Пример #2
0
        public override void ExecuteCommand(IList <Microsoft.EnterpriseManagement.ConsoleFramework.NavigationModelNodeBase> nodes, Microsoft.EnterpriseManagement.ConsoleFramework.NavigationModelNodeTask task, ICollection <string> parameters)
        {
            try
            {
                // LogFile _LogFile = new LogFile(@"C:\LogForms.txt", true);
                IDataItem dataItem = null;
                //There will only ever be one item because we are going to limit this task to single select
                foreach (NavigationModelNodeBase node in nodes)
                {
                    //Check if task was started from form
                    bool startedFromForm = FormUtilities.Instance.IsNodeWithinForm(nodes[0]);
                    //If started from form
                    if (startedFromForm)
                    {
                        dataItem = FormUtilities.Instance.GetFormDataContext(node);
                    }
                    //Else started from view
                    else
                    {
                        dataItem = node;
                    }
                }

                EnterpriseManagementGroup emg = GetSession();
                ManagementPack            mpAssetCore;
                ManagementPack            mpNetworkAssetLibrary;
                ManagementPack            mpCMLibrary;

                ManagementPackClass classWindowsComputer;
                ManagementPackClass classDeployedComputer;


                ManagementPackRelationship relComputerRunsWindowsComputer;
                mpAssetCore                    = emg.ManagementPacks.GetManagementPack("SMCenter.AssetManagement.Core", "75b45bd6835084b1", new Version());
                mpNetworkAssetLibrary          = emg.ManagementPacks.GetManagementPack("SMCenter.NetworkAssetManagement.Library", "75b45bd6835084b1", new Version());
                mpCMLibrary                    = emg.ManagementPacks.GetManagementPack("Microsoft.SystemCenter.ConfigurationManager", "31bf3856ad364e35", new Version());
                classWindowsComputer           = emg.EntityTypes.GetClass("SMCenter.WindowsComputer", mpNetworkAssetLibrary);
                classDeployedComputer          = emg.EntityTypes.GetClass("SMCenter.DeployedComputer", mpNetworkAssetLibrary);
                relComputerRunsWindowsComputer = emg.EntityTypes.GetRelationshipClass("Microsoft.SystemCenter.ConfigurationManager.DeployedComputerRunsWindowsComputer", mpCMLibrary);

                EnterpriseManagementObject WC = null;
                Guid CurrentNodeId            = (Guid)dataItem["$Id$"];
                EnterpriseManagementObject DC = emg.EntityObjects.GetObject <EnterpriseManagementObject>(CurrentNodeId, ObjectQueryOptions.Default);
                //if (WC.IsInstanceOf(classWindowsComputer))
                //{
                //    var rels = emg.EntityObjects.GetRelationshipObjectsWhereTarget<EnterpriseManagementObject>(WC.Id, relComputerRunsWindowsComputer, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                //    foreach (EnterpriseManagementRelationshipObject<EnterpriseManagementObject> rel in rels)
                //    {
                //        DC = rel.SourceObject;
                //    }
                //}
                //else
                //{
                //    //_LogFile.Write(String.Format("No DC"), false);
                //    System.Windows.MessageBox.Show(DateTime.Now + " : " + "ExecuteCommand Error : " + "Текущий объект не является Windows Computer.");
                //}

                if (DC.IsInstanceOf(classDeployedComputer))
                {
                    var rels = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(DC.Id, relComputerRunsWindowsComputer, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> rel in rels)
                    {
                        WC = rel.TargetObject;
                    }
                }
                else
                {
                    //_LogFile.Write(String.Format("No DC"), false);
                    System.Windows.MessageBox.Show(DateTime.Now + " : " + "ExecuteCommand Error : " + "Текущий объект не является Deployed Computer.");
                }

                if (WC != null)
                {
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classWindowsComputer);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(WC);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else
                {
                    System.Windows.MessageBox.Show(DateTime.Now + " : Нет связанных Windows Computer!", "Service Manager", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show(DateTime.Now + " : " + "ExecuteCommand Error : " + ex.Message);
            }
        }
Пример #3
0
        private void ModulesTreeView_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e)
        {
            try
            {
                int X;
                int Y;
                if (Map.Children.Contains(RoomUI))
                {
                    RoomUI.Opacity = 0;
                }

                if (SelectedUI != null && SelectedUI.ObjectType != MapUIElement.UIType.Room)
                {
                    SelectedUI.MaxHeight = 7;
                }

                TreeViewItem SelectedItem = (TreeViewItem)e.NewValue;
                Guid         Guid_Item    = new Guid(SelectedItem.Tag.ToString());

                if (Guid_Item == LinkedLocationID)//При выборе корневой локации - не отрисовываем Room UI
                {
                    return;
                }

                //TreeViewItem SelectedItem = (TreeViewItem)ModulesTreeView.SelectedItem;
                //Ищем координаты комнаты и отрисовываем RoomUI
                //Guid TVI_Id = (Guid)SelectedItem.Tag;

                _LogFile.Write(String.Format("Debug. Guid_Item {0}", Guid_Item), false);

                if (Guid_Item != null)
                {
                    EnterpriseManagementObject sel_emo = emg.EntityObjects.GetObject <EnterpriseManagementObject>(Guid_Item, ObjectQueryOptions.Default);
                    if (sel_emo.IsInstanceOf(classLocation))
                    {
                        //Ищем координаты связи с родительской локацией
                        var confitems = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(Guid_Item, relLoctoLoc, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                        foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> rel in confitems)
                        {
                            if (rel[relLoctoLoc, "X"].Value == null)
                            {
                                X = 0;
                            }
                            else
                            {
                                int.TryParse(rel[relLoctoLoc, "X"].Value.ToString(), out X);
                                //f = true;
                            }
                            if (rel[relLoctoLoc, "Y"].Value == null)
                            {
                                Y = 0;
                            }
                            else
                            {
                                int.TryParse(rel[relLoctoLoc, "Y"].Value.ToString(), out Y);
                                //f = true;
                            }
                            if (Map.Children.Contains(RoomUI))
                            {
                                Canvas.SetLeft(RoomUI, X);
                                Canvas.SetTop(RoomUI, Y);
                                RoomUI.Opacity = 1;
                                //if (X == 0 && Y == 0)
                                //{ RoomUI.Opacity = 0; }
                                //else
                                //{ RoomUI.Opacity = 1; }
                            }
                        }
                    }
                    else
                    {
                        SelectedUI           = (MapUIElement)Map.Children[EMOId_UI[Guid_Item]];
                        SelectedUI.MaxHeight = 15;
                    }
                }



                //private Dictionary<String, Guid> UItoConfId = new Dictionary<String, Guid>();
                //NAtoUI.Add(port.TargetObject.Id, mapUIElement1.Uid);
                //UItoConfId.Add(UIRack.Uid, ConfItemId);
                //string UI_Id = EMOId_UI[Guid_Item];


                //if (SelectedUI != RoomUI)
                //{
                //    if (SelectedUI != null)
                //    {
                //    SelectedUI.MaxHeight = 7;
                //    SelectedUI = null;
                //    this.CablesTreeView.Items.Clear();
                //    }
                //    else
                //    {
                //        SelectedUI = sender as MapUIElement;
                //        if (SelectedUI != RoomUI)
                //        {
                //            SelectedUI.MaxHeight = 15;
                //            foreach (Guid NA_Id in SelectedUI.Collection_NA_IDs)
                //            {
                //                this.CablesTreeView.Items.Clear();
                //                Fill_CabelsTreeView(NA_Id);
                //            }
                //        }
                //    }

                //}


                this.CablesTreeView.Items.Clear();
                if (Guid_Item != null)
                {
                    Fill_CabelsTreeView(Guid_Item);
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("ModulsTreeView_SelectedItemChanged procedure error : " + ex.Message, "Service Manager", MessageBoxButton.OK, MessageBoxImage.Error);
                //this.Close();
            }
        }
Пример #4
0
        public ConnectionsForm(IDataItem Node)
        {
            InitializeComponent();

            try
            {
                emg                                    = GetSession();
                mpWindows                              = emg.ManagementPacks.GetManagementPack("Microsoft.Windows.Library", "31bf3856ad364e35", new Version());
                mpAssetCore                            = emg.ManagementPacks.GetManagementPack("SMCenter.AssetManagement.Core", "75b45bd6835084b1", new Version());
                mpNetworkAssetLibrary                  = emg.ManagementPacks.GetManagementPack("SMCenter.NetworkAssetManagement.Library", "75b45bd6835084b1", new Version());
                mpNetworkLibrary                       = emg.GetManagementPack("System.NetworkManagement.Library", "31bf3856ad364e35", new Version());
                mpCMLibrary                            = emg.ManagementPacks.GetManagementPack("Microsoft.SystemCenter.ConfigurationManager", "31bf3856ad364e35", new Version());
                classModule                            = emg.EntityTypes.GetClass("SMCenter.Module", mpNetworkAssetLibrary);
                classWindowsComputer                   = emg.EntityTypes.GetClass("SMCenter.WindowsComputer", mpNetworkAssetLibrary);
                classDeployedComputer                  = emg.EntityTypes.GetClass("SMCenter.DeployedComputer", mpNetworkAssetLibrary);
                classComputerNetworkAdapter            = emg.EntityTypes.GetClass("Microsoft.Windows.ComputerNetworkAdapter", mpWindows);
                classNode                              = emg.EntityTypes.GetClass("SMCenter.Node", mpNetworkAssetLibrary);
                classNodePort                          = emg.EntityTypes.GetClass("SMCenter.NodePort", mpNetworkAssetLibrary);
                classLocation                          = emg.EntityTypes.GetClass("SMCenter.Location", mpAssetCore);
                classDevice                            = emg.EntityTypes.GetClass("SMCenter.Device", mpNetworkAssetLibrary);
                classDeviceNetworkAdapter              = emg.EntityTypes.GetClass("SMCenter.Device.NetworkAdapter", mpNetworkAssetLibrary);
                classPatchPanel                        = emg.EntityTypes.GetClass("SMCenter.PatchPanel", mpNetworkAssetLibrary);
                classPatchPanelPort                    = emg.EntityTypes.GetClass("SMCenter.PatchPanelPort", mpNetworkAssetLibrary);
                relComputerRunsWindowsComputer         = emg.EntityTypes.GetRelationshipClass("Microsoft.SystemCenter.ConfigurationManager.DeployedComputerRunsWindowsComputer", mpCMLibrary);
                relComputerHostsComputerNetworkAdapter = emg.EntityTypes.GetRelationshipClass("Microsoft.Windows.ComputerHostsComputerNetworkAdapter", mpWindows);
                relLoctoLoc                            = emg.EntityTypes.GetRelationshipClass("SMCenter.LocationContainsChildLocation", mpAssetCore);
                //relNetworkAdapterHasChildNetworkAdapter = emg.EntityTypes.GetRelationshipClass("SMCenter.NetworkAdapterHasChildNetworkAdapter", mpNetworkAssetLibrary);
                relChildNetworkAdapterRefParentNetworkAdapter = emg.EntityTypes.GetRelationshipClass("SMCenter.ChildNetworkAdapterRefParentNetworkAdapter", mpNetworkAssetLibrary);
                //relLocationContainsConfigItem = emg.EntityTypes.GetRelationshipClass("SMCenter.LocationContainsConfigItem", mpAssetCore);
                relConfigItemRefLocation        = emg.EntityTypes.GetRelationshipClass("SMCenter.ConfigItemRefLocation", mpAssetCore);
                relNodeComposedOfNetworkAdapter = emg.EntityTypes.GetRelationshipClass("System.NetworkManagement.NodeComposedOfNetworkAdapter", mpNetworkLibrary);
                relDeviceHostNetworkAdapter     = emg.EntityTypes.GetRelationshipClass("SMCenter.DeviceHostsNetworkAdapter", mpNetworkAssetLibrary);

                this.ConnectionsTreeView.Items.Clear();
                this.CabelsTreeView.Items.Clear();
                TreeViewItem treeitem = new TreeViewItem();

                LogFile = new LogFile(@"C:\LogFile.txt", true);

                CablesTree = new CablesTree(emg, relChildNetworkAdapterRefParentNetworkAdapter, classModule, relConfigItemRefLocation, LogFile);

                //Get CurrentNode
                Guid CurrentNodeId = (Guid)Node["$Id$"];
                EMO = emg.EntityObjects.GetObject <EnterpriseManagementObject>(CurrentNodeId, ObjectQueryOptions.Default);

                this.txtTargetObject.Text = EMO.FullName;

                Guid Id_NA = new Guid();
                if (EMO.IsInstanceOf(classModule))
                {
                    this.CabelsTreeView.Items.Add(CablesTree.CreateTreeViewItem(CurrentNodeId));
                }
                else if (EMO.IsInstanceOf(classWindowsComputer))
                {
                    #region
                    var T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(CurrentNodeId, relComputerHostsComputerNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
                    {
                        Id_NA = relobj.TargetObject.Id;
                    }
                    this.CabelsTreeView.Items.Add(CablesTree.CreateTreeViewItem(Id_NA));

                    treeitem = ConnectionsTree.Create(Id_NA, emg);
                    if (treeitem != null)
                    {
                        this.ConnectionsTreeView.Items.Add(treeitem);
                    }
                    #endregion
                }
                else if (EMO.IsInstanceOf(classDeployedComputer))
                {
                    #region
                    ObservableCollection <Guid> GuidCol = new ObservableCollection <Guid>();
                    var T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(CurrentNodeId, relComputerRunsWindowsComputer, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
                    {
                        GuidCol.Add(relobj.TargetObject.Id);
                    }
                    //Для каждого WindowsComputer ищем свой NetworkAdapter
                    foreach (Guid id in GuidCol)
                    {
                        T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(id, relComputerHostsComputerNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                        foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
                        {
                            Id_NA = relobj.TargetObject.Id;
                        }
                        this.CabelsTreeView.Items.Add(CablesTree.Go(Id_NA));
                        treeitem = ConnectionsTree.Create(Id_NA, emg);
                        if (treeitem != null)
                        {
                            this.ConnectionsTreeView.Items.Add(treeitem);
                        }
                    }
                    #endregion
                }
                else if (EMO.IsInstanceOf(classNode))
                {
                    #region
                    ObservableCollection <Guid> GuidCol = new ObservableCollection <Guid>();
                    var T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(CurrentNodeId, relNodeComposedOfNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
                    {
                        GuidCol.Add(relobj.TargetObject.Id);
                    }
                    foreach (Guid id in GuidCol)
                    {
                        this.CabelsTreeView.Items.Add(CablesTree.Go(id));
                        treeitem = ConnectionsTree.Create(id, emg);
                        if (treeitem != null)
                        {
                            this.ConnectionsTreeView.Items.Add(treeitem);
                        }
                    }
                    #endregion
                }
                else if (EMO.IsInstanceOf(classNodePort))
                {
                    this.CabelsTreeView.Items.Add(CablesTree.Go(CurrentNodeId));
                    treeitem = ConnectionsTree.Create(CurrentNodeId, emg);
                    if (treeitem != null)
                    {
                        this.ConnectionsTreeView.Items.Add(treeitem);
                    }
                }
                else if (EMO.IsInstanceOf(classDevice))
                {
                    #region
                    var T_objects = emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(CurrentNodeId, relDeviceHostNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in T_objects)
                    {
                        Id_NA = relobj.TargetObject.Id;
                    }
                    this.CabelsTreeView.Items.Add(CablesTree.Go(Id_NA));
                    treeitem = ConnectionsTree.Create(Id_NA, emg);
                    if (treeitem != null)
                    {
                        this.ConnectionsTreeView.Items.Add(treeitem);
                    }
                    #endregion
                }
                else if (EMO.IsInstanceOf(classDeviceNetworkAdapter))
                {
                    this.CabelsTreeView.Items.Add(CablesTree.Go(CurrentNodeId));
                    treeitem = ConnectionsTree.Create(CurrentNodeId, emg);
                    if (treeitem != null)
                    {
                        this.ConnectionsTreeView.Items.Add(treeitem);
                    }
                }
            }
            catch (Exception ex)
            {
                System.Windows.MessageBox.Show("Initialize procedure error : " + ex.Message, "Service Manager", MessageBoxButton.OK, MessageBoxImage.Error);
                this.Close();
            }
        }
Пример #5
0
        private void CabelsTreeView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            TreeViewItem SelectedTreeItem = (TreeViewItem)this.CabelsTreeView.SelectedItem;

            if (SelectedTreeItem.Header.ToString().Contains("Cable.Footage"))
            {
            }
            else
            {
                //Get CurrentNode

                Guid G = new Guid(SelectedTreeItem.Tag.ToString());
                EMO = emg.EntityObjects.GetObject <EnterpriseManagementObject>(G, ObjectQueryOptions.Default);

                //Guid Id_NA = new Guid();
                if (EMO.IsInstanceOf(classModule))
                {
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classModule);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(EMO);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else if (EMO.IsInstanceOf(classNodePort))
                {
                    var items = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(G, relNodeComposedOfNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in items)
                    {
                        EMO = relobj.SourceObject;
                    }
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classNode);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(EMO);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else if (EMO.IsInstanceOf(classDeviceNetworkAdapter))
                {
                    var items = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(G, relDeviceHostNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in items)
                    {
                        EMO = relobj.SourceObject;
                    }
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classDevice);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(EMO);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else if (EMO.IsInstanceOf(classComputerNetworkAdapter))
                {
                    var items = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(G, relComputerHostsComputerNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in items)
                    {
                        EMO = relobj.SourceObject;
                    }
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classWindowsComputer);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(EMO);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else if (EMO.IsInstanceOf(classPatchPanelPort))
                {
                    var items = emg.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(G, relNodeComposedOfNetworkAdapter, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default);
                    foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> relobj in items)
                    {
                        EMO = relobj.SourceObject;
                    }
                    EnterpriseManagementObjectDataType dataType = new EnterpriseManagementObjectDataType(classPatchPanel);
                    IDataItem itemIdentity = dataType.CreateProxyInstance(EMO);
                    Microsoft.EnterpriseManagement.GenericForm.FormUtilities.Instance.PopoutForm(itemIdentity);
                }
                else
                {
                    System.Windows.MessageBox.Show("Unknown object!");
                }
            }
        }
Пример #6
0
        public NewDestinationDialog(ManagementGroup managementGroup, Guid moId)
        {
            ManagementGroup  = managementGroup;
            ExistingObjectId = moId;
            InitializeComponent();

            relResourcePoolShouldManageEntity  = ManagementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.ManagementActionPointShouldManageEntityRelationshipId);
            relHealthServiceShouldManageEntiry = ManagementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.HealthServiceShouldManageEntityRelationshipId);
            relMAPManagesEntity = ManagementGroup.EntityTypes.GetRelationshipClass(SystemCenterId.ManagementActionPointManagesEntityRelationshipId);
            fqdnClass           = ManagementGroup.EntityTypes.GetClass(IDs.FullyQualifiedDomainNameClassId);

            cbResourcePools.Items.Clear();
            poolClass              = ManagementGroup.EntityTypes.GetClass(SystemCenterId.ManagementServicePoolClassId);
            healthServiceClass     = ManagementGroup.EntityTypes.GetClass(SystemCenterId.HealthServiceClassId);
            managementServiceClass = ManagementGroup.EntityTypes.GetClass(SystemCenterId.ManagementServiceClassId);
            cbResourcePools.Items.AddRange(ManagementGroup.EntityObjects.GetObjectReader <MonitoringObject>(poolClass, ObjectQueryOptions.Default).ToArray());

            if (ExistingObjectId != Guid.Empty)
            {
                // object
                ExistingObject            = ManagementGroup.EntityObjects.GetObject <MonitoringObject>(ExistingObjectId, ObjectQueryOptions.Default);
                tbDisplayName.Text        = ExistingObject[SystemId.EntityClassProperties.DisplayNamePropertyId].Value?.ToString() ?? "";
                tbFQDN.Text               = ExistingObject[IDs.FullyQualifiedDomainNameClassProperties.FullyQualifiedDomainNamePropertyId].Value?.ToString() ?? "";
                tbFQDN.ReadOnly           = true;
                cbAllowDuplicates.Enabled = false;
                nudTargetIndex.Value      = Convert.ToDecimal(ExistingObject[IDs.FullyQualifiedDomainNameClassProperties.TargetIndexPropertyId].Value ?? 0);
                nudTargetIndex.Enabled    = false;
                tbDescription.Text        = ExistingObject[IDs.FullyQualifiedDomainNameClassProperties.DescriptionPropertyId].Value?.ToString() ?? "";

                // not SHOULD, but MANAGES, i.e. factual
                IEnumerable <MonitoringObject> allManagingObject = FindActionPoints(ExistingObject);
                // this is what we submit as recommendations
                IEnumerable <EnterpriseManagementRelationshipObject <EnterpriseManagementObject> > allMAPRelations = ManagementGroup.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(ExistingObject.Id, relResourcePoolShouldManageEntity, DerivedClassTraversalDepth.Recursive, TraversalDepth.OneLevel, ObjectQueryOptions.Default).Where(x => !x.IsDeleted);
                IEnumerable <EnterpriseManagementRelationshipObject <EnterpriseManagementObject> > allHSRelations  = ManagementGroup.EntityObjects.GetRelationshipObjectsWhereTarget <EnterpriseManagementObject>(ExistingObject.Id, relHealthServiceShouldManageEntiry, DerivedClassTraversalDepth.Recursive, TraversalDepth.OneLevel, ObjectQueryOptions.Default).Where(x => !x.IsDeleted);
                bool outOfSync = (!allManagingObject.Any() && (allMAPRelations.Any() || allHSRelations.Any()));
                if (allManagingObject.Any())
                {
                    if (allManagingObject.Count() > 1)
                    {
                        MessageBox.Show($"There are more than one management action point associated with the current destination object. This may cause unpredictable results.\r\nTo fix the issue, please reassign different management action point.", "Warning!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    EnterpriseManagementObject managingObject = allManagingObject.First();
                    outOfSync = outOfSync || (allMAPRelations.Any() && allMAPRelations.First().SourceObject.Id != managingObject.Id) || (allHSRelations.Any() && allHSRelations.First().SourceObject.Id != managingObject.Id);

                    if (managingObject.IsInstanceOf(poolClass))
                    {
                        rbPool.Checked = true;
                        int newIndex = -1;
                        for (int idx = 0; idx < cbResourcePools.Items.Count; idx++)
                        {
                            if (((MonitoringObject)cbResourcePools.Items[idx]).Id == managingObject.Id)
                            {
                                newIndex = idx;
                            }
                        }
                        cbResourcePools.SelectedIndex = newIndex;
                    }
                    else if (managingObject.IsInstanceOf(healthServiceClass))
                    {
                        rbAgent.Checked = true;
                        lbAgentList.Items.Clear();
                        lbAgentList.Items.Add(ManagementGroup.EntityObjects.GetObject <MonitoringObject>(managingObject.Id, ObjectQueryOptions.Default));
                        lbAgentList.SelectedIndex = 0;
                    }
                    else
                    {
                        MessageBox.Show($"Unexpected result while looking for management action point.");
                        rbAgent.Checked = false;
                        rbPool.Checked  = false;
                    }
                }
                else
                {
                    rbAgent.Checked = false;
                    rbPool.Checked  = false;
                }
                if (outOfSync)
                {
                    lMAPOutOfSyncWarning.Visible = true;
                    cbUnlockControls.Visible     = true;
                    cbUnlockControls.Checked     = true;

                    rbPool.Enabled          = false;
                    cbResourcePools.Enabled = false;
                    rbAgent.Enabled         = false;
                    tbAgentLookup.Enabled   = false;
                    btAgentLookup.Enabled   = false;
                    lbAgentList.Enabled     = false;
                }
            }
        }