private ItemExists GetRegistrationAssemblyId(string xrmServerDetails, AssemblyName assemblyName)
 {
     try
     {
         using (xrmService = RegistrationService.GetService(xrmServerDetails))
         {
             XrmAssembly             = new ItemExists();
             AssemblyQuery           = new QueryByAttribute(PluginAssembly.EntityLogicalName);
             AssemblyQuery.ColumnSet = new ColumnSet(true);
             AssemblyQuery.Attributes.AddRange("name");
             AssemblyQuery.Values.AddRange(assemblyName.Name);
             AssemblyQueryResults = xrmService.RetrieveMultiple(AssemblyQuery);
             if (AssemblyQueryResults.Entities != null && AssemblyQueryResults.Entities.Count > 0)
             {
                 XrmAssembly.ItemId = AssemblyQueryResults.Entities[0].Id;
                 XrmAssembly.Exists = true;
             }
             else
             {
                 XrmAssembly.ItemId = Guid.NewGuid();
                 XrmAssembly.Exists = false;
             }
             return(XrmAssembly);
         }
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Example #2
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;
     }
 }
 internal XrmPluginAssembly GetRegistrationAssembly(string xrmServerDetails, Registration registration)
 {
     try
     {
         XrmPluginAssembly xrmPluginAssembly = new XrmPluginAssembly();
         xrmPluginAssembly.Path          = registration.AssemblyPath;
         xrmPluginAssembly.IsolationMode = registration.IsolationMode;
         Assembly     assembly         = Assembly.LoadFrom(registration.AssemblyPath);
         AssemblyName assemblyName     = assembly.GetName();
         string       defaultGroupName = string.Format(CultureInfo.InvariantCulture, "{0} ({1})", assemblyName.Name, assemblyName.Version);
         ItemExists   assemblyExists   = GetRegistrationAssemblyId(xrmServerDetails, assemblyName);
         xrmPluginAssembly.Exists     = assemblyExists.Exists;
         xrmPluginAssembly.AssemblyId = assemblyExists.ItemId;
         xrmPluginAssembly.SourceType = registration.AssemblySourceType;
         FileInfo fileInfo = new FileInfo(registration.AssemblyPath);
         xrmPluginAssembly.ServerFileName = fileInfo.Name;
         if (xrmPluginAssembly.SourceType != XrmAssemblySourceType.Disk)
         {
             xrmPluginAssembly.ServerFileName = null;
         }
         string cultureLabel;
         if (assemblyName.CultureInfo.LCID == System.Globalization.CultureInfo.InvariantCulture.LCID)
         {
             cultureLabel = "neutral";
         }
         else
         {
             cultureLabel = assemblyName.CultureInfo.Name;
         }
         xrmPluginAssembly.Name    = assemblyName.Name;
         xrmPluginAssembly.Version = assemblyName.Version.ToString();
         xrmPluginAssembly.Culture = cultureLabel;
         byte[] tokenBytes = assemblyName.GetPublicKeyToken();
         if (null == tokenBytes || 0 == tokenBytes.Length)
         {
             xrmPluginAssembly.PublicKeyToken = null;
         }
         else
         {
             xrmPluginAssembly.PublicKeyToken = string.Join(string.Empty, tokenBytes.Select(b => b.ToString("X2", CultureInfo.InvariantCulture)));
         }
         xrmPluginAssembly = PluginHelper.GetRegistrationPlugins(xrmServerDetails, registration, xrmPluginAssembly, assembly, defaultGroupName);
         return(xrmPluginAssembly);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Example #4
0
 /// <summary>
 /// Method to verify if the Image is already registered in Dynamics CRM.
 /// </summary>
 /// <param name="xrmPluginStep">The XRM Step Object.</param>
 /// <param name="image">The Image Object.</param>
 /// <param name="service">The XRM Service.</param>
 /// <param name="attributeCSV">A CSV of Attributes.</param>
 /// <returns>An Object containing the details of the verification. If the Image deosn't already exists, a new Image Identifier is returned.</returns>
 private ItemExists GetImageId(XrmPluginStep xrmPluginStep, Image image, XrmService service, string attributeCSV)
 {
     try
     {
         ImageDetails = new ItemExists();
         QuerySdkMessageProcessingStepImage = new QueryExpression(SdkMessageProcessingStepImage.EntityLogicalName)
         {
             ColumnSet = new ColumnSet("sdkmessageprocessingstepimageid"),
             Criteria  = new FilterExpression()
         };
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("entityalias", ConditionOperator.Equal, image.EntityAlias);
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("imagetype", ConditionOperator.Equal, (int)image.ImageType);
         if (!string.IsNullOrEmpty(attributeCSV))
         {
             QuerySdkMessageProcessingStepImage.Criteria.AddCondition("attributes", ConditionOperator.Equal, attributeCSV);
         }
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("name", ConditionOperator.Equal, image.MessageProperty);
         QuerySdkMessageProcessingStepImage.Criteria.AddCondition("sdkmessageprocessingstepid", ConditionOperator.Equal, xrmPluginStep.StepId);
         SdkMessageProcessingStepImageEntityCollection = service.RetrieveMultiple(QuerySdkMessageProcessingStepImage);
         if (SdkMessageProcessingStepImageEntityCollection.Entities.Count != 0)
         {
             foreach (Entity entity in SdkMessageProcessingStepImageEntityCollection.Entities)
             {
                 SdkMessageProcessingStepImage = (SdkMessageProcessingStepImage)entity;
                 if (SdkMessageProcessingStepImage.SdkMessageProcessingStepImageId.HasValue)
                 {
                     ImageDetails.ItemId = SdkMessageProcessingStepImage.SdkMessageProcessingStepImageId.Value;
                     ImageDetails.Exists = true;
                 }
                 else
                 {
                     ImageDetails.ItemId = Guid.NewGuid();
                     ImageDetails.Exists = false;
                 }
             }
         }
         else
         {
             ImageDetails.ItemId = Guid.NewGuid();
             ImageDetails.Exists = false;
         }
         return(ImageDetails);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Example #5
0
 /// <summary>
 /// Method to verify if a Step is already Registered in Dynamics CRM.
 /// </summary>
 /// <param name="step">The Step to verify.</param>
 /// <param name="xrmPluginStep">The Step to populate.</param>
 /// <param name="service">The XRM Service.</param>
 /// <returns>An object containing the details of the verification, including a new Step Identifier if the Step isn't Registered.</returns>
 private ItemExists GetStepId(PluginStep step, XrmPluginStep xrmPluginStep, XrmService service)
 {
     try
     {
         ItemExists stepDetails = new ItemExists();
         stepDetails.SecureConfigId = new Guid?();
         stepDetails.ItemId         = new Guid();
         stepDetails.Exists         = false;
         QueryByAttribute querySdkProcessingStepMessage = new QueryByAttribute(SdkMessageProcessingStep.EntityLogicalName);
         querySdkProcessingStepMessage.ColumnSet = new ColumnSet(true);
         querySdkProcessingStepMessage.AddAttributeValue("name", xrmPluginStep.Name);
         EntityCollection sdkMessageProcessingStepEntityCollection = service.RetrieveMultiple(querySdkProcessingStepMessage);
         if (sdkMessageProcessingStepEntityCollection.Entities.Count != 0)
         {
             foreach (Entity entity in sdkMessageProcessingStepEntityCollection.Entities)
             {
                 SdkMessageProcessingStep sdkMessageProcessingStep = (SdkMessageProcessingStep)entity;
                 if (sdkMessageProcessingStep.SdkMessageProcessingStepId.HasValue)
                 {
                     stepDetails.ItemId = sdkMessageProcessingStep.SdkMessageProcessingStepId.Value;
                     stepDetails.Exists = true;
                 }
                 else
                 {
                     stepDetails.ItemId = Guid.NewGuid();
                     stepDetails.Exists = false;
                 }
                 stepDetails.SecureConfigId = GetSecureConfigId(step, service, stepDetails.SecureConfigId, sdkMessageProcessingStep);
             }
         }
         else
         {
             stepDetails.ItemId = Guid.NewGuid();
             stepDetails.Exists = false;
             if (!string.IsNullOrEmpty(step.SecureConfiguration))
             {
                 stepDetails.SecureConfigId = Guid.NewGuid();
             }
         }
         return(stepDetails);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Example #6
0
 /// <summary>
 /// Method to retrieve the list of Images specified in the Registration Object linked to the Step object and populate the XRM Plugin Step accordingly.
 /// </summary>
 /// <param name="registration">The Registration Object.</param>
 /// <param name="step">The Step Object.</param>
 /// <param name="xrmPluginStep">The XRM Plugin Step Object.</param>
 internal XrmPluginStep GetRegistrationImages(string xrmServerDetails, PluginStep step, XrmPluginStep xrmPluginStep)
 {
     try
     {
         foreach (Image image in step.Images)
         {
             ValidateImage(step, image);
             XrmPluginImage xrmPluginImage = new XrmPluginImage();
             using (xrmService = RegistrationService.GetService(xrmServerDetails))
             {
                 string     attributeCSV = GetAttributeCSV(new XrmMetadata(xrmServerDetails), image, step.PrimaryEntity);
                 ItemExists imageDetails = GetImageId(xrmPluginStep, image, xrmService, attributeCSV);
                 xrmPluginImage.ImageId   = imageDetails.ItemId;
                 xrmPluginImage.Exists    = imageDetails.Exists;
                 xrmPluginImage.StepId    = xrmPluginStep.StepId;
                 xrmPluginImage.ImageType = image.ImageType;
                 if (!string.IsNullOrEmpty(attributeCSV))
                 {
                     xrmPluginImage.Attributes = attributeCSV;
                 }
                 xrmPluginImage.EntityAlias     = image.EntityAlias;
                 xrmPluginImage.MessageProperty = image.MessageProperty;
                 if (image.Merge.HasValue)
                 {
                     xrmPluginImage.MessagePropertyName = GetMessagePropertyName(step.PluginMessage, image.Merge.Value);
                 }
                 else
                 {
                     xrmPluginImage.MessagePropertyName = GetMessagePropertyName(step.PluginMessage);
                 }
                 xrmPluginStep.Images.Add(xrmPluginImage);
             }
         }
         return(xrmPluginStep);
     }
     catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> )
     {
         throw;
     }
 }
Example #7
0
 private ItemExists GetRegistrationPluginId(string pluginName, string xrmServerDetails)
 {
     using (xrmService = RegistrationService.GetService(xrmServerDetails))
     {
         Plugin = new ItemExists();
         QueryRegistrationPluginId           = new QueryByAttribute(PluginType.EntityLogicalName);
         QueryRegistrationPluginId.ColumnSet = new ColumnSet();
         QueryRegistrationPluginId.AddAttributeValue("typename", pluginName);
         ResultsRegistrationPluginId = xrmService.RetrieveMultiple(QueryRegistrationPluginId);
         if (ResultsRegistrationPluginId.Entities != null && ResultsRegistrationPluginId.Entities.Count > 0)
         {
             Plugin.ItemId = ResultsRegistrationPluginId.Entities[0].Id;
             Plugin.Exists = true;
         }
         else
         {
             Plugin.ItemId = Guid.NewGuid();
             Plugin.Exists = false;
         }
         return(Plugin);
     }
 }
Example #8
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;
     }
 }