/// <summary> /// /// </summary> /// <param name="input"></param> /// <returns></returns> public override bool Parse(string input) { var lexers = input.Split(new[] { " is " }, StringSplitOptions.RemoveEmptyEntries); if (lexers.Count() != 2) { return(false); } var left = lexers[0].Split(' '); if (left.Length < 2) { return(false); } var rValue = int.Parse(lexers[1].Split(' ')[0]); var primUnit = lexers[1].Split(' ')[1]; this.Context.PrimUnit = primUnit; var roman = RepeatChecker.Check(string.Join(" ", left.Take(left.Length - 1)), this.Context.Primitives); var calculated = roman.Calculate(); var unit = left.Last(); var unitValue = (double)rValue / (double)calculated; this.Context.Units[unit] = unitValue; return(true); }
/// <summary> /// 释放资源 /// </summary> public void Dispose() { if (!_repeatStopChecker.Check()) { return; } //开始stop _scheduleTaskLifetime.Stop(); //开始stop 具体需要stop的 //stop结束通知 _scheduleTaskLifetime.NotifyStopped(); }
/// <summary> /// /// </summary> /// <param name="question"></param> /// <param name="answer"></param> /// <returns></returns> public override bool Solve(string question, out string answer) { var qulifier = "how much is"; if (!question.StartsWith(qulifier)) { answer = null; return(false); } var body = question.Substring(qulifier.Length + 1); var value = RepeatChecker.Check(body, this.Context.Primitives).Calculate(); answer = value.ToString(); Console.WriteLine(body + " is " + answer); return(true); }
/// <summary> /// /// </summary> /// <param name="question"></param> /// <param name="answer"></param> /// <returns></returns> public override bool Solve(string question, out string answer) { var primUnit = this.Context.PrimUnit; var qulifier = string.Format("how many {0} is", primUnit); if (!question.StartsWith(qulifier)) { answer = null; return(false); } var body = question.Substring(qulifier.Length + 1); var lexers = body.Split(' '); var unit = lexers.Last().Trim(); var unitValue = this.Context.Units[unit]; var value = RepeatChecker.Check(string.Join(" ", lexers.Take(lexers.Length - 1)), this.Context.Primitives).Calculate(); answer = (value * unitValue) + " " + primUnit; Console.WriteLine(body + " is " + answer); return(true); }
/// <summary> /// 开始 /// </summary> /// <returns></returns> public Task Start() { if (!_repeatStartChecker.Check()) { return(Task.CompletedTask); } Task.Factory.StartNew(async() => { try { await Init(); await _expireLogExecutor.Start(); await _errorTaskExecutor.Start(); await StartProcessTask(); } catch (Exception ex) { _logger.LogError(ex, "Aix.ScheduleTask定时任务启动出错"); } }, TaskCreationOptions.LongRunning); _scheduleTaskLifetime.NotifyStarted(); return(Task.CompletedTask); }