Beispiel #1
0
        /* Runs in the background on load event.
         * Checks if database file exists at users data directory, if so whether they're
         * the same size, and downloads the latest one if either return false */
        public static void UpdateLocalDatabase()
        {
            Program.log.Info("Checking for database updates");

            if (UpdateLocalDatabaseFiles(UrlOpenDirectories, "open-directories.txt"))
            {
                using (var client = new WebClient()) { client.DownloadFile(new Uri(UrlOpenDirectories), $"{LocalExtensions.pathData}open-directories.txt"); }
                Program.log.Info("open-directories.txt updated");
            }
            MainForm.DataOpenDirectories.AddRange(File.ReadAllLines($"{LocalExtensions.pathData}open-directories.txt"));

            if (UpdateLocalDatabaseFiles(UrlOpenFiles, "open-files.json"))
            {
                using (var client = new WebClient()) { client.DownloadFile(new Uri(UrlOpenFiles), $"{LocalExtensions.pathData}open-files.json"); }
                Program.log.Info("open-files.json updated");
            }

            // Retrieve database items, skipping the first line (contains the meta info)
            foreach (var item in File.ReadAllLines($"{LocalExtensions.pathData}open-files.json").Skip(1))
            {
                if (TextExtensions.IsValidJSON(item))
                {
                    MainForm.FilesOpenDatabase.Add(JsonConvert.DeserializeObject <WebFile>(item));
                }
            }

            MainForm.DatabaseInfo = File.ReadLines($"{LocalExtensions.pathData}open-files.json").First(); // Gets first line in database which contains info
        }
Beispiel #2
0
        /// <summary>
        /// Get database stats
        /// </summary>
        /// <returns></returns>
        public static DateTime GetLastUpdateDate()
        {
            DateTime updateDate = DateTime.MinValue;

            if (TextExtensions.IsValidJSON(MainForm.DatabaseInfo))
            {
                var dataJsonInfo = JsonConvert.DeserializeObject <DatabaseInfo>(MainForm.DatabaseInfo);
                updateDate = dataJsonInfo.LastUpdated;
            }

            return(updateDate);
        }
Beispiel #3
0
        /*************************************************************************/
        /* Home Tab                                                              */
        /*************************************************************************/

        /// <summary>
        /// Get database info located on the first line of the file
        /// </summary>
        public void GetDatabaseInfo()
        {
            Program.log.Info("Getting latest database information");

            long totalSize = 0;

            try
            {
                // Total size of all files in database

                Program.log.Info("Getting absolute total size of all files");

                foreach (var jsonData in FilesOpenDatabase)
                {
                    totalSize += jsonData.Size;
                }

                labelDatabaseStats.Text = String.Format(labelDatabaseStats.Text, TextExtensions.GetFormattedNumber(FilesOpenDatabase.Count.ToString()), TextExtensions.BytesToString(totalSize), TextExtensions.GetFormattedNumber(DataOpenDirectories.Count.ToString()));

                Program.log.Info("Total size of all files successful");
            }
            catch (Exception ex)
            {
                labelDatabaseStats.Text = String.Format(labelDatabaseStats.Text, TextExtensions.GetFormattedNumber(FilesOpenDatabase.Count.ToString()), TextExtensions.BytesToString(totalSize), TextExtensions.GetFormattedNumber(DataOpenDirectories.Count.ToString()));
                Program.log.Error("Unable to get absolute total size of all files", ex);
            }

            try
            {
                // Get database stats

                if (TextExtensions.IsValidJSON(DatabaseInfo))
                {
                    Program.log.Info("Getting latest database update date");
                    var dataJsonInfo = JsonConvert.DeserializeObject <DatabaseInfo>(DatabaseInfo);
                    labelDatabaseUpdatedDate.Text = String.Format(labelDatabaseUpdatedDate.Text, dataJsonInfo.LastUpdated.ToShortDateString());
                    Program.log.Info("Latest database update date successful");
                }
            }
            catch (Exception ex)
            {
                labelDatabaseUpdatedDate.Text = String.Format(labelDatabaseUpdatedDate.Text, "n/a");
                Program.log.Error("Error getting latest database update date", ex);
            }
        }