Пример #1
0
        /// <summary>
        /// Checks if local database needs to be updated
        /// </summary>
        /// <param name="webFile">String URL of the file to check for update</param>
        /// <param name="fileName">File name, used to check local directory</param>
        /// <returns></returns>
        public static bool IsFileOutOfDate(string webFile, string fileName)
        {
            try
            {
                Program.log.Info($"Checking if file '{fileName}' needs to be updated");

                if (File.Exists(LocalExtensions.pathData + fileName))
                {
                    if (WebFileExtensions.FileSize($"{webFile}") == new FileInfo(LocalExtensions.pathData + fileName).Length)
                    {
                        return(false);
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(true);
                }
            }
            catch (Exception ex) { Program.log.Error($"Unable to check database file '{fileName}' for update, URL : {webFile}", ex); return(true); }
        }
Пример #2
0
 private void BtnRequestFileSize_ClickButtonArea(object Sender, MouseEventArgs e)
 {
     // Request file size from URL
     buttonRequestFileSize.Visible = false;
     BackGroundWorker.RunWorkAsync <string>(() => StringExtensions.BytesToPrefix(WebFileExtensions.FileSize(currentFile.URL)), (data) => { labelValueSize.Text = data; });
 }
Пример #3
0
        /// <summary>
        /// Get web file info from internal database, or creates a new object if it doesn't exist
        /// </summary>
        /// <param name="URL">Used to match with WebFile.URL to return class</param>
        /// <returns>WebFile object</returns>
        public static WebFile WebFile(string URL)
        {
            // Checks loaded files for a matching URL and returns the Web File object
            foreach (var file in MainForm.FilesOpenDatabase)
            {
                if (file.URL == URL)
                {
                    return(file);
                }
            }

            // Create a new Web File object as this URL doesn't exist in the database there anymore
            var newWebFile = new WebFile(Path.GetExtension(URL).Replace(".", "").ToUpper(), Path.GetFileNameWithoutExtension(new Uri(URL).LocalPath), WebFileExtensions.FileSize(URL), WebFileExtensions.FileLastModified(URL), new Uri(URL).Host.Replace("www.", ""), new Uri(URL).AbsoluteUri);

            // Add the new Web File to this instance of application
            MainForm.FilesOpenDatabase.Add(newWebFile);

            // Return the new Web File
            return(newWebFile);
        }