public void OnPublished(string channel, string publish) { if (!AsyncPublications) { Publish?.Invoke(channel, publish); } else if (AsyncPublications && UseSyncContext) { Task.Run(() => syncContext.Send(s => { Publish?.Invoke(channel, publish); }, publish)); } else { Task.Run(() => Publish?.Invoke(channel, publish)); } }
private SmsAnalyzer() { this.ExternalApiSmsService = ExternalApiSmsService.Instance; this.SmsRenderModelsCache = new List <SmsRenderModel>(); this.ProcessedSmsHashes = new List <string>(); ExternalApiSmsService.Publish += () => { this.SmsCache = ExternalApiSmsService.GetAllSms().OrderBy(s => s.Value.Timestamp); var unprocessedSms = SmsCache.Except(SmsCache.Where(s => ProcessedSmsHashes.Contains(s.Key))); var smsRenderModels = ProcessSms(unprocessedSms); if (smsRenderModels.Any()) { ProcessedSmsHashes.AddRange(smsRenderModels.Select(s => s.Sms.Hash)); SmsRenderModelsCache.AddRange(smsRenderModels); Publish.Invoke(); } }; }
private void QueryExternalApi() { var mClient = new RestClient("https://mayhem-clockwork.herokuapp.com"); var req = new RestRequest { Resource = "/", Method = Method.GET }; var resp = mClient.Execute(req); var content = resp.Content; var smsListJsonTokens = JArray.Parse(content); if (!smsListJsonTokens.Any()) { return; } foreach (var smsJsonToken in smsListJsonTokens) { var sms = new SMS() { FromNumber = (string)smsJsonToken.SelectToken("from"), ID = (string)smsJsonToken.SelectToken("id"), Text = (string)smsJsonToken.SelectToken("content"), Timestamp = (string)smsJsonToken.SelectToken("timestamp") }; sms.Hash = ("" + sms.Timestamp + sms.Text + sms.FromNumber).ComputeHash(Hasher.eHashType.SHA1); if (!SmsCache.ContainsKey(sms.Hash)) { SmsCache.Add(sms.Hash, sms); } } Publish.Invoke(); }
public void Hit() { Publish?.Invoke(); //Debug.Log(Publish.); }
protected void OnPublish(EventArgs e) { Publish?.Invoke(this, e); }