public void SearchFiles() { SetStatus("Searching files.."); if (Uri.TryCreate(textBoxSearchQuery.Text, UriKind.Absolute, out Uri uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps) && uriResult != null) { if (WebFileExtensions.URLExists(uriResult.ToString())) { try { ShowFileDetails(Database.WebFile(textBoxSearchQuery.Text), dataGridFiles); textBoxSearchQuery.Text = null; } catch (Exception ex) { MessageBox.Show("There was an issue requesting this file. Make sure it exists on the server you're trying to access.\n\n" + ex.Message); } } else { MessageBox.Show(this, "There was an issue requesting this file. Make sure it exists on the server you're trying to access."); } } else { ShowFiles(); } }
/// <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.WebFileSize($"{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); } }
private void btnRequestFileSize_ClickButtonArea(object Sender, MouseEventArgs e) { // Request file size from URL buttonRequestFileSize.Visible = false; BackGroundWorker.RunWorkAsync <string>(() => TextExtensions.BytesToString(WebFileExtensions.GetFileSize(currentFile.URL)), (data) => { infoSize.Text = data; }); }
/// <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.DbOpenFiles) { 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.FtpFileSize(URL), WebFileExtensions.FtpFileTimestamp(URL), new Uri(URL).Host.Replace("www.", ""), new Uri(URL).AbsoluteUri); // Add the new Web File to this instance of application MainForm.DbOpenFiles.Add(newWebFile); // Return the new Web File return(newWebFile); }
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; }); }
/// <summary> /// Get web file info from internal database, or creates a new object if it doesn't exist /// </summary> /// <param name="URL">Matches URL with WebFile.URL to return object</param> /// <returns>WebFile object</returns> public static WebFile FileInfoFromURL(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.GetFileSize(URL), WebFileExtensions.GetFileLastModified(URL), new Uri(URL).Host.Replace("www.", ""), new Uri(URL).AbsoluteUri); // Add the new Web File to current local database MainForm.FilesOpenDatabase.Add(newWebFile); // Return the new Web File return(newWebFile); }