示例#1
0
        public bool DeleteProjectConnector(IDataItem item)
        {
            try
            {
                //get the connector class.  Later we will get the type projection so we can delete related objects.
                //item = ConsoleContextHelper.Instance.GetInstance((Guid)item["$Id$"]);

                //get type projection of the connector (Cireson.ProjectAutomation.ConnectorRelatesToProjects.ProjectionType) (34e516cf-644f-11b7-be02-6c886ec0573b)
                item = ConsoleContextHelper.Instance.GetProjectionInstance((Guid)item["$Id$"], new Guid("34e516cf-644f-11b7-be02-6c886ec0573b"));
                //add in some sort of confirmation on delete... later.
                if (MessageBox.Show(
                        String.Format(ServiceManagerLocalization.GetStringFromManagementPack("strConfirmDelete") + " {0}", item["DisplayName"]),
                        ServiceManagerLocalization.GetStringFromManagementPack("strDeleteConnector"), MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
                {
                    return(false);
                }
                var emg          = ConsoleContext.GetConsoleEMG();
                var emoConnector = emg.EntityObjects.GetObject <EnterpriseManagementObject>((Guid)item["$Id$"], ObjectQueryOptions.Default);
                var iddRemove    = new IncrementalDiscoveryData();

                // (Cireson.ProjectAutomation.Library) (System.ProjectConfigItemRelatesToProjectConnector) (da061582-3f6c-d7b7-d17d-0a91b8a51ace)
                ManagementPackRelationship mprConnectorHasProject = emg.EntityTypes.GetRelationshipClass(new Guid("da061582-3f6c-d7b7-d17d-0a91b8a51ace"));

                //remove the related project CIs.
                foreach (EnterpriseManagementRelationshipObject <EnterpriseManagementObject> obj in
                         emg.EntityObjects.GetRelationshipObjectsWhereSource <EnterpriseManagementObject>(emoConnector.Id, mprConnectorHasProject, DerivedClassTraversalDepth.None, TraversalDepth.OneLevel, ObjectQueryOptions.Default))
                {
                    iddRemove.Remove(obj.TargetObject);
                }



                //remove workflow rule for the connector
                try
                {
                    //Cireson Project Server Automation Library Configuration (Cireson.ProjectAutomation.Library.Configuration) (19b2a173-bea9-9e50-0709-1470424916f2)
                    ManagementPack mpConnectorWorkflow = emg.ManagementPacks.GetManagementPack(new Guid("19b2a173-bea9-9e50-0709-1470424916f2"));
                    //Project Server Connector (Cireson.ProjectAutomation.Library) (Microsoft.SystemCenter.Connector.ProjectServer) (d581d2d6-b6cd-b558-7ac7-db233a7c82ec)
                    ManagementPackClass mpcConnector    = emg.EntityTypes.GetClass(new Guid("d581d2d6-b6cd-b558-7ac7-db233a7c82ec"));
                    string             sConnectorRuleId = string.Format("{0}.{1}", "Cireson.ProjectServer.Automation", new Guid(emoConnector[mpcConnector, "Id"].Value.ToString()).ToString("N"));
                    ManagementPackRule mprConnector     = mpConnectorWorkflow.GetRule(sConnectorRuleId);
                    mprConnector.Status = ManagementPackElementStatus.PendingDelete;

                    mpConnectorWorkflow.AcceptChanges();
                }
                catch
                { }

                iddRemove.Remove(emoConnector);
                iddRemove.Commit(emg);
                return(true);
            }
            catch (Exception ex)
            {
                ConsoleContextHelper.Instance.ShowErrorDialog(ex, string.Empty, ConsoleJobExceptionSeverity.Error);
                return(false);
            }
        }
示例#2
0
 public static string GetStringFromManagementPack(string resource)
 {
     try
     {
         if (projectMP == null)
         {
             EnterpriseManagementGroup emg = ConsoleContext.GetConsoleEMG();
             projectMP = emg.ManagementPacks.GetManagementPack(new Guid("171d60e8-a0df-e4b2-f032-a5af5c8ebe39"));
         }
         return(projectMP.GetStringResource(resource).DisplayName);
     }
     catch
     {
         return("Localization Error.");
     }
 }