/// <summary> /// /// </summary> /// <param name="longFormat">Если истина - запишет в лог всю доступную информацию о диалоге.</param> void SaveToLog(TwoChatsHandlerAndAnother dialogAndAnother, string message, bool longFormat) { if (!SaveLog) { return; } string logFile = string.Format("{0}/work_story.log", dialogAndAnother.TwoChatsHandler.UsedFolder); string logText = ""; logText += string.Format("DateTime: {0}", DateTime.Now.ToLongDateString() + " " + DateTime.Now.ToLongTimeString()); logText += string.Format("=n=Dialog number: {0}", dialogAndAnother.TwoChatsHandler.CurrentDialogNumber.ToString()); logText += string.Format("=n=Message: \" {0} \"", message); if (longFormat) { if (dialogAndAnother.TwoChatsHandler.BotScenario != null && dialogAndAnother.TwoChatsHandler.BotScenario.LastException != null) { logText += string.Format("=n=BotScenario exception: \" {0} \"", dialogAndAnother.TwoChatsHandler.BotScenario.LastException.Message); } string exStr = dialogAndAnother.TwoChatsHandler?.LastException?.Message ?? "No exception!"; var ex = dialogAndAnother.TwoChatsHandler.LastException; logText += string.Format("=n=Exception: \" {0} \"", exStr); logText += string.Format("=n=TwoChatsHandler status: {0}", dialogAndAnother.TwoChatsHandler.Status.ToString()); } logText = logText.Replace("\n", "\n ").Replace("=n=", "\n"); logText += string.Format("\n-------\n\n"); File.AppendAllLines(logFile, logText.Split('\n')); }
void OnAfterFinishConversation(TwoChatsHandlerAndAnother dialogAndAnother) { if (carefullyStop) { dialogAndAnother.DoOnNextLoop = CommandToDoWithChat.Remove; } else { dialogAndAnother.DoOnNextLoop = CommandToDoWithChat.Start; } }
void RemoveDialogHandler(TwoChatsHandlerAndAnother dialogAndAnother) { allDialogsList.Remove(dialogAndAnother); FactoryOfChatHandler.OnChatsDisposed( dialogAndAnother.TwoChatsHandler.Chat1, dialogAndAnother.TwoChatsHandler.Chat2, dialogAndAnother.TwoChatsHandler.Status ); dialogAndAnother.TwoChatsHandler.StopCallForwarding(); dialogAndAnother.TwoChatsHandler.Free(); }
TwoChatsHandlerAndAnother AddNewDialogHandler() { TwoChatsHandler dialog = new TwoChatsHandler( ChatsSettings, FactoryOfChatHandler.CreateChat1(ChatsSettings), FactoryOfChatHandler.CreateChat2(ChatsSettings) ); ///////////////////////// TwoChatsHandlerAndAnother newItem = new TwoChatsHandlerAndAnother(dialog); allDialogsList.Add(newItem); newItem.DoOnNextLoop = CommandToDoWithChat.Start; return(newItem); }