private static async Task PushWebNotification(DataCollectedEventArgs e) { //1.推送完整15期计划 await Pk10Context.Clients.Group(e.Rule.ToString()).SendAsync("ShowPlans", e.Plans); //2.推送最新期计划 await Pk10Context.Clients.Group("AllRules").SendAsync("ShowPlans", e.LastForecastData); }
private static async void Service_DataCollectedSuccess(object sender, DataCollectedEventArgs e) { //推送Web通知 await PushWebNotification(e); //推送App消息 await PushAppNotification(e); //更新缓存 UpdateCache(e); }
private static void UpdateCache(DataCollectedEventArgs e) { lock (Cache) { if (Cache.TryGetValue(e.Lottery, out ConcurrentDictionary <int, List <IForecastPlanModel> > ps)) { ps[(int)e.Rule] = e.Plans; } else { Cache.Set(e.Lottery, new ConcurrentDictionary <int, List <IForecastPlanModel> >() { [(int)e.Rule] = e.Plans }); } } }
void wc_DataCollected(DataCollectedEventArgs e) { try { if (InvokeRequired) { AccessUI del = delegate { wc_DataCollected(e); }; Invoke(del); return; } if (!chkSilent.Checked) { //aici restul de cod TreeNode root = this.treeResults.Nodes[0]; //verificam daca avem nod adaugat. Daca nu cream unul nou pentru pozitia curenta TreeNode tn; if (root.Nodes.Count <= e.CrawlerID) { //generam unul nou tn = new TreeNode(); root.Nodes.Add(tn); tn.ImageIndex = 1; tn.SelectedImageIndex = 1; tn.StateImageIndex = 1; tn.Text = e.URL; tn.Tag = "Crawler ID = " + e.CrawlerID; } else { tn = root.Nodes[e.CrawlerID]; } //avem nodul pe care trebuie sa punem datele TreeNode newChild = new TreeNode(); tn.Nodes.Add(newChild); newChild.Text = "[" + e.Language.ToString() + "] " + e.URL; newChild.ImageIndex = 2; newChild.SelectedImageIndex = 2; newChild.StateImageIndex = 2; newChild.Tag = e.Text; } //} else { // if (chkWordCounter.Checked) { // //TextWriter tw = new StreamWriter(this.edtPath.Text + e.CrawlerID + "_" + e.Language.ToString() + ".txt", false, Encoding.UTF8); // //tw.Write(e.Text); // //tw.Flush(); // //tw.Close(); // //tw.Dispose(); // int word_count = e.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length; // if (e.Language == LanguageType.RO) { // ro_en += word_count; // ro_de += word_count; // } // if (e.Language == LanguageType.EN) { // ro_en += word_count; // } // if (e.Language == LanguageType.DE) { // ro_de += word_count; // } // this.lblResults.Text = "Results: " + ro_en + "/" + ro_de; // //TextWriter twDesc = new StreamWriter(this.edtPath.Text + "descriptor.txt", true); // //twDesc.WriteLine(this.edtPath.Text + e.CrawlerID + "_" + e.Language.ToString() + ".txt " + word_count.ToString() + " " + e.URL); // //twDesc.Flush(); // //twDesc.Close(); // //twDesc.Dispose(); // if ((ro_en > this.edtPagesNeeded.Value) && (ro_de > this.edtPagesNeeded.Value)) { // this.button1_Click(null, new EventArgs()); // } // } //} this.progressBar1.Value = e.CrawlerID + 1; this.lblResults.Text = "Results: " + this.progressBar1.Value + "/" + this.edtPagesNeeded.Value; int wcount = e.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Length; string d = ""; if (this.edtPath.Text[this.edtPath.Text.Length - 1] != '\\') { d = "\\"; } TextWriter tw = new StreamWriter(this.edtPath.Text + d + e.CrawlerID + "_" + e.Language.ToString() + ".txt", false, Encoding.UTF8); tw.Write(e.Text); tw.Flush(); tw.Close(); tw.Dispose(); TextWriter twDesc = new StreamWriter(this.edtPath.Text + d + "descriptor.txt", true); twDesc.WriteLine(this.edtPath.Text + d + e.CrawlerID + "_" + e.Language.ToString() + ".txt " + wcount.ToString() + " " + e.URL); twDesc.Flush(); twDesc.Close(); twDesc.Dispose(); } catch (Exception ex) { MessageBox.Show("There was an exception inside the WIKICRAWLER plugin. Please report the following :" + ex.ToString()); this.button1_Click(null, EventArgs.Empty); } }
private static async Task PushAppNotification(DataCollectedEventArgs e) { if (e.Rule == Pk10Rule.Sum) { return; } var plans = e.LastForecastData; bool isTwoSide = (int)e.Rule > 4; //实时更新 var realTimeAudience = isTwoSide ? new { tag_and = new string[] { "realtime", "twoside" } } : (object)new { tag = new string[] { "realtime" } }; await JPushUtil.PushMessageAsync("PK10最新预测", JsonConvert.SerializeObject(plans), realTimeAudience); //连挂提醒 plans.ForEach(async p => { var tags = new List <string>(); for (var i = 1; i <= 4; i++) { if (p.KeepGuaCnt < i) { break; } tags.Add($"liangua{i}"); } var msg = $"{p.KeepGuaCnt}连挂 {p.LastDrawnPeriod + 1}期 {p.Rule} {p.ForecastNo}"; if (tags.Any()) { var audience = isTwoSide ? new { tag = tags, tag_and = new string[] { "twoside" } } : (object)new { tag = tags }; await JPushUtil.PushNotificationAsync("PK10连挂提醒", msg, audience); } if (p.KeepGuaCnt >= MinKeepGua) { await TelegramBotUtil.SendMessageAsync(msg); } }); //重复度提醒 if (isTwoSide) { return; } var repetition = new List <string>(); var plan = plans.FirstOrDefault(); for (var i = 60; i <= 100; i += 20) { if (plan.RepetitionScore < i) { break; } repetition.Add($"repetition{i}"); } var rMsg = $"重{plan.RepetitionScore}% {plan.LastDrawnPeriod + 1}期 {plan.Rule} {plan.ForecastNo}/{plans.LastOrDefault().ForecastNo}"; if (repetition.Any()) { await JPushUtil.PushNotificationAsync("PK10高重提醒", rMsg, new { tag = repetition }); } // if (plan.RepetitionScore >= MinRepetition) // await TelegramBotUtil.SendMessageAsync(rMsg); }