Пример #1
0
 /// <summary>
 /// Method to retrieve the Plugins from the Assembly Object.
 /// </summary>
 /// <param name="xrmPlugin">The Plugin Assembly Object.</param>
 /// <returns>The Dynamics CRM Plugin.</returns>
 private PluginType GetPluginType(XrmPlugin xrmPlugin)
 {
     try
     {
         PluginType = new PluginType()
         {
             PluginTypeId     = xrmPlugin.PluginId,
             PluginAssemblyId = new EntityReference()
             {
                 LogicalName = PluginAssembly.EntityLogicalName,
                 Id          = xrmPlugin.AssemblyId
             },
             TypeName     = xrmPlugin.TypeName,
             FriendlyName = xrmPlugin.FriendlyName,
             Name         = xrmPlugin.Name,
             Description  = xrmPlugin.Description,
             WorkflowActivityGroupName = xrmPlugin.WorkflowActivityGroupName
         };
         return(PluginType);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #2
0
 /// <summary>
 /// Method to Unregister a Plugin.
 /// </summary>
 /// <param name="xrmPlugin">The Plugin to Unregister.</param>
 /// <returns>Result.</returns>
 internal bool UnregisterPlugin(string xrmServerDetails, XrmPlugin xrmPlugin, Collection <string> errors, SolutionComponentType solutionComponentType)
 {
     try
     {
         Result = RegistrationService.Unregister(xrmServerDetails, PluginType.EntityLogicalName, xrmPlugin.PluginId, errors, solutionComponentType);
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #3
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;
     }
 }
Пример #4
0
 /// <summary>
 /// Method to Update a Plugin Registration.
 /// </summary>
 /// <param name="xrmPlugin">The Plugin to Update.</param>
 /// <returns>Result.</returns>
 internal bool UpdatePlugin(string xrmServerDetails, XrmPlugin xrmPlugin)
 {
     try
     {
         Result = false;
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             PluginType pluginType = GetPluginType(xrmPlugin);
             xrmService.Update(pluginType);
         }
         Result = true;
         return(Result);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Пример #5
0
 /// <summary>
 /// Method to Register a Plugin.
 /// </summary>
 /// <param name="xrmPlugin">The Plugin to Register.</param>
 /// <returns>The Identifier of the newly Registered Plugin.</returns>
 internal Guid RegisterPlugin(string xrmServerDetails, XrmPlugin xrmPlugin, Collection <string> errors)
 {
     try
     {
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             PluginType pluginType = GetPluginType(xrmPlugin);
             return(xrmService.Create(pluginType));
         }
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> e)
     {
         if (e.Message == "Plug-in assembly does not contain the required types or assembly content cannot be updated.")
         {
             errors.Add("Attempt to register a Type in the Assembly failed because it is not a Plugin. Type is: " + xrmPlugin.Name);
             return(Guid.Empty);
         }
         else
         {
             throw;
         }
     }
 }
Пример #6
0
 /// <summary>
 /// Method to retrieve Steps according to the Registration Object.
 /// </summary>
 /// <param name="plugin">The Registration Object, which indicates which Steps to retrieve.</param>
 /// <param name="xrmPlugin">The Plugin Object to populate with the Steps retrieved.</param>
 /// <param name="pluginName">The Name of the Plugin for which to retrieve Steps.</param>
 /// <param name="pluginExists">An object containing the Identifier of the Plugin and if the Plugin exists.</param>
 internal XrmPlugin GetPluginSteps(string xrmServerDetails, Plugin plugin, XrmPlugin xrmPlugin, string pluginName, ItemExists pluginExists)
 {
     try
     {
         foreach (PluginStep step in plugin.Steps)
         {
             if (plugin.PluginName == pluginName)
             {
                 XrmPluginStep xrmPluginStep = new XrmPluginStep();
                 xrmPluginStep.PluginId = pluginExists.ItemId;
                 if (!string.IsNullOrEmpty(step.Name))
                 {
                     xrmPluginStep.Name = step.Name;
                 }
                 else
                 {
                     xrmPluginStep.Name = pluginName + ": " + step.PluginMessage + " of " + step.PrimaryEntity;
                     if (!string.IsNullOrEmpty(step.SecondaryEntity))
                     {
                         xrmPluginStep.Name += " and " + step.SecondaryEntity;
                     }
                 }
                 if (!string.IsNullOrEmpty(step.Description))
                 {
                     xrmPluginStep.Description = step.Description;
                 }
                 else
                 {
                     xrmPluginStep.Description = xrmPluginStep.Name;
                 }
                 using (xrmService = RegistrationService.GetService(xrmServerDetails))
                 {
                     xrmPluginStep.MessageEntityId     = GetSdkMessageEntityId(xrmServerDetails, step, xrmService);
                     xrmPluginStep.MessageId           = GetSdkMessageId(step, xrmService);
                     xrmPluginStep.ImpersonatingUserId = GetImpersonatingUserId(step, xrmService);
                     ItemExists stepDetails = GetStepId(step, xrmPluginStep, xrmService);
                     xrmPluginStep.StepId = stepDetails.ItemId;
                     xrmPluginStep.Exists = stepDetails.Exists;
                     if (!string.IsNullOrEmpty(step.SecureConfiguration))
                     {
                         xrmPluginStep.SecureConfiguration = new XrmSecureConfiguration();
                         xrmPluginStep.SecureConfiguration.SecureConfiguration   = step.SecureConfiguration;
                         xrmPluginStep.SecureConfiguration.SecureConfigurationId = stepDetails.SecureConfigId;
                     }
                 }
                 xrmPluginStep.UnsecureConfiguration = step.UnsecureConfiguration;
                 xrmPluginStep.FilteringAttributes   = step.FilteringAttributes;
                 xrmPluginStep.Mode             = step.Mode;
                 xrmPluginStep.Rank             = step.Rank;
                 xrmPluginStep.InvocationSource = step.InvocationSource;
                 xrmPluginStep.Stage            = step.Stage;
                 xrmPluginStep.Deployment       = step.Deployment;
                 xrmPluginStep = ImageHelper.GetRegistrationImages(xrmServerDetails, step, xrmPluginStep);
                 xrmPlugin.Steps.Add(xrmPluginStep);
             }
         }
         return(xrmPlugin);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }