Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx35 / System.WorkflowServices / System / ServiceModel / Dispatcher / WorkflowOperationInvoker.cs / 1305376 / WorkflowOperationInvoker.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Dispatcher { using System.Diagnostics; using System.Reflection; using System.Runtime; using System.Security; using System.ServiceModel.Channels; using System.ServiceModel.Description; using System.ServiceModel.Diagnostics; using System.Workflow.Runtime; class WorkflowOperationInvoker : IOperationInvoker { static object[] emptyObjectArray = new object[0]; bool canCreateInstance; DispatchRuntime dispatchRuntime; int inParameterCount; bool isOneWay; OperationDescription operationDescription; ServiceAuthorizationManager serviceAuthorizationManager; string staticQueueName; MethodInfo syncMethod; WorkflowInstanceLifetimeManagerExtension workflowInstanceLifeTimeManager; WorkflowRuntime workflowRuntime; public WorkflowOperationInvoker(OperationDescription operationDescription, WorkflowOperationBehavior workflowOperationBehavior, WorkflowRuntime workflowRuntime, DispatchRuntime dispatchRuntime) { if (operationDescription == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("operationDescription"); } if (workflowRuntime == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowRuntime"); } if (workflowOperationBehavior == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("workflowOperationBehavior"); } this.isOneWay = operationDescription.IsOneWay; if (operationDescription.BeginMethod != null) { this.syncMethod = operationDescription.BeginMethod; inParameterCount = GetFlowedInParameterCount(operationDescription.BeginMethod.GetParameters()) - 2; } else { this.syncMethod = operationDescription.SyncMethod; inParameterCount = GetFlowedInParameterCount(operationDescription.SyncMethod.GetParameters()); } this.operationDescription = operationDescription; this.workflowRuntime = workflowRuntime; this.canCreateInstance = workflowOperationBehavior.CanCreateInstance; this.serviceAuthorizationManager = workflowOperationBehavior.ServiceAuthorizationManager; this.dispatchRuntime = dispatchRuntime; staticQueueName = QueueNameHelper.Create(this.syncMethod.DeclaringType, operationDescription.Name); } public bool CanCreateInstance { get { return this.canCreateInstance; } } public DispatchRuntime DispatchRuntime { get { return this.dispatchRuntime; } } public WorkflowInstanceLifetimeManagerExtension InstanceLifetimeManager { get { if (this.workflowInstanceLifeTimeManager == null) { this.workflowInstanceLifeTimeManager = this.dispatchRuntime.ChannelDispatcher.Host.Extensions.Find(); } return this.workflowInstanceLifeTimeManager; } } public bool IsOneWay { get { return this.isOneWay; } } public bool IsSynchronous { get { return false; } } public string StaticQueueName { get { return this.staticQueueName; } } public object[] AllocateInputs() { if (inParameterCount == 0) { return emptyObjectArray; } return new object[inParameterCount]; } public object Invoke(object instance, object[] inputs, out object[] outputs) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new NotImplementedException()); } public IAsyncResult InvokeBegin(object instance, object[] inputs, AsyncCallback callback, object state) { long beginTime = 0; if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodCalled(this.operationDescription.Name); try { if (UnsafeNativeMethods.QueryPerformanceCounter(out beginTime) == 0) { beginTime = -1; } } catch (SecurityException exception) { if (DiagnosticUtility.ShouldTraceWarning) { DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning); } throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new SecurityException(SR.GetString("PartialTrustPerformanceCountersNotEnabled"), exception)); } } Authorize(); WorkflowDurableInstance durableInstance = (WorkflowDurableInstance) instance; Fx.Assert(durableInstance.CurrentOperationInvocation == null, "At the time WorkflowOperationInvoker.InvokeBegin is called, the WorkflowDurableInstance.CurrentOperationInvocation is expected to be null given the ConcurrencyMode.Single."); durableInstance.CurrentOperationInvocation = new WorkflowOperationAsyncResult( this, durableInstance, inputs, callback, state, beginTime); return durableInstance.CurrentOperationInvocation; } public object InvokeEnd(object instance, out object[] outputs, IAsyncResult result) { bool methodThrewException = false; if (result == null) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("result"); } WorkflowDurableInstance durableInstance = (WorkflowDurableInstance) instance; WorkflowOperationAsyncResult asyncResult = (WorkflowOperationAsyncResult) result; Fx.Assert(durableInstance.CurrentOperationInvocation != null, "At the time WorkflowOperationInvoker.InvokeEnd is called, the WorkflowDurableInstance.CurrentOperationInvocation is expected to be present."); try { return WorkflowOperationAsyncResult.End(asyncResult, out outputs); } catch (FaultException) { methodThrewException = true; if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodReturnedFault(this.operationDescription.Name); } throw; } catch (Exception e) { methodThrewException = true; if (Fx.IsFatal(e)) { throw; } if (PerformanceCounters.PerformanceCountersEnabled) { PerformanceCounters.MethodReturnedError(this.operationDescription.Name); } throw; } finally { durableInstance.CurrentOperationInvocation = null; if (!methodThrewException) { if (PerformanceCounters.PerformanceCountersEnabled) { long currentTime = 0; long duration = 0; if ((asyncResult.BeginTime >= 0) && (UnsafeNativeMethods.QueryPerformanceCounter(out currentTime) != 0)) { duration = currentTime - asyncResult.BeginTime; } PerformanceCounters.MethodReturnedSuccess(this.operationDescription.Name, duration); } } } } static int GetFlowedInParameterCount(System.Reflection.ParameterInfo[] parameterInfos) { int inputCount = 0; foreach (System.Reflection.ParameterInfo parameterInfo in parameterInfos) { if (parameterInfo.IsOut) { if (parameterInfo.IsIn) { ++inputCount; } } else { ++inputCount; } } return inputCount; } void Authorize() { Fx.Assert(OperationContext.Current != null, "Not in service dispatch thread"); if (this.serviceAuthorizationManager != null) { if (!this.serviceAuthorizationManager.CheckAccess(OperationContext.Current)) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(AuthorizationBehavior.CreateAccessDeniedFaultException()); } } } } } // 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
- NamedObject.cs
- BuildResultCache.cs
- KeyValueInternalCollection.cs
- SoundPlayerAction.cs
- ContentValidator.cs
- AggregatePushdown.cs
- Run.cs
- TypeReference.cs
- StringSorter.cs
- CorrelationTokenTypeConvertor.cs
- SmtpCommands.cs
- OleDbSchemaGuid.cs
- PresentationUIStyleResources.cs
- XmlSchemaSimpleContentExtension.cs
- ConversionValidationRule.cs
- NonClientArea.cs
- ParameterCollection.cs
- CultureTable.cs
- HttpCookieCollection.cs
- DependencyPropertyDescriptor.cs
- Triplet.cs
- StringArrayConverter.cs
- ValidatingPropertiesEventArgs.cs
- SqlConnectionStringBuilder.cs
- SmtpNtlmAuthenticationModule.cs
- OleDbDataAdapter.cs
- LabelEditEvent.cs
- OverlappedAsyncResult.cs
- SoapSchemaImporter.cs
- HttpServerChannel.cs
- DataServiceExpressionVisitor.cs
- PointHitTestParameters.cs
- DataChangedEventManager.cs
- Control.cs
- UrlMapping.cs
- DataTableMapping.cs
- ProcessInfo.cs
- SqlDataSourceCustomCommandEditor.cs
- UICuesEvent.cs
- ConfigurationValidatorBase.cs
- CommandTreeTypeHelper.cs
- ActiveXContainer.cs
- ThreadAttributes.cs
- RouteParser.cs
- TypefaceCollection.cs
- ThreadInterruptedException.cs
- Brush.cs
- RelatedImageListAttribute.cs
- XmlAttributeCollection.cs
- UInt64Converter.cs
- ValueConversionAttribute.cs
- SafeUserTokenHandle.cs
- Button.cs
- RelationshipEndMember.cs
- FontStyles.cs
- BitmapScalingModeValidation.cs
- ResXResourceWriter.cs
- EditCommandColumn.cs
- KeyValuePairs.cs
- FormView.cs
- Missing.cs
- MultiPageTextView.cs
- ProvidersHelper.cs
- HMACRIPEMD160.cs
- UnsignedPublishLicense.cs
- NetworkAddressChange.cs
- DesignSurfaceManager.cs
- HashHelper.cs
- PassportAuthenticationModule.cs
- SqlBooleanizer.cs
- AbsoluteQuery.cs
- ReceiveActivityDesignerTheme.cs
- PrintingPermission.cs
- IPipelineRuntime.cs
- DrawingGroup.cs
- ConnectionStringsSection.cs
- PeerNameRegistration.cs
- ColorAnimationUsingKeyFrames.cs
- CapabilitiesAssignment.cs
- Perspective.cs
- UIElement3D.cs
- MetadataHelper.cs
- SurrogateEncoder.cs
- XmlILConstructAnalyzer.cs
- ValueExpressions.cs
- ValidationUtility.cs
- ReversePositionQuery.cs
- Debug.cs
- ColumnWidthChangingEvent.cs
- MbpInfo.cs
- HttpVersion.cs
- HierarchicalDataBoundControl.cs
- BitmapMetadata.cs
- ToolStrip.cs
- UrlPath.cs
- Authorization.cs
- UInt64Storage.cs
- HotSpot.cs
- XmlReader.cs
- ArgumentOutOfRangeException.cs