예제 #1
0
        protected override void ProcessRecord()
        {
            var query = new QueryExpression
            {
                EntityName = Workflow.EntityLogicalName,
                ColumnSet  = new ColumnSet(true),
                Criteria   =
                {
                    Conditions =
                    {
                        new ConditionExpression("category",  ConditionOperator.Equal, (int)Workflow_Category.Workflow),
                        new ConditionExpression("type",      ConditionOperator.In,    new int[] { (int)Workflow_Type.Definition,(int)Workflow_Type.Template    }),
                        new ConditionExpression("ismanaged", ConditionOperator.Equal, false),
                    }
                }
            };

            if (!string.IsNullOrEmpty(Name))
            {
                query.Criteria.AddCondition("name", ConditionOperator.Equal, Name);
            }
            else
            {
                query.Criteria.AddCondition("name", ConditionOperator.Like, Pattern);
            }

            using (var context = new CIContext(OrganizationService))
            {
                var workflows = OrganizationService.RetrieveMultiple(query)
                                .Entities
                                .Select(x => x.ToEntity <Workflow>())
                                .ToList();

                if (workflows.Count == 0)
                {
                    WriteVerbose("Couldn't find matching unmanaged workflows.");
                    return;
                }

                var pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context, WriteVerbose, WriteWarning);
                var deletingHashSet          = new HashSet <string>();
                foreach (var wf in workflows)
                {
                    pluginRegistrationHelper.DeleteObjectWithDependencies(wf.Id, ComponentType.Workflow, deletingHashSet);
                    WriteVerbose($"Workflow {wf.Name} / {wf.Id} removed from CRM");
                }
            }
        }
예제 #2
0
        protected override void ProcessRecord()
        {
            using (var context = new CIContext(OrganizationService))
            {
                var pluginAssembly = context.PluginAssemblySet.SingleOrDefault(x => x.Name == AssemblyName);
                if (pluginAssembly == null)
                {
                    WriteWarning($"Couldn't find assembly in CRM: {AssemblyName}");
                    return;
                }

                var pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context, WriteVerbose, WriteWarning);
                pluginRegistrationHelper.DeleteObjectWithDependencies(pluginAssembly.Id, ComponentType.PluginAssembly);
                WriteVerbose($"Assembly {pluginAssembly.Name} / {pluginAssembly.Id} removed from CRM");
            }
        }