private async void CacheItem(ContentLoadedEvent obj) { var cachedItem = await cache.Retrieve(obj.RequestEvent); // If item wasn't cached or was cached long time ago. if (cachedItem == null || (obj.LoadedAt - cachedItem.Value.LoadedAt) > TimeSpan.FromSeconds(1)) { await cache.Save(obj); } }
private void LoadNext(ContentLoadedEvent evt, int loadedCount) { int offset = ((dynamic)evt.RequestEvent.FormData)?.o + loadedCount ?? loadedCount; queue.Publish(new LoadPageEvent(Constants.AjaxSeriesesUrl, HttpMethod.Post, new { act = "serial", type = "search", o = offset, s = 1, t = 0 })); }
private IEnumerator OpenAsync() { FormContent asset = null; if (_contentAsyncLoading) { var request = Resources.LoadAsync <FormContent>("UI/Contents/" + ContentName); yield return(request); asset = request.asset as FormContent; } else { asset = Resources.Load <FormContent>("UI/Contents/" + ContentName); } Debug.Assert(asset != null); if (asset != null) { var content = GameObject.Instantiate <FormContent>(asset); content.transform.SetParent(_contentContainer, false); content.gameObject.name = string.Format("Content - {0}", ContentName); Content = content as FormContent; var size = (content.transform as RectTransform).sizeDelta; _dialog.sizeDelta = size + _oversize; _contentContainer.sizeDelta = size; typeof(FormContent) .GetProperty("Dialog") .SetValue(Content, this, null); IsContentLoaded = true; } IsContentLoading = false; if (IsContentLoaded) { if (ContentLoadedEvent != null) { ContentLoadedEvent.Invoke(); } } }
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)); } }
public async Task Save(ContentLoadedEvent evt) { await repository.Add(new WebPage() { Url = evt.RequestEvent.Url, HttpMethod = evt.RequestEvent.Method.ToString(), Content = evt.Content, Headers = new List <Header>(), LoadedAt = evt.LoadedAt, Parameters = evt.RequestEvent.FormData.ToDictionary().Select(f => new Parameter() { Key = f.Key, Value = f.Value }).ToList() }); await repository.SaveChanges(); }
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)); } }
private bool UrlIsMine(ContentLoadedEvent evt) => !evt.RequestEvent.Url.Equals(Constants.AjaxSeriesesUrl);
private void HandleHTML(ContentLoadedEvent obj) { ParseHTML(obj); }
private void PageHandler(ContentLoadedEvent evt) => ParseJSON(evt);