Beispiel #1
0
        void ParseStackFrame(string line)
        {
            var atpart = line.Trim();

            if (atpart == "")
            {
                return;
            }
            if (atpart.StartsWith("at ", StringComparison.Ordinal))
            {
                atpart = atpart.Substring(3);
            }

            var inpart = "";
            var inpos  = atpart.IndexOf(" in ", StringComparison.Ordinal);

            if (inpos >= 0)
            {
                inpart = atpart.Substring(inpos + 4);
                atpart = atpart.Substring(0, inpos);
            }

            StackTrace.Add(new StackFrameInfo()
            {
                At = atpart, In = inpart
            });
        }
Beispiel #2
0
        /// <summary>
        /// Checks if input is compatible and address accordingly (Exception, Empty or Fail)
        /// </summary>
        /// <returns>False if stack in fail state and needs to end, true otherwise</returns>
        public bool AssertCurrentBlockInput()
        {
            if (CurrentBlockSpec.InputType != null)
            {
                try
                {
                    NextInput = NextInput.ConvertTo(CurrentBlockSpec.InputType);
                }
                catch (Exception e)
                {
                    if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Exception)
                    {
                        throw new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message);
                    }
                    else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.AssumeEmpty)
                    {
                        NextInput = Emptyable.Empty;
                    }
                    else if (options.IncompatibleInputTypeBehaviour == IncompatibleInputTypeBehaviour.Fail)
                    {
                        IsFail = true;
                        var error = ExceptionErrorBuilder <TOperationEvent> .Build(new OperationStackExecutionException("Invalid input coming from " + PreviousBlockSpec?.Tag ?? "unknwon" + " block and going into " + CurrentBlockSpec.Tag + " block. Exception was " + e.Message));

                        StackTrace.Add(new BlockTraceResult <TOperationEvent>(CurrentBlockSpec.Tag, error, NextInput));
                        return(false);
                    }
                }
            }
            return(true);
        }
Beispiel #3
0
        /// <summary>
        /// Handle current block result and set next block to execute
        /// </summary>
        /// <param name="block">The execution block</param>
        /// <param name="blockResult">The execution block result</param>
        public void HandleBlockResultAndSetNext(StackBlockBase <TInput, TState, TOperationEvent> block, IBlockResult blockResult)
        {
            PreviousBlockSpec = CurrentBlockSpec;

            //Add to stack trace
            //Should we add trace to empty event blocks? To event blocks?
            StackTrace.Add(new BlockTraceResult <TOperationEvent>(block, blockResult));

            //Handle Reset state in case of reset
            State = blockResult.Target.FlowTarget == BlockFlowTarget.Reset ?
                    (blockResult.Target.ResetStateSet ? (TState)Convert.ChangeType(blockResult.Target.State, typeof(TState)) : default(TState)) :
                    block.StackState;

            //Check fail state
            if (options.FailOnException && block.Events.HasUnhandledErrors)
            {
                IsFail = true;
            }

            //Override result is only applicable on Complete. Cache here in case of finally
            OverrideResult = blockResult.Target.OverrideResult;

            //Set next input
            NextInput = blockResult.GetNextInput();

            //Get next block to execute
            CurrentBlockSpec = IsFail ? blocks.GotoEnd(CurrentBlockSpec.Index) : GetNext(CurrentBlockSpec, blockResult.Target);

            //If complete set overriden result if any
            if (CurrentBlockSpec == null && OverrideResult.HasValue)
            {
                //Set last result
                LastResult = OverrideResult;
                blockResult.OverrideResult(OverrideResult);
            }
            else
            {
                //Set last result
                LastResult = blockResult.Result;
            }
        }
Beispiel #4
0
 private void CheckEvent(LoggingEvent loggingEvent)
 {
     if (loggingEvent.Level.Name.Equals("INFO"))
     {
         string id = loggingEvent.ThreadName;
         if (loggingEvent.MessageObject.ToString().ToUpper().Equals("BEGIN"))
         {
             if (!_traces.ContainsKey(id))
             {
                 StackTrace st = new StackTrace(loggingEvent.TimeStamp, loggingEvent.LocationInformation.ClassName, loggingEvent.LocationInformation.MethodName);
                 _traces.Add(id, st);
             }
             else
             {
                 StackTrace temp = _traces[id];
                 if (temp.LevelExceeded)
                 {
                     _traces[id] = null;
                     _traces.Remove(id);
                 }
                 else
                 {
                     temp.Add(loggingEvent.TimeStamp, loggingEvent.LocationInformation.ClassName, loggingEvent.LocationInformation.MethodName);
                 }
             }
         }
         if (loggingEvent.MessageObject.ToString().ToUpper().Equals("END"))
         {
             if (_traces.ContainsKey(id))
             {
                 _traces[id].SetEnd(loggingEvent.TimeStamp, loggingEvent.LocationInformation.ClassName, loggingEvent.LocationInformation.MethodName);
                 if (_traces[id].Completed)
                 {
                     Write(_traces[id].ToXml);
                     _traces[id] = null;
                     _traces.Remove(id);
                 }
             }
         }
     }
 }
Beispiel #5
0
 internal void AddTraceLine(Script script, int line_number)
 {
     StackTrace.Add(new TraceLine(script, line_number));
 }
Beispiel #6
0
        private void AddTraceFrames(Exception ex)
        {
            this.StackTrace = new List <TraceFrame>();
            var stackTrace = new StackTrace(ex, true);

            var errorframes = stackTrace.GetFrames();

            string lastErrorFrameMethodName = null;

            if (errorframes != null)
            {
                foreach (StackFrame frame in errorframes)
                {
                    MethodBase method = frame.GetMethod();

                    var fullName = GetMethodFullName(method);

                    bool isSource = false;

#if NETFULL
                    isSource = (ex.TargetSite != null && ex.TargetSite == method);
#endif

                    if (isSource)
                    {
                        this.SourceMethod = fullName;
                    }

                    StackTrace.Add(new TraceFrame()
                    {
                        CodeFileName = frame.GetFileName(),
                        LineNum      = frame.GetFileLineNumber(),
                        Method       = fullName
                    });

                    lastErrorFrameMethodName = fullName;
                }
            }

#if NETFULL
            var stackTrace2 = new StackTrace(true);
            var allFrames   = stackTrace2.GetFrames();


            //logic to add missing frames not showing up in the normal exception stack trace some times
            if (allFrames != null && (lastErrorFrameMethodName != null || this.SourceMethod == null))
            {
                bool foundLast = false;

                foreach (StackFrame frame in allFrames)
                {
                    MethodBase method = frame.GetMethod();

                    var fullName = GetMethodFullName(method);

                    if (!foundLast)
                    {
                        if (lastErrorFrameMethodName == fullName)
                        {
                            foundLast = true;
                            continue;
                        }
                    }

                    if (foundLast)
                    {
                        StackTrace.Add(new TraceFrame()
                        {
                            // LibraryName = method.Module.Name,
                            CodeFileName = frame.GetFileName(),
                            LineNum      = frame.GetFileLineNumber(),
                            Method       = GetMethodFullName(method)
                        });
                    }
                }
            }
#endif
        }