public ActionResult Login(int?id) { var DefaultLoginModel = new LoginModel() { ImageEditorID = Guid.NewGuid().ToString() }; if (!id.HasValue) { return(View(DefaultLoginModel)); } else { string Code = id.Value.ToString("0000"); EEContext db = new EEContext(); var empresa = db.Empresas.Where(e => e.Codigo == Code).FirstOrDefault(); if (empresa != null) { var viewModel = new LoginModel() { HaveEmpresa = true, DisplayLoginCaption = empresa.Nombre, EmpresaLogoURL = string.IsNullOrEmpty(empresa.LogoUrl) ? "/Images/i2e.png" : empresa.LogoUrl, ImageEditorID = Guid.NewGuid().ToString() }; return(View(viewModel)); } else { return(View(DefaultLoginModel)); } } }
public ConversationInfo Answer(string userId, string userInput) { EEContext context = luHandler.Understand(userId, userInput); string answer = "No Response"; switch (context.intent) { case "DoExam": answer = examController.HandleMessage(userId, userInput, ref context); break; case "IntelligenceRoute": answer = irController.HandleMessage(userId, userInput, ref context); break; default: answer = qaController.HandleMessage(userId, userInput, ref context); break; } if (context.stage != StageType.InProcess) { luHandler.Refresh(userId, context); } ConversationInfo result = new ConversationInfo(); result.answer = answer; result.context = context; return(result); }
public string HandleMessage(string userId, string userInput, ref EEContext eContext) { QAContext context = (QAContext)eContext; string answer = this.mapper.GetResponse(userId, userInput, context); return(answer); }
object IMultiplicable.Multiply(object right) { var r = EEContext.ConvertVal<int>(right); var sb = new StringBuilder(); for(int i = 1; i <= r; i++) { sb.Append(this); } return new StringValue(sb.ToString()); }
public void Refresh(string userId, EEContext context) { if (context.stage == StageType.Completed || context.stage == StageType.Paused) { cStore.RemoveContext(userId); } else { cStore.SetContext(userId, context); } }
private bool IsValid(EEContext context) { DateTime currentTime = DateTime.Now; if (currentTime.Subtract(context.timestamp).Hours >= 8) { log.Info("[Warn]: EEContext is invalid."); return(false); } else { return(true); } }
public EEContext Understand(string userId, string userInput) { EEContext context = cStore.GetContext(userId); if ((context == null) || (!IsValid(context))) { log.Info("No valid EEContxt exists. Create new EEContext."); LUInfo luinfo = this.Parse(userInput); context = CreateContext(userId, luinfo); cStore.SetContext(userId, context); } else { log.Info("EEContxt exists. \r\n" + JsonConvert.SerializeObject(context)); MergeContext(userId, userInput, ref context); cStore.SetContext(userId, context); } return(context); }
private void MergeContext(string userId, string userInput, ref EEContext context) { if (context.intent == "DoExam") { return; } else if (context.intent == "IntelligenceRoute") { return; } else { LUInfo luinfo = this.Parse(userInput); context.intent = luinfo.Intent.intent; if (luinfo.EntityList != null && luinfo.EntityList.Count > 0) { ((QAContext)context).entities = luinfo.EntityList; } if (context.intent == "DoExam") { ExamContext savedContext = examCStore.GetContext(userId); if (savedContext != null && IsValid(savedContext)) { context = savedContext; } } else if (context.intent == "IntelligenceRoute") { IRContext savedContext = irCStore.GetContext(userId); if (savedContext != null && IsValid(savedContext)) { context = savedContext; } } } }
public string HandleMessage(string userId, string userInput, ref EEContext eContext) { if (eContext.GetType() != typeof(ExamContext)) { eContext = new ExamContext(userId); } ExamContext context = (ExamContext)eContext; ExamProcessor processor = new ExamProcessor(); string respStr = null; ExamSelectionInfo sInfo = sStore.GetSelectionInfo(); Dictionary <string, ExamOption> selectionOptionMap = sStore.GetSelectionMap(); ExamInfo info = null; switch (context.stage) { case StageType.Init: respStr = sInfo.optionMessage + "\r\n"; foreach (string key in selectionOptionMap.Keys) { respStr += "(" + key + ")" + selectionOptionMap[key].courseName + " "; } context.stage = StageType.Start; break; case StageType.Start: bool isMatched = Utils.Utils.IsRegexMatched(sInfo.optionRegex, userInput); if (isMatched) { if (selectionOptionMap.ContainsKey(userInput)) { ExamOption option = selectionOptionMap[userInput]; ExamPreProcessor preProcessor = new ExamPreProcessor(); info = preProcessor.GenerateProcessItems(option); eStore.SetExamInfo(userId, info); respStr = info.courseName + "\r\n" + (string.IsNullOrWhiteSpace(info.description)?"":(info.description + "\r\n")) + info.items[context.processContext.index].question; context.stage = StageType.InProcess; } else { throw new Exception("Option " + userInput + " is not available."); } } else { respStr = sInfo.askbackMessage + "\r\n" + sInfo.optionMessage; context.selectContext.askbackTime++; } break; case StageType.InProcess: info = eStore.GetExamInfo(userId); respStr = processor.ProcessItem(userId, userInput, ref context, ref info); break; case StageType.Paused: info = eStore.GetExamInfo(userId); respStr = info.restartMessage; context.stage = StageType.Restarted; break; case StageType.Restarted: info = eStore.GetExamInfo(userId); if (userInput.Trim().ToLower() != "y") { context.processContext = new ExamProcessContext(); } respStr = processor.ProcessItem(userId, userInput, ref context, ref info); context.stage = StageType.InProcess; break; } if (context.stage == StageType.Completed) { cStore.RemoveContext(userId); eStore.RemoveExamInfo(userId); } else { if (context.stage == StageType.Paused) { context.processContext.askbackTime = 0; } cStore.SetContext(userId, context); } return(respStr); }