Пример #1
0
            internal SessionState ReadLastState(out DateTime start_time, out string session_time_mark)
            {
                start_time        = DateTime.Now;
                session_time_mark = null;
                try
                {
                    if (!startReading())
                    {
                        return(SessionState.NULL);
                    }
                    SessionState state = SessionState.NULL;
                    while (true)
                    {
                        Dictionary <string, object> names2value = readNextElementByTag(SessionTag);
                        if (names2value == null)
                        {
                            return(state);
                        }

                        state = (SessionState)names2value["state"];
                        if (state == SessionState.STARTING)
                        {
                            start_time        = (DateTime)names2value["session_start_time"];
                            session_time_mark = (string)names2value["session_time_mark"];
                        }
                    }
                }
                catch (Exception e)
                {
                    Session.__ErrorClose(e, true);
                    return(SessionState.NULL);
                }
            }
Пример #2
0
        public static void Start()
        {
            try
            {
                if (!Settings.Log.WriteLog)
                {
                    Log.DefaultLevel = Log.Level.NONE;
                }
                Log.Initialize(Log.Mode.FOLDER_PER_SESSION, new List <string> {
                    Settings.Log.PreWorkDir
                }, Settings.Log.DeleteLogsOlderDays);

                Log.Main.Inform("Version compiled: " + Program.GetCustomizationCompiledTime().ToString());
                Log.Main.Inform("Command line parameters: " + string.Join("|", Environment.GetCommandLineArgs()));

                if (This != null)
                {
                    throw new Exception("Previous session was not closed.");
                }
                Activator.Create <Session>(true);
                if (This == null)
                {
                    return;
                }
                BotCycle.Start();
                Session.State = SessionState.RUNNING;
                This.Storage.WriteState(SessionState.RUNNING, new { });
            }
            catch (ThreadAbortException)
            {
                Close();
                throw;
            }
            catch (Exception e)
            {
                Session.__ErrorClose(e, true);
            }
        }
Пример #3
0
 static void max_error_count(int count)
 {
     Session.__ErrorClose("Errors in succession: " + count + "\r\nTerminating the session.", false);
 }
Пример #4
0
        void bot_cycle()
        {
            try
            {
                try
                {
                    Created?.Invoke(Id);

                    __Starting();
                    while (run)
                    {
                        current_item = Session.This.GetNext();
                        if (current_item == null)
                        {
                            return;
                        }
                        InputItemState state = InputItemState.COMPLETED;
                        try
                        {
                            current_item.__Processor(this);
                        }
                        catch (ThreadAbortException)
                        {
                            Thread.ResetAbort();
                            return;
                        }
                        catch (Session.FatalException)
                        {
                            throw;
                        }
                        catch (Exception e)
                        {
                            if (e is TargetInvocationException)
                            {
                                e = e.InnerException;
                                //throw;
                            }
                            if (e is ProcessorException)
                            {
                                switch (((ProcessorException)e).Type)
                                {
                                case ProcessorExceptionType.ERROR:
                                    state = InputItemState.ERROR;
                                    break;

                                //case ProcessorExceptionType.FatalError:
                                case ProcessorExceptionType.RESTORE_AS_NEW:
                                    state = InputItemState.ERROR_RESTORE_AS_NEW;
                                    Session.This.IsItem2Restore = true;
                                    break;

                                case ProcessorExceptionType.COMPLETED:
                                    break;

                                default: throw new Exception("No case for " + ((ProcessorException)e).Type.ToString());
                                }
                            }
                            else
                            {
                                if (TreatExceptionAsFatal)
                                {
                                    throw new Session.FatalException(e);
                                }
                                state = InputItemState.ERROR;
                            }
                            Log.Error(e);
                        }

                        current_item.__State = state;

                        if (state == InputItemState.ERROR || state == InputItemState.ERROR_RESTORE_AS_NEW)
                        {
                            Session.This.ProcessorErrors.Increment();
                        }
                        else
                        {
                            Session.This.ProcessorErrors.Reset();
                        }

                        Start();
                    }
                }
                catch (ThreadAbortException)
                {
                    Thread.ResetAbort();
                }
                //catch (Exception e)
                //{
                //    throw new Session.FatalException(e);
                //}
                finally
                {
                    __Exiting();
                    if (Finishing != null)
                    {
                        Finishing.Invoke(Id);
                    }
                }
            }
            catch (Exception e)
            {
                Session.__ErrorClose(e, true);
            }
            finally
            {
                close_thread(Thread.CurrentThread);
            }
        }