Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 27 additions & 27 deletions src/XrmMockup365/Core.cs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,8 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
MessageName = RequestNameToMessageName(request.RequestName),
Depth = 1,
ExtensionDepth = 1,
OrganizationName = this.OrganizationName,
OrganizationId = this.OrganizationId,
OrganizationName = OrganizationName,
OrganizationId = OrganizationId,
PrimaryEntityName = primaryRef?.LogicalName,
};
if (primaryRef != null)
Expand All @@ -757,7 +757,10 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
var buRef = GetBusinessUnit(userRef);
pluginContext.BusinessUnitId = buRef.Id;

Mappings.RequestToEventOperation.TryGetValue(request.GetType(), out var eventOp);
// Get the request message from the mapping, if present, otherwise use the RequestName
var requestMessage = Mappings.RequestToEventOperation.TryGetValue(request.GetType(), out var eventOperation)
? eventOperation.ToString()
: request.RequestName;

var entityInfo = GetEntityInfo(request);

Expand All @@ -778,12 +781,12 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
if (preImage != null)
primaryRef.Id = preImage.Id;

if (shouldTrigger && eventOp is EventOperation preValidationOperation)
if (shouldTrigger)
{
// System Pre-validation
pluginManager.TriggerSystem(preValidationOperation, ExecutionStage.PreValidation, entityInfo.Item1, preImage, null, pluginContext, this);
pluginManager.TriggerSystem(requestMessage, ExecutionStage.PreValidation, entityInfo.Item1, preImage, null, pluginContext, this);
// Pre-validation
pluginManager.TriggerSync(preValidationOperation, ExecutionStage.PreValidation, entityInfo.Item1, preImage, null, pluginContext, this, (_) => true);
pluginManager.TriggerSync(requestMessage, ExecutionStage.PreValidation, entityInfo.Item1, preImage, null, pluginContext, this, (_) => true);
}

//perform security checks for the request
Expand All @@ -792,19 +795,19 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
//perform initialization of preoperation
InitializePreOperation(request, userRef, preImage);

if (shouldTrigger && eventOp is EventOperation preOperationOperation)
if (shouldTrigger)
{
// Shared variables should be moved to parent context when transitioning from 10 to 20.
pluginContext.ParentContext = pluginContext.Clone();
pluginContext.SharedVariables.Clear();

// Pre-operation
pluginManager.TriggerSync(preOperationOperation, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this, (p) => p.GetExecutionOrder() == 0);
workflowManager.TriggerSync(preOperationOperation, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this);
pluginManager.TriggerSync(preOperationOperation, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this, (p) => p.GetExecutionOrder() != 0);
pluginManager.TriggerSync(requestMessage, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this, (p) => p.GetExecutionOrder() == 0);
workflowManager.TriggerSync(requestMessage, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this);
pluginManager.TriggerSync(requestMessage, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this, (p) => p.GetExecutionOrder() != 0);

// System Pre-operation
pluginManager.TriggerSystem(preOperationOperation, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this);
pluginManager.TriggerSystem(requestMessage, ExecutionStage.PreOperation, entityInfo.Item1, preImage, null, pluginContext, this);
}

// Core operation
Expand All @@ -824,26 +827,23 @@ internal OrganizationResponse Execute(OrganizationRequest request, EntityReferen
pluginContext.OutputParameters["BusinessEntity"] = TryRetrieve((request as RetrieveRequest).Target);
}

if (eventOp is EventOperation postOperationOperation)
{
var syncPostImage = TryRetrieve(primaryRef);
var syncPostImage = TryRetrieve(primaryRef);

//copy the createon etc system attributes onto the target so they are available for postoperation processing
if (syncPostImage != null)
{
CopySystemAttributes(syncPostImage, entityInfo.Item1 as Entity);
}
//copy the createon etc system attributes onto the target so they are available for postoperation processing
if (syncPostImage != null)
{
CopySystemAttributes(syncPostImage, entityInfo.Item1 as Entity);
}

pluginManager.TriggerSystem(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this);
pluginManager.TriggerSystem(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this);

pluginManager.TriggerSync(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this, (p) => p.GetExecutionOrder() == 0);
workflowManager.TriggerSync(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this);
pluginManager.TriggerSync(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this, (p) => p.GetExecutionOrder() != 0);
pluginManager.TriggerSync(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this, (p) => p.GetExecutionOrder() == 0);
workflowManager.TriggerSync(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this);
pluginManager.TriggerSync(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, syncPostImage, pluginContext, this, (p) => p.GetExecutionOrder() != 0);

var asyncPostImage = TryRetrieve(primaryRef);
pluginManager.StageAsync(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, asyncPostImage, pluginContext, this);
workflowManager.StageAsync(postOperationOperation, ExecutionStage.PostOperation, entityInfo.Item1, preImage, asyncPostImage, pluginContext, this);
}
var asyncPostImage = TryRetrieve(primaryRef);
pluginManager.StageAsync(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, asyncPostImage, pluginContext, this);
workflowManager.StageAsync(requestMessage, ExecutionStage.PostOperation, entityInfo.Item1, preImage, asyncPostImage, pluginContext, this);

//When last Sync has been executed we trigger the Async jobs.
if (parentPluginContext == null)
Expand Down
9 changes: 9 additions & 0 deletions src/XrmMockup365/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using XrmPluginCore.Enums;

namespace DG.Tools.XrmMockup.Extensions
{
internal static class StringExtensions
{
public static bool Matches(this string value, EventOperation operation) => value.Equals(operation.ToString());
}
}
5 changes: 2 additions & 3 deletions src/XrmMockup365/Mappings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DG.Tools.XrmMockup {

internal static partial class Mappings {

internal static class Mappings
{
public static Dictionary<Type, string> EntityImageProperty = new Dictionary<Type, string>()
{
{ typeof(AssignRequest), nameof(AssignRequest.Target) },
Expand Down
Loading