Exemplo n.º 1
0
        public static void Until(Func<CancellationToken, Task<bool>> taskFactory, TimeSpan sleepDuration, TimeSpan timeOut, string exceptionMessage = "", params object[] items)
        {
            ExceptionState lastExceptionState = new ExceptionState();

            using (CancellationTokenSource tokenSource = new CancellationTokenSource(timeOut))
            using (Task task = UntilAsync(taskFactory, tokenSource.Token, lastExceptionState, sleepDuration, timeOut, exceptionMessage, items))
            {
                if (task.Wait(timeOut))
                {
                    return;
                }

                tokenSource.Cancel();
                task.Wait(timeOut);
            }

            string lastMessage = "None found";

            if (lastExceptionState.LastException != null)
            {
                lastMessage = lastExceptionState.LastException.Message;
            }

            throw new TimeoutException(string.Format("{0} Timed out after {1} seconds. Last exception: {2}", String.Format(exceptionMessage, items), timeOut.TotalSeconds, lastMessage), lastExceptionState.LastException);
        }
Exemplo n.º 2
0
 public Category(string name, string displayName, string shortDisplayName, ExceptionState state)
 {
     Name             = name;
     DisplayName      = displayName;
     ShortDisplayName = shortDisplayName;
     State            = state;
 }
Exemplo n.º 3
0
        public ToolboxException(ExceptionState state, params object[] arguments)
        {
            var converter = new EnumToResouceConverter();

            Arguments        = arguments;
            _friendlyMessage = string.Format((string)converter.Convert(state, typeof(string), null, CultureInfo.CurrentUICulture), Arguments);
        }
Exemplo n.º 4
0
 public void UpdateExceptionInfo(Exception clrException, object type, object value, List <DynamicStackFrame> traceback)
 {
     lock (this) {
         _exceptionState = new ExceptionState(clrException, type, value, traceback);
         _setValues      = _removedValues = 0;
     }
 }
Exemplo n.º 5
0
        private bool TryGetExcValue(ExceptionState exState, string strKey, out object value)
        {
            switch (strKey)
            {
            case "exc_type":
                lock (this) {
                    if ((_removedValues & ExceptionStateFlags.Type) == 0)
                    {
                        if ((_setValues & ExceptionStateFlags.Type) != 0)
                        {
                            value = _excType;
                        }
                        else
                        {
                            value = exState.Type;
                        }
                        return(true);
                    }
                }
                break;

            case "exc_value":
                lock (this) {
                    if ((_removedValues & ExceptionStateFlags.Value) == 0)
                    {
                        if ((_setValues & ExceptionStateFlags.Value) != 0)
                        {
                            value = _excValue;
                        }
                        else
                        {
                            value = exState.Value;
                        }
                        return(true);
                    }
                }
                break;

            case "exc_traceback":
                lock (this) {
                    if ((_removedValues & ExceptionStateFlags.Traceback) == 0)
                    {
                        if ((_setValues & ExceptionStateFlags.Traceback) != 0)
                        {
                            value = _excTraceback;
                        }
                        else
                        {
                            _excTraceback = CreateTraceBack(exState);
                            _setValues   |= ExceptionStateFlags.Traceback;
                            value         = _excTraceback;
                        }
                        return(true);
                    }
                }
                break;
            }
            value = null;
            return(false);
        }
Exemplo n.º 6
0
 public void UpdateExceptionInfo(object type, object value, object traceback)
 {
     lock (this) {
         _exceptionState = new ExceptionState(null, type, value, null);
         _excTraceback   = traceback;
         _setValues      = ExceptionStateFlags.Traceback;
         _removedValues  = 0;
     }
 }
Exemplo n.º 7
0
 public void ExceptionHandled()
 {
     lock (this) {
         _setValues      = ExceptionStateFlags.Traceback | ExceptionStateFlags.Type | ExceptionStateFlags.Value;
         _removedValues  = 0;
         _exceptionState = null;
         _excTraceback   = _excType = _excValue = null;
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Creates a new ImportException
        /// </summary>
        /// <param name="msg">exception message</param>
        /// <param name="fatal">true if the exception is fatal</param>
        public ImportException(string msg, bool fatal = false)
            : base(msg)
        {
            // Create exception state
            this.state = new ExceptionState(fatal);

            // Add serialization method
            this.SerializeObjectState +=
                (ex, args) => args.AddSerializedState(state);
        }
Exemplo n.º 9
0
 public override void Clear(ref DictionaryStorage storage)
 {
     lock (this) {
         _exceptionState = null;
         _setValues      = 0;
         _removedValues  = 0;
         _excTraceback   = _excType = _excValue = null;
         base.Clear(ref storage);
     }
 }
Exemplo n.º 10
0
 static void AppendFlags(StringBuilder sb, ExceptionState state, ExceptionState flag, string flagName, bool expValue = true)
 {
     if (((state & flag) != 0) != expValue)
     {
         return;
     }
     if (sb.Length > 0)
     {
         sb.Append(", ");
     }
     sb.Append(flagName);
 }
Exemplo n.º 11
0
        /// <summary>
        ///    Intercepts the specified invocation.
        /// </summary>
        /// <param name="invocation">The invocation.</param>
        public virtual void Intercept(IInvocation invocation)
        {
            if (Condition != null && !Condition(invocation))
            {
                invocation.Proceed();
                return;
            }

            try
            {
                if (Before != null)
                {
                    Before(invocation);
                }

                Action <IInvocation> proceed = Proceed ?? (call => call.Proceed());
                proceed(invocation);

                if (After != null)
                {
                    After(invocation);
                }
            }
            catch (Exception error)
            {
                Func <IInvocation, Exception, ExceptionState> errorHandler = OnError
                                                                             ?? ((thisCall, thisBug) => new ExceptionState(thisBug, false));
                ExceptionState state = errorHandler(invocation, error);

                if (state.IsHandled)
                {
                    return;
                }

                if (!ReferenceEquals(error, state.Exception) && state.Exception != null)
                {
                    throw state.Exception;
                }

                throw;
            }
            finally
            {
                if (Finally != null)
                {
                    Finally(invocation);
                }
            }
        }
        public override bool TryGetValue(object key, out object value)
        {
            ExceptionState exState = _exceptionState;

            // check the strKey only if we have some exception info set
            if (exState != null || _setValues != 0)
            {
                if (key is string strKey && TryGetExcValue(exState, strKey, out value))
                {
                    return(true);
                }
            }

            return(base.TryGetValue(key, out value));
        }
 private void UpdateExceptionState()
 {
     if (exceptionList.Count > 0)
     {
         foreach (ExceptionState exceptionState in exceptionList)
         {
             //Debug.Log("exceptionState " + exceptionState.name + " - " + exceptionState.state);
             SetBool(exceptionState.name, exceptionState.state);
         }
     }
     while (exceptionOnceQueue.Count > 0)
     {
         ExceptionState exceptionState = exceptionOnceQueue.Dequeue();
         SetBool(exceptionState.name, exceptionState.state);
     }
 }
Exemplo n.º 14
0
        internal void EndExceptionBlock()
        {
            _ilg.EndExceptionBlock();

            ExceptionState state = _exceptionState.Pop();

            if (state == ExceptionState.Catch)
            {
                AdvanceOffsetWithLabel(OpCodes.Leave);
            }
            else if (state == ExceptionState.Finally || state == ExceptionState.Fault)
            {
                AdvanceOffset(OpCodes.Endfinally);
            }

            AssertOffsetMatches();
        }
Exemplo n.º 15
0
        internal void BeginFinallyBlock()
        {
            _ilg.BeginFinallyBlock();

            ExceptionState state = _exceptionState.Pop();

            if (state != ExceptionState.Try)
            {
                // leave for any preceeding catch clause
                AdvanceOffsetWithLabel(OpCodes.Leave);
            }

            // leave for try clause
            AdvanceOffsetWithLabel(OpCodes.Leave);
            _exceptionState.Push(ExceptionState.Finally);

            AssertOffsetMatches();
        }
Exemplo n.º 16
0
        internal static StreamChatException FromResponse(RestResponse response)
        {
            ExceptionState state = null;

            if (!string.IsNullOrWhiteSpace(response.Content))
            {
                state = JsonConvert.DeserializeObject <ExceptionState>(response.Content);
                state.HttpStatusCode = (int)response.StatusCode;
            }
            if (state == null)
            {
                state = new ExceptionState()
                {
                    Code = null, Message = response.ErrorMessage, HttpStatusCode = (int)response.StatusCode
                };
            }
            throw new StreamChatException(state);
        }
Exemplo n.º 17
0
        internal void BeginCatchBlock(Type exceptionType)
        {
            _ilg.BeginCatchBlock(exceptionType);

            ExceptionState state = _exceptionState.Pop();

            if (state == ExceptionState.Filter)
            {
                AdvanceOffset(OpCodes.Endfilter);
            }
            else
            {
                AdvanceOffsetWithLabel(OpCodes.Leave);
            }

            _exceptionState.Push(ExceptionState.Catch);

            AssertOffsetMatches();
        }
Exemplo n.º 18
0
        public override bool Remove(ref DictionaryStorage storage, object key)
        {
            // check the strKey only if we have some exception info set
            ExceptionState exState = _exceptionState;

            if (exState != null || _setValues != 0)
            {
                string strKey = key as string;
                if (strKey != null)
                {
                    switch (strKey)
                    {
                    case "exc_type":
                        lock (this) {
                            _excType        = null;
                            _setValues     &= ~ExceptionStateFlags.Type;
                            _removedValues |= ExceptionStateFlags.Type;
                        }
                        break;

                    case "exc_value":
                        lock (this) {
                            _excValue       = null;
                            _setValues     &= ~ExceptionStateFlags.Value;
                            _removedValues |= ExceptionStateFlags.Value;
                        }
                        break;

                    case "exc_traceback":
                        lock (this) {
                            _excTraceback   = null;
                            _setValues     &= ~ExceptionStateFlags.Traceback;
                            _removedValues |= ExceptionStateFlags.Traceback;
                        }
                        break;
                    }
                }
            }

            return(base.Remove(ref storage, key));
        }
Exemplo n.º 19
0
        internal static StreamException FromResponse(RestResponse response)
        {
            //If we get an error response from getstream.io with the following structure then use it to populate the exception details,
            //otherwise fill in the properties from the response, the most likely case being when we get a timeout.
            //{"code": 6, "detail": "The following feeds are not configured: 'secret'", "duration": "4ms", "exception": "FeedConfigException", "status_code": 400}

            ExceptionState state = null;

            if (!string.IsNullOrWhiteSpace(response.Content))
            {
                state = JsonConvert.DeserializeObject <ExceptionState>(response.Content);
            }
            if (state == null)
            {
                state = new ExceptionState()
                {
                    Code = null, Detail = response.ErrorMessage, @Exception = response.ErrorException.ToString(), HttpStatusCode = (int)response.StatusCode
                };
            }
            throw new StreamException(state);
        }
        // Token: 0x0600011E RID: 286 RVA: 0x00005460 File Offset: 0x00003660
        public int SetException(EXCEPTION_INFO[] pException)
        {
            if (pException[0].guidType != Guids.guidLanguageCSharp)
            {
                return(1);
            }
            ExceptionState exceptionState = ExceptionState.None;

            if ((pException[0].dwState & enum_EXCEPTION_STATE.EXCEPTION_STOP_FIRST_CHANCE) != 0 || (pException[0].dwState & enum_EXCEPTION_STATE.EXCEPTION_STOP_USER_FIRST_CHANCE) != 0)
            {
                exceptionState |= ExceptionState.StopWhenThrown;
            }
            if ((pException[0].dwState & enum_EXCEPTION_STATE.EXCEPTION_STOP_SECOND_CHANCE) != 0 || (pException[0].dwState & enum_EXCEPTION_STATE.EXCEPTION_STOP_USER_UNCAUGHT) != 0)
            {
                exceptionState |= ExceptionState.StopIfUnhandled;
            }
            ExceptionInfo exception = new ExceptionInfo(pException[0].bstrExceptionName, exceptionState);

            this.SetException(exception);
            return(0);
        }
Exemplo n.º 21
0
		public EXCEPTION_INFO(string name, uint code, ExceptionState state) {
			this.Name = name;
			this.Code = code;
			this.State = state;
		}
Exemplo n.º 22
0
 public ExceptionInfo(string name, int code, ExceptionState state)
 {
     Name  = name;
     Code  = code;
     State = state;
 }
Exemplo n.º 23
0
 internal StreamException(ExceptionState state)
     : base(message: state.Detail)
 {
 }
Exemplo n.º 24
0
 public ToolboxException(ExceptionState state, params string[] arguments)
 {
     var converter = new EnumToResouceConverter();
     Arguments = arguments;
     _friendlyMessage = string.Format((string)converter.Convert(state, typeof(string), null, CultureInfo.CurrentUICulture), Arguments);
 }
Exemplo n.º 25
0
 internal StreamException(ExceptionState state)
     : base(message: state.Detail)
 {
 }
 public void UpdateExceptionInfo(Exception clrException, object type, object value, List<DynamicStackFrame> traceback) {
     lock (this) {
         _exceptionState = new ExceptionState(clrException, type, value, traceback);
         _setValues = _removedValues = 0;
     }
 }
Exemplo n.º 27
0
 // Token: 0x0600012F RID: 303 RVA: 0x00005679 File Offset: 0x00003879
 public ExceptionInfo(string name, ExceptionState state)
 {
     this.Name  = name;
     this.State = state;
 }
 public void UpdateExceptionInfo(object type, object value, object traceback) {
     lock (this) {
         _exceptionState = new ExceptionState(null, type, value, null);
         _excTraceback = traceback;
         _setValues = ExceptionStateFlags.Traceback;
         _removedValues = 0;
     }
 }
 private bool TryGetExcValue(ExceptionState exState, string strKey, out object value) {
     switch (strKey) {
         case "exc_type":
             lock (this) {
                 if ((_removedValues & ExceptionStateFlags.Type) == 0) {
                     if ((_setValues & ExceptionStateFlags.Type) != 0) {
                         value = _excType;
                     } else {
                         value = exState.Type;
                     }
                     return true;
                 }
             }
             break;
         case "exc_value":
             lock (this) {
                 if ((_removedValues & ExceptionStateFlags.Value) == 0) {
                     if ((_setValues & ExceptionStateFlags.Value) != 0) {
                         value = _excValue;
                     } else {
                         value = exState.Value;
                     }
                     return true;
                 }
             }
             break;
         case "exc_traceback":
             lock (this) {
                 if ((_removedValues & ExceptionStateFlags.Traceback) == 0) {
                     if ((_setValues & ExceptionStateFlags.Traceback) != 0) {
                         value = _excTraceback;
                     } else {
                         _excTraceback = CreateTraceBack(exState);
                         _setValues |= ExceptionStateFlags.Traceback;
                         value = _excTraceback;
                     }
                     return true;
                 }
             }
             break;
     }
     value = null;
     return false;
 }
Exemplo n.º 30
0
 private static object CreateTraceBack(ExceptionState list)
 {
     return(PythonOps.CreateTraceBack(list.ClrException, list.Traceback, null, list.FrameCount));
 }
 private static object CreateTraceBack(ExceptionState list) {
     return PythonOps.CreateTraceBack(list.ClrException, list.Traceback, list.FrameCount);
 }
 public void ExceptionHandled() {
     lock (this) {
         _setValues = ExceptionStateFlags.Traceback | ExceptionStateFlags.Type | ExceptionStateFlags.Value;
         _removedValues = 0;
         _exceptionState = null;
         _excTraceback = _excType = _excValue = null;
     }
 }
Exemplo n.º 33
0
		public EXCEPTION_INFO(string name, uint code, ExceptionState state) {
			Name = name;
			Code = code;
			State = state;
		}
Exemplo n.º 34
0
 public static async Task UntilAsync(Func<CancellationToken, Task<bool>> taskFactory, CancellationToken token, TimeSpan sleepDuration, TimeSpan timeOut, string exceptionMessage = null, params object[] items)
 {
     ExceptionState state = new ExceptionState();
     await UntilAsync(taskFactory, token, state, sleepDuration, timeOut, exceptionMessage, items);
     if (state.LastException != null)
     {
         throw new TimeoutException(string.Format("{0} Timed out after {1} seconds. Last exception: {2}", String.Format(exceptionMessage, items), timeOut.TotalSeconds, state.LastException.Message), state.LastException);
     }
 }
Exemplo n.º 35
0
 internal StreamChatException(ExceptionState state)
     : base(message: state.Message)
 {
     this.Code = state.Code;
 }
 public override void Clear(ref DictionaryStorage storage) {
     lock (this) {
         _exceptionState = null;
         _setValues = 0;
         _removedValues = 0;
         _excTraceback = _excType = _excValue = null;
         base.Clear(ref storage);
     }
 }
Exemplo n.º 37
0
        private static async Task UntilAsync(Func<CancellationToken, Task<bool>> taskFactory, CancellationToken token, ExceptionState lastExceptionState, TimeSpan sleepDuration, TimeSpan timeOut, string exceptionMessage, params object[] items)
        {
            while (!token.IsCancellationRequested)
            {
                try
                {
                    using (Task<bool> task = taskFactory(token))
                    {
                        bool result = await task;
                        if (result)
                        {
                            return;
                        }
                    }
                }
                catch (Exception e)
                {
                    lastExceptionState.LastException = e;
                }

                if (sleepDuration != TimeSpan.Zero)
                {
                    await Task.Delay(sleepDuration, token);
                }
            }
        }
Exemplo n.º 38
0
 internal StreamChatException(ExceptionState state)
     : base(message: state.Message)
 {
 }