private bool CollectAndMap() { var success = false; try { if (this.instance.HasPersistenceModule) { var modules = this.instance.GetExtensions <IPersistencePipelineModule>(); this.pipeline = new PersistencePipeline(modules, PersistenceManager.GenerateInitialData(this.instance)); this.pipeline.Collect(); this.pipeline.Map(); this.data = this.pipeline.Values; } success = true; } finally { if (!success && this.context != null) { this.context.Abort(); } } if (this.instance.HasPersistenceProvider) { return(this.Persist()); } else { return(this.Save()); } }
private void UnregisterPipelineInUse(PersistencePipeline pipeline) { lock (this.ThisLock) { if (!this.aborted) { this.pipelinesInUse.Remove(pipeline); } } }
private void RegisterPipelineInUse(PersistencePipeline pipeline) { lock (this.ThisLock) { if (this.aborted) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new OperationCanceledException(System.ServiceModel.Activities.SR.DirectoryAborted)); } this.pipelinesInUse.Add(pipeline); } }
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(); } }
private bool AfterLoad() { if (!this.isInstanceInitialized) { if (!this.canCreateInstance) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.PersistenceViolationNoCreate)); } if (this.view == null) { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.suggestedIdOrId, null, true, false, null); } else { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, from keyView in this.view.InstanceKeys.Values select new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata), true, true, this.view); } this.handle = null; } else { this.EnsureWorkflowHostType(); this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, from keyView in this.view.InstanceKeys.Values select new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata), false, true, this.view); this.handle = null; IEnumerable <IPersistencePipelineModule> pipelineModules = this.context.GetInstance(null).PipelineModules; if (pipelineModules != null) { IAsyncResult result; this.pipeline = new PersistencePipeline(pipelineModules); this.pipeline.SetLoadedValues(this.view.InstanceData); this.ppd.RegisterPipelineInUse(this.pipeline); using (base.PrepareTransactionalCall(this.transaction)) { result = this.pipeline.BeginLoad(this.timeoutHelper.RemainingTime(), base.PrepareAsyncCompletion(handleLoadPipeline), this); } return(base.SyncContinue(result)); } } return(this.Finish()); }
// 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(); } }
// Used by OnPersist() and OnNotifyPaused(). protected async Task SaveAsync() { if (this.Controller.TrackingEnabled) { this.Controller.Track(new WorkflowInstanceRecord(this.Id, this.WorkflowDefinition.DisplayName, System.Activities.Tracking.WorkflowInstanceStates.Persisted, this.DefinitionIdentity)); await IfHasPendingThenFlushTrackingRecordsAsync(); } var instanceValues = SaveWorkflow(); this.IsReloaded = false; // 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, this.Parameters.PersistWriteOnlyValues); persistencePipeline.Collect(); persistencePipeline.Map(); await persistencePipeline.OnSaveAsync(this.Parameters.ExtensionsPersistenceTimeout); await this.host.SaveAsync(instanceValues); await persistencePipeline.OnSavedAsync(this.Parameters.ExtensionsPersistenceTimeout); } else { await this.host.SaveAsync(instanceValues); } }
bool CollectAndMap() { // From this point forward we'll update the state unless we get a persistence exception this.updateState = true; Dictionary<XName, InstanceValue> initialPersistenceData = this.instance.GeneratePersistenceData(); bool success = false; try { List<IPersistencePipelineModule> modules = this.instance.PipelineModules; if (modules != null) { Fx.Assert(modules.Count > 0, "should only setup modules if we have some"); this.pipeline = new PersistencePipeline(modules, initialPersistenceData); this.pipeline.Collect(); this.pipeline.Map(); this.data = this.pipeline.Values; } else { this.data = initialPersistenceData; } success = true; } finally { if (!success && this.context != null) { this.context.Abort(); } } if (this.instance.persistenceContext != null) { return Persist(); } else { return Save(); } }
void UnregisterPipelineInUse(PersistencePipeline pipeline) { lock (ThisLock) { if (!this.aborted) { this.pipelinesInUse.Remove(pipeline); } } }
void RegisterPipelineInUse(PersistencePipeline pipeline) { lock (ThisLock) { if (this.aborted) { throw FxTrace.Exception.AsError(new OperationCanceledException(SR.DirectoryAborted)); } this.pipelinesInUse.Add(pipeline); } }
bool AfterLoad() { if (!this.isInstanceInitialized) { if (!this.canCreateInstance) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.PersistenceViolationNoCreate)); } if (this.view == null) { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.suggestedIdOrId, null, true, false, null, null); } else { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, this.view.InstanceKeys.Values.Select((keyView) => new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata)), true, true, this.view, null); } this.handle = null; } else { EnsureWorkflowHostType(); // The constructor of PersistenceContext will create the WorkflowServiceInstance in this case. this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, this.view.InstanceKeys.Values.Select((keyView) => new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata)), false, true, this.view, this.updatedIdentity); this.handle = null; IEnumerable<IPersistencePipelineModule> modules = this.context.GetInstance(null).PipelineModules; if (modules != null) { this.pipeline = new PersistencePipeline(modules); this.pipeline.SetLoadedValues(this.view.InstanceData); this.ppd.RegisterPipelineInUse(this.pipeline); IAsyncResult loadResult; using (PrepareTransactionalCall(this.transaction)) { loadResult = this.pipeline.BeginLoad(this.timeoutHelper.RemainingTime(), PrepareAsyncCompletion(LoadOrCreateAsyncResult.handleLoadPipeline), this); } return SyncContinue(loadResult); } } return Finish(); }
private bool LoadValues(IAsyncResult result) { IAsyncResult loadResult = null; var success = false; try { Fx.Assert((result == null) != (this.values == null), "We should either have values already retrieved, or an IAsyncResult to retrieve them"); if (result != null) { if (this.loadAny) { if (!this.persistenceManager.EndTryLoad(result, out this.values)) { throw FxTrace.Exception.AsError(new InstanceNotReadyException(SR.NoRunnableInstances)); } if (this.application != null) { if (this.application.instanceIdSet) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.WorkflowApplicationAlreadyHasId)); } this.application.instanceId = this.persistenceManager.InstanceId; this.application.instanceIdSet = true; } } else { this.values = this.persistenceManager.EndLoad(result); } } if (this.application != null) { this.pipeline = this.application.ProcessInstanceValues(this.values, out this.deserializedRuntimeState); if (this.pipeline != null) { this.pipeline.SetLoadedValues(this.values); this.application.persistencePipelineInUse = this.pipeline; Thread.MemoryBarrier(); if (this.application.state == WorkflowApplicationState.Aborted) { throw FxTrace.Exception.AsError(new OperationCanceledException(SR.DefaultAbortReason)); } using (this.PrepareTransactionalCall(this.context.PublicTransaction)) { loadResult = this.pipeline.BeginLoad(this.timeoutHelper.RemainingTime(), this.PrepareAsyncCompletion(loadPipelineCallback), this); } } } success = true; } finally { if (!success) { this.context.Abort(); } } if (this.pipeline != null) { return(this.SyncContinue(loadResult)); } else { return(this.CompleteContext()); } }
private bool AfterLoad() { if (!this.isInstanceInitialized) { if (!this.canCreateInstance) { throw System.ServiceModel.Activities.FxTrace.Exception.AsError(new InvalidOperationException(System.ServiceModel.Activities.SR.PersistenceViolationNoCreate)); } if (this.view == null) { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.suggestedIdOrId, null, true, false, null); } else { this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, from keyView in this.view.InstanceKeys.Values select new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata), true, true, this.view); } this.handle = null; } else { this.EnsureWorkflowHostType(); this.context = new PersistenceContext(this.ppd, this.ppd.store, this.handle, this.view.InstanceId, from keyView in this.view.InstanceKeys.Values select new InstanceKey(keyView.InstanceKey, keyView.InstanceKeyMetadata), false, true, this.view); this.handle = null; IEnumerable<IPersistencePipelineModule> pipelineModules = this.context.GetInstance(null).PipelineModules; if (pipelineModules != null) { IAsyncResult result; this.pipeline = new PersistencePipeline(pipelineModules); this.pipeline.SetLoadedValues(this.view.InstanceData); this.ppd.RegisterPipelineInUse(this.pipeline); using (base.PrepareTransactionalCall(this.transaction)) { result = this.pipeline.BeginLoad(this.timeoutHelper.RemainingTime(), base.PrepareAsyncCompletion(handleLoadPipeline), this); } return base.SyncContinue(result); } } return this.Finish(); }
private bool CollectAndMap() { this.updateState = true; Dictionary<XName, InstanceValue> initialValues = this.instance.GeneratePersistenceData(); bool flag = false; try { List<IPersistencePipelineModule> pipelineModules = this.instance.PipelineModules; if (pipelineModules != null) { this.pipeline = new PersistencePipeline(pipelineModules, initialValues); this.pipeline.Collect(); this.pipeline.Map(); this.data = this.pipeline.Values; } else { this.data = initialValues; } flag = true; } finally { if (!flag && (this.context != null)) { this.context.Abort(); } } if (this.instance.persistenceContext != null) { return this.Persist(); } return this.Save(); }