Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Activities / LocalService / CorrelationTokenInvalidatedHandler.cs / 1305376 / CorrelationTokenInvalidatedHandler.cs
using System; using System.Diagnostics; using System.Collections.Generic; using System.Collections; using System.Reflection; using System.Runtime.Serialization; using System.Workflow.ComponentModel; using System.Workflow.Runtime; using System.Workflow.Runtime.Hosting; namespace System.Workflow.Activities { [Serializable] internal sealed class CorrelationTokenInvalidatedHandler : IActivityEventListener{ IActivityEventListener eventHandler; EventQueueName queueName; Guid subscriptionId; Guid instanceId; bool queueCreator; Type interfaceType; string followerOperation; internal CorrelationTokenInvalidatedHandler(Type interfaceType, string operation, IActivityEventListener eventHandler, Guid instanceId) { this.eventHandler = eventHandler; this.interfaceType = interfaceType; this.followerOperation = operation; this.instanceId = instanceId; } #region IActivityEventListener Members void IActivityEventListener .OnEvent(object sender, CorrelationTokenEventArgs dataChangeEventArgs) { if (sender == null) throw new ArgumentException("sender"); if (dataChangeEventArgs == null) throw new ArgumentException("dataChangeEventArgs"); ActivityExecutionContext context = sender as ActivityExecutionContext; Activity activity = context.Activity; ICollection correlationValues = dataChangeEventArgs.CorrelationToken.Properties; if (dataChangeEventArgs.IsInitializing) { CreateSubscription(this.instanceId, context, correlationValues); return; } if (queueName != null) { if (!CorrelationResolver.IsInitializingMember(queueName.InterfaceType, queueName.MethodName, correlationValues == null ? null : new object[] { correlationValues })) { DeleteSubscription(context); } } dataChangeEventArgs.CorrelationToken.UnsubscribeFromCorrelationTokenInitializedEvent(activity, this); } #endregion private void CreateSubscription(Guid instanceId, ActivityExecutionContext context, ICollection correlationValues) { WorkflowQueuingService queueSvcs = context.GetService (); EventQueueName queueId = new EventQueueName(this.interfaceType, this.followerOperation, correlationValues); WorkflowQueue workflowQueue = null; if (!queueSvcs.Exists(queueId)) { WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler: creating q {0} ", queueId.GetHashCode()); workflowQueue = queueSvcs.CreateWorkflowQueue(queueId, true); queueCreator = true; } else { workflowQueue = queueSvcs.GetWorkflowQueue(queueId); } if (this.eventHandler != null) { workflowQueue.RegisterForQueueItemAvailable(this.eventHandler); } WorkflowSubscriptionService subscriptionService = (WorkflowSubscriptionService)context.GetService(typeof(WorkflowSubscriptionService)); MessageEventSubscription subscription = new MessageEventSubscription(queueId, instanceId); this.queueName = queueId; this.subscriptionId = subscription.SubscriptionId; subscription.InterfaceType = this.interfaceType; subscription.MethodName = this.followerOperation; this.interfaceType = null; this.followerOperation = null; if (correlationValues != null) { foreach (CorrelationProperty property in correlationValues) { subscription.CorrelationProperties.Add(property); } } if (this.eventHandler != null) return; if (subscriptionService == null) return; subscriptionService.CreateSubscription(subscription); } private void DeleteSubscription(ActivityExecutionContext context) { if (this.queueName == null) return; WorkflowQueuingService queueSvcs = context.GetService (); if (queueCreator) queueSvcs.DeleteWorkflowQueue(this.queueName); if (this.eventHandler != null) return; WorkflowSubscriptionService subscriptionService = context.GetService (); if (subscriptionService != null) subscriptionService.DeleteSubscription(this.subscriptionId); WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", this.subscriptionId, this.queueName); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Diagnostics; using System.Collections.Generic; using System.Collections; using System.Reflection; using System.Runtime.Serialization; using System.Workflow.ComponentModel; using System.Workflow.Runtime; using System.Workflow.Runtime.Hosting; namespace System.Workflow.Activities { [Serializable] internal sealed class CorrelationTokenInvalidatedHandler : IActivityEventListener { IActivityEventListener eventHandler; EventQueueName queueName; Guid subscriptionId; Guid instanceId; bool queueCreator; Type interfaceType; string followerOperation; internal CorrelationTokenInvalidatedHandler(Type interfaceType, string operation, IActivityEventListener eventHandler, Guid instanceId) { this.eventHandler = eventHandler; this.interfaceType = interfaceType; this.followerOperation = operation; this.instanceId = instanceId; } #region IActivityEventListener Members void IActivityEventListener .OnEvent(object sender, CorrelationTokenEventArgs dataChangeEventArgs) { if (sender == null) throw new ArgumentException("sender"); if (dataChangeEventArgs == null) throw new ArgumentException("dataChangeEventArgs"); ActivityExecutionContext context = sender as ActivityExecutionContext; Activity activity = context.Activity; ICollection correlationValues = dataChangeEventArgs.CorrelationToken.Properties; if (dataChangeEventArgs.IsInitializing) { CreateSubscription(this.instanceId, context, correlationValues); return; } if (queueName != null) { if (!CorrelationResolver.IsInitializingMember(queueName.InterfaceType, queueName.MethodName, correlationValues == null ? null : new object[] { correlationValues })) { DeleteSubscription(context); } } dataChangeEventArgs.CorrelationToken.UnsubscribeFromCorrelationTokenInitializedEvent(activity, this); } #endregion private void CreateSubscription(Guid instanceId, ActivityExecutionContext context, ICollection correlationValues) { WorkflowQueuingService queueSvcs = context.GetService (); EventQueueName queueId = new EventQueueName(this.interfaceType, this.followerOperation, correlationValues); WorkflowQueue workflowQueue = null; if (!queueSvcs.Exists(queueId)) { WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler: creating q {0} ", queueId.GetHashCode()); workflowQueue = queueSvcs.CreateWorkflowQueue(queueId, true); queueCreator = true; } else { workflowQueue = queueSvcs.GetWorkflowQueue(queueId); } if (this.eventHandler != null) { workflowQueue.RegisterForQueueItemAvailable(this.eventHandler); } WorkflowSubscriptionService subscriptionService = (WorkflowSubscriptionService)context.GetService(typeof(WorkflowSubscriptionService)); MessageEventSubscription subscription = new MessageEventSubscription(queueId, instanceId); this.queueName = queueId; this.subscriptionId = subscription.SubscriptionId; subscription.InterfaceType = this.interfaceType; subscription.MethodName = this.followerOperation; this.interfaceType = null; this.followerOperation = null; if (correlationValues != null) { foreach (CorrelationProperty property in correlationValues) { subscription.CorrelationProperties.Add(property); } } if (this.eventHandler != null) return; if (subscriptionService == null) return; subscriptionService.CreateSubscription(subscription); } private void DeleteSubscription(ActivityExecutionContext context) { if (this.queueName == null) return; WorkflowQueuingService queueSvcs = context.GetService (); if (queueCreator) queueSvcs.DeleteWorkflowQueue(this.queueName); if (this.eventHandler != null) return; WorkflowSubscriptionService subscriptionService = context.GetService (); if (subscriptionService != null) subscriptionService.DeleteSubscription(this.subscriptionId); WorkflowActivityTrace.Activity.TraceEvent(TraceEventType.Information, 0, "CorrelationTokenInvalidatedHandler subscription deleted SubId {0} QueueId {1}", this.subscriptionId, this.queueName); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FrugalMap.cs
- errorpatternmatcher.cs
- FilteredDataSetHelper.cs
- DrawingGroupDrawingContext.cs
- WebPartDisplayModeCollection.cs
- ScriptControlManager.cs
- Error.cs
- SoapRpcMethodAttribute.cs
- BoundConstants.cs
- DetailsViewCommandEventArgs.cs
- AnyReturnReader.cs
- UpdateRecord.cs
- HtmlTernaryTree.cs
- LogicalChannelCollection.cs
- SHA256Managed.cs
- HttpCookiesSection.cs
- SystemFonts.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- TypeGeneratedEventArgs.cs
- Keywords.cs
- PageFunction.cs
- QilValidationVisitor.cs
- EventKeyword.cs
- RightsManagementEncryptionTransform.cs
- DecoderFallbackWithFailureFlag.cs
- FileLevelControlBuilderAttribute.cs
- InteropExecutor.cs
- TableDetailsCollection.cs
- UrlMappingCollection.cs
- Timeline.cs
- TransformCryptoHandle.cs
- Bidi.cs
- RuntimeEnvironment.cs
- BufferedOutputStream.cs
- UpdateManifestForBrowserApplication.cs
- GcSettings.cs
- SqlUDTStorage.cs
- FacetValueContainer.cs
- DataGridViewColumnStateChangedEventArgs.cs
- RouteParser.cs
- QuotedPrintableStream.cs
- PolyBezierSegment.cs
- ColorBlend.cs
- Clause.cs
- ImageIndexConverter.cs
- PersistChildrenAttribute.cs
- EditorReuseAttribute.cs
- HttpListenerRequest.cs
- HasCopySemanticsAttribute.cs
- ApplicationSettingsBase.cs
- MD5HashHelper.cs
- CompressStream.cs
- TableCellCollection.cs
- Int16AnimationBase.cs
- SafeFileMappingHandle.cs
- ZoneIdentityPermission.cs
- PeerCustomResolverBindingElement.cs
- FullTextLine.cs
- NameTable.cs
- OperationCanceledException.cs
- StringAnimationUsingKeyFrames.cs
- EncoderNLS.cs
- ResourcePermissionBaseEntry.cs
- BlurEffect.cs
- Tracer.cs
- SeverityFilter.cs
- AssemblyBuilder.cs
- Margins.cs
- DecoderFallbackWithFailureFlag.cs
- FrameworkContentElement.cs
- mda.cs
- KnownBoxes.cs
- Inflater.cs
- ItemsPresenter.cs
- TypedReference.cs
- StandardRuntimeEnumValidatorAttribute.cs
- LinearGradientBrush.cs
- ExecutionEngineException.cs
- XmlBindingWorker.cs
- ToolStripDropDownMenu.cs
- HttpGetProtocolImporter.cs
- AssemblyBuilder.cs
- AppSettingsExpressionBuilder.cs
- XmlnsCompatibleWithAttribute.cs
- FixedPageAutomationPeer.cs
- EventDescriptor.cs
- EmbeddedMailObjectsCollection.cs
- StandardCommands.cs
- DesignerActionGlyph.cs
- DateTimeStorage.cs
- TextContainer.cs
- MachineKeySection.cs
- SoapExtensionReflector.cs
- NativeMethods.cs
- WinEventHandler.cs
- NativeObjectSecurity.cs
- FontFamilyIdentifier.cs
- DataDocumentXPathNavigator.cs
- ViewKeyConstraint.cs
- HMAC.cs