Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / InvokeDelegate.cs / 1305376 / InvokeDelegate.cs
//------------------------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------------------------- namespace System.Activities.Statements { using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Diagnostics.CodeAnalysis; using System.Globalization; using System.Runtime; using System.Windows.Markup; [SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldNotHaveIncorrectSuffix, Justification = "Approved Workflow naming")] [ContentProperty("Delegate")] public sealed class InvokeDelegate : NativeActivity { IDictionarydelegateArguments; bool hasOutputArguments; public InvokeDelegate() { this.delegateArguments = new Dictionary (); } [DefaultValue(null)] public ActivityDelegate Delegate { get; set; } public IDictionary DelegateArguments { get { return this.delegateArguments; } } protected override void CacheMetadata(NativeActivityMetadata metadata) { Collection arguments = new Collection (); foreach (KeyValuePair entry in this.DelegateArguments) { RuntimeArgument argument = new RuntimeArgument(entry.Key, entry.Value.ArgumentType, entry.Value.Direction); metadata.Bind(entry.Value, argument); arguments.Add(argument); } metadata.SetArgumentsCollection(arguments); metadata.AddDelegate(this.Delegate); if (this.Delegate != null) { IList targetDelegateArguments = this.Delegate.RuntimeDelegateArguments; if (this.DelegateArguments.Count != targetDelegateArguments.Count) { metadata.AddValidationError(SR.WrongNumberOfArgumentsForActivityDelegate); } // Validate that the names and directionality of arguments in DelegateArguments dictionary // match the names and directionality of arguments returned by the ActivityDelegate.GetDelegateParameters // call above. for (int i = 0; i < targetDelegateArguments.Count; i++) { RuntimeDelegateArgument expectedParameter = targetDelegateArguments[i]; Argument delegateArgument = null; string parameterName = expectedParameter.Name; if (this.DelegateArguments.TryGetValue(parameterName, out delegateArgument)) { if (delegateArgument.Direction != expectedParameter.Direction) { metadata.AddValidationError(SR.DelegateParameterDirectionalityMismatch(parameterName, delegateArgument.Direction, expectedParameter.Direction)); } if (expectedParameter.Direction == ArgumentDirection.In) { if (!TypeHelper.AreTypesCompatible(delegateArgument.ArgumentType, expectedParameter.Type)) { metadata.AddValidationError(SR.DelegateInArgumentTypeMismatch(parameterName, expectedParameter.Type, delegateArgument.ArgumentType)); } } else { if (!TypeHelper.AreTypesCompatible(expectedParameter.Type, delegateArgument.ArgumentType)) { metadata.AddValidationError(SR.DelegateOutArgumentTypeMismatch(parameterName, expectedParameter.Type, delegateArgument.ArgumentType)); } } } else { metadata.AddValidationError(SR.InputParametersMissing(expectedParameter.Name)); } if (!this.hasOutputArguments && ArgumentDirectionHelper.IsOut(expectedParameter.Direction)) { this.hasOutputArguments = true; } } } } protected override void Execute(NativeActivityContext context) { if (Delegate == null || Delegate.Handler == null) { return; } Dictionary inputParameters = new Dictionary (); if (DelegateArguments.Count > 0) { foreach (KeyValuePair entry in DelegateArguments) { if (ArgumentDirectionHelper.IsIn(entry.Value.Direction)) { inputParameters.Add(entry.Key, entry.Value.Get(context)); } } } context.ScheduleDelegate(Delegate, inputParameters, new DelegateCompletionCallback(OnHandlerComplete), null); } void OnHandlerComplete(NativeActivityContext context, ActivityInstance completedInstance, IDictionary outArguments) { if (this.hasOutputArguments) { foreach (KeyValuePair entry in outArguments) { Argument argument = null; if (DelegateArguments.TryGetValue(entry.Key, out argument)) { if (ArgumentDirectionHelper.IsOut(argument.Direction)) { DelegateArguments[entry.Key].Set(context, entry.Value); } else { Fx.Assert(string.Format(CultureInfo.InvariantCulture, "Expected argument named '{0}' in the DelegateArguments collection to be an out argument.", entry.Key)); } } } } } } } // 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
- ADMembershipProvider.cs
- XamlFxTrace.cs
- AnnotationResource.cs
- DataReaderContainer.cs
- MemberAccessException.cs
- SQLUtility.cs
- CodeMethodInvokeExpression.cs
- EntityProxyFactory.cs
- ReflectTypeDescriptionProvider.cs
- TypeSystem.cs
- WmpBitmapDecoder.cs
- XsdDataContractImporter.cs
- CacheHelper.cs
- RSAOAEPKeyExchangeFormatter.cs
- StylusButtonCollection.cs
- DataViewManagerListItemTypeDescriptor.cs
- HttpRawResponse.cs
- DaylightTime.cs
- DetailsViewDeletedEventArgs.cs
- ToolBarTray.cs
- InheritanceContextChangedEventManager.cs
- CreateUserWizard.cs
- ServicePerformanceCounters.cs
- VarInfo.cs
- ServiceBehaviorElementCollection.cs
- DynamicRouteExpression.cs
- PaginationProgressEventArgs.cs
- MatrixCamera.cs
- HwndSourceKeyboardInputSite.cs
- EqualityComparer.cs
- UnhandledExceptionEventArgs.cs
- LiteralText.cs
- DataGridViewCellPaintingEventArgs.cs
- SourceLocationProvider.cs
- AnchoredBlock.cs
- SortedList.cs
- LicFileLicenseProvider.cs
- MetafileHeaderWmf.cs
- GeometryHitTestResult.cs
- RenameRuleObjectDialog.Designer.cs
- KnownAssembliesSet.cs
- ContractValidationHelper.cs
- Win32Native.cs
- PostBackTrigger.cs
- SHA256Cng.cs
- PrtCap_Reader.cs
- InstanceKeyView.cs
- DataGridViewUtilities.cs
- SqlProcedureAttribute.cs
- WebPartZone.cs
- MexTcpBindingCollectionElement.cs
- LazyTextWriterCreator.cs
- SymbolResolver.cs
- DbBuffer.cs
- SecurityState.cs
- TemplatePartAttribute.cs
- StreamSecurityUpgradeInitiatorAsyncResult.cs
- ZoneButton.cs
- SEHException.cs
- HideDisabledControlAdapter.cs
- AnnotationHelper.cs
- FileReader.cs
- ValueTypeFixupInfo.cs
- HandlerBase.cs
- WebColorConverter.cs
- Font.cs
- Hex.cs
- DayRenderEvent.cs
- MtomMessageEncodingElement.cs
- ScriptControl.cs
- GeneralTransform3DGroup.cs
- HttpModuleAction.cs
- PersistenceProviderFactory.cs
- UserPreferenceChangingEventArgs.cs
- ClientUrlResolverWrapper.cs
- PropertyItem.cs
- ColorAnimation.cs
- NavigationWindow.cs
- InternalResources.cs
- SizeValueSerializer.cs
- Label.cs
- SignedPkcs7.cs
- ComponentConverter.cs
- ObjectAnimationBase.cs
- TitleStyle.cs
- ToolStripDropDownClosingEventArgs.cs
- RawStylusSystemGestureInputReport.cs
- EmptyCollection.cs
- UpdatePanelTrigger.cs
- activationcontext.cs
- CornerRadius.cs
- UIPermission.cs
- Bits.cs
- CustomWebEventKey.cs
- ExpressionBindings.cs
- ProfileSettingsCollection.cs
- ScriptReference.cs
- FixedStringLookup.cs
- PointValueSerializer.cs
- HierarchicalDataSourceControl.cs