Esempio n. 1
0
 /// <summary>
 /// Method to Unregister a Registration Collection.
 /// </summary>
 /// <param name="registrationCollection">The Registration Collection to Unregister.</param>
 /// <returns>Result.</returns>
 public bool Unregister(AssemblyRegistration registrationCollection)
 {
     try
     {
         this.errors = new Collection <string>();
         Result      = false;
         if (registrationCollection != null)
         {
             foreach (Registration registration in registrationCollection.Registrations)
             {
                 XrmPluginAssembly assembly = AssemblyHelper.GetRegistrationAssembly(registrationCollection.ConnectionString, registration);
                 if (assembly.Plugins.Count != 0)
                 {
                     foreach (XrmPlugin plugin in assembly.Plugins)
                     {
                         if (plugin.Steps.Count != 0)
                         {
                             foreach (XrmPluginStep step in plugin.Steps)
                             {
                                 if (step.Images.Count != 0)
                                 {
                                     foreach (XrmPluginImage image in step.Images)
                                     {
                                         Result = ImageHelper.UnregisterImage(registrationCollection.ConnectionString, image, errors, SolutionComponentType.SDKMessageProcessingStepImage);
                                         if (!Result)
                                         {
                                             throw new ArgumentException("Unregister image failed!");
                                         }
                                     }
                                 }
                                 Result = StepHelper.UnregisterStep(registrationCollection.ConnectionString, step, errors, SolutionComponentType.SDKMessageProcessingStep);
                                 if (!Result)
                                 {
                                     throw new ArgumentException("Unregister step failed!");
                                 }
                                 if (step.SecureConfiguration != null && step.SecureConfiguration.SecureConfigurationId.HasValue)
                                 {
                                     Result = StepHelper.UnregisterSecureConfiguration(registrationCollection.ConnectionString, step.SecureConfiguration, errors, SolutionComponentType.SDKMessageProcessingStepSecureConfig);
                                     if (!Result)
                                     {
                                         throw new ArgumentException("Unregister secure configuration failed!");
                                     }
                                 }
                             }
                         }
                         Result = PluginHelper.UnregisterPlugin(registrationCollection.ConnectionString, plugin, errors, SolutionComponentType.PluginType);
                         if (!Result)
                         {
                             throw new ArgumentException("Unregister plugin failed!");
                         }
                     }
                 }
                 Result = AssemblyHelper.UnregisterAssembly(registrationCollection.ConnectionString, assembly, errors, SolutionComponentType.PluginAssembly);
                 if (!Result)
                 {
                     throw new ArgumentException("Unregister assembly failed!");
                 }
             }
         }
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Method to Register a Registration Collection.
 /// </summary>
 /// <param name="registrationCollection">The Registration Collection to Register.</param>
 /// <returns>Result.</returns>
 public bool Register(AssemblyRegistration registrationCollection)
 {
     try
     {
         this.errors = new Collection <string>();
         Result      = false;
         if (registrationCollection != null && registrationCollection.Registrations.Count != 0)
         {
             foreach (Registration registration in registrationCollection.Registrations)
             {
                 XrmPluginAssembly assembly = AssemblyHelper.GetRegistrationAssembly(registrationCollection.ConnectionString, registration);
                 if (assembly.Exists)
                 {
                     Result = AssemblyHelper.UpdateAssembly(registrationCollection.ConnectionString, assembly);
                     AssemblyHelper.AddAssemblyToSolution(registrationCollection, registration, assembly);
                 }
                 else
                 {
                     assembly.AssemblyId = AssemblyHelper.RegisterAssembly(registrationCollection.ConnectionString, assembly);
                     AssemblyHelper.AddAssemblyToSolution(registrationCollection, registration, assembly);
                     Result = true;
                 }
                 if (assembly.Plugins.Count != 0)
                 {
                     foreach (XrmPlugin plugin in assembly.Plugins)
                     {
                         if (plugin.Exists)
                         {
                             Result = PluginHelper.UpdatePlugin(registrationCollection.ConnectionString, plugin);
                         }
                         else
                         {
                             plugin.PluginId = PluginHelper.RegisterPlugin(registrationCollection.ConnectionString, plugin, errors);
                             Result          = true;
                         }
                         if (plugin.Steps.Count != 0)
                         {
                             foreach (XrmPluginStep step in plugin.Steps)
                             {
                                 if (step.Exists)
                                 {
                                     Result = StepHelper.UpdateStep(registrationCollection.ConnectionString, step);
                                     StepHelper.AddStepToSolution(registrationCollection, registration, step);
                                 }
                                 else
                                 {
                                     step.StepId = StepHelper.RegisterStep(registrationCollection.ConnectionString, step);
                                     StepHelper.AddStepToSolution(registrationCollection, registration, step);
                                     Result = true;
                                 }
                                 if (step.Images.Count != 0)
                                 {
                                     foreach (XrmPluginImage image in step.Images)
                                     {
                                         if (image.Exists)
                                         {
                                             Result = ImageHelper.UpdateImage(registrationCollection.ConnectionString, image);
                                         }
                                         else
                                         {
                                             image.ImageId = ImageHelper.RegisterImage(registrationCollection.ConnectionString, image);
                                         }
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }