Exemplo n.º 1
0
        public static async Task DoLogOut(Interfaces.IStorage storageService, Interfaces.IUxService uxService, ServicesEngine.ServiceBroker broker)
        {
            await broker.DoLogout(AppBase.Current.User);

            AppBase.Current.User = null;
            await storageService.Delete(Constants.AUTHORIZATION);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
0
 public Repository(Interfaces.IStorage storage)
 {
     _storage = storage;
 }
Exemplo n.º 4
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);
        }