Example #1
0
        public async Task LoadAsync(IDictionary <XName, InstanceValue> instanceValues, IEnumerable <object> extensions, IParameters parameters)
        {
            switch (instanceValues[WorkflowNamespace.Status].Value as string)
            {
            case WorkflowStatus.Closed:
                var outputArgumentsRead = new Dictionary <string, object>();
                foreach (var kvp in instanceValues.Where((iv) => iv.Key.Namespace == WorkflowNamespace.OutputPath))
                {
                    outputArgumentsRead.Add(kvp.Key.LocalName, kvp.Value.Value);
                }
                if (outputArgumentsRead.Count > 0)
                {
                    this.outputArguments = outputArgumentsRead;
                }
                this.completionState = ActivityInstanceState.Closed;
                break;

            case WorkflowStatus.Canceled:
                this.completionState = ActivityInstanceState.Canceled;
                break;

            case WorkflowStatus.Faulted:
                this.terminationException = instanceValues[WorkflowNamespace.Exception].Value as Exception;
                this.completionState      = ActivityInstanceState.Faulted;
                break;

            default:
                throw new ArgumentOutOfRangeException(WorkflowNamespace.Status.ToString());
            }

            // Yes, IEnumerable<object> is ugly, but there is nothing common in IPersistenceParticipant and PersistenceParticipant.
            var persistenceParticipants =
                ((IEnumerable <object>)extensions.OfType <System.Activities.Persistence.PersistenceParticipant>())
                .Concat(
                    ((IEnumerable <object>)extensions.OfType <IPersistenceParticipant>()));

            // If the persistenceParticipants throw during OnLoadAsync(), the pipeline will rethrow
            if (persistenceParticipants.Any())
            {
                var persistencePipeline = new PersistencePipeline(persistenceParticipants, instanceValues);
                await persistencePipeline.OnLoadAsync(parameters.ExtensionsPersistenceTimeout);

                persistencePipeline.Publish();
            }
        }
        // Used by IWorkflowInstance.LoadAsync()
        protected async Task LoadAsync(IDictionary <XName, InstanceValue> instanceValues)
        {
            Initialize(LoadWorkflow(instanceValues), default);
            if (this.Controller.State == WorkflowInstanceState.Runnable)
            {
                this.IsReloaded = true;
            }

            // Yes, IEnumerable<object> is ugly, but there is nothing common in IPersistenceParticipant and PersistenceParticipant.
            var persistenceParticipants =
                ((IEnumerable <object>)GetExtensions <System.Activities.Persistence.PersistenceParticipant>())
                .Concat(
                    ((IEnumerable <object>)GetExtensions <IPersistenceParticipant>()));

            // If the persistenceParticipants throw during OnSaveAsync() and OnLoadAsync(), the pipeline will rethrow, and the controller/executor will abort.
            if (persistenceParticipants.Any())
            {
                var persistencePipeline = new PersistencePipeline(persistenceParticipants, instanceValues);
                await persistencePipeline.OnLoadAsync(this.Parameters.ExtensionsPersistenceTimeout);

                persistencePipeline.Publish();
            }
        }