private void AddInstanceExtension(WorkflowInstanceExtensionProvider extensionProvider) { Fx.Assert(this.instanceExtensions != null, "instanceExtensions should be setup by now"); var newExtension = extensionProvider.ProvideValue(); if (newExtension is SymbolResolver) { throw FxTrace.Exception.AsError(new InvalidOperationException(SR.SymbolResolverMustBeSingleton)); } // for IWorkflowInstance we key off the type of the value, not the declared type if (!this.shouldSetInstanceForInstanceExtensions && newExtension is IWorkflowInstanceExtension) { this.shouldSetInstanceForInstanceExtensions = true; } if (!this.hasTrackingParticipant && extensionProvider.IsMatch <TrackingParticipant>(newExtension)) { this.hasTrackingParticipant = true; } if (!this.hasPersistenceModule && extensionProvider.IsMatch <IPersistencePipelineModule>(newExtension)) { this.hasPersistenceModule = true; } this.instanceExtensions?.Add(new KeyValuePair <WorkflowInstanceExtensionProvider, object>(extensionProvider, newExtension)); WorkflowInstanceExtensionManager.AddExtensionClosure(newExtension, ref this.additionalInstanceExtensions, ref this.hasTrackingParticipant, ref this.hasPersistenceModule); }
// locks down the given extensions manager and runs cache metadata on the workflow definition protected void RegisterExtensionManager(WorkflowInstanceExtensionManager extensionManager) { ValidateWorkflow(extensionManager); this.extensions = WorkflowInstanceExtensionManager.CreateInstanceExtensions(this.WorkflowDefinition, extensionManager); if (this.extensions != null) { this.HasPersistenceModule = this.extensions.HasPersistenceModule; } }
void ValidateWorkflow(WorkflowInstanceExtensionManager extensionManager) { if (!WorkflowDefinition.IsRuntimeReady) { LocationReferenceEnvironment localEnvironment = this.hostEnvironment; if (localEnvironment == null) { LocationReferenceEnvironment parentEnvironment = null; if (extensionManager != null && extensionManager.SymbolResolver != null) { parentEnvironment = extensionManager.SymbolResolver.AsLocationReferenceEnvironment(); } localEnvironment = new ActivityLocationReferenceEnvironment(parentEnvironment); } IList <ValidationError> validationErrors = null; ActivityUtilities.CacheRootMetadata(WorkflowDefinition, localEnvironment, ProcessActivityTreeOptions.FullCachingOptions, null, ref validationErrors); ActivityValidationServices.ThrowIfViolationsExist(validationErrors); } }
private void AddInstanceExtension(WorkflowInstanceExtensionProvider extensionProvider) { object obj2 = extensionProvider.ProvideValue(); if (obj2 is SymbolResolver) { throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.SymbolResolverMustBeSingleton)); } if (!this.shouldSetInstanceForInstanceExtensions && (obj2 is IWorkflowInstanceExtension)) { this.shouldSetInstanceForInstanceExtensions = true; } if (!this.hasTrackingParticipant && extensionProvider.IsMatch <TrackingParticipant>(obj2)) { this.hasTrackingParticipant = true; } if (!this.hasPersistenceModule && extensionProvider.IsMatch <IPersistencePipelineModule>(obj2)) { this.hasPersistenceModule = true; } this.instanceExtensions.Add(new KeyValuePair <WorkflowInstanceExtensionProvider, object>(extensionProvider, obj2)); WorkflowInstanceExtensionManager.AddExtensionClosure(obj2, ref this.additionalInstanceExtensions, ref this.hasTrackingParticipant, ref this.hasPersistenceModule); }
internal static WorkflowInstanceExtensionCollection CreateInstanceExtensions(Activity workflowDefinition, WorkflowInstanceExtensionManager extensionManager) { Fx.Assert(workflowDefinition.IsRuntimeReady, "activity should be ready with extensions after a successful CacheMetadata call"); if (extensionManager != null) { extensionManager.MakeReadOnly(); return(new WorkflowInstanceExtensionCollection(workflowDefinition, extensionManager)); } else if ((workflowDefinition.DefaultExtensionsCount > 0) || (workflowDefinition.RequiredExtensionTypesCount > 0)) { return(new WorkflowInstanceExtensionCollection(workflowDefinition, null)); } else { return(null); } }
internal WorkflowInstanceExtensionCollection(Activity workflowDefinition, WorkflowInstanceExtensionManager extensionManager) { Dictionary <Type, WorkflowInstanceExtensionProvider> dictionary; HashSet <Type> set; this.extensionManager = extensionManager; int capacity = 0; if (extensionManager != null) { capacity = extensionManager.ExtensionProviders.Count; this.hasTrackingParticipant = extensionManager.HasSingletonTrackingParticipant; this.hasPersistenceModule = extensionManager.HasSingletonPersistenceModule; this.allSingletonExtensions = this.extensionManager.GetAllSingletonExtensions(); } else { this.allSingletonExtensions = WorkflowInstanceExtensionManager.EmptySingletonExtensions; } Dictionary <Type, WorkflowInstanceExtensionProvider> dictionary2 = null; if (workflowDefinition.GetActivityExtensionInformation(out dictionary, out set)) { HashSet <Type> extensionTypes = new HashSet <Type>(); if (extensionManager != null) { extensionManager.AddAllExtensionTypes(extensionTypes); } if (dictionary != null) { dictionary2 = new Dictionary <Type, WorkflowInstanceExtensionProvider>(dictionary.Count); foreach (KeyValuePair <Type, WorkflowInstanceExtensionProvider> pair in dictionary) { Type key = pair.Key; if (!System.Runtime.TypeHelper.ContainsCompatibleType(extensionTypes, key)) { List <Type> list = null; bool flag = false; foreach (Type type2 in dictionary2.Keys) { if (System.Runtime.TypeHelper.AreReferenceTypesCompatible(type2, key)) { flag = true; break; } if (System.Runtime.TypeHelper.AreReferenceTypesCompatible(key, type2)) { if (list == null) { list = new List <Type>(); } list.Add(type2); } } if (list != null) { for (int i = 0; i < list.Count; i++) { dictionary2.Remove(list[i]); } } if (!flag) { dictionary2.Add(key, pair.Value); } } } if (dictionary2.Count > 0) { extensionTypes.UnionWith(dictionary2.Keys); capacity += dictionary2.Count; } } if ((set != null) && (set.Count > 0)) { foreach (Type type3 in set) { if (!System.Runtime.TypeHelper.ContainsCompatibleType(extensionTypes, type3)) { throw FxTrace.Exception.AsError(new ValidationException(System.Activities.SR.RequiredExtensionTypeNotFound(type3.ToString()))); } } } } if (capacity > 0) { this.instanceExtensions = new List <KeyValuePair <WorkflowInstanceExtensionProvider, object> >(capacity); if (extensionManager != null) { List <KeyValuePair <Type, WorkflowInstanceExtensionProvider> > extensionProviders = extensionManager.ExtensionProviders; for (int j = 0; j < extensionProviders.Count; j++) { KeyValuePair <Type, WorkflowInstanceExtensionProvider> pair2 = extensionProviders[j]; this.AddInstanceExtension(pair2.Value); } } if (dictionary2 != null) { foreach (WorkflowInstanceExtensionProvider provider in dictionary2.Values) { this.AddInstanceExtension(provider); } } } }
internal WorkflowInstanceExtensionCollection(Activity workflowDefinition, WorkflowInstanceExtensionManager extensionManager) { this.extensionManager = extensionManager; int extensionProviderCount = 0; if (extensionManager != null) { extensionProviderCount = extensionManager.ExtensionProviders.Count; this.hasTrackingParticipant = extensionManager.HasSingletonTrackingParticipant; this.hasPersistenceModule = extensionManager.HasSingletonPersistenceModule; // create an uber-IEnumerable to simplify our iteration code this.allSingletonExtensions = this.extensionManager.GetAllSingletonExtensions(); } else { this.allSingletonExtensions = WorkflowInstanceExtensionManager.EmptySingletonExtensions; } // Resolve activity extensions Dictionary <Type, WorkflowInstanceExtensionProvider> filteredActivityExtensionProviders = null; if (workflowDefinition.GetActivityExtensionInformation(out Dictionary <Type, WorkflowInstanceExtensionProvider> activityExtensionProviders, out HashSet <Type> requiredActivityExtensionTypes)) { // a) filter out the extension Types that were already configured by the host. Note that only "primary" extensions are in play here, not // "additional" extensions HashSet <Type> allExtensionTypes = new HashSet <Type>(); if (extensionManager != null) { extensionManager.AddAllExtensionTypes(allExtensionTypes); } if (activityExtensionProviders != null) { filteredActivityExtensionProviders = new Dictionary <Type, WorkflowInstanceExtensionProvider>(activityExtensionProviders.Count); foreach (KeyValuePair <Type, WorkflowInstanceExtensionProvider> keyedActivityExtensionProvider in activityExtensionProviders) { Type newExtensionProviderType = keyedActivityExtensionProvider.Key; if (!TypeHelper.ContainsCompatibleType(allExtensionTypes, newExtensionProviderType)) { // first see if the new provider supersedes any existing ones List <Type> typesToRemove = null; bool skipNewExtensionProvider = false; foreach (Type existingExtensionProviderType in filteredActivityExtensionProviders.Keys) { // Use AreReferenceTypesCompatible for performance since we know that all of these must be reference types if (TypeHelper.AreReferenceTypesCompatible(existingExtensionProviderType, newExtensionProviderType)) { skipNewExtensionProvider = true; break; } if (TypeHelper.AreReferenceTypesCompatible(newExtensionProviderType, existingExtensionProviderType)) { if (typesToRemove == null) { typesToRemove = new List <Type>(); } typesToRemove.Add(existingExtensionProviderType); } } // prune unnecessary extension providers (either superseded by the new extension or by an existing extension that supersedes them both) if (typesToRemove != null) { for (int i = 0; i < typesToRemove.Count; i++) { filteredActivityExtensionProviders.Remove(typesToRemove[i]); } } // and add a new extension if necessary if (!skipNewExtensionProvider) { filteredActivityExtensionProviders.Add(newExtensionProviderType, keyedActivityExtensionProvider.Value); } } } if (filteredActivityExtensionProviders.Count > 0) { allExtensionTypes.UnionWith(filteredActivityExtensionProviders.Keys); extensionProviderCount += filteredActivityExtensionProviders.Count; } } // b) Validate that all required extensions will be provided if (requiredActivityExtensionTypes != null && requiredActivityExtensionTypes.Count > 0) { foreach (Type requiredType in requiredActivityExtensionTypes) { if (!TypeHelper.ContainsCompatibleType(allExtensionTypes, requiredType)) { throw FxTrace.Exception.AsError(new ValidationException(SR.RequiredExtensionTypeNotFound(requiredType.ToString()))); } } } } // Finally, if our checks of passed, resolve our delegates if (extensionProviderCount > 0) { this.instanceExtensions = new List <KeyValuePair <WorkflowInstanceExtensionProvider, object> >(extensionProviderCount); if (extensionManager != null) { List <KeyValuePair <Type, WorkflowInstanceExtensionProvider> > extensionProviders = extensionManager.ExtensionProviders; for (int i = 0; i < extensionProviders.Count; i++) { KeyValuePair <Type, WorkflowInstanceExtensionProvider> extensionProvider = extensionProviders[i]; AddInstanceExtension(extensionProvider.Value); } } if (filteredActivityExtensionProviders != null) { foreach (WorkflowInstanceExtensionProvider extensionProvider in filteredActivityExtensionProviders.Values) { AddInstanceExtension(extensionProvider); } } } }
protected void RegisterExtensionManager(WorkflowInstanceExtensionManager extensionManager) { throw new NotImplementedException(); }
internal static WorkflowInstanceExtensionCollection CreateInstanceExtensions(Activity workflowDefinition, WorkflowInstanceExtensionManager extensionManager) { if (extensionManager != null) { extensionManager.MakeReadOnly(); return(new WorkflowInstanceExtensionCollection(workflowDefinition, extensionManager)); } if ((workflowDefinition.DefaultExtensionsCount <= 0) && (workflowDefinition.RequiredExtensionTypesCount <= 0)) { return(null); } return(new WorkflowInstanceExtensionCollection(workflowDefinition, null)); }