private Task MakeAppointment4User(UserModel userInfo) { var shopInfo = maskDataBase.GetShop(userInfo.ShopID).ConfigureAwait(false).GetAwaiter().GetResult(); var parm = new RequestParm() { pharmacyName = shopInfo.serviceName, pharmcayId = shopInfo.id, pharmacyAddress = shopInfo.serviceAddress, realName = userInfo.Name.RSAEncrypt(), idcard = userInfo.IDCard.RSAEncrypt(), mobile = userInfo.Tel.RSAEncrypt() }; var cts = new CancellationTokenSource(); return(Task.Run(() => { while (DatetimeUtils.GetChinaDatetimeNow().TimeOfDay < endTime) { Enumerable.Range(1, threadNum).Select(p => new Task(() => { if (serviceProvider.GetService <MaskWebClient>().MakeAppointment(parm, out var result)) { cts.Cancel(); } else { } }, cts.Token)); Thread.Sleep(sleepTime); } }, cts.Token)); }
private PSAContext initPSAContext(string userId, LUInfo luinfo) { PSAContext context = new PSAContext(userId); string intent = luinfo.Intent.intent; string coursename = DatetimeUtils.GetCourseName(luinfo); TimeRange range = DatetimeUtils.GetTimeRange(luinfo); context.Intent = intent; context.CourseName = coursename; context.timeRange = range; context.validTime = DateTime.Now; if (context.timeRange == null) { context.timeRange = new TimeRange(); DateTime now = DateTime.Now; context.timeRange.startDate = now; context.timeRange.endDate = now; } return(context); }
public override string GetAnswer(WBContext context, LUInfo luInfo) { string response = DatetimeUtils.GetOutofScopeAnswer(); string location = context.Location; TimeRange range = context.timeRange; List <string> stations = DatetimeUtils.GetEntity(luInfo, "Station"); string station = null; if (stations != null && stations.Count > 0) { station = stations[0]; } if (range == null) { response = client.GetRealTimeAirQuality(location, station); } else if (!range.IsHourly) { response = client.GetPredictedSmogDaily(location, range.startDate, range.endDate); } else { response = client.GetPredictedSmogHourly(location, range.startDate, range.endDate); } return(response); }
private PSAContext updatePSAContext(ref PSAContext context, LUInfo luinfo) { string intent = luinfo.Intent.intent; if (!string.IsNullOrWhiteSpace(intent) && ValidPSAIntents.Contains(intent)) { context.Intent = intent; } string cn = DatetimeUtils.GetCourseName(luinfo); if (!string.IsNullOrWhiteSpace(cn)) { context.CourseName = cn; } TimeRange range = DatetimeUtils.GetTimeRange(luinfo); if (range != null) { context.timeRange = range; } return(context); }
private TaskFlowContext InitTFContext(string userId, TestLUInfo currentLUInfo) { TaskFlowContext tfContext = new TaskFlowContext(userId); tfContext.Intent = currentLUInfo.Intent.intent; tfContext.CourseName = DatetimeUtils.GetCourseName(currentLUInfo); tfContext.currentIndex = 0; return(tfContext); }
public void TestUnixTime() { var dt = DateTime.Now; //unix 时间 var unixTime = DatetimeUtils.GetUnixTime(dt); //c#时间 var csharpTime = DatetimeUtils.GetDTFromUnixTime(unixTime); //Assert.AreEqual(dt,csharpTime); //注意这2个不相等是因为dt还有毫秒数,而unixTime只计算了秒数 Assert.AreEqual(unixTime, DatetimeUtils.GetUnixTime(csharpTime)); }
private string Answer(string userId, string utterance) { string answer = this.bot.Answer(userId, utterance); if (string.IsNullOrWhiteSpace(answer) || answer.Contains(DatetimeUtils.GetOutofScopeAnswer())) { answer = Utils.Utils.GetDefaultAnswer(); } return(answer); }
private void initContext(ref PSAContext context, LUInfo luinfo, string utterance) { string intent = luinfo.Intent.intent; string coursename = DatetimeUtils.GetCourseName(luinfo); TimeRange range = DatetimeUtils.GetTimeRange(luinfo); context.Intent = intent; context.CourseName = coursename; context.timeRange = range; context.validTime = DateTime.Now; }
private TravelReview GetTravelReview(TravelReviewViewModel viewModel) { DateTime datetimeFrom = DatetimeUtils.GetDateTime(viewModel.DatetimeFrom); DateTime datetimeUntil = DatetimeUtils.GetDateTime(viewModel.DatetimeUntil); TravelReview travelReview = new TravelReview(); travelReview.DatetimeFrom = datetimeFrom; travelReview.DatetimeUntil = datetimeUntil; travelReview.TravelFeeling = this.GetReviewTravelFeeling(viewModel); travelReview.ReviewTransport = this.GetReviewTransport(viewModel); return(travelReview); }
public void DoJob(bool isToday) { var users = maskDataBase.GetAllNeedAppointmentUsers().ConfigureAwait(false).GetAwaiter().GetResult(); var appointmentDate = isToday ? DatetimeUtils.GetChinaDatetimeNow() : DatetimeUtils.GetChinaDatetimeNow().AddDays(1); var targetDate = appointmentDate.ToString("yyyy-MM-dd"); Parallel.ForEach(users, user => { if (serviceProvider.GetService <MaskWebClient>().IsSuccessed(user.IDCard, targetDate, out var code)) { user.LastAppointmentDate = targetDate; user.AppointmentCode = code; maskDataBase.AddOrUpdateUser(user).Wait(); } }); }
private bool IsLocationOnly(LUInfo luinfo, string utterance) { string location = DatetimeUtils.GetLocation(luinfo, false); if (string.IsNullOrWhiteSpace(location)) { return(false); } if (location == utterance) { return(true); } else { return(false); } }
public override string GetAnswer(WBContext context, LUInfo luInfo) { string response = DatetimeUtils.GetOutofScopeAnswer(); string location = context.Location; TimeRange range = context.timeRange; if (range == null) { response = client.GetRestrictedNumber(location, null, null); } else { response = client.GetRestrictedNumber(location, range.startDate, range.endDate); } return(response); }
private void initContext(ref WBContext context, LUInfo luinfo, string utterance) { string intent = luinfo.Intent.intent; if ((IsLocationOnly(luinfo, utterance)) || ContainsLocationDateOnly(luinfo, utterance)) { intent = "DefaultIntent"; } string location = DatetimeUtils.GetLocation(luinfo, true); TimeRange range = DatetimeUtils.GetTimeRange(luinfo); context.Intent = intent; context.Location = location; context.timeRange = range; context.validTime = DateTime.Now; }
public override string GetAnswer(WBContext context, LUInfo luInfo) { string response = DatetimeUtils.GetOutofScopeAnswer(); string location = context.Location; TimeRange range = context.timeRange; if (range == null) { response = client.GetRealTimeWeather(location); } else if (!range.IsHourly) { response = client.GetPredictedWeatherDaily(location, range.startDate, range.endDate); } else { response = client.GetPredictedWeatherHourly(location, range.startDate, range.endDate); } return(response + "\r\n"); }
private void updateContext(ref WBContext context, LUInfo luinfo) { string intent = luinfo.Intent.intent; if (!string.IsNullOrWhiteSpace(intent) && ValidIntent.Contains(intent)) { context.Intent = intent; } string location = DatetimeUtils.GetLocation(luinfo, false); if (!string.IsNullOrWhiteSpace(location)) { context.Location = location; } TimeRange range = DatetimeUtils.GetTimeRange(luinfo); if (range != null) { context.timeRange = range; } }
public string Answer(string userId, string utterance) { LUInfo luinfo = this.luController.Understand(utterance); WBContext context = contextStore.GetContext(userId); if (!context.IsValid()) { initContext(ref context, luinfo, utterance); } else { updateContext(ref context, luinfo); } switch (context.Intent) { case "DefaultIntent": this.srvs.Add(new WeatherSrv()); this.srvs.Add(new SmogSrv()); break; case "CarWashing": this.srvs.Add(new CarWashingSrv()); break; case "Weather": this.srvs.Add(new WeatherSrv()); break; case "Smog": this.srvs.Add(new SmogSrv()); break; case "RestrictedDriving": this.srvs.Add(new RestrictedDrivingSrv()); break; case "Cloth": this.srvs.Add(new ClothSrv()); break; default: break; } string answer = ""; DateTime startTime = DateTime.Now; foreach (IntentSrv srv in this.srvs) { string singleAnswer = srv.GetAnswer(context, luinfo); answer += singleAnswer; } this.srvs.Clear(); if (string.IsNullOrWhiteSpace(answer)) { answer = DatetimeUtils.GetOutofScopeAnswer(); } DateTime endTime = DateTime.Now; LogUtils.Log(startTime, endTime, "[Seniverse Service]"); return(answer); }
public override string GetAnswer(PSAContext context) { TimeRange range = context.timeRange; string type = "Course"; switch (context.Intent) { case "AskCourseSchedule": type = "Course"; break; case "AskDelivery": type = "Delivery"; break; case "AskTrainingSchedule": type = "Training"; break; } string typeCondition = " Type=N'" + type + "' "; string dateCondition = "Date >= '" + range.startDate.ToString("yyyy-MM-dd") + "' "; if (range.endDate != null) { dateCondition += " AND Date <= '" + range.endDate.ToString("yyyy-MM-dd") + "' "; } string weekdaystr = DatetimeUtils.GetTodayWeekDayString(range.startDate); string weekdayCondition = " Weekday=N'" + weekdaystr + "'"; string timesectionCondition = null; if (context.Intent == "AskCourseSchedule" && range.startDate != null && range.endDate != null && range.endDate != range.startDate) { if (range.endDate.Subtract(range.startDate).Hours < 24) { if (range.startDate.Hour == 6) { timesectionCondition = " TimeSector=N'上午' "; } else if (range.startDate.Hour == 12) { timesectionCondition = " TimeSector=N'下午' "; } } } string[] columns = { "Date", "Weekday", "TimeSector", "StartTime", "EndTime", "Name", "Condition", "IsActive" }; string activeCondition = " IsActive=1 "; List <string> conditionsFirstRound = new List <string>(); conditionsFirstRound.Add(activeCondition); conditionsFirstRound.Add(typeCondition); conditionsFirstRound.Add(dateCondition); if (!string.IsNullOrWhiteSpace(timesectionCondition)) { conditionsFirstRound.Add(timesectionCondition); } List <string> conditionsSecondRound = new List <string>(); conditionsSecondRound.Add(activeCondition); conditionsSecondRound.Add(typeCondition); conditionsSecondRound.Add(weekdayCondition); if (!string.IsNullOrWhiteSpace(timesectionCondition)) { conditionsSecondRound.Add(timesectionCondition); } List <Dictionary <string, string> > results = dbChecker.SearchTable(tableName, columns, conditionsFirstRound); if (results == null || results.Count == 0) { results = dbChecker.SearchTable(tableName, columns, conditionsSecondRound); } string result = ""; switch (context.Intent) { case "AskCourseSchedule": if (results == null || results.Count == 0) { result += weekdaystr + "没有安排课程"; break; } result += "课程安排\r\n"; foreach (Dictionary <string, string> dict in results) { string line = ""; if (!string.IsNullOrWhiteSpace(dict["Date"])) { line += DateTime.Parse(dict["Date"]).ToString("yyyy-MM-dd") + " "; } line += dict["Weekday"] + dict["TimeSector"] + " " + dict["Name"]; result += line + "\r\n"; } break; case "AskDelivery": if (results == null || results.Count == 0) { result += weekdaystr + "不上学,不需要家长接送"; break; } foreach (Dictionary <string, string> dict in results) { string line = ""; if (!string.IsNullOrWhiteSpace(dict["Date"])) { line += DateTime.Parse(dict["Date"]).ToString("yyyy-MM-dd") + " "; } line += dict["Weekday"] + dict["TimeSector"] + "," + dict["Condition"] + " " + dict["StartTime"] + " " + dict["Name"]; result += line + "\r\n"; } break; case "AskTrainingSchedule": if (results == null || results.Count == 0) { result += weekdaystr + "没有兴趣小组"; break; } result += "兴趣小组\r\n"; foreach (Dictionary <string, string> dict in results) { string line = ""; if (!string.IsNullOrWhiteSpace(dict["Date"])) { line += DateTime.Parse(dict["Date"]).ToString("yyyy-MM-dd") + " "; } line += dict["Weekday"] + " " + dict["Name"]; result += line + "\r\n"; } break; } return(result); }