Beispiel #1
0
 private void OnShowInstanceProperties(object sender, CommandEventArgs e)
 {
     using (InstancePropertiesDialog propertiesDialog = new InstancePropertiesDialog())
     {
         Site.Container.Add(propertiesDialog);
         if (SelectedItem is PartialMonitoringObject pmo)
         {
             MonitoringObject mo = ManagementGroup.EntityObjects.GetObject <MonitoringObject>(pmo.Id, ObjectQueryOptions.Default);
             propertiesDialog.Entity = mo;
             propertiesDialog.Type   = mo.GetMostDerivedClasses().FirstOrDefault();
             if (propertiesDialog.Type == null)
             {
                 return;
             }
             propertiesDialog.ShowDialog();
         }
     }
 }
        public NewTestDialog(ManagementGroup managementGroup, ManagementPackClass managementPackClass, MonitoringObject baseDestinationObject, Guid existingTestObjectId)
        {
            InitializeComponent();
            ManagementGroup = managementGroup;

            if (existingTestObjectId == Guid.Empty)
            {
                if (baseDestinationObject == null)
                {
                    throw new ArgumentNullException(nameof(baseDestinationObject));
                }
                TargetClass = managementPackClass ?? throw new ArgumentNullException(nameof(managementPackClass));
            }
            else
            {
                ExistingObject = ManagementGroup.EntityObjects.GetObject <MonitoringObject>(existingTestObjectId, ObjectQueryOptions.Default);
                TargetClass    = ExistingObject.GetMostDerivedClasses().First();
            }
            rtbDescription.Text = TargetClass.Description;
            try
            {
                ManagementPackKnowledgeArticle kb = TargetClass.GetKnowledgeArticle(Thread.CurrentThread.CurrentUICulture);
                btDocumentation.Enabled = kb != null;
                llLearnMore.Enabled     = kb != null;
            }
            catch (ObjectNotFoundException)
            {
                btDocumentation.Enabled = false;
                llLearnMore.Enabled     = false;
            }

            if (existingTestObjectId == Guid.Empty)
            {
                Text = $"New {(string.IsNullOrWhiteSpace(TargetClass.DisplayName) ? TargetClass.Name : TargetClass.DisplayName)}";
            }
            else
            {
                Text = $"Edit {(string.IsNullOrWhiteSpace(TargetClass.DisplayName) ? TargetClass.Name : TargetClass.DisplayName)}";
            }

            CreatableEnterpriseManagementObject testObject = new CreatableEnterpriseManagementObject(managementGroup, TargetClass);

            // initialize or load other properties
            if (existingTestObjectId == Guid.Empty)
            {
                testObject[IDs.TestBaseClassProperties.TestIdPropertyId].Value         = Guid.NewGuid();
                testObject[SystemId.EntityClassProperties.DisplayNamePropertyId].Value = string.IsNullOrWhiteSpace(TargetClass.DisplayName) ? TargetClass.Name : TargetClass.DisplayName;
                // bind to host object -- from explicit parent
                testObject[IDs.FullyQualifiedDomainNameClassProperties.FullyQualifiedDomainNamePropertyId].Value = baseDestinationObject[IDs.FullyQualifiedDomainNameClassProperties.FullyQualifiedDomainNamePropertyId].Value; // parent key 1
                testObject[IDs.FullyQualifiedDomainNameClassProperties.TargetIndexPropertyId].Value = baseDestinationObject[IDs.FullyQualifiedDomainNameClassProperties.TargetIndexPropertyId].Value;                           // parent key 2
            }
            else
            {
                // host object binding will be done automatically as a part of property copying
                foreach (ManagementPackProperty mpProperty in ExistingObject.GetProperties())
                {
                    testObject[mpProperty].Value = ExistingObject[mpProperty].Value;
                }
            }
            CreatableObjectAdapter        = new CreatableObjectAdapter(testObject);
            pgObjectEditor.SelectedObject = CreatableObjectAdapter;
        }
        private void OnDeleteTest(object sender, CommandEventArgs e)
        {
            if (DetailView is TestBrowser tb && tb.Grid.SelectedRows != null && tb.Grid.SelectedRows.Count > 0)
            {
                try
                {
                    TestObjectAdapter firstDataItem = (TestObjectAdapter)tb.Grid.SelectedRows[0].DataBoundItem;

                    bool doDelete = false;
                    if (tb.Grid.SelectedRows.Count == 1)
                    {
                        doDelete = MessageBox.Show($"You're about to delete the {firstDataItem.DisplayName} destination.\r\nAre you sure?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                    }
                    else
                    {
                        doDelete = MessageBox.Show($"You're about to delete multiple destinations.\r\nAre you sure?", "Warning!", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes;
                    }
                    if (doDelete)
                    {
                        EnterpriseManagementConnector connector            = ManagementGroup.ConnectorFramework.GetMonitoringConnector();
                        IncrementalDiscoveryData      incrementalDiscovery = new IncrementalDiscoveryData();
                        ManagementPackClass           fqdnClass            = ManagementGroup.EntityTypes.GetClass(IDs.FullyQualifiedDomainNameClassId);

                        foreach (DataGridViewRow gridRow in tb.Grid.SelectedRows)
                        {
                            TestObjectAdapter dataItem      = (TestObjectAdapter)gridRow.DataBoundItem;
                            MonitoringObject  currentObject = ManagementGroup.EntityObjects.GetObject <MonitoringObject>(dataItem.Source.Id, ObjectQueryOptions.Default);
                            CreatableEnterpriseManagementObject oldInstance = new CreatableEnterpriseManagementObject(ManagementGroup, currentObject.GetMostDerivedClasses().First());
                            // host keys
                            oldInstance[IDs.FullyQualifiedDomainNameClassProperties.FullyQualifiedDomainNamePropertyId].Value = currentObject[IDs.FullyQualifiedDomainNameClassProperties.FullyQualifiedDomainNamePropertyId].Value;
                            oldInstance[IDs.FullyQualifiedDomainNameClassProperties.TargetIndexPropertyId].Value = currentObject[IDs.FullyQualifiedDomainNameClassProperties.TargetIndexPropertyId].Value;
                            // key
                            oldInstance[IDs.TestBaseClassProperties.TestIdPropertyId].Value = currentObject[IDs.TestBaseClassProperties.TestIdPropertyId].Value;
                            incrementalDiscovery.Remove(oldInstance);
                        }

                        incrementalDiscovery.Commit(connector);
                    }

                    // emulate Refresh command for detail view
                    SendRefreshCommandToDetailView();
                }
                catch (Exception ex)
                {
                    MessageBox.Show($"In {System.Reflection.MethodBase.GetCurrentMethod().Name} {ex.GetType().Name} said {ex.Message} at {ex.StackTrace}");
                }
            }
        }