/// <summary>
        /// Executes a code activity passing the primary entity
        /// </summary>
        /// <typeparam name="T"></typeparam>
        public IDictionary <string, object> ExecuteCodeActivity <T>(XrmFakedWorkflowContext wfContext, Dictionary <string, object> inputs, T instance = null) where T : CodeActivity, new()
        {
            WorkflowInvoker invoker = null;
            WorkflowInstanceExtensionManager mngr = null;
            string sDebug = "";

            try
            {
                sDebug = "Creating instance..." + System.Environment.NewLine;
                if (instance == null)
                {
                    instance = new T();
                }
                invoker = new WorkflowInvoker(instance);
                sDebug += "Invoker created" + System.Environment.NewLine;
                sDebug += "Adding extensions..." + System.Environment.NewLine;
                invoker.Extensions.Add <ITracingService>(() =>
                {
                    _tracingService = new XrmFakedTracingService();
                    return(_tracingService);
                });
                invoker.Extensions.Add <IWorkflowContext>(() =>
                {
                    return(wfContext);
                });
                invoker.Extensions.Add <IOrganizationServiceFactory>(() => {
                    var fakedServiceFactory = A.Fake <IOrganizationServiceFactory>();
                    A.CallTo(() => fakedServiceFactory.CreateOrganizationService(A <Guid?> ._))
                    .ReturnsLazily((Guid? g) =>
                    {
                        return(GetOrganizationService());
                    });
                    return(fakedServiceFactory);
                });

                sDebug += "Adding extensions...ok." + System.Environment.NewLine;
                sDebug += "Invoking activity..." + System.Environment.NewLine;
                return(invoker.Invoke(inputs));
            }
            catch (TypeLoadException tlex)
            {
                var typeName = tlex.TypeName != null ? tlex.TypeName : "(null)";
                throw new TypeLoadException("When loading type: " + typeName + "." + tlex.Message + "in domain directory: " + AppDomain.CurrentDomain.BaseDirectory + "Debug=" + sDebug);
            }
        }
        // Used by IWorkflowInstance.Start() and IWorkflowInstance.LoadAsync()
        protected void RegisterExtensions(IEnumerable <object> extensions)
        {
            var extensionManager = new WorkflowInstanceExtensionManager();

            extensionManager.Add(new ActivityContextExtension(this));

            // Add it in advance to prevent existing TimerExtension dependent activities to create DurableTimerExtension.
            this.durableReminderExtension = new DurableReminderExtension(this);
            extensionManager.Add(this.durableReminderExtension);

            if (extensions != null)
            {
                foreach (var extension in extensions)
                {
                    extensionManager.Add(extension);
                }
            }

            RegisterExtensionManager(extensionManager);
        }
            /// <summary>
            /// Initializes a new instance of the <see cref="InvokeAsyncResult"/> class.
            /// </summary>
            /// <param name="activity">The activity.</param>
            /// <param name="inputs">The inputs.</param>
            /// <param name="extensions">The extensions.</param>
            /// <param name="timeout">The timeout.</param>
            /// <param name="syncContext">The synchronize context.</param>
            /// <param name="invokeContext">The invoke context.</param>
            /// <param name="callback">The callback.</param>
            /// <param name="state">The state.</param>
            public InvokeAsyncResult(
                Activity activity,
                IDictionary <string, object> inputs,
                WorkflowInstanceExtensionManager extensions,
                TimeSpan timeout,
                SynchronizationContext syncContext,
                AsyncInvokeContext invokeContext,
                AsyncCallback callback,
                object state)
                : base(callback, state)
            {
                if (activity == null)
                {
                    throw new ArgumentNullException(nameof(activity));
                }

                this.completionWaiter = new AsyncWaitHandle();
                syncContext ??= SynchronousSynchronizationContext.Value;

                this.instance = WorkflowApplication.StartInvoke(activity, inputs, extensions, syncContext, new Action(this.OnInvokeComplete), invokeContext);

                if (this.completionWaiter.WaitAsync(WaitCompleteCallback, this, timeout))
                {
                    var completeSelf = this.OnWorkflowCompletion();

                    if (completeSelf)
                    {
                        if (this.completionException != null)
                        {
                            throw FxTrace.Exception.AsError(this.completionException);
                        }
                        else
                        {
                            this.Complete(true);
                        }
                    }
                }
            }
        void SetupExtensions(WorkflowInstanceExtensionManager extensionManager)
        {
            base.RegisterExtensionManager(extensionManager);

            // cache IPersistencePipelineModules
            IEnumerable<IPersistencePipelineModule> modules = base.GetExtensions<IPersistencePipelineModule>();
            int modulesCount = modules.Count<IPersistencePipelineModule>();
            if (modulesCount > 0)
            {
                this.PipelineModules = new List<IPersistencePipelineModule>(modulesCount);
                this.PipelineModules.AddRange(modules);
            }
        }
Beispiel #5
0
        private IAsyncResult BeginInvoke(Activity workflow, IDictionary <string, object> inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions, AsyncCallback callback, object state)
        {
            if (inputs == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("inputs");
            }

            TimeoutHelper.ThrowIfNegativeArgument(timeout);

            return(WorkflowApplication.BeginInvoke(workflow, inputs, extensions, timeout, null, null, callback, state));
        }
Beispiel #6
0
        private IAsyncResult BeginInvoke(Activity workflow, TimeSpan timeout, WorkflowInstanceExtensionManager extensions, AsyncCallback callback, object state)
        {
            TimeoutHelper.ThrowIfNegativeArgument(timeout);

            return(WorkflowApplication.BeginInvoke(workflow, null, extensions, timeout, null, null, callback, state));
        }
Beispiel #7
0
        private static IDictionary <string, object> Invoke(Activity workflow, IDictionary <string, object> inputs, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
        {
            if (workflow == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("workflow");
            }

            if (inputs == null)
            {
                throw CoreWf.Internals.FxTrace.Exception.ArgumentNull("inputs");
            }

            TimeoutHelper.ThrowIfNegativeArgument(timeout);

            IDictionary <string, object> outputs = WorkflowApplication.Invoke(workflow, inputs, extensions, timeout);

            if (outputs == null)
            {
                return(ActivityUtilities.EmptyParameters);
            }
            else
            {
                return(outputs);
            }
        }
Beispiel #8
0
        private static IDictionary <string, object> Invoke(Activity workflow, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
        {
            if (workflow == null)
            {
                throw FxTrace.Exception.ArgumentNull(nameof(workflow));
            }

            TimeoutHelper.ThrowIfNegativeArgument(timeout);

            var outputs = WorkflowApplication.Invoke(workflow, null, extensions, timeout);

            if (outputs == null)
            {
                return(ActivityUtilities.EmptyParameters);
            }
            else
            {
                return(outputs);
            }
        }
Beispiel #9
0
        static void testOffline()
        {
            SESampleProcess2 p2 = new SESampleProcess2();
            //SESampleWorkFlow p2 = new SESampleWorkFlow();
            WorkflowApplication app = new WorkflowApplication(p2);
            AutoResetEvent      rre = new AutoResetEvent(false);

            app.Idle = (e) =>
            {
                rre.Set();
            };
            //TrackingProfile trackingProfile = new TrackingProfile();

            ////trackingProfile.Queries.Add(new WorkflowInstanceQuery

            ////{

            ////    States = { "*"}

            ////});

            ////trackingProfile.Queries.Add(new ActivityStateQuery

            ////{

            ////    States = {"*" }

            ////});

            //trackingProfile.Queries.Add(new CustomTrackingQuery

            //{

            //   ActivityName="*",

            //   Name = "*"

            //});
            //SETrackingParticipant p = new SETrackingParticipant();
            //p.TrackingProfile = trackingProfile;
            //app.Extensions.Add(p);

            app.Completed = (e) =>
            {
                Console.WriteLine("shit");
            };
            ReadOnlyCollection <BookmarkInfo> bookmarks = null;

            //bookmarks = app.GetBookmarks();
            //rre.WaitOne();
            WorkflowInstanceExtensionManager extensions = app.Extensions;

            BookmarkResumptionResult result;


            //result= app.ResumeBookmark("ProcessStart", new ChooseTransitionResult());
            //rre.WaitOne();
            //bookmarks = app.GetBookmarks();

            app.Run();

            rre.WaitOne();
            bookmarks = app.GetBookmarks();


            result = app.ResumeBookmark("RequireMoreInformation", new ChooseTransitionResult());
            rre.WaitOne();
            bookmarks = app.GetBookmarks();
            //app.Run();

            result = app.ResumeBookmark("ProvideMoreInformation", new ChooseTransitionResult());
            rre.WaitOne();
            bookmarks = app.GetBookmarks();


            result = app.ResumeBookmark("AssignToInvestigation", new ChooseTransitionResult());
            rre.WaitOne();
            bookmarks = app.GetBookmarks();


            result = app.ResumeBookmark("AssignToTriage", new ChooseTransitionResult());
            rre.WaitOne();
            bookmarks = app.GetBookmarks();

            result = app.ResumeBookmark("FinishProcess", new ChooseTransitionResult());
            rre.WaitOne();
            bookmarks = app.GetBookmarks();

            // ChooseTransitionResult rslt=new ChooseTransitionResult();
            //// rslt.ChooseResult="Not Need";
            // result=app.ResumeBookmark("AssignToTriage", rslt);
            // rre.WaitOne();
            // result = app.ResumeBookmark("FinishProcess", rslt);
            // rre.WaitOne();

            bookmarks = app.GetBookmarks();

            Console.WriteLine();
        }
Beispiel #10
0
        private static IDictionary <string, object> Invoke(Activity workflow, TimeSpan timeout, WorkflowInstanceExtensionManager extensions)
        {
            if (workflow == null)
            {
                throw FxTrace.Exception.ArgumentNull("workflow");
            }
            TimeoutHelper.ThrowIfNegativeArgument(timeout);
            IDictionary <string, object> dictionary = System.Activities.WorkflowApplication.Invoke(workflow, null, extensions, timeout);

            if (dictionary == null)
            {
                return(ActivityUtilities.EmptyParameters);
            }
            return(dictionary);
        }
 private void SetupExtensions(WorkflowInstanceExtensionManager extensionManager)
 {
     base.RegisterExtensionManager(extensionManager);
     IEnumerable<IPersistencePipelineModule> extensions = base.GetExtensions<IPersistencePipelineModule>();
     int capacity = extensions.Count<IPersistencePipelineModule>();
     if (capacity > 0)
     {
         this.PipelineModules = new List<IPersistencePipelineModule>(capacity);
         this.PipelineModules.AddRange(extensions);
     }
 }