예제 #1
0
        public static async Task <RESTModels.Category.RootObject> GetCategoryContent(string idCategory, Interfaces.IStorage storageService, ServicesEngine.ServiceBroker broker)
        {
            Debug.WriteLine($"going for :{idCategory}");
            var isCategoryCached = await storageService.Exists(Constants.CATEGORIES + idCategory, new TimeSpan(0, 12, 0, 0));

            RESTModels.Category.RootObject category;
            if (isCategoryCached)
            {
                var rd = await storageService.ReadData(Constants.CATEGORIES + idCategory);

                category = rd.LoadFromJson <RESTModels.Category.RootObject>();
                Debug.WriteLine($"loaded from cache :{idCategory}");
            }
            else
            {
                Debug.WriteLine($"getting from service :{idCategory}");
                category = await broker.GetCategory(idCategory);

                await storageService.WriteData(Constants.CATEGORIES + idCategory, category.SaveAsJson());

                Debug.WriteLine($"caching from service :{idCategory}");
            }

            // Process(category.contents_raw);
            return(category);
        }
예제 #2
0
        public async Task <List <Models.Ui.HomeItem> > GetUpdates(string category, Interfaces.IStorage storage)
        {
            List <Models.Ui.HomeItem> LastResult = new List <Models.Ui.HomeItem>();
            List <Models.Ui.HomeItem> OutResult  = new List <Models.Ui.HomeItem>();

            try
            {
                var onld = await storage.Exists(Constants.StorageKeys.AGENT_DATA);

                if (onld)
                {
                    var lastResultjson = await storage.ReadData(Constants.StorageKeys.AGENT_DATA);

                    LastResult = lastResultjson.LoadFromJson <List <Models.Ui.HomeItem> >();
                }
                var current = await service.GetPostsFrom(category, 0);

                foreach (var item in current.posts)
                {
                    string img = item.thumbnail;
                    if (string.IsNullOrEmpty(img))
                    {
                        img = Regex.Match(item.content, "<img.+?src=[\"'](.+?)[\"'].+?>", RegexOptions.IgnoreCase).Groups[1].Value;
                    }
                    var p = new Models.Ui.HomeItem
                    {
                        Title      = item.title_plain,
                        Resume     = item.excerpt,
                        CategoryId = "112",
                        Date       = item.date,
                        UniqueId   = item.id.ToString(),
                        Url        = img,
                        Author     = item.author.name
                    };

                    if (!LastResult.Any(o => o.UniqueId == p.UniqueId))
                    {
                        OutResult.Add(p);
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }

            // await storage.WriteData(Constants.StorageKeys.AGENT_DATA, Result.SaveAsJson());


            return(OutResult);
        }