コード例 #1
0
        internal WorkflowTree ExecuteWorkflow(WorkflowTree workflow, Entity primaryEntity, PluginContext pluginContext, Core core)
        {
            var provider = new MockupServiceProviderAndFactory(core, pluginContext, new TracingService());
            var service  = provider.CreateAdminOrganizationService(new MockupServiceSettings(true, true, MockupServiceSettings.Role.SDK));

            return(workflow.Execute(primaryEntity, core.TimeOffset, service, provider, provider.GetService(typeof(ITracingService)) as ITracingService));
        }
コード例 #2
0
ファイル: PluginManager.cs プロジェクト: reager/XrmMockup
            public void ExecuteIfMatch(object entityObject, Entity preImage, Entity postImage, PluginContext pluginContext, Core core)
            {
                // Check if it is supposed to execute. Returns preemptively, if it should not.
                var entity    = entityObject as Entity;
                var entityRef = entityObject as EntityReference;

                var guid        = (entity != null) ? entity.Id : entityRef.Id;
                var logicalName = (entity != null) ? entity.LogicalName : entityRef.LogicalName;

                if (VerifyPluginTrigger(entity, logicalName, guid, preImage, postImage, pluginContext))
                {
                    var thisPluginContext = CreatePluginContext(pluginContext, guid, logicalName, preImage, postImage);

                    //Create Serviceprovider, and execute plugin
                    MockupServiceProviderAndFactory provider = new MockupServiceProviderAndFactory(core, thisPluginContext, new TracingService());
                    try
                    {
                        pluginExecute(provider);
                    }
                    catch (TargetInvocationException e)
                    {
                        ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                    }

                    foreach (var parameter in thisPluginContext.SharedVariables)
                    {
                        pluginContext.SharedVariables[parameter.Key] = parameter.Value;
                    }
                }
            }
コード例 #3
0
 /// <summary>
 /// Create a new XrmMockup instance
 /// </summary>
 /// <param name="settings"></param>
 /// <param name="metadata"></param>
 /// <param name="workflows"></param>
 /// <param name="securityRoles"></param>
 protected XrmMockupBase(XrmMockupSettings settings, MetadataSkeleton metadata, List <Entity> workflows, List <SecurityRole> securityRoles)
 {
     this.Core           = new Core(settings, metadata, workflows, securityRoles);
     this.ServiceFactory = new MockupServiceProviderAndFactory(this.Core);
     if (settings.EnableProxyTypes == true)
     {
         EnableProxyTypes();
     }
 }
コード例 #4
0
        /// <summary>
        /// Creates a new instance of Core
        /// </summary>
        /// <param name="Settings"></param>
        /// <param name="metadata"></param>
        /// <param name="SecurityRoles"></param>
        /// <param name="Workflows"></param>
        public Core(XrmMockupSettings Settings, MetadataSkeleton metadata, List <Entity> Workflows, List <SecurityRole> SecurityRoles)
        {
            this.dataMethods    = new DataMethods(this, metadata, SecurityRoles);
            this.ServiceFactory = new MockupServiceProviderAndFactory(this);
            this.settings       = Settings;
            this.InitRequestMap();
            this.pluginManager   = new PluginManager(Settings.BasePluginTypes, metadata.EntityMetadata, metadata.Plugins);
            this.workflowManager = new WorkflowManager(Settings.CodeActivityInstanceTypes, Settings.IncludeAllWorkflows, Workflows, metadata.EntityMetadata);

            var tracingService = new TracingService();
            var factory        = new MockupServiceProviderAndFactory(this, null, tracingService);
            var service        = factory.CreateOrganizationService(null, new MockupServiceSettings(false, true, MockupServiceSettings.Role.SDK));

            dataMethods.SetWorkflowServices(tracingService, factory, service);
        }
コード例 #5
0
        /// <summary>
        /// Create a new XrmMockup instance
        /// </summary>
        /// <param name="settings"></param>
        protected XrmMockupBase(XrmMockupSettings settings)
        {
            var metadataDirectory = "../../Metadata/";

            if (settings.MetadataDirectoryPath != null)
            {
                metadataDirectory = settings.MetadataDirectoryPath;
            }
            MetadataSkeleton    metadata      = Utility.GetMetadata(metadataDirectory);
            List <Entity>       workflows     = Utility.GetWorkflows(metadataDirectory);
            List <SecurityRole> securityRoles = Utility.GetSecurityRoles(metadataDirectory);

            this.Core           = new Core(settings, metadata, workflows, securityRoles);
            this.ServiceFactory = new MockupServiceProviderAndFactory(this.Core);
            if (settings.EnableProxyTypes == true)
            {
                EnableProxyTypes();
            }
        }
コード例 #6
0
        internal void ExecuteWaitingWorkflows(PluginContext pluginContext, Core core)
        {
            var provider = new MockupServiceProviderAndFactory(core, pluginContext, new TracingService());
            var service  = provider.CreateOrganizationService(null, new MockupServiceSettings(true, true, MockupServiceSettings.Role.SDK));

            foreach (var waitInfo in waitingWorkflows.ToList())
            {
                waitingWorkflows.Remove(waitInfo);
                var variables     = waitInfo.VariablesInstance;
                var shadowService = core.ServiceFactory.CreateAdminOrganizationService(new MockupServiceSettings(false, true, MockupServiceSettings.Role.SDK));

                var primaryEntity = shadowService.Retrieve(waitInfo.PrimaryEntity.LogicalName, waitInfo.PrimaryEntity.Id, new ColumnSet(true));
                variables["InputEntities(\"primaryEntity\")"] = primaryEntity;
                waitInfo.Element.Execute(waitInfo.ElementIndex, ref variables, core.TimeOffset, service, provider, new TracingService(), false);
                if (variables["Wait"] != null)
                {
                    waitingWorkflows.Add(variables["Wait"] as WaitInfo);
                }
            }
        }
コード例 #7
0
            public void ExecuteIfMatch(object entityObject, Entity preImage, Entity postImage, PluginContext pluginContext, Core core)
            {
                // Check if it is supposed to execute. Returns preemptively, if it should not.
                var entity    = entityObject as Entity;
                var entityRef = entityObject as EntityReference;

                var guid        = (entity != null) ? entity.Id : entityRef.Id;
                var logicalName = (entity != null) ? entity.LogicalName : entityRef.LogicalName;

                if (entityName != "" && entityName != logicalName)
                {
                    return;
                }

                if (entity != null && metadata.GetMetadata(logicalName)?.PrimaryIdAttribute != null)
                {
                    entity[metadata.GetMetadata(logicalName).PrimaryIdAttribute] = guid;
                }

                if (pluginContext.Depth > 8)
                {
                    throw new FaultException(
                              "This workflow job was canceled because the workflow that started it included an infinite loop." +
                              " Correct the workflow logic and try again.");
                }

                if (operation == EventOperation.Update && stage == ExecutionStage.PostOperation)
                {
                    var shadowAddedAttributes = postImage.Attributes.Where(a => !preImage.Attributes.ContainsKey(a.Key) && !entity.Attributes.ContainsKey(a.Key));
                    entity = entity.CloneEntity();
                    entity.Attributes.AddRange(shadowAddedAttributes);
                }

                if (operation == EventOperation.Update && attributes.Count > 0)
                {
                    var foundAttr = false;
                    foreach (var attr in entity.Attributes)
                    {
                        if (attributes.Contains(attr.Key))
                        {
                            foundAttr = true;
                            break;
                        }
                    }
                    if (!foundAttr)
                    {
                        return;
                    }
                }

                if (entityName != "" && (operation == EventOperation.Associate || operation == EventOperation.Disassociate))
                {
                    throw new MockupException(
                              $"An {operation} plugin step was registered for a specific entity, which can only be registered on AnyEntity");
                }

                // Create the plugin context
                var thisPluginContext = pluginContext.Clone();

                thisPluginContext.Mode  = (int)this.mode;
                thisPluginContext.Stage = (int)this.stage;
                if (thisPluginContext.PrimaryEntityId == Guid.Empty)
                {
                    thisPluginContext.PrimaryEntityId = guid;
                }
                thisPluginContext.PrimaryEntityName = logicalName;

                foreach (var image in this.images)
                {
                    var type = (ImageType)image.Item3;
                    var cols = image.Item4 != null ? new ColumnSet(image.Item4.Split(',')) : new ColumnSet(true);
                    if (postImage != null && stage == ExecutionStage.PostOperation && (type == ImageType.PostImage || type == ImageType.Both))
                    {
                        thisPluginContext.PostEntityImages.Add(image.Item1, postImage.CloneEntity(metadata.GetMetadata(postImage.LogicalName), cols));
                    }
                    if (preImage != null && type == ImageType.PreImage || type == ImageType.Both)
                    {
                        thisPluginContext.PreEntityImages.Add(image.Item1, preImage.CloneEntity(metadata.GetMetadata(preImage.LogicalName), cols));
                    }
                }

                // Create service provider and execute the plugin
                MockupServiceProviderAndFactory provider = new MockupServiceProviderAndFactory(core, thisPluginContext, new TracingService());

                try {
                    pluginExecute(provider);
                } catch (TargetInvocationException e) {
                    ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                }
            }