This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OpportunityRepository : IOpportunityRepository | |
| { | |
| protected IOrganizationService orgService; | |
| public OpportunityRepository(IOrganizationService service) | |
| { | |
| this.orgService = service; | |
| } | |
| public Opportunity GetById(Guid id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class OpportunityRepository : IOpportunityRepository | |
| { | |
| protected Dyn365ServiceContext serviceContext; | |
| public OpportunityRepository(IOrganizationService service) | |
| { | |
| this.serviceContext = new Dyn365ServiceContext(service); | |
| } | |
| public Opportunity GetById(Guid id) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public interface IOpportunityRepository | |
| { | |
| Opportunity GetById(Guid id); | |
| Guid Create(Opportunity opportunity); | |
| void SaveChanges(); | |
| void Dispose(); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class FooPlugin : PluginBase | |
| { | |
| public FooPlugin(string unsecureString, string secureString) : base(unsecureString, secureString) | |
| { | |
| } | |
| public override bool IsContextValid(IPluginExecutionContext context) | |
| { | |
| //TODO: Add your validation code here… | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| try | |
| { | |
| //Validate input and run business logic here… | |
| } | |
| catch (InvalidPluginExecutionException e) | |
| { | |
| throw; | |
| } | |
| catch (CustomIntegrationException e) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var targetAccount = this.GetTargetEntity<Account>(pluginExecutionContext); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| protected T GetTargetEntity<T>(IPluginExecutionContext pluginExecutionContext) where T: Entity | |
| { | |
| if (pluginExecutionContext.InputParameters.Contains(TargetAttributeName) && pluginExecutionContext.InputParameters[TargetAttributeName] is Entity) | |
| { | |
| return ((Entity)pluginExecutionContext.InputParameters[TargetAttributeName])?.ToEntity<T>(); | |
| } | |
| else | |
| { | |
| throw new InvalidPluginExecutionException(OperationStatus.Failed, "Missing target value or target is not an Entity"); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if (this.IsContextValid(pluginExecutionContext)) | |
| { | |
| this.Execute(pluginExecutionContext, tracingService); | |
| } | |
| else | |
| { | |
| tracingService.Trace($"Invalid plugin execution context detected (Plugin: {this.Name})"); | |
| tracingService.Trace($"Execution context: [{pluginExecutionContext.ToFormattedString()}]"); | |
| tracingService.Trace("Plugin execution aborted"); | |
| throw new InvalidPluginExecutionException("Invalid plugin execution context detected"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public void Execute(IServiceProvider serviceProvider) | |
| { | |
| if (serviceProvider == null) | |
| { | |
| throw new ArgumentNullException(nameof(serviceProvider)); | |
| } | |
| ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService)); | |
| if (tracingService == null) | |
| { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| [TestFixture] | |
| public class TestProgram | |
| { | |
| private string expectedText = "Expected text"; | |
| private string initialText = "Initial text"; | |
| [Test] | |
| public void TestChangeValue() | |
| { | |
| var mySample = new SampleClass(initialText); |