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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ConfigXmlWhitespace.cs
- BaseTreeIterator.cs
- TextBoxView.cs
- ProcessInfo.cs
- FormatSelectingMessageInspector.cs
- PropertyFilterAttribute.cs
- MSAAEventDispatcher.cs
- DrawingContextDrawingContextWalker.cs
- OutputCacheSection.cs
- WasNotInstalledException.cs
- OleDbCommand.cs
- ConditionCollection.cs
- InputBindingCollection.cs
- _ConnectStream.cs
- MatrixKeyFrameCollection.cs
- Focus.cs
- SqlResolver.cs
- Model3DCollection.cs
- dbenumerator.cs
- RootBrowserWindowProxy.cs
- AutomationElementCollection.cs
- SubstitutionResponseElement.cs
- EdgeModeValidation.cs
- CommonRemoteMemoryBlock.cs
- CompilationPass2Task.cs
- ArrayList.cs
- DataTableMappingCollection.cs
- ParameterCollectionEditorForm.cs
- ZipIOCentralDirectoryFileHeader.cs
- BindableTemplateBuilder.cs
- TcpHostedTransportConfiguration.cs
- QueueProcessor.cs
- ListViewTableRow.cs
- PtsCache.cs
- QuaternionKeyFrameCollection.cs
- ProfileServiceManager.cs
- ObfuscationAttribute.cs
- BevelBitmapEffect.cs
- AssemblyName.cs
- FixedSOMTableRow.cs
- precedingsibling.cs
- FontStyle.cs
- DictionaryGlobals.cs
- X500Name.cs
- PropertyRef.cs
- SBCSCodePageEncoding.cs
- AnnotationMap.cs
- LassoSelectionBehavior.cs
- PopupRootAutomationPeer.cs
- MetadataPropertyCollection.cs
- FormViewModeEventArgs.cs
- SimpleBitVector32.cs
- ErrorWrapper.cs
- UnmanagedMemoryStreamWrapper.cs
- Compiler.cs
- SoapReflectionImporter.cs
- Pen.cs
- WindowsSolidBrush.cs
- _NtlmClient.cs
- MailWebEventProvider.cs
- TrueReadOnlyCollection.cs
- MenuBindingsEditor.cs
- DataTableNewRowEvent.cs
- StorageTypeMapping.cs
- XmlNode.cs
- ApplySecurityAndSendAsyncResult.cs
- FunctionMappingTranslator.cs
- KnownTypesHelper.cs
- ReadOnlyPermissionSet.cs
- HistoryEventArgs.cs
- RegexCharClass.cs
- BitmapEffectGroup.cs
- COM2Enum.cs
- MatrixValueSerializer.cs
- XmlObjectSerializerWriteContextComplex.cs
- DragStartedEventArgs.cs
- StructuredTypeEmitter.cs
- SimpleBitVector32.cs
- XmlILCommand.cs
- DataShape.cs
- ContextStaticAttribute.cs
- RootBrowserWindow.cs
- LayoutEngine.cs
- Event.cs
- NetworkInterface.cs
- CodeMemberMethod.cs
- BaseParser.cs
- MD5Cng.cs
- FolderBrowserDialog.cs
- AffineTransform3D.cs
- CustomErrorCollection.cs
- TextTreeTextElementNode.cs
- HttpRuntimeSection.cs
- BitmapVisualManager.cs
- AssemblyLoader.cs
- MsmqIntegrationInputMessage.cs
- TraceContextEventArgs.cs
- DependencyObject.cs
- DetailsViewInsertEventArgs.cs
- Mappings.cs