private async Task LoadPageInternal(LoadPageEvent uri) { const string logMessage = "Recieve URL to load:"; log?.WriteLine(logMessage + uri.Url); if (await CheckCache(uri, logMessage.Length)) { return; } HttpClient client = new HttpClient(); HttpResponseMessage result; if (uri.Method == HttpMethod.Get) { result = await client.GetAsync(uri.Url); } else { result = await client.PostAsync(uri.Url, new FormUrlEncodedContent(uri.FormData.ToDictionary())); } result.EnsureSuccessStatusCode(); var content = await result.Content.ReadAsStringAsync(); lastLoaded = DateTime.Now; log?.WriteLine("URL loaded: ".PadRight(logMessage.Length) + uri.Url); queue.Publish(new ContentLoadedEvent(uri, content, lastLoaded)); }
public void Pair(int parentId, int childId) { AssertAlive(parentId); AssertAlive(childId); // Get or create children collection for parent. if (!entityChildren.TryGetValue(parentId, out var children)) { children = new HashSet <int>(); entityChildren.Add(parentId, children); } // Get or create parent collection for children. if (!entityParents.TryGetValue(childId, out var parents)) { parents = new HashSet <int>(); entityParents.Add(childId, parents); } // Do the actual pairing and invoke events. parents.Add(parentId); children.Add(childId); madeParentOfEvents.Publish(parentId, e => e.Invoke(parentId, childId)); madeChildOfEvents.Publish(childId, e => e.Invoke(parentId, childId)); }
private void ParseJSON(ContentLoadedEvent obj) { var content = JObject.Parse(obj.Content); var data = (JArray)content.GetValue("data"); if (data.Count > 0) { LoadNext(obj, data.Count); } foreach (JToken item in data) { queue.Publish(new LoadPageEvent( new Uri(obj.RequestEvent.Url, item.Value <string>("link") + "/seasons/"), HttpMethod.Get, null)); } }
private void Commit(AccountAggregate aggregate) { var changes = _repository.Save(aggregate); foreach (var change in changes) { _publisher.Publish(change); } }
public void Delete(int id) { if (!aliveEntities.Remove(id)) { throw new InvalidOperationException($"entity {id} not alive"); } // Notify events. deletedEvents.Publish(id, e => e(id)); // Delete and unpair children. if (entityChildren.TryGetValue(id, out var children)) { foreach (var childId in children) { Unpair(id, childId); Delete(childId); } entityChildren.Remove(id); } // Unpair from parents. if (entityParents.TryGetValue(id, out var parents)) { foreach (var parentId in parents) { Unpair(parentId, id); } parents.Remove(id); } // Clear rest of the state and return id to pool. deletedEvents.Delete(id); unpairedFromChildEvents.Delete(id); unpairedFromParentEvents.Delete(id); madeParentOfEvents.Delete(id); madeChildOfEvents.Delete(id); entityTags.Remove(id); entityAnnotations.Remove(id); freeEntities.Return(id); }
private void ParseHTML(ContentLoadedEvent obj) { HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(obj.Content); // TODO Extract all links that // looks like: http://www.lostfilm.tv/series/<SERIES_NAME>/season_<SESAON_NUMBER>/episode_<EPISODE_NUMBER>/ // Publish them as LoadPageEvents Regex episodeLink = new Regex(@"(?:goTo).'(\/series\/\w+\/\w+\/\w+\/)"); string permaLink = "http://www.lostfilm.tv"; MatchCollection matches = episodeLink.Matches(obj.Content); foreach (Match item in matches) { queue.Publish(new LoadPageEvent( new Uri(permaLink + item.Groups[1].Value), HttpMethod.Get, null)); } }
public void Unpair(int parentId, int childId) { AssertAlive(parentId); AssertAlive(childId); // Make sure parent has accepted children in the past. if (!entityChildren.TryGetValue(parentId, out var children)) { return; } // Make sure children has accepted parent in the past. if (!entityParents.TryGetValue(childId, out var parents)) { return; } // Do the actual unpairing and invoke events. children.Remove(childId); parents.Remove(parentId); unpairedFromChildEvents.Publish(parentId, e => e.Invoke(parentId, childId)); unpairedFromParentEvents.Publish(childId, e => e.Invoke(parentId, childId)); }