/// <summary> /// Override this method to create the default Response handler for your web scraper. /// If you have multiple page types, you can add additional similar methods. /// </summary> /// public override void Parse(Response response) { // Loop on all Links foreach (var links in response.Css("li[data-testing-id=\"event-card\"] a")) { var runningEvent = new RunningEvent(); // set working directory for the project runningEvent.URL = links.GetAttribute("href"); this.WorkingDirectory = @"C:\Users\jenir\source\repos\WebScraper\Output"; this.Request(runningEvent.URL, ParseDetails, new MetaData() { { "link", runningEvent } }); } if (response.CssExists("a[rel^=\"next\"]")) { // Get Link URL= var next_page = response.Css("a[rel^=\"next\"]")[0].Attributes["href"]; // Scrpae Next URL this.Request(next_page, Parse); } }
/// <summary> /// Override this method to create the default Response handler for your web scraper. /// If you have multiple page types, you can add additional similar methods. /// </summary> public override void Parse(Response response) { // set working directory for the project this.WorkingDirectory = @"C:\Users\jenir\source\repos\WebScraper\Output"; // Loop on all Links foreach (var links in response.Css("article.activity-feed a")) { var runningEvent = new RunningEvent(); // set working directory for the project runningEvent.URL = links.GetAttribute("href"); this.Request(runningEvent.URL, ParseDetails, new MetaData() { { "link", runningEvent } }); } // Loop On All Links if (response.CssExists("a.next-pagebtn-small-yellow")) { // Get Link URL var next_page = response.Css("a.next-page.btn-small-yellow")[0].Attributes["href"]; // Scrpae Next URL this.Request(next_page, Parse); } }
private void ProcessMessage(string nsPayload) { var msg = JObject.Parse(nsPayload); var id = msg["id"].Value(0); var accepted = msg["accepted"].Value(false); var targetId = msg["targetId"].Value(String.Empty); var @event = msg["event"].Value(string.Empty); var error = msg["error"].Value(string.Empty); var reason = msg["reason"].Value(string.Empty); var data = msg["data"].Value(string.Empty); // If a response retrieve its associated request. if (id > 0) { if (!_sents.TryGetValue(id, out Sent sent)) { _logger.LogError($"ProcessMessage() | received response does not match any sent request [id:{id}]"); return; } if (accepted) { _logger.LogDebug($"ProcessMessage() | request succeed [method:{sent.RequestMessage.Method}, id:{sent.RequestMessage.Id}]"); sent.Resolve?.Invoke(data); } else if (!error.IsNullOrWhiteSpace()) { // 在 Node.js 实现中,error 的值可能是 "Error" 或 "TypeError"。 _logger.LogWarning($"ProcessMessage() | request failed [method:{sent.RequestMessage.Method}, id:{sent.RequestMessage.Id}]: {reason}"); sent.Reject?.Invoke(new Exception(reason)); } else { _logger.LogError($"ProcessMessage() | received response is not accepted nor rejected [method:{sent.RequestMessage.Method}, id:{sent.RequestMessage.Id}]"); } } // If a notification emit it to the corresponding entity. else if (!targetId.IsNullOrWhiteSpace() && [email protected]()) { if (@event == "running") { RunningEvent?.Invoke(targetId); } MessageEvent?.Invoke(targetId, @event, data); } // Otherwise unexpected message. else { _logger.LogError($"ProcessMessage() | received message is not a response nor a notification: {nsPayload}"); } }
//POST api/resource public HttpResponseMessage Post(RunningEvent runningEvent) { _resources = MemoryCache.Default["resource"] == null ? new Dictionary <string, Resource>() : (Dictionary <string, Resource>)MemoryCache.Default["resource"]; runningEvent.Date = DateTime.Now; //Notify the connected clients Hub.Clients.All.addRunningEvent(runningEvent); var response = Request.CreateResponse(HttpStatusCode.Created, runningEvent); //string link = Url.Link("apiRoute", new { controller = "todo", id = item.ID }); //response.Headers.Location = new Uri(link); Resource resource = null; if (!_resources.ContainsKey(runningEvent.UserName)) { resource = new Resource() { RegistrationNumber = runningEvent.UserName, Positions = new List <RunningEvent>() { runningEvent } }; _resources.Add(runningEvent.UserName, resource); } else { resource = _resources[runningEvent.UserName]; TimeSpan span1, span2; if (ShouldResetRoute(runningEvent, resource)) { resource.Positions = new List <RunningEvent>() { runningEvent }; } else { resource.Positions.Add(runningEvent); } //if (resource.Positions.Last().Date.AddMinutes(5) < DateTime.Now || resource.Positions.Last().Date < DateTime.Now && resource.Positions.Last().RunningEventType == RunningEventType.Paused) //&& resource.Positions.Last().TotalTime > runningEvent.TotalTime)) //{ // resource.Positions = new List<RunningEvent>(){runningEvent}; //} } MemoryCache.Default.Set("resource", _resources, DateTimeOffset.Now.AddDays(5)); return(response); }
private bool ShouldResetRoute(RunningEvent runningEvent, Resource resource) { if (runningEvent.RunningEventType == RunningEventType.Started && string.IsNullOrEmpty(runningEvent.TotalTime)) { return(true); } TimeSpan span1, span2; return(TimeSpan.TryParse(runningEvent.TotalTime.Replace("m", "").Replace("h", ""), out span1) && TimeSpan.TryParse(resource.Positions.Last().TotalTime.Replace("m", "").Replace("h", ""), out span2) && span1 < span2); }
private IEvent eventFactory(string value) { IEvent theEvent; switch (value) { case "1": theEvent = new RunningEvent(5) as IEvent; break; case "2": theEvent = new SwimmingEvent(3) as IEvent; break; default: theEvent = new NoSupplementEvent() as IEvent; break; } return(theEvent); }
private static void OnResuming(RunningModeEventArgs args) { RunningEvent?.Invoke(null, args); }
public override string ToString() { return(EventParticipant.UserName + " has signed up for " + RunningEvent.ToString() + RunningLocation.ToString()); }
public bool WaitOnRun() { return(RunningEvent.WaitOne(-1)); }
/// <summary> /// Resets the Running Event /// </summary> public void Stop() { RunningEvent.Reset(); }
public void Start() { RunningEvent.Set(); PauseEvent.Reset(); }