コード例 #1
0
 /// <summary>
 /// Method to populate the Plugins according to the Registration Object.
 /// </summary>
 /// <param name="registration">The Registration Object indicating which Plugins to retrieve.</param>
 /// <param name="xrmPluginAssembly">The Assembly object to populate.</param>
 /// <param name="assembly">The Assembly from whence to extract Assembly Details.</param>
 /// <param name="defaultGroupName">The Default Group Name String Property.</param>
 internal XrmPluginAssembly GetRegistrationPlugins(string xrmServerDetails, Registration registration, XrmPluginAssembly xrmPluginAssembly, Assembly assembly, string defaultGroupName)
 {
     try
     {
         foreach (Type type in assembly.GetExportedTypes())
         {
             if (type.IsAbstract || !type.IsClass)
             {
                 continue;
             }
             foreach (Plugin plugin in registration.Plugins)
             {
                 if (type.FullName == plugin.PluginName)
                 {
                     XrmPluginType       xrmPluginType       = XrmPluginType.Plugin;
                     XrmPluginIsolatable xrmPluginIsolatable = XrmPluginIsolatable.Unknown;
                     string  workflowGroupName = defaultGroupName;
                     string  pluginName        = type.FullName;
                     Version sdkVersion        = GetSdkVersion(type, ref xrmPluginType, ref xrmPluginIsolatable, ref workflowGroupName, ref pluginName);
                     if (sdkVersion != null)
                     {
                         xrmPluginAssembly.SdkVersion = new Version(sdkVersion.Major, sdkVersion.Minor);
                         XrmPlugin xrmPlugin = new XrmPlugin();
                         xrmPlugin.TypeName   = type.FullName;
                         xrmPlugin.Name       = pluginName;
                         xrmPlugin.PluginType = xrmPluginType;
                         ItemExists pluginExists = GetRegistrationPluginId(pluginName, xrmServerDetails);
                         xrmPlugin.PluginId     = pluginExists.ItemId;
                         xrmPlugin.FriendlyName = pluginExists.ItemId.ToString();
                         xrmPlugin.Exists       = pluginExists.Exists;
                         xrmPlugin.AssemblyId   = xrmPluginAssembly.AssemblyId;
                         xrmPlugin.AssemblyName = xrmPluginAssembly.Name;
                         xrmPlugin.Isolatable   = xrmPluginIsolatable;
                         if (xrmPluginType == XrmPluginType.WorkflowActivity && !string.IsNullOrWhiteSpace(workflowGroupName))
                         {
                             xrmPlugin.WorkflowActivityGroupName = workflowGroupName;
                         }
                         xrmPlugin = StepHelper.GetPluginSteps(xrmServerDetails, plugin, xrmPlugin, pluginName, pluginExists);
                         xrmPluginAssembly.Plugins.Add(xrmPlugin);
                     }
                 }
             }
         }
         return(xrmPluginAssembly);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
コード例 #2
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;
     }
 }
コード例 #3
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;
     }
 }