public void ProcessLogsByTxHash(UInt256 txHash, Snapshot snapshot) { List <Log> logs = Singleton.EthHelper.GetTransactionReceiptLogs(txHash); for (var i = 0; i < logs.Count; i++) { Log l = logs[i]; LogKey lk = new LogKey() { LogIndex = l.LogIndex, TransactionHash = l.TransactionHash }; if (l.Topics.Length == 0) { continue; } UInt256 eventHash = new UInt256(l.Topics[0]); //如果这个通知是需要在意的合约和通知 就再处理一波 CareEvent ce = snapshot.CareEvents.TryGet(eventHash); UInt160 asset = snapshot.CareAssets.TryGet(l.ContractAddress); if (ce != null && asset != null) { l.Event = ce.EventStr; snapshot.Logs.Add(lk, l); //如果是transfer通知那就再额外处理一波 if (ce.EventStr == "Transfer(address,address,uint256)") { ProcessTransferLog(l); } } } }
public void addEvent(CareEvent careEvent) { foreach (CareEventListener eventListener in eventListeners) { CareEvent[] careEvents = new CareEvent[1]; careEvents[0] = careEvent; eventListener.onTriggered(careEvents); } }
/*public void startThread() { Thread aThread = new Thread(new ThreadStart(runThread)); aThread.Start(); }*/ public void runThread() { //while (true) { String str = random.Next().ToString(); CareEvent careEvent = new CareEvent(str); CareEventLogger.Instance.addEvent(careEvent); //Thread.Sleep(1000); } }
public async Task <IActionResult> CreateCareEvent( [FromBody] CareEventForUpdateDto careEventForUpdate) { if (careEventForUpdate == null) { ModelState.AddModelError("Message", "Unable to locate payload for new request"); return(BadRequest(ModelState)); } if (Regex.Matches(careEventForUpdate.CareEventName, @"[a-zA-Z ']").Count < careEventForUpdate.CareEventName.Length) { ModelState.AddModelError("Message", "Description contains invalid characters (Enter A-Z, a-z)"); return(BadRequest(ModelState)); } if (_unitOfWork.Repository <CareEvent>().Queryable(). Where(l => l.Description == careEventForUpdate.CareEventName) .Count() > 0) { ModelState.AddModelError("Message", "Item with same name already exists"); return(BadRequest(ModelState)); } long id = 0; if (ModelState.IsValid) { var newCareEvent = new CareEvent() { Description = careEventForUpdate.CareEventName }; _careEventRepository.Save(newCareEvent); id = newCareEvent.Id; } var mappedCareEvent = await GetCareEventAsync <CareEventIdentifierDto>(id); if (mappedCareEvent == null) { return(StatusCode(500, "Unable to locate newly added item")); } return(CreatedAtAction("GetCareEventByIdentifier", new { id = mappedCareEvent.Id }, CreateLinksForCareEvent <CareEventIdentifierDto>(mappedCareEvent))); }
public ActionResult AddCareEvent(CareEventAddModel model) { ViewBag.MenuItem = CurrentMenuItem; if (ModelState.IsValid) { if (unitOfWork.Repository <CareEvent>().Queryable().Any(ce => ce.Description == model.Description)) { ModelState.AddModelError("Description", "A care event with the specified description already exists."); return(View(model)); } if (Regex.Matches(model.Description, @"[a-zA-Z ']").Count < model.Description.Length) { ModelState.AddModelError("Description", "Description contains invalid characters (Enter A-Z, a-z)"); return(View(model)); } var encodedDescription = System.Web.Security.AntiXss.AntiXssEncoder.HtmlEncode(model.Description, false); var newCareEvent = new CareEvent { Description = encodedDescription }; try { unitOfWork.Repository <CareEvent>().Save(newCareEvent); return(Redirect("/Admin/ManageCareEvent.aspx")); } catch (Exception ex) { ModelState.AddModelError("", string.Format("Unable to add the care event: {0}", ex.Message)); } } return(View(model)); }
public void onTriggered(CareEvent[] careEvents) { this.careEvents.Add(careEvents[0]); }
protected override JArray ProcessRes(JsonRPCrequest req) { JArray result = new JArray(); result = base.ProcessRes(req); switch (req.method) { case "addCareAddr": { using (var snapshot = Singleton.Store.GetSnapshot()) { snapshot.CareAddrs.Add(new UInt160((string)req.@params[0]), new UInt160((string)req.@params[0])); snapshot.Commit(); } result = getJAbyKV("result", true); break; } case "existCareAddr": { UInt160 key = new UInt160((string)req.@params[0]); UInt160 value = Singleton.Store.GetCareAddrs().TryGet(key); result = result = getJAbyKV("result", key.Equals(value)); break; } case "addCareAsset": { using (var snapshot = Singleton.Store.GetSnapshot()) { snapshot.CareAssets.Add(new UInt160((string)req.@params[0]), new UInt160((string)req.@params[0])); snapshot.Commit(); } result = getJAbyKV("result", true); break; } case "existCareAsset": { UInt160 key = new UInt160((string)req.@params[0]); UInt160 value = Singleton.Store.GetCareAssets().TryGet(key); result = result = getJAbyKV("result", key.Equals(value)); break; } case "addCareEvent": { string eventStr = (string)req.@params[0]; string hexStr = Conversion.Bytes2HexString(Encoding.UTF8.GetBytes(eventStr)); UInt256 hash = Singleton.EthHelper.GetSha3(hexStr); CareEvent careEvent = new CareEvent() { Hash = hash, EventStr = eventStr, HexStr = hexStr }; using (var snapshot = Singleton.Store.GetSnapshot()) { snapshot.CareEvents.Add(hash, careEvent); snapshot.Commit(); } result = getJAbyKV("result", true); break; } case "getCareEvents": { JArray j = new JArray(); j.Add(Singleton.Store.GetCareEvents().Find().Select(p => p.Value.ToJson())); result = j; break; } case "getCareEventByEventHash": { UInt256 eventHash = new UInt256((string)req.@params[0]); CareEvent careEvent = Singleton.Store.GetCareEvents().TryGet(eventHash); result = getJAbyKV("result", careEvent.ToJson()); break; } } return(result); }