Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / RunTime / WorkflowQueue.cs / 1305376 / WorkflowQueue.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Workflow.ComponentModel; namespace System.Workflow.Runtime { public class WorkflowQueue { IComparable queueName; WorkflowQueuingService qService; internal WorkflowQueue(WorkflowQueuingService qService, IComparable queueName) { this.qService = qService; this.queueName = queueName; } public event EventHandlerQueueItemAvailable { add { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { EventQueueState qState = qService.GetQueueState(this.queueName); ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (value, qService.CallingActivity); qState.AsynchronousListeners.Add(subscriber); WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable subscribe for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); if (qState.AsynchronousListeners.Count == 1) qService.NotifyAsynchronousSubscribers(this.queueName, qState, qState.Messages.Count); } } remove { lock (qService.SyncRoot) { ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (value, qService.CallingActivity); bool removed = qService.GetQueueState(this.queueName).AsynchronousListeners.Remove(subscriber); if (!removed) { WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable unsubscribe failed for activity '{0}' with context Id {1} ", subscriber.ActivityQualifiedName, subscriber.ContextId); } } } } public void RegisterForQueueItemAvailable(IActivityEventListener eventListener) { RegisterForQueueItemAvailable(eventListener, null); } public void RegisterForQueueItemAvailable(IActivityEventListener eventListener, string subscriberQualifiedName) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { EventQueueState qState = qService.GetQueueState(this.queueName); ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity); if (subscriberQualifiedName != null) { subscriber.SubscribedActivityQualifiedName = subscriberQualifiedName; } qState.AsynchronousListeners.Add(subscriber); WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable subscribe for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); if (qState.AsynchronousListeners.Count == 1) qService.NotifyAsynchronousSubscribers(this.queueName, qState, qState.Messages.Count); } } public void UnregisterForQueueItemAvailable(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity); bool removed = qService.GetQueueState(this.queueName).AsynchronousListeners.Remove(subscriber); if (!removed) { WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable unsubscribe failed for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); } } } public event EventHandler QueueItemArrived { add { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Add(new ActivityExecutorDelegateInfo (value, qService.CallingActivity)); } } remove { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Remove(new ActivityExecutorDelegateInfo (value, qService.CallingActivity)); } } } public void RegisterForQueueItemArrived(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Add(new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity)); } } public void UnregisterForQueueItemArrived(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Remove(new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity)); } } public IComparable QueueName { get { return this.queueName; } } public WorkflowQueuingService QueuingService { get { return this.qService; } } public void Enqueue(object item) { lock (qService.SyncRoot) { qService.EnqueueEvent(this.queueName, item); } } public object Dequeue() { lock (qService.SyncRoot) { object message = qService.Peek(this.queueName); return qService.DequeueEvent(this.queueName); } } public object Peek() { lock (qService.SyncRoot) { object message = qService.Peek(this.queueName); return message; } } public int Count { get { lock (qService.SyncRoot) { return this.qService.GetQueueState(this.queueName).Messages.Count; } } } public bool Enabled { get { lock (qService.SyncRoot) { return this.qService.GetQueueState(this.queueName).Enabled; } } set { lock (qService.SyncRoot) { this.qService.GetQueueState(this.queueName).Enabled = value; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using System.Text; using System.Diagnostics; using System.Workflow.ComponentModel; namespace System.Workflow.Runtime { public class WorkflowQueue { IComparable queueName; WorkflowQueuingService qService; internal WorkflowQueue(WorkflowQueuingService qService, IComparable queueName) { this.qService = qService; this.queueName = queueName; } public event EventHandler QueueItemAvailable { add { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { EventQueueState qState = qService.GetQueueState(this.queueName); ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (value, qService.CallingActivity); qState.AsynchronousListeners.Add(subscriber); WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable subscribe for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); if (qState.AsynchronousListeners.Count == 1) qService.NotifyAsynchronousSubscribers(this.queueName, qState, qState.Messages.Count); } } remove { lock (qService.SyncRoot) { ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (value, qService.CallingActivity); bool removed = qService.GetQueueState(this.queueName).AsynchronousListeners.Remove(subscriber); if (!removed) { WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable unsubscribe failed for activity '{0}' with context Id {1} ", subscriber.ActivityQualifiedName, subscriber.ContextId); } } } } public void RegisterForQueueItemAvailable(IActivityEventListener eventListener) { RegisterForQueueItemAvailable(eventListener, null); } public void RegisterForQueueItemAvailable(IActivityEventListener eventListener, string subscriberQualifiedName) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { EventQueueState qState = qService.GetQueueState(this.queueName); ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity); if (subscriberQualifiedName != null) { subscriber.SubscribedActivityQualifiedName = subscriberQualifiedName; } qState.AsynchronousListeners.Add(subscriber); WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable subscribe for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); if (qState.AsynchronousListeners.Count == 1) qService.NotifyAsynchronousSubscribers(this.queueName, qState, qState.Messages.Count); } } public void UnregisterForQueueItemAvailable(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { ActivityExecutorDelegateInfo subscriber = new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity); bool removed = qService.GetQueueState(this.queueName).AsynchronousListeners.Remove(subscriber); if (!removed) { WorkflowTrace.Runtime.TraceEvent(TraceEventType.Information, 0, "WorkflowQueue:QueueItemAvailable unsubscribe failed for activity '{0}' with context Id {1}", subscriber.ActivityQualifiedName, subscriber.ContextId); } } } public event EventHandler QueueItemArrived { add { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Add(new ActivityExecutorDelegateInfo (value, qService.CallingActivity)); } } remove { if (value == null) throw new ArgumentNullException("value"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Remove(new ActivityExecutorDelegateInfo (value, qService.CallingActivity)); } } } public void RegisterForQueueItemArrived(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Add(new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity)); } } public void UnregisterForQueueItemArrived(IActivityEventListener eventListener) { if (eventListener == null) throw new ArgumentNullException("eventListener"); lock (qService.SyncRoot) { qService.GetQueueState(this.queueName).SynchronousListeners.Remove(new ActivityExecutorDelegateInfo (eventListener, qService.CallingActivity)); } } public IComparable QueueName { get { return this.queueName; } } public WorkflowQueuingService QueuingService { get { return this.qService; } } public void Enqueue(object item) { lock (qService.SyncRoot) { qService.EnqueueEvent(this.queueName, item); } } public object Dequeue() { lock (qService.SyncRoot) { object message = qService.Peek(this.queueName); return qService.DequeueEvent(this.queueName); } } public object Peek() { lock (qService.SyncRoot) { object message = qService.Peek(this.queueName); return message; } } public int Count { get { lock (qService.SyncRoot) { return this.qService.GetQueueState(this.queueName).Messages.Count; } } } public bool Enabled { get { lock (qService.SyncRoot) { return this.qService.GetQueueState(this.queueName).Enabled; } } set { lock (qService.SyncRoot) { this.qService.GetQueueState(this.queueName).Enabled = value; } } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
![Network programming in C#, Network Programming in VB.NET, Network Programming in .NET](/images/book.jpg)
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- TextControl.cs
- SiteMapDataSource.cs
- RegexMatch.cs
- FontStretchConverter.cs
- CharAnimationBase.cs
- Pool.cs
- DesignerGenericWebPart.cs
- Storyboard.cs
- WrappedReader.cs
- ObjectDataSourceFilteringEventArgs.cs
- DetailsViewRowCollection.cs
- MailBnfHelper.cs
- TitleStyle.cs
- FixedSOMPageConstructor.cs
- GACIdentityPermission.cs
- SQLBinary.cs
- _AutoWebProxyScriptEngine.cs
- XmlDocumentType.cs
- FileDialogCustomPlacesCollection.cs
- wmiprovider.cs
- SoapAttributeOverrides.cs
- SafeMemoryMappedFileHandle.cs
- documentsequencetextpointer.cs
- DBAsyncResult.cs
- ProfileProvider.cs
- SafeUserTokenHandle.cs
- HierarchicalDataSourceConverter.cs
- PropertyInfoSet.cs
- WindowsImpersonationContext.cs
- OptionalRstParameters.cs
- EventLogTraceListener.cs
- _SslStream.cs
- ServiceHandle.cs
- ToolStripRenderer.cs
- HierarchicalDataTemplate.cs
- OdbcErrorCollection.cs
- CommandLibraryHelper.cs
- RegexMatch.cs
- KeyValuePair.cs
- TaiwanLunisolarCalendar.cs
- SignatureResourceHelper.cs
- LoginViewDesigner.cs
- Queue.cs
- DeviceSpecificDesigner.cs
- EncoderBestFitFallback.cs
- ConsoleEntryPoint.cs
- WebBodyFormatMessageProperty.cs
- CopyNodeSetAction.cs
- EditorZoneBase.cs
- BitmapEffectCollection.cs
- IntPtr.cs
- CodeGen.cs
- TextBoxBase.cs
- MultiByteCodec.cs
- DataServiceException.cs
- WSFederationHttpSecurityMode.cs
- DesignerDataTable.cs
- ListenerConnectionDemuxer.cs
- BamlRecordHelper.cs
- DataSourceCache.cs
- _NestedSingleAsyncResult.cs
- WindowsListViewGroupHelper.cs
- EntityCodeGenerator.cs
- EditorZone.cs
- Rule.cs
- HandlerMappingMemo.cs
- CacheHelper.cs
- ObjectSpanRewriter.cs
- CharacterMetricsDictionary.cs
- WebRequestModuleElementCollection.cs
- CodeSnippetTypeMember.cs
- Panel.cs
- WinOEToolBoxItem.cs
- NullReferenceException.cs
- QuaternionRotation3D.cs
- MissingMemberException.cs
- GridViewColumn.cs
- LinqDataSourceView.cs
- RedBlackList.cs
- NumberFormatInfo.cs
- BulletedList.cs
- NullExtension.cs
- WindowsGraphics2.cs
- documentsequencetextpointer.cs
- HttpCapabilitiesSectionHandler.cs
- odbcmetadatacollectionnames.cs
- AppDomain.cs
- PageTheme.cs
- Activator.cs
- MarkupCompilePass1.cs
- ToolStripSeparatorRenderEventArgs.cs
- PackageStore.cs
- HashCodeCombiner.cs
- StyleHelper.cs
- SessionEndedEventArgs.cs
- GZipStream.cs
- QilReplaceVisitor.cs
- ReflectEventDescriptor.cs
- EnterpriseServicesHelper.cs
- EFAssociationProvider.cs