Пример #1
0
        private void ScheduleBody(NativeActivityContext context, CompensationExtension compensationExtension)
        {
            Fx.Assert(compensationExtension != null, "CompensationExtension must be valid");

            CompensationToken parentToken = null;
            long parentCompensationId     = CompensationToken.RootCompensationId;

            parentToken = (CompensationToken)context.Properties.Find(CompensationToken.PropertyName);

            if (parentToken != null)
            {
                if (compensationExtension.Get(parentToken.CompensationId).IsTokenValidInSecondaryRoot)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(SR.NoCAInSecondaryRoot));
                }

                parentCompensationId = parentToken.CompensationId;
            }

            CompensationTokenData tokenData = new CompensationTokenData(compensationExtension.GetNextId(), parentCompensationId)
            {
                CompensationState = CompensationState.Active,
                DisplayName       = this.DisplayName,
            };
            CompensationToken token = new CompensationToken(tokenData);

            context.Properties.Add(CompensationToken.PropertyName, token);

            this.currentCompensationId.Set(context, token.CompensationId);
            this.currentCompensationToken.Set(context, token);

            compensationExtension.Add(token.CompensationId, tokenData);

            if (TD.CompensationStateIsEnabled())
            {
                TD.CompensationState(tokenData.DisplayName, tokenData.CompensationState.ToString());
            }

            if (this.Body != null)
            {
                context.ScheduleActivity(this.Body, new CompletionCallback(OnBodyExecutionComplete));
            }
            else
            {
                //empty body case. Assume the body has completed successfully
                tokenData.CompensationState = CompensationState.Completed;
                if (TD.CompensationStateIsEnabled())
                {
                    TD.CompensationState(tokenData.DisplayName, tokenData.CompensationState.ToString());
                }

                ScheduleSecondaryRoot(context, compensationExtension, tokenData);
            }
        }
        private void ScheduleBody(NativeActivityContext context, CompensationExtension compensationExtension)
        {
            CompensationToken token   = null;
            long parentCompensationId = 0L;

            token = (CompensationToken)context.Properties.Find("System.Compensation.CompensationToken");
            if (token != null)
            {
                if (compensationExtension.Get(token.CompensationId).IsTokenValidInSecondaryRoot)
                {
                    throw FxTrace.Exception.AsError(new InvalidOperationException(System.Activities.SR.NoCAInSecondaryRoot));
                }
                parentCompensationId = token.CompensationId;
            }
            CompensationTokenData tokenData = new CompensationTokenData(compensationExtension.GetNextId(), parentCompensationId)
            {
                CompensationState = CompensationState.Active,
                DisplayName       = base.DisplayName
            };
            CompensationToken property = new CompensationToken(tokenData);

            context.Properties.Add("System.Compensation.CompensationToken", property);
            this.currentCompensationId.Set(context, property.CompensationId);
            this.currentCompensationToken.Set(context, property);
            compensationExtension.Add(property.CompensationId, tokenData);
            if (TD.CompensationStateIsEnabled())
            {
                TD.CompensationState(tokenData.DisplayName, tokenData.CompensationState.ToString());
            }
            if (this.Body != null)
            {
                context.ScheduleActivity(this.Body, new CompletionCallback(this.OnBodyExecutionComplete));
            }
            else
            {
                tokenData.CompensationState = CompensationState.Completed;
                if (TD.CompensationStateIsEnabled())
                {
                    TD.CompensationState(tokenData.DisplayName, tokenData.CompensationState.ToString());
                }
                this.ScheduleSecondaryRoot(context, compensationExtension, tokenData);
            }
        }