Example #1
0
        private void buttonReset_Click(object sender, RoutedEventArgs e)
        {
            try {
                if (connection.TestWCF())
                {
                    new SystemMessage(null, "WCF test", "WCF connection test passed",
                                      MemeType.FuckYea).ShowDialog();
                }
                else
                {
                    throw new Exception("test returned false");
                }
            } catch (Exception ex) {
                var ae = new ActionException("WCF test failed", ActionType.User, null, ex);
                new SystemMessage(ae).ShowDialog();
            }

            try {
                if (connection.TestEF())
                {
                    new SystemMessage(null, "EF test", "Enitity Framework connection test passed",
                                      MemeType.FuckYea).ShowDialog();
                }
                else
                {
                    throw new Exception("test returned false");
                }
            } catch (Exception ex) {
                var ae = new ActionException("EF test failed", ActionType.User, null, ex);
                new SystemMessage(ae).ShowDialog();
            }
        }
Example #2
0
 public SystemMessage(ActionException ex, bool toggleOk = true, bool toggleCancel = false,
                      bool toggleHelp = false)
     : this("FileSync: System message", ex.Title, ex.Message, ex.Image, toggleOk,
            toggleCancel, toggleHelp)
 {
     //nothing needed here
 }
Example #3
0
        public override void Report(Core.Actions.ActionBase action, Exception ex)
        {
            ActionException aex = CreateActionException(action, ex);

            ServerApiInvoker.ExceptionReport(aex.ScriptId, aex.ActionId
                                             , aex.Message, aex.ActionIndex.ToString(), aex.ActionType, action.Title);
        }
Example #4
0
 /// <summary>
 /// Creates new result of some acition.
 /// </summary>
 /// <param name="actionTitle"></param>
 /// <param name="actionDescription"></param>
 /// <param name="actionType">type of the action, value from ActionType enum</param>
 /// <param name="wasSuccessful">indicates whether the action completed successfully</param>
 /// <param name="resultContext"></param>
 /// <param name="errorContext"></param>
 public ActionResult(string actionTitle, string actionDescription, ActionType actionType,
                     bool wasSuccessful           = true, ActionResult resultContext = null,
                     ActionException errorContext = null)
 {
     title   = actionTitle;
     desc    = actionDescription;
     type    = actionType;
     success = wasSuccessful;
     context = resultContext;
 }
Example #5
0
        public void DisplayActionException(ActionException ex)
        {
            io.Error.Write("Exception: {0}", ex.GetType());
            io.Error.Write("Message: {0}", ex.Message);
            io.Error.Write("-----------------------------");
            io.Error.Write(ex.ToString());
            io.Error.Write("-----------------------------");

            if (ex.InnerException != null)
            {
                io.Error.Write("Inner Exception: {0}", ex.InnerException.GetType());
                io.Error.Write("Inner Message: {0}", ex.InnerException.Message);
            }
            io.Error.Write("-----------------------------");
            io.Error.Write("FinTS Trace:");
        }
Example #6
0
        protected ActionResult Error(ActionException exception)
        {
            if (exception.InnerExceptions.Any())
            {
                var sb = new StringBuilder(TaskStrings.ProductsNotProcessed);

                foreach (var ex in exception.InnerExceptions.OfType <ProductException>())
                {
                    sb.AppendLine();

                    var exText   = ex.Message;
                    var rm       = new ResourceManager(typeof(TaskStrings));
                    var result   = ActionTaskResult.FromString(exText);
                    var resource = rm.GetString(exText);
                    if (result != null)
                    {
                        exText = result.ToString();
                    }
                    else if (resource != null && resource.Contains("{0}"))
                    {
                        exText = string.Format(resource, ex.ProductId);
                    }
                    else
                    {
                        exText = $"{ex.ProductId}: {exText}";
                        if (ex.InnerException != null)
                        {
                            exText += ". " + ex.InnerException.Message;
                        }
                    }

                    sb.AppendFormat(exText);
                }

                return(Error(sb.ToString()));
            }
            else
            {
                return(Error(exception.Message));
            }
        }
Example #7
0
        /// <summary>
        /// Runs until no runnable tasklets left.
        /// This function is reentrant.
        /// </summary>
        public void Run()
        {
            int managedThreadId = Thread.CurrentThread.ManagedThreadId;

            MicroThreadCallbackList callbacks = default(MicroThreadCallbackList);

            while (true)
            {
                SchedulerEntry schedulerEntry;
                MicroThread    microThread;
                lock (ScheduledEntries)
                {
                    // Reclaim callbacks of previous microthread
                    MicroThreadCallbackNode callback;
                    while (callbacks.TakeFirst(out callback))
                    {
                        callback.Clear();
                        CallbackNodePool.Add(callback);
                    }

                    if (ScheduledEntries.Count == 0)
                    {
                        break;
                    }
                    schedulerEntry = ScheduledEntries.Dequeue();
                    microThread    = schedulerEntry.MicroThread;
                    if (microThread != null)
                    {
                        callbacks             = microThread.Callbacks;
                        microThread.Callbacks = default(MicroThreadCallbackList);
                    }
                }

                // Since it can be reentrant, it should be restored after running the callback.
                var previousRunningMicrothread = runningMicroThread.Value;
                if (previousRunningMicrothread != null)
                {
                    MicroThreadCallbackEnd?.Invoke(this, new SchedulerThreadEventArgs(previousRunningMicrothread, managedThreadId));
                }

                runningMicroThread.Value = microThread;

                if (microThread != null)
                {
                    var previousSyncContext = SynchronizationContext.Current;
                    SynchronizationContext.SetSynchronizationContext(microThread.SynchronizationContext);

                    // TODO: Do we still need to try/catch here? Everything should be caught in the continuation wrapper and put into MicroThread.Exception
                    try
                    {
                        if (microThread.State == MicroThreadState.Starting)
                        {
                            MicroThreadStarted?.Invoke(this, new SchedulerThreadEventArgs(microThread, managedThreadId));
                        }

                        MicroThreadCallbackStart?.Invoke(this, new SchedulerThreadEventArgs(microThread, managedThreadId));

                        var profilingKey = microThread.ProfilingKey ?? schedulerEntry.ProfilingKey ?? MicroThreadProfilingKeys.ProfilingKey;
                        using (Profiler.Begin(profilingKey))
                        {
                            var callback = callbacks.First;
                            while (callback != null)
                            {
                                callback.Invoke();
                                callback = callback.Next;
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Log.Error("Unexpected exception while executing a micro-thread", e);
                        microThread.SetException(e);
                    }
                    finally
                    {
                        MicroThreadCallbackEnd?.Invoke(this, new SchedulerThreadEventArgs(microThread, managedThreadId));

                        SynchronizationContext.SetSynchronizationContext(previousSyncContext);
                        if (microThread.IsOver)
                        {
                            lock (microThread.AllLinkedListNode)
                            {
                                if (microThread.CompletionTask != null)
                                {
                                    if (microThread.State == MicroThreadState.Failed || microThread.State == MicroThreadState.Canceled)
                                    {
                                        microThread.CompletionTask.TrySetException(microThread.Exception);
                                    }
                                    else
                                    {
                                        microThread.CompletionTask.TrySetResult(1);
                                    }
                                }
                                else if (microThread.State == MicroThreadState.Failed && microThread.Exception != null)
                                {
                                    // Nothing was listening on the micro thread and it crashed
                                    // Let's treat it as unhandled exception and propagate it
                                    // Use ExceptionDispatchInfo.Capture to not overwrite callstack
                                    if (PropagateExceptions && (microThread.Flags & MicroThreadFlags.IgnoreExceptions) != MicroThreadFlags.IgnoreExceptions)
                                    {
                                        ExceptionDispatchInfo.Capture(microThread.Exception).Throw();
                                    }
                                }

                                MicroThreadEnded?.Invoke(this, new SchedulerThreadEventArgs(microThread, managedThreadId));
                            }
                        }

                        runningMicroThread.Value = previousRunningMicrothread;
                        if (previousRunningMicrothread != null)
                        {
                            MicroThreadCallbackStart?.Invoke(this, new SchedulerThreadEventArgs(previousRunningMicrothread, managedThreadId));
                        }
                    }
                }
                else
                {
                    try
                    {
                        var profilingKey = schedulerEntry.ProfilingKey ?? MicroThreadProfilingKeys.ProfilingKey;
                        using (Profiler.Begin(profilingKey))
                        {
                            schedulerEntry.Action();
                        }
                    }
                    catch (Exception e)
                    {
                        ActionException?.Invoke(this, schedulerEntry, e);
                    }
                }
            }

            while (FrameChannel.Balance < 0)
            {
                FrameChannel.Send(0);
            }
        }
Example #8
0
 /// <summary>
 /// Creates an action result from an action exception.
 /// </summary>
 /// <param name="ex">exception to be converted to the result</param>
 public ActionResult(ActionException ex)
     : this(ex.Title, ex.Message, ex.Type, ex.Image.Equals(MemeType.FuckYea), null, ex)
 {
     //nothing needed here
 }