/// <summary> /// Method to retrieve the SDK Message Identifier. /// </summary> /// <param name="step">The Step Object.</param> /// <param name="service">The XRM Service.</param> /// <returns>The SDK Message Identifier.</returns> private Guid GetSdkMessageId(PluginStep step, XrmService service) { try { SdkMessageId = new Guid(); QuerySdkMessage = new QueryByAttribute(SdkMessage.EntityLogicalName); QuerySdkMessage.AddAttributeValue("name", step.PluginMessage); SdkMessageEntityCollection = service.RetrieveMultiple(QuerySdkMessage); foreach (Entity entity in SdkMessageEntityCollection.Entities) { SdkMessage = (SdkMessage)entity; if (SdkMessage.SdkMessageId.HasValue) { SdkMessageId = SdkMessage.SdkMessageId.Value; } else { throw new ArgumentException("The message could not be found!"); } } return(SdkMessageId); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <summary> /// Method to retrieve the Impersonating User Identifier. /// </summary> /// <param name="step">The Step Object containing the user account details.</param> /// <param name="service">The XRM Service.</param> /// <returns>The Impersonating User Identifier.</returns> private Guid GetImpersonatingUserId(PluginStep step, XrmService service) { try { ImpersonatingUserId = new Guid(); QuerySystemUser = new QueryByAttribute(SystemUser.EntityLogicalName); QuerySystemUser.AddAttributeValue("domainname", step.ImpersonatingUserDomainName); SystemUserEntityCollection = service.RetrieveMultiple(QuerySystemUser); foreach (Entity entity in SystemUserEntityCollection.Entities) { User = (SystemUser)entity; if (User.SystemUserId.HasValue) { ImpersonatingUserId = User.SystemUserId.Value; } else { throw new ArgumentException("The user could not be found!"); } } return(ImpersonatingUserId); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <summary> /// Method to retrieve the SDK Message Filter Identifier. /// </summary> /// <param name="registration">The Registration Object.</param> /// <param name="step">The Step Object</param> /// <param name="service">The XRM Service.</param> /// <returns>The SDK Message Filter Identifier.</returns> private Guid GetSdkMessageEntityId(string xrmServerDetails, PluginStep step, XrmService service) { try { SdkMessageEntityId = new Guid(); XrmMetadata = new XrmMetadata(xrmServerDetails); PrimaryEntityMetadata = XrmMetadata.RetrieveEntity(step.PrimaryEntity); SecondaryEntityMetadata = new EntityMetadata(); if (!string.IsNullOrEmpty(step.SecondaryEntity)) { SecondaryEntityMetadata = XrmMetadata.RetrieveEntity(step.SecondaryEntity); } if (PrimaryEntityMetadata.MetadataId.HasValue) { QuerySdkMessageFilter = new QueryExpression { EntityName = SdkMessageFilter.EntityLogicalName, ColumnSet = new ColumnSet("sdkmessagefilterid"), Criteria = new FilterExpression() }; QuerySdkMessageFilter.Criteria.AddCondition("sdkmessageidname", ConditionOperator.Equal, step.PluginMessage); QuerySdkMessageFilter.Criteria.AddCondition("primaryobjecttypecode", ConditionOperator.Equal, PrimaryEntityMetadata.ObjectTypeCode); if (SecondaryEntityMetadata.MetadataId.HasValue) { QuerySdkMessageFilter.Criteria.AddCondition("secondaryobjecttypecode", ConditionOperator.Equal, SecondaryEntityMetadata.ObjectTypeCode); } else { if (!string.IsNullOrEmpty(step.SecondaryEntity)) { throw new ArgumentException("The secondary entity could not be found!"); } } SdkMessageFilterEntityCollection = service.RetrieveMultiple(QuerySdkMessageFilter); foreach (Entity entity in SdkMessageFilterEntityCollection.Entities) { SdkMessageFilter = (SdkMessageFilter)entity; if (SdkMessageFilter.SdkMessageFilterId.HasValue) { SdkMessageEntityId = SdkMessageFilter.SdkMessageFilterId.Value; } else { throw new ArgumentException("The message filter could not be found!"); } } } else { throw new ArgumentException("The primary entity could not be found!"); } return(SdkMessageEntityId); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <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; } }
public Publisher CreatePublisher(string uniqueName, string friendlyName, Uri supportingWebsiteUrl, string customizationPrefix, string eMailAddress, string description) { try { Publisher crmSdkPublisher = new Publisher(); using (XrmService service = new XrmService(XRMConnectionString)) { if (supportingWebsiteUrl != null) { crmSdkPublisher = new Publisher { UniqueName = uniqueName, FriendlyName = friendlyName, SupportingWebsiteUrl = supportingWebsiteUrl.AbsoluteUri, CustomizationPrefix = customizationPrefix, EMailAddress = eMailAddress, Description = description }; QueryExpression queryPublisher = new QueryExpression { EntityName = Publisher.EntityLogicalName, ColumnSet = new ColumnSet("publisherid", "customizationprefix"), Criteria = new FilterExpression() }; queryPublisher.Criteria.AddCondition("uniquename", ConditionOperator.Equal, crmSdkPublisher.UniqueName); EntityCollection queryPublisherResults; queryPublisherResults = service.RetrieveMultiple(queryPublisher); Publisher SDKPublisherResults = null; if (queryPublisherResults.Entities.Count > 0) { SDKPublisherResults = (Publisher)queryPublisherResults.Entities[0]; crmSdkPublisher.Id = (Guid)SDKPublisherResults.PublisherId; crmSdkPublisher.CustomizationPrefix = SDKPublisherResults.CustomizationPrefix; } if (SDKPublisherResults == null) { crmSdkPublisher.Id = service.Create(crmSdkPublisher); } } } return(crmSdkPublisher); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <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; } }
/// <summary> /// Method to create a new solution in Dynamics CRM. /// </summary> /// <param name="uniqueName">The unique name of the solution.</param> /// <param name="friendlyName">The friendly name of the solution.</param> /// <param name="publisherId">The identity of the publisher.</param> /// <param name="description">The description of the solution.</param> /// <param name="version">The version of the solution.</param> /// <returns>A new solution object containing the details of the new solution.</returns> public Solution CreateSolution(string uniqueName, string friendlyName, Guid publisherId, string description, string version) { try { Solution solution; using (XrmService service = new XrmService(XRMConnectionString)) { solution = new Solution { UniqueName = uniqueName, FriendlyName = friendlyName, PublisherId = new EntityReference(Publisher.EntityLogicalName, publisherId), Description = description, Version = version }; QueryExpression querySampleSolution = new QueryExpression { EntityName = Solution.EntityLogicalName, ColumnSet = new ColumnSet(), Criteria = new FilterExpression() }; querySampleSolution.Criteria.AddCondition("uniquename", ConditionOperator.Equal, solution.UniqueName); EntityCollection querySampleSolutionResults = service.RetrieveMultiple(querySampleSolution); Solution SampleSolutionResults = null; if (querySampleSolutionResults.Entities.Count > 0) { SampleSolutionResults = (Solution)querySampleSolutionResults.Entities[0]; solution.Id = (Guid)SampleSolutionResults.SolutionId; } if (SampleSolutionResults == null) { solution.Id = service.Create(solution); } return(solution); } } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }
/// <summary> /// Method to retrieve a solution from Dynamics CRM. /// </summary> /// <param name="uniqueName">The unique name of the solution to retrieve.</param> /// <returns>A solution object containing the details of the retrieved solution.</returns> public Solution RetrieveSolution(string uniqueName) { try { Solution solution; using (XrmService service = new XrmService(XRMConnectionString)) { QueryExpression querySampleSolution = new QueryExpression { EntityName = Solution.EntityLogicalName, ColumnSet = new ColumnSet(true), Criteria = new FilterExpression() }; querySampleSolution.Criteria.AddCondition("uniquename", ConditionOperator.Equal, uniqueName); solution = (Solution)service.RetrieveMultiple(querySampleSolution).Entities[0]; } return(solution); } catch (FaultException <Microsoft.Xrm.Sdk.OrganizationServiceFault> ) { throw; } }