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
- PerfCounterSection.cs
- ControlBindingsCollection.cs
- SecUtil.cs
- WriteFileContext.cs
- XamlStyleSerializer.cs
- CryptoConfig.cs
- XmlSubtreeReader.cs
- ResourceDescriptionAttribute.cs
- EnvelopedPkcs7.cs
- WizardPanel.cs
- DefaultValueAttribute.cs
- ReadOnlyTernaryTree.cs
- XmlSecureResolver.cs
- TransactionCache.cs
- TextTreeInsertElementUndoUnit.cs
- FileLevelControlBuilderAttribute.cs
- AppDomainInstanceProvider.cs
- PropertyValueUIItem.cs
- UniqueEventHelper.cs
- CacheOutputQuery.cs
- _ListenerAsyncResult.cs
- DataFormats.cs
- IpcChannel.cs
- ObjectDataSourceEventArgs.cs
- DragStartedEventArgs.cs
- XmlSchemaImporter.cs
- CfgRule.cs
- ReplyAdapterChannelListener.cs
- TCPClient.cs
- CorrelationManager.cs
- TTSEvent.cs
- SchemaMapping.cs
- GZipStream.cs
- KnownTypes.cs
- InheritanceRules.cs
- EventSinkActivity.cs
- FactorySettingsElement.cs
- NameValueFileSectionHandler.cs
- BaseServiceProvider.cs
- DuplexChannel.cs
- NameValueFileSectionHandler.cs
- ContractNamespaceAttribute.cs
- Thickness.cs
- TableLayoutSettings.cs
- WebControlAdapter.cs
- ExclusiveTcpListener.cs
- ArcSegment.cs
- FormsAuthenticationModule.cs
- objectquery_tresulttype.cs
- DataServiceCollectionOfT.cs
- PointLight.cs
- TreeNodeSelectionProcessor.cs
- Number.cs
- GenerateTemporaryAssemblyTask.cs
- ExcCanonicalXml.cs
- VisualBrush.cs
- CqlParser.cs
- Enum.cs
- MetadataUtil.cs
- ThrowHelper.cs
- AgileSafeNativeMemoryHandle.cs
- XmlHierarchicalDataSourceView.cs
- AllMembershipCondition.cs
- BuildDependencySet.cs
- DefaultValueMapping.cs
- PostBackOptions.cs
- ConfigXmlDocument.cs
- IOException.cs
- RangeExpression.cs
- EntityContainer.cs
- ColorDialog.cs
- XmlStreamNodeWriter.cs
- DesignerForm.cs
- AlgoModule.cs
- MetadataArtifactLoaderCompositeFile.cs
- WindowsComboBox.cs
- CategoryEditor.cs
- DependencyPropertyDescriptor.cs
- LabelLiteral.cs
- _Semaphore.cs
- ConnectionStringsSection.cs
- StylusEditingBehavior.cs
- GroupBoxAutomationPeer.cs
- Timer.cs
- PackageRelationship.cs
- DbgCompiler.cs
- SystemTcpConnection.cs
- Exceptions.cs
- ToolStripItemImageRenderEventArgs.cs
- HttpWrapper.cs
- DoubleKeyFrameCollection.cs
- ButtonBaseAutomationPeer.cs
- DebuggerAttributes.cs
- OracleNumber.cs
- BulletedList.cs
- Crc32.cs
- DropShadowBitmapEffect.cs
- Evidence.cs
- mil_commands.cs
- _NegoStream.cs