void close() { lock (This_) { BotCycle.Abort(); if (This.items_xtw != null) { This.items_xtw.WriteEndElement(); This.items_xtw.WriteEndDocument(); This.items_xtw.Close(); } if (This.input_item_queue_name2input_item_queues.Count > 0) { if (This.IsUnprocessedInputItem) { This.set_session_state(SessionState.ABORTED); } else if (This.IsItem2Restore) { This.set_session_state(SessionState.UNCOMPLETED); } else { This.set_session_state(SessionState.COMPLETED); } } This.workflow_xtw.WriteEndElement(); This.workflow_xtw.WriteEndDocument(); This.workflow_xtw.Close(); try { CustomizationApi.SessionClosing(); } catch (Exception e) { LogMessage.Error(e); } try { if (Closing != null) { Closing.Invoke(); } } catch (Exception e) { LogMessage.Error(e); } InputItemQueue.Close(); FileWriter.ClearSession(); Cache.ClearSession(); Proxies.ClearSession(); WebRoutine.ClearSession(); Log.Main.Write("Closing session."); Cliver.Log.ClearSession(); This_ = null; } }
void close() { lock (This_) { try { Log.Main.Write("Closing the bot session: " + Session.State.ToString()); BotCycle.Abort(); if (This.IsUnprocessedInputItem) { State = SessionState.BROKEN; } else if (This.IsItem2Restore) { State = SessionState.UNCOMPLETED; } else { State = SessionState.COMPLETED; } This.Storage.WriteState(State, new { }); try { __Closing(); } catch (Exception e) { Session.State = SessionState.FATAL_ERROR; This.Storage.WriteState(State, new { }); LogMessage.Error(e); __ErrorClosing(e.Message); } try { Closing?.Invoke(); } catch (Exception e) { Session.State = SessionState.FATAL_ERROR; This.Storage.WriteState(State, new { }); LogMessage.Error(e); __ErrorClosing(e.Message); } InputItemQueue.Close(); FileWriter.ClearSession(); } catch (ThreadAbortException) { } catch (Exception e) { Session.State = SessionState.FATAL_ERROR; This.Storage.WriteState(State, new { }); LogMessage.Error(e); __ErrorClosing(e.Message); } finally { Storage.Close(); switch (State) { case SessionState.NULL: case SessionState.STARTING: case SessionState.COMPLETED: case SessionState.FATAL_ERROR: Directory.Move(Dir, Dir + "_" + TimeMark + "_" + State); break; case SessionState.RESTORING: case SessionState.RUNNING: case SessionState.CLOSING: case SessionState.UNCOMPLETED: case SessionState.BROKEN: case SessionState.NONFATAL_ERROR: break; default: throw new Exception("Unknown option: " + State); } This_ = null; Cliver.Log.Head.Close(false); } } try { Closed?.Invoke(); } catch (Exception e) { LogMessage.Error(e); __ErrorClosing(e.Message); } }