Exemple #1
0
        //Database Reset
        public static async Task DatabaseReset()
        {
            try
            {
                if (EventProgressDisableUI != null)
                {
                    EventProgressDisableUI("Resetting the database.", true);
                }
                Debug.WriteLine("Resetting the database.");

                //Delete all files from local storage
                string[] localFiles = AVFiles.Directory_ListFiles(string.Empty, true);
                foreach (string localFile in localFiles)
                {
                    AVFiles.File_Delete(localFile, false);
                }

                //Reset the online status
                OnlineUpdateFeeds   = true;
                OnlineUpdateNews    = true;
                OnlineUpdateStarred = true;
                ApiMessageError     = string.Empty;

                //Reset the last update setting
                await AppSettingSave("LastItemsUpdate", "Never");

                Debug.WriteLine("Resetted the database.");
            }
            catch (Exception ex)
            {
                Debug.WriteLine("Failed resetting the database: " + ex.Message);
            }
        }
Exemple #2
0
 //Cleanup image download cache
 public static void CleanImageDownloadCache()
 {
     try
     {
         Debug.WriteLine("Cleaning image download cache...");
         string[] fileNames = AVFiles.Directory_ListFiles("Cache", true);
         foreach (string fileName in fileNames)
         {
             DateTime fileDate   = AVFiles.File_CreationTime(fileName, false);
             int      removeDays = Convert.ToInt32(AppSettingLoad("RemoveItemsRange"));
             if (DateTime.Now.Subtract(fileDate).TotalDays > removeDays)
             {
                 AVFiles.File_Delete(fileName, false);
                 Debug.WriteLine("Removing image cache: " + fileName + fileDate);
             }
         }
     }
     catch { }
 }
Exemple #3
0
        //Clear Database Thread
        async Task ClearDatabase()
        {
            ProgressDisableUI("Clearing stored items...");
            try
            {
                //Reset the online status
                OnlineUpdateFeeds   = true;
                OnlineUpdateNews    = true;
                OnlineUpdateStarred = true;
                ApiMessageError     = string.Empty;

                //Reset the last update setting
                await AppSettingSave("LastItemsUpdate", "Never");

                await ClearObservableCollection(List_Feeds);
                await ClearObservableCollection(List_FeedSelect);
                await ClearObservableCollection(List_NewsItems);
                await ClearObservableCollection(List_SearchItems);
                await ClearObservableCollection(List_StarredItems);

                await vSQLConnection.DeleteAllAsync <TableFeeds>();

                await vSQLConnection.DropTableAsync <TableFeeds>();

                await vSQLConnection.CreateTableAsync <TableFeeds>();

                await vSQLConnection.DeleteAllAsync <TableOffline>();

                await vSQLConnection.DropTableAsync <TableOffline>();

                await vSQLConnection.CreateTableAsync <TableOffline>();

                await vSQLConnection.DeleteAllAsync <TableItems>();

                await vSQLConnection.DropTableAsync <TableItems>();

                await vSQLConnection.CreateTableAsync <TableItems>();

                await vSQLConnection.DeleteAllAsync <TableSearchHistory>();

                await vSQLConnection.DropTableAsync <TableSearchHistory>();

                await vSQLConnection.CreateTableAsync <TableSearchHistory>();

                //Delete all feed icons from local storage
                foreach (string localFile in AVFiles.Directory_ListFiles(string.Empty, true))
                {
                    try
                    {
                        if (localFile.EndsWith(".png"))
                        {
                            AVFiles.File_Delete(localFile, false);
                        }
                    }
                    catch { }
                }

                //Load and set database size
                await UpdateSizeInformation();
            }
            catch { }
            ProgressEnableUI();
        }
Exemple #4
0
        static public async Task <bool> Feeds(bool Silent, bool EnableUI)
        {
            try
            {
                if (!Silent)
                {
                    EventProgressDisableUI("Downloading latest feeds...", true);
                }
                Debug.WriteLine("Downloading latest feeds...");

                string[][] RequestHeader  = new string[][] { new[] { "Authorization", "GoogleLogin auth=" + AppSettingLoad("ConnectApiAuth").ToString() } };
                string     DownloadString = await AVDownloader.DownloadStringAsync(10000, "News Scroll", RequestHeader, new Uri(ApiConnectionUrl + "subscription/list?output=json"));

                JObject WebJObject = JObject.Parse(DownloadString);
                if (WebJObject["subscriptions"] != null && WebJObject["subscriptions"].HasValues)
                {
                    if (!Silent)
                    {
                        EventProgressDisableUI("Processing " + WebJObject["subscriptions"].Count() + " feeds...", true);
                    }
                    Debug.WriteLine("Processing " + WebJObject["subscriptions"].Count() + " feeds...");

                    List <string> ApiFeedIdList = new List <string>();
                    string[]      LocalFileList = AVFiles.Directory_ListFiles(string.Empty, true);

                    List <TableFeeds> TableUpdatedFeeds = new List <TableFeeds>();
                    List <TableFeeds> TableCurrentFeeds = await vSQLConnection.Table <TableFeeds>().ToListAsync();

                    foreach (JToken JTokenRoot in WebJObject["subscriptions"])
                    {
                        string FeedId    = JTokenRoot["sortid"].ToString();
                        string FeedTitle = JTokenRoot["title"].ToString();

                        string HtmlUrl = WebUtility.HtmlDecode(JTokenRoot["htmlUrl"].ToString());
                        HtmlUrl = WebUtility.UrlDecode(HtmlUrl);

                        Uri FullUrl = new Uri(HtmlUrl);
                        ApiFeedIdList.Add(FeedId);

                        TableFeeds TableResult = TableCurrentFeeds.Where(x => x.feed_id == FeedId).FirstOrDefault();
                        if (TableResult == null)
                        {
                            //Debug.WriteLine("Adding feed: " + FeedTitle);

                            TableFeeds AddFeed = new TableFeeds();
                            AddFeed.feed_id    = FeedId;
                            AddFeed.feed_title = FeedTitle;
                            AddFeed.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            AddFeed.feed_ignore_status = false;
                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                AddFeed.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(AddFeed);
                        }
                        else
                        {
                            //Debug.WriteLine("Updating feed: " + FeedTitle);

                            TableResult.feed_title = FeedTitle;
                            TableResult.feed_link  = FullUrl.Scheme + "://" + FullUrl.Host;

                            if (JTokenRoot["categories"] != null && JTokenRoot["categories"].HasValues)
                            {
                                TableResult.feed_folder = JTokenRoot["categories"][0]["label"].ToString();
                            }

                            TableUpdatedFeeds.Add(TableResult);
                        }

                        //Check and download feed logo
                        if (!LocalFileList.Any(x => x.EndsWith(FeedId + ".png")))
                        {
                            try
                            {
                                if (!Silent)
                                {
                                    EventProgressDisableUI("Downloading " + FeedTitle + " icon...", true);
                                }

                                Uri    IconUrl      = new Uri("https://s2.googleusercontent.com/s2/favicons?domain=" + FullUrl.Host);
                                byte[] HttpFeedIcon = await AVDownloader.DownloadByteAsync(3000, "News Scroll", null, IconUrl);

                                if (HttpFeedIcon != null && HttpFeedIcon.Length > 75)
                                {
                                    AVFiles.File_SaveBytes(FeedId + ".png", HttpFeedIcon, true, true);
                                    Debug.WriteLine("Downloaded transparent logo: " + HttpFeedIcon.Length + "bytes/" + IconUrl);
                                }
                                else
                                {
                                    Debug.WriteLine("No logo found for: " + IconUrl);
                                }
                            }
                            catch { }
                        }
                    }

                    //Update the feeds in database
                    if (TableUpdatedFeeds.Any())
                    {
                        await vSQLConnection.InsertAllAsync(TableUpdatedFeeds, "OR REPLACE");
                    }

                    //Delete removed feeds from the database
                    List <string> DeletedFeeds = TableCurrentFeeds.Select(x => x.feed_id).Except(ApiFeedIdList).ToList();
                    Debug.WriteLine("Found deleted feeds: " + DeletedFeeds.Count());
                    foreach (string DeleteFeedId in DeletedFeeds)
                    {
                        await DeleteFeed(DeleteFeedId);
                    }
                }

                if (EnableUI)
                {
                    EventProgressEnableUI();
                }
                return(true);
            }
            catch
            {
                EventProgressEnableUI();
                return(false);
            }
        }