protected Session() { This_ = this; State = SessionState.STARTING; Log.Main.Inform("Loading configuration from " + Config.DefaultStorageDir); Config.Reload(Config.DefaultStorageDir); ConfigurationDir = Dir + "\\" + Config.CONFIG_FOLDER_NAME; Restored = false; Storage = new SessionStorage(); DateTime old_start_time; string old_time_mark; SessionState old_state = Storage.ReadLastState(out old_start_time, out old_time_mark); switch (old_state) { case SessionState.NULL: break; case SessionState.STARTING: case SessionState.COMPLETED: case SessionState.FatalError: break; case SessionState.RESTORING: case SessionState.RUNNING: case SessionState.CLOSING: case SessionState.UNCOMPLETED: case SessionState.BROKEN: if (Settings.Engine.RestoreBrokenSession && !ProgramRoutines.IsParameterSet(CommandLineParameters.NOT_RESTORE_SESSION)) { if (LogMessage.AskYesNo("Previous session " + old_time_mark + " is not completed. Restore it?", true)) { StartTime = old_start_time; TimeMark = old_time_mark; Storage.WriteState(SessionState.RESTORING, new { restoring_time = RestoreTime, restoring_session_time_mark = get_time_mark(RestoreTime) }); Log.Main.Inform("Loading configuration from " + ConfigurationDir); Config.Reload(ConfigurationDir); Storage.RestoreSession(); Restored = true; } } break; default: throw new Exception("Unknown option: " + old_state); } if (!Restored) { if (old_state != SessionState.NULL) { string old_dir_new_path = Log.WorkDir + "\\Data" + "_" + old_time_mark + "_" + old_state; Log.Main.Write("The old session folder moved to " + old_dir_new_path); Storage.Close(); if(Directory.Exists(Dir)) Directory.Move(Dir, old_dir_new_path); PathRoutines.CreateDirectory(Dir); Storage = new SessionStorage(); } StartTime = Log.MainSession.CreatedTime;// DateTime.Now; TimeMark = get_time_mark(StartTime); Storage.WriteState(SessionState.STARTING, new { session_start_time = StartTime, session_time_mark = TimeMark }); read_input_file(); Config.CopyFiles(Dir); } Creating?.Invoke(); __Creating(); }
protected Session() { This_ = this; State = SessionState.STARTING; Config.Reload(); Dir = FileSystemRoutines.CreateDirectory(Log.RootDir + "\\Data"); Directory.SetLastWriteTime(Dir, DateTime.Now);//to avoid cleaning up ConfigFile = Dir + "\\" + ConfigFileName; Restored = false; Storage = new SessionStorage(); DateTime old_start_time; string old_time_mark; SessionState old_state = Storage.ReadLastState(out old_start_time, out old_time_mark); switch (old_state) { case SessionState.NULL: break; case SessionState.STARTING: case SessionState.COMPLETED: case SessionState.FATAL_ERROR: break; case SessionState.RESTORING: case SessionState.RUNNING: case SessionState.CLOSING: case SessionState.UNCOMPLETED: case SessionState.BROKEN: case SessionState.NONFATAL_ERROR: if (Settings.Engine.RestoreBrokenSession && !CommandLine.IsParameterSet(CommandLineParameters.NOT_RESTORE_SESSION)) { if (LogMessage.AskYesNo("Previous session " + old_time_mark + " is not completed. Restore it?", true)) { StartTime = old_start_time; TimeMark = old_time_mark; Storage.WriteState(SessionState.RESTORING, new { restoring_time = RestoreTime, restoring_session_time_mark = get_time_mark(RestoreTime) }); Log.Main.Inform("Loading configuration from " + ConfigFile); Config.Reload(ConfigFile); Storage.RestoreSession(); Restored = true; } } break; default: throw new Exception("Unknown option: " + old_state); } if (!Restored) { if (old_state != SessionState.NULL) { string old_dir_new_path = Log.RootDir + "\\Data" + "_" + old_time_mark + "_" + old_state; Log.Main.Write("The old session folder moved to " + old_dir_new_path); Storage.Close(); if (Directory.Exists(Dir)) { Directory.Move(Dir, old_dir_new_path); } FileSystemRoutines.CreateDirectory(Dir); Storage = new SessionStorage(); } StartTime = Log.Head.CreatedTime;// DateTime.Now; TimeMark = get_time_mark(StartTime); Storage.WriteState(SessionState.STARTING, new { session_start_time = StartTime, session_time_mark = TimeMark }); read_input_file(); Config.Save(ConfigFile); } Creating?.Invoke(); __Creating(); }