DefaultCompensation.cs source code in C# .NET

Source code for the .NET framework in C#

                        

Code:

/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / System.Activities / System / Activities / Statements / DefaultCompensation.cs / 1305376 / DefaultCompensation.cs

                            //---------------------------------------------------------------- 
// Copyright (c) Microsoft Corporation.  All rights reserved.
//---------------------------------------------------------------
namespace System.Activities.Statements
{ 
    using System;
    using System.Collections.Generic; 
    using System.Runtime; 
    using System.Collections.ObjectModel;
 
    sealed class DefaultCompensation : NativeActivity
    {
        Activity body;
 
        Variable toCompensateToken;
 
        CompletionCallback onChildCompensated; 

        public DefaultCompensation() 
            : base()
        {
            this.toCompensateToken = new Variable();
 
            this.body = new InternalCompensate()
                { 
                    Target = new InArgument(toCompensateToken), 
                };
        } 

        public InArgument Target
        {
            get; 
            set;
        } 
 
        Activity Body
        { 
            get { return this.body; }
        }

        protected override void CacheMetadata(NativeActivityMetadata metadata) 
        {
            RuntimeArgument targetArgument = new RuntimeArgument("Target", typeof(CompensationToken), ArgumentDirection.In); 
            metadata.Bind(this.Target, targetArgument); 

            metadata.SetArgumentsCollection(new Collection { targetArgument }); 

            metadata.SetImplementationVariablesCollection(new Collection { this.toCompensateToken });

            Fx.Assert(this.Body != null, "Body must be valid"); 
            metadata.SetImplementationChildrenCollection(new Collection { this.Body });
        } 
 
        protected override void Execute(NativeActivityContext context)
        { 
            InternalExecute(context, null);
        }

        void InternalExecute(NativeActivityContext context, ActivityInstance completedInstance) 
        {
            CompensationExtension compensationExtension = context.GetExtension(); 
            if (compensationExtension == null) 
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.CompensateWithoutCompensableActivity(this.DisplayName))); 
            }

            CompensationToken token = Target.Get(context);
            CompensationTokenData tokenData = token == null ? null : compensationExtension.Get(token.CompensationId); 

            Fx.Assert(tokenData != null, "CompensationTokenData must be valid"); 
 
            if (tokenData.ExecutionTracker.Count > 0)
            { 
                if (this.onChildCompensated == null)
                {
                    this.onChildCompensated = new CompletionCallback(InternalExecute);
                } 

                this.toCompensateToken.Set(context, new CompensationToken(tokenData.ExecutionTracker.Get())); 
 
                Fx.Assert(Body != null, "Body must be valid");
                context.ScheduleActivity(Body, this.onChildCompensated); 
            }
        }

        protected override void Cancel(NativeActivityContext context) 
        {
            // Suppress Cancel 
        } 

    } 

}

// 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
This book is available now!
Buy at Amazon US or
Buy at Amazon UK