private static void ArrangeExecutionSteps(this ExecutionStepDictionary execSteps,
                                                  IDictionary <string, ExecutionStepCollection> messageWiseSteps,
                                                  IDictionary <int, ExecutionStepCollection> groupedSteps)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "ArrangeExecutionSteps"))
            {
                try
                {
                    Stack <IExecutionStep> st = new Stack <IExecutionStep>();
                    st.Push(execSteps.Start);
                    IDictionary <string, IExecutionStep> steps = new StringDictionary <IExecutionStep>();

                    while (st.Count != 0)
                    {
                        IExecutionStep step  = st.Pop();
                        int            level = Math.Max(0, (from p in step.PrevSteps
                                                            select p.Level).DefaultIfEmpty().Max()) + 1;
                        if (!steps.ContainsKey(step.UniqueKey))
                        {
                            step.Level = level;
                            steps.Add(step.UniqueKey, step);
                        }

                        foreach (var step2 in step.NextSteps)
                        {
                            if (!steps.ContainsKey(step2.UniqueKey))
                            {
                                st.Push(step2);
                            }
                        }
                    }

                    // last step
                    execSteps.End.Level = Math.Max(0, (from p in steps.Values
                                                       select p.Level).DefaultIfEmpty().Max()) + 1;

                    // Ordered projects
                    groupedSteps.Clear();
                    var orderedSteps = (from p in execSteps.Values
                                        orderby p.Level
                                        group p by p.Level);
                    foreach (var orderedStep in orderedSteps)
                    {
                        ExecutionStepCollection stepsList = new ExecutionStepCollection();
                        groupedSteps.Add(orderedStep.Key, stepsList);

                        foreach (var step in orderedStep)
                        {
                            stepsList.Add(step);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
        internal Exception ExecuteStep(IExecutionStep step, ref bool completedSynchronously)
        {
            Exception exception = null;

            //try
            //{
            //try
            //{
            if (step.IsCancellable)
            {
                _context.WorkerRequest.BeginCancellablePeriod();
                try { step.Execute(); }
                finally { _context.WorkerRequest.EndCancellablePeriod(); }
                _context.WorkerRequest.WaitForExceptionIfCancelled();
            }
            else
            {
                step.Execute();
            }
            if (!step.CompletedSynchronously)
            {
                completedSynchronously = false;
                return(null);
            }
            //}
            //catch (Exception ex)
            //{
            //    exception = ex;
            //    if ((ex is ThreadAbortException) && ((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) == ThreadState.Running))
            //    {
            //        exception = null;
            //        _stepManager.CompleteRequest();
            //    }
            //}
            //catch { }
            //}
            //catch (ThreadAbortException ex)
            //{
            //    if ((ex.ExceptionState != null) && (ex.ExceptionState is CancelModuleException))
            //    {
            //        var exceptionState = (CancelModuleException)ex.ExceptionState;
            //        if (exceptionState.Timeout)
            //            exception = new HttpException("Request_timed_out", null, 0xbb9);
            //        else
            //        {
            //            exception = null;
            //            _stepManager.CompleteRequest();
            //        }
            //        Thread.ResetAbort();
            //    }
            //}
            completedSynchronously = true;
            return(exception);
        }
Beispiel #3
0
        public void ExecuteStep(IExecutionStep step)
        {
            // this position does not take the area dimensions into account
            var position = step.GetNextPosition(Position, Direction);

            // the final position takes the area dimensions into account
            Position = new Vector(
                _ComputeSlidingValue(position.X, AreaDimensions.X),
                _ComputeSlidingValue(position.Y, AreaDimensions.Y)
                );

            Direction = step.GetNextDirection(Direction);
        }
        private static IExecutionStep AddOrUpdate(this _ExecutionStepFactory factory, Type dependency, string dependencyName)
        {
            IExecutionStep result = null;

            if (!factory.ExecutionSteps.ContainsKey(dependencyName))
            {
                factory.ExecutionSteps.Add(dependencyName, (result = Activator.CreateInstance(dependency) as IExecutionStep));
                result.Factory = factory;
                result.Level   = 1;
            }
            else
            {
                result = factory.ExecutionSteps[dependencyName];
            }
            return(result);
        }
        internal static void CreateExecutionSteps(this _ExecutionStepFactory factory)
        {
            using (ILogMethod method = Log.LogMethod(DYN_MODULE_NAME, "CreateExecutionSteps"))
            {
                try
                {
                    ExecutionStepDictionary  execSteps  = factory.ExecutionSteps;
                    ExecutionStepDeviceTypes deviceType = ExecutionStepFactory.Current.DeviceType;
                    IDictionary <string, ExecutionStepCollection> messageWiseSteps = factory.MessageWiseSteps;
                    IDictionary <int, ExecutionStepCollection>    groupedSteps     = factory.GroupedSteps;

                    var mappings = (from m in _mappings
                                    from j in m.Attributes
                                    where j.DeviceType == deviceType
                                    select m).ToArray();

                    foreach (var mapping in mappings)//.AsParallel())
                    {
                        Type           classType = mapping.Type;
                        IExecutionStep step      = factory.AddOrUpdate(classType, classType.Name);

                        foreach (var mappingAttribute in mapping.Attributes
                                 .Where(d => d.DeviceType == deviceType))
                        {
                            if (mappingAttribute.IsStart && (execSteps.Start == null))
                            {
                                execSteps.Start = step;
                            }
                            if (mappingAttribute.IsEnd && (execSteps.End == null))
                            {
                                execSteps.End = step;
                            }
                            step.PostTypeG2H    = mappingAttribute.PostTypeG2H;
                            step.PostTypeH2G    = mappingAttribute.PostTypeH2G;
                            step.MoveToNextStep = mappingAttribute.MoveToNextStep;

                            //if (mappingAttribute.Dependencies != null)
                            //{
                            //    foreach (var dependency in mappingAttribute.Dependencies)
                            //    {
                            //        IExecutionStep parentStep = execSteps.AddOrUpdate(dependency, dependency.Name);
                            //        if (!parentStep.NextSteps.Contains(step))
                            //            parentStep.NextSteps.Add(step);
                            //    }
                            //}

                            //if (mappingAttribute.NextDependency != null)
                            //{
                            //    var dependency = mappingAttribute.NextDependency;
                            //    IExecutionStep nextStep = execSteps.AddOrUpdate(dependency, dependency.Name);
                            //    if (!step.NextSteps.Contains(nextStep))
                            //        step.NextSteps.Add(nextStep);
                            //    step.NextStep = nextStep;
                            //    step.SetNextStep = mappingAttribute.SetNextStep;
                            //    nextStep.PrevStep = step;
                            //}
                            if (mappingAttribute.NextSteps != null)
                            {
                                foreach (var dependency in mappingAttribute.NextSteps)
                                {
                                    IExecutionStep nextStep = factory.AddOrUpdate(dependency, dependency.Name);
                                    //nextStep.Level = step.Level + 1;
                                    bool resetNextStep = false;

                                    if (!step.NextSteps.Contains(nextStep))
                                    {
                                        step.NextSteps.Add(nextStep);
                                        resetNextStep = (step.NextSteps.Count > 1);
                                    }
                                    step.NextStep = (resetNextStep ? null : nextStep);

                                    if (!nextStep.PrevSteps.Contains(step))
                                    {
                                        nextStep.PrevSteps.Add(step);
                                    }
                                    //step.SetNextStep = mappingAttribute.SetNextStep;
                                    //nextStep.PrevStep = step;
                                }
                            }

                            if (messageWiseSteps != null &&
                                mappingAttribute.AllowedMessages != null)
                            {
                                var direction = mappingAttribute.AllowedMessageDirectionAll;
                                int length    = mappingAttribute.AllowedMessages.Length;

                                for (int i = 0; i < mappingAttribute.AllowedMessages.Length; i++)
                                {
                                    if (mappingAttribute.AllowedMessageDirections != null)
                                    {
                                        direction = mappingAttribute.AllowedMessageDirections[i];
                                    }

                                    ExecutionStepKeyValue pair = new ExecutionStepKeyValue(mappingAttribute.AllowedMessages[i].Name, direction);
                                    string pairKey             = pair.FullKey;
                                    if (!step.AllowedMessages.ContainsKey(pair))
                                    {
                                        step.AllowedMessages.Add(pair, 1);
                                    }

                                    ExecutionStepCollection execSteps2 = null;
                                    if (messageWiseSteps.ContainsKey(pairKey))
                                    {
                                        execSteps2 = messageWiseSteps[pairKey];
                                    }
                                    else
                                    {
                                        messageWiseSteps.Add(pairKey, (execSteps2 = new ExecutionStepCollection()));
                                    }
                                    execSteps2.Add(step);
                                }

                                if (mappingAttribute.AllowedReplyMessages != null &&
                                    mappingAttribute.AllowedReplyMessages.Length == length)
                                {
                                    for (int j = 0; j < length; j++)
                                    {
                                        Type type1 = mappingAttribute.AllowedMessages[j];
                                        Type type2 = mappingAttribute.AllowedReplyMessages[j];
                                        if (type1 != null && type2 != null)
                                        {
                                            factory.RequestResponseMappings.Add(type1.Name, type2.Name, new RequestResponseMapItem());
                                        }
                                    }
                                }
                            }
                        }
                    }

                    // execution step grouping
                    if (messageWiseSteps != null &&
                        groupedSteps != null)
                    {
                        execSteps.ArrangeExecutionSteps(messageWiseSteps, groupedSteps);
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
            }
        }
        private void AddEventMapping(string moduleName,
                                      RequestNotification requestNotification,
                                      bool isPostNotification,
                                      IExecutionStep step) {

            ThrowIfEventBindingDisallowed();

            // Add events to the IExecutionStep containers only if
            // InitSpecial has completed and InitInternal has not completed.
            if (!IsContainerInitalizationAllowed) {
                return;
            }

            Debug.Assert(!String.IsNullOrEmpty(moduleName), "!String.IsNullOrEmpty(moduleName)");
            Debug.Trace("PipelineRuntime", "AddEventMapping: for " + moduleName +
                        " for " + requestNotification + "\r\n" );


            PipelineModuleStepContainer container = GetModuleContainer(moduleName);
            //WOS 1985878: HttpModule unsubscribing an event handler causes AV in Integrated Mode
            if (container != null) {
#if DBG
                container.DebugModuleName = moduleName;
#endif
                container.AddEvent(requestNotification, isPostNotification, step);
            }
        }
        /*
         * Execute single step catching exceptions in a fancy way (see below)
         */
        internal Exception ExecuteStep(IExecutionStep step, ref bool completedSynchronously) {
            Exception error = null;

            try {
                try {
                    if (step.IsCancellable) {
                        _context.BeginCancellablePeriod();  // request can be cancelled from this point

                        try {
                            step.Execute();
                        }
                        finally {
                            _context.EndCancellablePeriod();  // request can be cancelled until this point
                        }

                        _context.WaitForExceptionIfCancelled();  // wait outside of finally
                    }
                    else {
                        step.Execute();
                    }

                    if (!step.CompletedSynchronously) {
                        completedSynchronously = false;
                        return null;
                    }
                }
                catch (Exception e) {
                    error = e;

                    // Since we will leave the context later, we need to remember if we are impersonating
                    // before we lose that info - VSWhidbey 494476
                    if (ImpersonationContext.CurrentThreadTokenExists) {
                        e.Data[System.Web.Management.WebThreadInformation.IsImpersonatingKey] = String.Empty;
                    }
                    // This might force ThreadAbortException to be thrown
                    // automatically, because we consumed an exception that was
                    // hiding ThreadAbortException behind it

                    if (e is ThreadAbortException &&
                        ((Thread.CurrentThread.ThreadState & ThreadState.AbortRequested) == 0))  {
                        // Response.End from a COM+ component that re-throws ThreadAbortException
                        // It is not a real ThreadAbort
                        // VSWhidbey 178556
                        error = null;
                        _stepManager.CompleteRequest();
                    }
                }
#pragma warning disable 1058
                catch {
                    // ignore non-Exception objects that could be thrown
                }
#pragma warning restore 1058
            }
            catch (ThreadAbortException e) {
                // ThreadAbortException could be masked as another one
                // the try-catch above consumes all exceptions, only
                // ThreadAbortException can filter up here because it gets
                // auto rethrown if no other exception is thrown on catch

                if (e.ExceptionState != null && e.ExceptionState is CancelModuleException) {
                    // one of ours (Response.End or timeout) -- cancel abort

                    CancelModuleException cancelException = (CancelModuleException)e.ExceptionState;

                    if (cancelException.Timeout) {
                        // Timed out
                        error = new HttpException(SR.GetString(SR.Request_timed_out),
                                            null, WebEventCodes.RuntimeErrorRequestAbort);
                        PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_TIMED_OUT);
                    }
                    else {
                        // Response.End
                        error = null;
                        _stepManager.CompleteRequest();
                    }

                    Thread.ResetAbort();
                }
            }

            completedSynchronously = true;
            return error;
        }
        public bool Execute(IFreeformEntity_Msg request)
        {
            using (ILogMethod method = Log.LogMethod(this.DYN_MODULE_NAME, "Execute"))
            {
                bool   result = default(bool);
                string key    = string.Empty;

                try
                {
                    key = request.IpAddress;
                    ExecutionStepDictionary steps = _executionSteps;
                    _isExecuting = true;

                    //_gmuExecutionStepsExecuting.AddOrUpdate(key, true, (k, b) => { return true; });

                    //if (!_gmuExecutionSteps.ContainsKey(key))
                    //{
                    //    steps = new ExecutionStepDictionary();
                    //    steps.Entity.GmuIpAddress = key;
                    //    steps.CreateExecutionSteps(ExecutionStepFactory.Current.DeviceType, _messageWiseSteps, _groupedSteps);
                    //    _gmuExecutionSteps.Add(key, steps);
                    //    _entities.Add(steps.Entity);
                    //}
                    //else
                    //{
                    //    steps = _gmuExecutionSteps[key];
                    //}

                    if (steps != null)
                    {
                        // has clients
                        bool hasClients = false;
                        ExCommsExecutionStepEntity entity          = steps.Entity;
                        IExecutionStep             execStepCurrent = null;
                        IExecutionStep             execStepLatest  = null;
                        entity.Steps.Clear();

                        if (ExCommsServerImpl.Current != null)
                        {
                            hasClients = ExCommsServerImpl.Current.HasStepChangedClients;
                        }

#if !OLD_CODE
                        // 1. find the execution step by message
                        string messageKey = request.EntityUniqueKeyDirection;
                        if (_messageWiseSteps.ContainsKey(messageKey))
                        {
                            var stepList = _messageWiseSteps[messageKey];
                            if (stepList.Count == 1)
                            {
                                execStepCurrent = stepList[0];
                            }
                        }

                        // execute the step
                        if (execStepCurrent != null)
                        {
                            // last step
                            IExecutionStep execStepLast = (steps.Current ?? steps.Start);
                            if (hasClients && execStepLast != null)
                            {
                                entity.Steps.Add(execStepLast.GetType().Name);
                            }

                            // execute the current step
                            execStepLatest = execStepCurrent.Execute(request);

                            //// move to or set to next step
                            //if (execStepLatest != null &&
                            //    execStepLatest.ExecutionResult == ExecutionStepResult.Success)
                            //{
                            //    if (execStepLatest.NextStep != null)
                            //    {
                            //        if (execStepLatest.MoveToNextStep)
                            //        {
                            //            if (hasClients && execStepLatest.NextStep != null)
                            //                entity.Steps.Add(execStepLatest.NextStep.GetType().Name);
                            //            execStepLatest = execStepLatest.NextStep.Execute(request);
                            //        }

                            //        //if (execStepLatest.SetNextStep)
                            //        //{
                            //        //    if (hasClients)
                            //        //        entity.Steps.Add(execStepLatest.GetType().Name);
                            //        //    execStepLatest = execStepLatest.NextStep;
                            //        //    execStepLatest.ExecutionResult = ExecutionStepResult.Success;
                            //        //}
                            //    }
                            //}

                            if (execStepLatest != null &&
                                execStepLatest.ExecutionResult == ExecutionStepResult.Success &&
                                !Object.ReferenceEquals(steps.Current, execStepLatest))
                            {
                                steps.Current = execStepLatest;
                            }
                        }
#else
                        // last step
                        IExecutionStep step = (steps.Current ?? steps.Start);
                        if (hasClients && step != null)
                        {
                            entity.Steps.Add(step.GetType().Name);
                        }

                        // previous step
                        if (step.ExecutionResult == ExecutionStepResult.Failed &&
                            step.PrevStep != null)
                        {
                            step = step.PrevStep;
                        }

                        // execute the current step
                        if (hasClients && step != null)
                        {
                            entity.Steps.Add(step.GetType().Name);
                        }
                        IExecutionStep step2 = step.Execute(request);

                        // move to or set to next step
                        if (step2 != null &&
                            step2.ExecutionResult == ExecutionStepResult.Success)
                        {
                            if (step2.NextStep != null)
                            {
                                if (step2.MoveToNextStep)
                                {
                                    if (hasClients && step2.NextStep != null)
                                    {
                                        entity.Steps.Add(step2.NextStep.GetType().Name);
                                    }
                                    step2 = step2.NextStep.Execute(request);
                                }

                                if (step2.SetNextStep)
                                {
                                    if (hasClients)
                                    {
                                        entity.Steps.Add(step2.GetType().Name);
                                    }
                                    step2 = step2.NextStep;
                                    step2.ExecutionResult = ExecutionStepResult.Success;
                                }
                            }
                        }

                        if (step2 != null &&
                            step2.ExecutionResult == ExecutionStepResult.Success &&
                            !Object.ReferenceEquals(steps.Current, step2))
                        {
                            steps.Current = step2;
                        }
#endif

                        if (hasClients)
                        {
                            if (execStepLatest != null)
                            {
                                entity.Steps.Add(execStepLatest.UniqueKey);
                            }
                            ExCommsServerImpl.Current.OnNotifyExecutionStepChanged(entity);
                        }
                    }
                }
                catch (Exception ex)
                {
                    method.Exception(ex);
                }
                finally
                {
                    //_gmuExecutionStepsExecuting.AddOrUpdate(key, false, (k, b) => { return false; });
                    _isExecuting = false;
                }

                return(result);
            }
        }
 public ImportedExecutionStep(Fixture innerFixture, IExecutionStep inner)
 {
     _innerFixture = innerFixture;
     _inner = inner;
 }
Beispiel #10
0
 public ImportedExecutionStep(Fixture innerFixture, IExecutionStep inner)
 {
     _innerFixture = innerFixture;
     _inner        = inner;
 }
 private void AddEventMapping(string moduleName, RequestNotification requestNotification, bool isPostNotification, IExecutionStep step)
 {
     ThrowIfEventBindingDisallowed();
     //if (IsContainerInitalizationAllowed)
     //{
     //    var moduleContainer = GetModuleContainer(moduleName);
     //    if (moduleContainer != null)
     //        moduleContainer.AddEvent(requestNotification, isPostNotification, step);
     //}
 }
 internal Exception ExecuteStep(IExecutionStep step, ref bool completedSynchronously)
 {
     Exception exception = null;
     try
     {
         try
         {
             if (step.IsCancellable)
             {
                 this._context.BeginCancellablePeriod();
                 try
                 {
                     step.Execute();
                 }
                 finally
                 {
                     this._context.EndCancellablePeriod();
                 }
                 this._context.WaitForExceptionIfCancelled();
             }
             else
             {
                 step.Execute();
             }
             if (!step.CompletedSynchronously)
             {
                 completedSynchronously = false;
                 return null;
             }
         }
         catch (Exception exception2)
         {
             exception = exception2;
             if (ImpersonationContext.CurrentThreadTokenExists)
             {
                 exception2.Data["ASPIMPERSONATING"] = string.Empty;
             }
             if ((exception2 is ThreadAbortException) && ((Thread.CurrentThread.ThreadState & System.Threading.ThreadState.AbortRequested) == System.Threading.ThreadState.Running))
             {
                 exception = null;
                 this._stepManager.CompleteRequest();
             }
         }
         catch
         {
         }
     }
     catch (ThreadAbortException exception3)
     {
         if ((exception3.ExceptionState != null) && (exception3.ExceptionState is CancelModuleException))
         {
             CancelModuleException exceptionState = (CancelModuleException) exception3.ExceptionState;
             if (exceptionState.Timeout)
             {
                 exception = new HttpException(System.Web.SR.GetString("Request_timed_out"), null, 0xbb9);
                 PerfCounters.IncrementCounter(AppPerfCounter.REQUESTS_TIMED_OUT);
             }
             else
             {
                 exception = null;
                 this._stepManager.CompleteRequest();
             }
             Thread.ResetAbort();
         }
     }
     completedSynchronously = true;
     return exception;
 }
 private void AddEventMapping(string moduleName, RequestNotification requestNotification, bool isPostNotification, IExecutionStep step)
 {
     this.ThrowIfEventBindingDisallowed();
     if (this.IsContainerInitalizationAllowed)
     {
         PipelineModuleStepContainer moduleContainer = this.GetModuleContainer(moduleName);
         if (moduleContainer != null)
         {
             moduleContainer.AddEvent(requestNotification, isPostNotification, step);
         }
     }
 }