/// <summary> /// 开始计数 /// </summary> /// <returns></returns> private void Handle(OpenDoorArg data) { if (data == null) { return; } if (data.UserId % 2 == 1) { WebSocketNotify.Publish("event", "openDoor", JsonConvert.SerializeObject(new { name = "胡天水", msg = data.InOrOut == "进" ? $"欢迎胡天水先生光临" : "祝胡天水先生一路顺风", data = JsonConvert.SerializeObject(data) })); } else { WebSocketNotify.Publish("event", "openDoor", JsonConvert.SerializeObject(new { name = "刘强东", msg = data.InOrOut == "进" ? $"刘强东来了,美女们注意安全" : "刘强东走了,警报解除", data = JsonConvert.SerializeObject(data) })); } }
public static void RemovePlan(ZeroPlan plan) { if (Plans.TryGetValue(plan.plan_id, out var old)) { Plans.Remove(plan.plan_id); plan.plan_state = plan_message_state.remove; WebSocketNotify.Publish("plan_notify", "remove", JsonConvert.SerializeObject(plan)); } }
public static void SyncPlan(ZeroPlan plan) { if (Plans.ContainsKey(plan.plan_id)) { Plans[plan.plan_id] = plan; } else { Plans.Add(plan.plan_id, plan); } WebSocketNotify.Publish("plan_notify", "add", JsonConvert.SerializeObject(plan)); }
void DoPublish() { if ((DateTime.Now - preSend).TotalSeconds < 1 || Root.UnitCount == 0) { return; } Root.End(); var json = JsonConvert.SerializeObject(Root); Root.Start(); preSend = DateTime.Now; WebSocketNotify.Publish("api", "root", json); }
public static void UpdatePlan(ZeroPlan plan) { if (Plans.TryGetValue(plan.plan_id, out var old)) { old.exec_time = plan.exec_time; old.exec_state = plan.exec_state; old.plan_state = plan.plan_state; old.plan_time = plan.plan_time; old.real_repet = plan.real_repet; old.skip_set = plan.skip_set; old.skip_num = plan.skip_num; WebSocketNotify.Publish("plan_notify", "update", JsonConvert.SerializeObject(plan)); } }
private void PublishConfig(StationConfig config) { if (config == null) { return; } var info = new StationInfo(config); if (StationCountItems.TryGetValue(config.Name, out var status)) { info.Status = status; } var json = JsonConvert.SerializeObject(info); WebSocketNotify.Publish("config", config.StationName, json); }
/// <summary> /// 执行命令 /// </summary> /// <returns></returns> private void Collect(StationConfig station, string json) { using (OnceScope.CreateScope(minuteLine)) { var now = JsonConvert.DeserializeObject <StationCountItem>(json); if (!StationCountItems.TryGetValue(station.StationName, out var item)) { now.Count = 1; StationCountItems.Add(station.StationName, now); return; } item.CheckValue(station, now); WebSocketNotify.Publish("status", station.StationName, JsonConvert.SerializeObject(item)); long value = station.StationType == ZeroStationType.Api || station.StationType == ZeroStationType.Vote ? item.LastTps : item.LastQps; if (minuteLine.TryGetValue(station.StationName, out var kLine)) { if (kLine.Count == 0) { kLine.Total = value; kLine.Open = value; kLine.Close = value; kLine.Max = value; kLine.Min = value; } else { kLine.Total += value; kLine.Close = value; if (kLine.Max < value) { kLine.Max = value; } if (kLine.Min > value) { kLine.Min = value; } } kLine.Count++; } else { minuteLine.Add(station.StationName, kLine = new KLine { Time = GetTime(BaseLine), Count = 1, Total = value, Open = value, Close = value, Max = value, Min = value, Avg = value }); KLines.Add(station.StationName, new List <KLine> { kLine }); } } if ((DateTime.Now - BaseLine).TotalMinutes < 1) { return; } NewBaseTime(); foreach (var key in KLines.Keys.ToArray()) { if (!minuteLine.TryGetValue(key, out var line)) { minuteLine.Add(key, line = new KLine { Time = GetTime(BaseLine), Count = 1 }); } if (line.Count == 0) { line.Avg = 0; } else { line.Avg = decimal.Round(line.Total / line.Count, 4); } while (KLines[key].Count > 240) { KLines[key].RemoveAt(0); } KLines[key].Add(line); WebSocketNotify.Publish("kline", key, JsonConvert.SerializeObject(line)); var nLine = new KLine { Time = GetTime(BaseLine) }; minuteLine[key] = nLine; } }