/// <summary> /// Creates the registration in CRM. /// </summary> /// <returns></returns> public RegistrationInfo Deploy() { var result = new RegistrationInfo(this); try { var pluginHelper = new PluginHelper(_ServiceProvider); foreach (var par in _Registration.PluginAssemblyRegistrations) { var pa = par.PluginAssembly; var pluginExists = pluginHelper.DoesPluginAssemblyExist(pa.Name); if (!pluginExists.Exists) { // Create new plugin assembly registration. var newRecordId = pluginHelper.RegisterAssembly(pa); pa.PluginAssemblyId = newRecordId; result.RecordChange(pa.LogicalName, newRecordId); } else { pa.PluginAssemblyId = pluginExists.EntityReference.Id; result.RecordChange(pa.LogicalName, pluginExists.EntityReference.Id); pluginHelper.CleanOutPlugin(par); } foreach (var ptr in par.PluginTypeRegistrations) { // Create new plugin type registration. var newRecordId = pluginHelper.RegisterType(ptr.PluginType); ptr.PluginType.PluginTypeId = newRecordId; result.RecordChange(ptr.PluginType.LogicalName, newRecordId); // for each step foreach (var ps in ptr.PluginStepRegistrations) { // todo: check primary and secondary entity are valid. // check message name is valid. var messageId = pluginHelper.GetMessageId(ps.SdkMessageName); ps.SdkMessageProcessingStep.SdkMessageId = new EntityReference("sdkmessage", messageId); ps.SdkMessageProcessingStep.Configuration = ps.Config; var sdkFilterMessageId = pluginHelper.GetSdkMessageFilterId(ps.PrimaryEntityName, ps.SecondaryEntityName, messageId); ps.SdkMessageProcessingStep.SdkMessageFilterId = new EntityReference("sdkmessagefilter", sdkFilterMessageId); newRecordId = pluginHelper.RegisterStep(ps.SdkMessageProcessingStep); result.RecordChange(ps.SdkMessageProcessingStep.LogicalName, newRecordId); } } } result.Success = true; } catch (Exception e) { result.Error = e; result.Success = false; } return result; }
public void RegisterPlugin() { var crmConnectionString = ConfigurationManager.ConnectionStrings["CrmOrganisationService"]; var deployer = DeploymentBuilder.CreateDeployment() .ForTheAssemblyContainingThisPlugin<TestPlugin>("Test plugin assembly") .RunsInSandboxMode() .RegisterInDatabase() .HasPlugin<TestPlugin>() .WhichExecutesOn(SdkMessageNames.Create, "contact") .Synchronously() .PostOperation() .OnlyOnCrmServer() .AndExecutesOn(SdkMessageNames.Update, "contact") .Synchronously() .PostOperation() .OnCrmServerAndOffline() .DeployTo(crmConnectionString.ConnectionString); RegistrationInfo = deployer.Deploy(); if (!RegistrationInfo.Success) { var reason = RegistrationInfo.Error.Message; Assert.Fail("Registration failed because: {0}.", reason); // registrationInfo.Undeploy(); // Console.WriteLine("Deployment was rolled back.."); } //.AndExecutesOn(SdkMessageNames.Delete, "contact") // .Synchronously() // .PostOperation() // .OnlyOffline() }
/// <summary> /// Deletes any entities related to the registration, removing the registration from CRM. /// </summary> /// <param name="regisrationInfo"></param> public void Undeploy(RegistrationInfo regisrationInfo) { // Ensure custom test entity removed. var service = new CrmServiceProvider(new ExplicitConnectionStringProviderWithFallbackToConfig(), new CrmClientCredentialsProvider()); // clean up in reverse creation order. regisrationInfo.RelatedEntities.Reverse(); DeleteEntities(service, regisrationInfo.RelatedEntities); }
/// <summary> /// Creates the registration in CRM. /// </summary> /// <returns></returns> public RegistrationInfo Deploy() { var result = new RegistrationInfo(this); try { var pluginHelper = new PluginHelper(_ServiceProvider); foreach (var par in _Registration.PluginAssemblyRegistrations) { var pa = par.PluginAssembly; var pluginExists = pluginHelper.DoesPluginAssemblyExist(pa.Name); if (!pluginExists.Exists) { // Create new plugin assembly registration. var newRecordId = pluginHelper.RegisterAssembly(pa); pa.PluginAssemblyId = newRecordId; result.RecordChange(pa.LogicalName, newRecordId); } else { pa.PluginAssemblyId = pluginExists.EntityReference.Id; result.RecordChange(pa.LogicalName, pluginExists.EntityReference.Id); } foreach (var ptr in par.PluginTypeRegistrations) { var pluginTypeExists = pluginHelper.DoesPluginTypeExist(ptr.PluginType.TypeName); if (!pluginTypeExists.Exists) { // Create new plugin type registration. var newRecordId = pluginHelper.RegisterType(ptr.PluginType); ptr.PluginType.PluginTypeId = newRecordId; result.RecordChange(ptr.PluginType.LogicalName, newRecordId); } else { ptr.PluginType.PluginTypeId = pluginTypeExists.EntityReference.Id; result.RecordChange(ptr.PluginType.LogicalName, pluginTypeExists.EntityReference.Id); } // for each step foreach (var ps in ptr.PluginStepRegistrations) { // todo: check primary and secondary entity are valid. // check message name is valid. var messageId = pluginHelper.GetMessageId(ps.SdkMessageName); ps.SdkMessageProcessingStep.SdkMessageId = new EntityReference("sdkmessage", messageId); var sdkFilterMessageId = pluginHelper.GetSdkMessageFilterId(ps.PrimaryEntityName, ps.SecondaryEntityName, messageId); ps.SdkMessageProcessingStep.SdkMessageFilterId = new EntityReference("sdkmessagefilter", sdkFilterMessageId); var newRecordId = pluginHelper.RegisterStep(ps.SdkMessageProcessingStep); result.RecordChange(ps.SdkMessageProcessingStep.LogicalName, newRecordId); } } } result.Success = true; } catch (Exception e) { result.Error = e; result.Success = false; } return(result); }
/// <summary> /// Deletes any entities related to the registration, removing the registration from CRM. /// </summary> /// <param name="regisrationInfo"></param> public void Undeploy(RegistrationInfo regisrationInfo) { // clean up in reverse creation order. regisrationInfo.RelatedEntities.Reverse(); DeleteEntities(_ServiceProvider, regisrationInfo.RelatedEntities); }