protected override void ProcessRecord() { base.ProcessRecord(); base.WriteVerbose("Plugin Registration intiated"); FileInfo assemblyInfo = new FileInfo(AssemblyPath); var lastIndex = assemblyInfo.Name.LastIndexOf(".dll"); string assemblyName = lastIndex > 0 ? assemblyInfo.Name.Remove(lastIndex, 4) : assemblyInfo.Name; string version = FileVersionInfo.GetVersionInfo(AssemblyPath).FileVersion; string content = Convert.ToBase64String(File.ReadAllBytes(AssemblyPath)); base.WriteVerbose(string.Format("Assembly Name: {0}", assemblyName)); base.WriteVerbose(string.Format("Assembly Version: {0}", version)); using (var context = new CIContext(OrganizationService)) { PluginRegistrationHelper pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context); base.WriteVerbose("PluginRegistrationHelper intiated"); Assembly pluginAssembly = null; Guid pluginAssemblyId = Guid.Empty; if (File.Exists(MappingJsonPath)) { base.WriteVerbose("Reading mapping json file"); string json = File.ReadAllText(MappingJsonPath); pluginAssembly = JsonConvert.DeserializeObject <Assembly>(json); base.WriteVerbose("Deserialized mapping json file"); } else { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); } if (pluginAssembly != null) { // var assemblyTypes = IsWorkflowActivityAssembly ? pluginAssembly.WorkflowTypes : pluginAssembly.PluginTypes; if (pluginAssembly.PluginTypes == null) { base.WriteVerbose("No mapping found for types."); } else { if (RegistrationType.Equals("delsert", StringComparison.InvariantCultureIgnoreCase)) { pluginRegistrationHelper.RemoveComponentsNotInMapping(assemblyName, pluginAssembly); RegistrationType = "upsert"; } pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); foreach (var type in pluginAssembly.PluginTypes) { var pluginTypeId = pluginRegistrationHelper.UpsertPluginType(pluginAssemblyId, type, SolutionName, RegistrationType, IsWorkflowActivityAssembly, assemblyName); base.WriteVerbose(string.Format("UpsertPluginType {0} completed", pluginTypeId)); if (!IsWorkflowActivityAssembly) { foreach (var step in type.Steps) { var sdkMessageProcessingStepId = pluginRegistrationHelper.UpsertSdkMessageProcessingStep(pluginTypeId, step, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStep {0} completed", sdkMessageProcessingStepId)); foreach (var image in step.Images) { var sdkMessageProcessingStepImageId = pluginRegistrationHelper.UpsertSdkMessageProcessingStepImage(sdkMessageProcessingStepId, image, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStepImage {0} completed", sdkMessageProcessingStepImageId)); } } } } } } } base.WriteVerbose("Plugin Registration completed"); }
protected override void ProcessRecord() { base.ProcessRecord(); base.WriteVerbose("Plugin Registration intiated"); if (UseSplitAssembly) { if (!File.Exists(ProjectFilePath)) { throw new Exception("Project File Path is required if you want to split assembly."); } if (RegistrationType.Equals("delsert", StringComparison.InvariantCultureIgnoreCase)) { throw new Exception("Registration type 'Remove Plugin Types and Steps which are not in mapping and Upsert' will not work when 'Split Assembly' is enabled."); } if (!File.Exists(MappingJsonPath)) { throw new Exception("Mapping Json Path is required if you want to split assembly."); } } var assemblyDetails = AssemblyInfo.GetAssemblyInfo(AssemblyPath); string assemblyName = assemblyDetails.AssemblyName; string version = assemblyDetails.Version; string content = assemblyDetails.Content; base.WriteVerbose(string.Format("Assembly Name: {0}", assemblyName)); base.WriteVerbose(string.Format("Assembly Version: {0}", version)); using (var context = new CIContext(OrganizationService)) { PluginRegistrationHelper pluginRegistrationHelper = new PluginRegistrationHelper(OrganizationService, context, this); base.WriteVerbose("PluginRegistrationHelper intiated"); Assembly pluginAssembly = null; Guid pluginAssemblyId = Guid.Empty; if (File.Exists(MappingJsonPath)) { base.WriteVerbose("Reading mapping json file"); string json = File.ReadAllText(MappingJsonPath); pluginAssembly = JsonConvert.DeserializeObject <Assembly>(json); base.WriteVerbose("Deserialized mapping json file"); } else { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); } if (pluginAssembly != null) { // var assemblyTypes = IsWorkflowActivityAssembly ? pluginAssembly.WorkflowTypes : pluginAssembly.PluginTypes; if (pluginAssembly.PluginTypes == null) { base.WriteVerbose("No mapping found for types."); } else { if (RegistrationType.Equals("delsert", StringComparison.InvariantCultureIgnoreCase)) { pluginRegistrationHelper.RemoveComponentsNotInMapping(assemblyName, pluginAssembly); RegistrationType = "upsert"; } if (!UseSplitAssembly) { pluginAssemblyId = pluginRegistrationHelper.UpsertPluginAssembly(pluginAssembly, assemblyName, version, content, SolutionName, IsWorkflowActivityAssembly, RegistrationType); base.WriteVerbose(string.Format("UpsertPluginAssembly {0} completed", pluginAssemblyId)); } foreach (var type in pluginAssembly.PluginTypes) { if (UseSplitAssembly) { pluginAssemblyId = UploadSplitAssembly(assemblyDetails, assemblyName, version, content, pluginRegistrationHelper, pluginAssembly, type); } var pluginTypeId = pluginRegistrationHelper.UpsertPluginType(pluginAssemblyId, type, SolutionName, RegistrationType, IsWorkflowActivityAssembly, assemblyName); base.WriteVerbose(string.Format("UpsertPluginType {0} completed", pluginTypeId)); if (!IsWorkflowActivityAssembly) { foreach (var step in type.Steps) { var sdkMessageProcessingStepId = pluginRegistrationHelper.UpsertSdkMessageProcessingStep(pluginTypeId, step, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStep {0} completed", sdkMessageProcessingStepId)); foreach (var image in step.Images) { var sdkMessageProcessingStepImageId = pluginRegistrationHelper.UpsertSdkMessageProcessingStepImage(sdkMessageProcessingStepId, image, SolutionName, RegistrationType); base.WriteVerbose(string.Format("UpsertSdkMessageProcessingStepImage {0} completed", sdkMessageProcessingStepImageId)); } } } } } } } base.WriteVerbose("Plugin Registration completed"); }