Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / TerminateWorkflow.cs / 1305376 / TerminateWorkflow.cs
//------------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
namespace System.Activities.Statements
{
using System;
using System.Activities;
using System.ComponentModel;
using System.Collections.ObjectModel;
public sealed class TerminateWorkflow : NativeActivity
{
public TerminateWorkflow() { }
[DefaultValue(null)]
public InArgument Reason { get; set; }
[DefaultValue(null)]
public InArgument Exception { get; set; }
protected override void CacheMetadata(NativeActivityMetadata metadata)
{
Collection arguments = new Collection();
RuntimeArgument reasonArgument = new RuntimeArgument("Reason", typeof(string), ArgumentDirection.In, false);
metadata.Bind(this.Reason, reasonArgument);
RuntimeArgument exceptionArgument = new RuntimeArgument("Exception", typeof(Exception), ArgumentDirection.In, false);
metadata.Bind(this.Exception, exceptionArgument);
arguments.Add(reasonArgument);
arguments.Add(exceptionArgument);
metadata.SetArgumentsCollection(arguments);
if((this.Reason == null || this.Reason.IsEmpty) &&
(this.Exception == null || this.Exception.IsEmpty))
{
metadata.AddValidationError(SR.OneOfTwoPropertiesMustBeSet("Reason", "Exception", "TerminateWorkflow", this.DisplayName));
}
}
protected override void Execute(NativeActivityContext context)
{
// If Reason is provided, we'll create a WorkflowApplicationTerminatedException from
// it, wrapping Exception if it is also provided. Otherwise just use Exception.
// If neither is provided just throw a new WorkflowTerminatedException.
string reason = Reason.Get(context);
Exception exception = Exception.Get(context);
if (!string.IsNullOrEmpty(reason))
{
context.Terminate(new WorkflowTerminatedException(reason, exception));
}
else if(exception != null)
{
context.Terminate(exception);
}
else
{
context.Terminate(new WorkflowTerminatedException());
}
}
}
}
// 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
- ObjectSet.cs
- SqlConnection.cs
- NamespaceMapping.cs
- DrawingAttributes.cs
- RemoteWebConfigurationHost.cs
- LocalizableAttribute.cs
- QilDataSource.cs
- ExpandCollapsePattern.cs
- CardSpaceSelector.cs
- Command.cs
- TypeElement.cs
- PropertyPath.cs
- ExclusiveTcpListener.cs
- ChannelSinkStacks.cs
- PathSegment.cs
- CodeSnippetTypeMember.cs
- SpellerError.cs
- ProfilePropertySettings.cs
- TraceLog.cs
- SqlInternalConnection.cs
- NativeMethods.cs
- FieldBuilder.cs
- DetailsViewPageEventArgs.cs
- TabControlAutomationPeer.cs
- EndOfStreamException.cs
- ZipIOExtraField.cs
- SessionPageStateSection.cs
- QilTernary.cs
- OleDbEnumerator.cs
- SmtpNtlmAuthenticationModule.cs
- XmlMtomReader.cs
- RuleAttributes.cs
- PolyQuadraticBezierSegment.cs
- WrapperSecurityCommunicationObject.cs
- ThrowHelper.cs
- XPathConvert.cs
- EpmAttributeNameBuilder.cs
- Timeline.cs
- DesignerListAdapter.cs
- ToolboxBitmapAttribute.cs
- TextProperties.cs
- WebBrowser.cs
- EdmEntityTypeAttribute.cs
- SerTrace.cs
- contentDescriptor.cs
- PageRequestManager.cs
- Context.cs
- OlePropertyStructs.cs
- SafeNativeMethods.cs
- EntityDataSourceSelectedEventArgs.cs
- ResourceCategoryAttribute.cs
- ReflectionPermission.cs
- XPathDocument.cs
- RtfFormatStack.cs
- DataRowChangeEvent.cs
- ZipIOExtraFieldZip64Element.cs
- Domain.cs
- AncillaryOps.cs
- DataDocumentXPathNavigator.cs
- FrameworkReadOnlyPropertyMetadata.cs
- SqlCachedBuffer.cs
- HtmlDocument.cs
- TableLayoutSettings.cs
- TimeSpanMinutesOrInfiniteConverter.cs
- InkSerializer.cs
- XmlDictionary.cs
- AdapterUtil.cs
- ViewStateChangedEventArgs.cs
- EnumUnknown.cs
- XmlEnumAttribute.cs
- UriSection.cs
- Misc.cs
- XPathChildIterator.cs
- ProxyWebPartManagerDesigner.cs
- RuleSettings.cs
- SoapDocumentServiceAttribute.cs
- ImplicitInputBrush.cs
- SingleTagSectionHandler.cs
- OrthographicCamera.cs
- _DigestClient.cs
- X509Certificate2.cs
- StyleModeStack.cs
- RijndaelManagedTransform.cs
- CodeEntryPointMethod.cs
- ProjectionPlan.cs
- FolderBrowserDialog.cs
- panel.cs
- Animatable.cs
- DesignOnlyAttribute.cs
- PathFigureCollection.cs
- XmlDictionaryWriter.cs
- TypographyProperties.cs
- PKCS1MaskGenerationMethod.cs
- ValueOfAction.cs
- GroupQuery.cs
- DataObjectAttribute.cs
- SimpleModelProvider.cs
- Pkcs9Attribute.cs
- ClientConvert.cs
- AuthenticatingEventArgs.cs