private void LoadTopSearches() { try { Program.log.Info("Getting most searches"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetTopSearches(), (data) => { if (this.InvokeRequired) { Invoke(new LoadTopSearchesCallBack(LoadTopSearches), new object[] { }); } else { int count = 0; foreach (var tag in data) { if (count <= 100) { flowPanelMostSearches.Controls.Add(ControlExtensions.GetMostSearchTag(tag, count)); count++; } } Program.log.Info("Most searches returned successfully"); } }); } catch (Exception ex) { labelMostSearches.Visible = false; flowPanelMostSearches.Visible = false; Program.log.Error("Error getting top searches", ex); } /* Error occurred, so hide controls/skip... */ }
void showHosts() { imgSpinner.Visible = true; BackGroundWorker.RunWorkAsync <List <string> >(() => getFileHosts(), (data) => { if (tabDiscover.InvokeRequired) { loadHostsCallBack b = new loadHostsCallBack(showHosts); Invoke(b, new object[] { }); } else { dataGridDiscover.Rows.Clear(); int count = 1; foreach (string url in data) { dataGridDiscover.Rows.Add(count.ToString(), url, "Web", url); count += 1; } tab.SelectedTab = currentTab; imgSpinner.Visible = false; } }); }
private void ShowHosts() { Program.log.Info("Getting file hosts for Discover"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetFileHosts(), (data) => { if (tabDiscover.InvokeRequired) { var b = new loadHostsCallBack(ShowHosts); Invoke(b, new object[] { }); } else { dataGridDiscover.Rows.Clear(); int count = 1; foreach (string url in data) { dataGridDiscover.Rows.Add(count.ToString(), url, "Web", url); count += 1; } tab.SelectedTab = CurrentTab; } }); Program.log.Info("Successfully loaded hosts/servers"); }
private void LoadMostSearches() { try { ExceptionEvents.RetryOnException(3, TimeSpan.FromSeconds(2), () => { Program.Log.Info("Preparing to display most searches"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetMostSearches(), (data) => { if (InvokeRequired) { Invoke(new LoadMostSearchesCallBack(LoadMostSearches), new object[] { }); } else { int count = 0; foreach (var tag in data) { if (count <= 100) { FlowPanelMostSearches.Controls.Add(ControlExtensions.LabelMostSearch(tag, count)); } } count++; Program.Log.Info("Completed most searches"); } }); }); } catch (Exception ex) { LabelMostSearches.Visible = false; FlowPanelMostSearches.Visible = false; Program.Log.Error("Unable to get most searches", ex); } // Error occurred, so hide controls and skip... }
public void QueryFiles() { SetStatus("Searching files..."); Program.Log.InfoFormat("Starting to search files. Preferences - Query: {0}, Sort: {1}, Type: {2}, Host: {3}", TextBoxSearchQuery.Text, SelectedFilesSort.ToString(), SelectedFilesType.ToArray(), SelectedFilesHost); Stopwatch stopWatch = new Stopwatch(); EnableSearchControls(false); stopWatch.Start(); BackGroundWorker.RunWorkAsync(() => Query.Search(DbOpenFiles, TextBoxSearchQuery.Text, SelectedFilesSort, SelectedFilesType, SelectedFilesHost), (ftpFiles) => { if (InvokeRequired) { Invoke(new QueryFilesCallBack(QueryFiles), new object[] { }); } else { DataGridFiles.Rows.Clear(); ComboBoxHost.Items.Clear(); ComboBoxHost.Items.Add("Any"); //foreach (var ftpFile in data) //{ // DataGridFiles.Rows.Add(ftpFile.Name, StringExtensions.BytesToPrefix(ftpFile.Size), StringExtensions.TimeSpanAge(ftpFile.DateModified), new Uri(ftpFile.URL).Host, ftpFile.URL); // if (!(ComboBoxHost.Items.Contains(new Uri(ftpFile.URL).Host))) // ComboBoxHost.Items.Add(new Uri(ftpFile.URL).Host); //} ftpFiles.ForEach(ftpFile => { DataGridFiles.Rows.Add(ftpFile.Name, StringExtensions.BytesToPrefix(ftpFile.Size), StringExtensions.TimeSpanAge(ftpFile.DateModified), new Uri(ftpFile.URL).Host, ftpFile.URL); if (!(ComboBoxHost.Items.Contains(new Uri(ftpFile.URL).Host))) { ComboBoxHost.Items.Add(new Uri(ftpFile.URL).Host); } }); //for (int i = 0; i < ftpFiles.Count; ++i) //{ // var ftpFile = ftpFiles[i]; // DataGridFiles.Rows.Add(ftpFile.Name, StringExtensions.BytesToPrefix(ftpFile.Size), StringExtensions.TimeSpanAge(ftpFile.DateModified), new Uri(ftpFile.URL).Host, ftpFile.URL); // if (!(ComboBoxHost.Items.Contains(new Uri(ftpFile.URL).Host))) ComboBoxHost.Items.Add(new Uri(ftpFile.URL).Host); //} stopWatch.Stop(); SetStatus(string.Format("{0} Files ({1} seconds)", StringExtensions.FormatNumber(DataGridFiles.Rows.Count.ToString()), String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds))); stopWatch.Reset(); // Sets selected item to host if (SelectedFilesHost == "") { ComboBoxHost.SelectedIndex = 0; } else { ComboBoxHost.SelectedItem = SelectedFilesHost; } EnableSearchControls(true); Program.Log.Info(StatusStripStatus.Text); } }); }
/*************************************************************************/ /* Form Events */ /*************************************************************************/ private void MainForm_Load(object sender, EventArgs e) { Program.log.Info("Loading application"); LoadUserSettings(); CurrentTab = tabHome; CurrentTabTitle = titleHome; Directory.CreateDirectory(LocalExtensions.pathRoot); Directory.CreateDirectory(LocalExtensions.pathData); if (LocalExtensions.CheckForInternetConnection()) { BackGroundWorker.RunWorkAsync(() => Updates.CheckForUpdate()); LoadTopSearches(); BackGroundWorker.RunWorkAsync(() => Database.UpdateLocalDatabase(), CompletedChecks); } else { Controls.Remove(FrmSplashScreen); MessageBox.Show(this, "No Internet connection found. You need to be connected to the Internet to use FileMasta. Please check your connection and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Program.log.Info("Loaded application"); }
public void ShowFiles() { EnableSearchControls(false); var stopWatch = new Stopwatch(); Program.log.InfoFormat("Starting query. Preferences - Sort: {0}, Type: {1}, Host: {2}", SelectedFilesSort.ToString(), SelectedFilesType.ToList(), SelectedFilesHost); BackGroundWorker.RunWorkAsync <List <WebFile> >(() => Query.Search(DbOpenFiles, textBoxSearchQuery.Text, SelectedFilesSort), (data) => { if (this.InvokeRequired) { var b = new ShowFilesCallBack(ShowFiles); Invoke(b, new object[] { }); } else { dataGridFiles.Rows.Clear(); comboBoxHost.Items.Clear(); comboBoxHost.Items.Add("Any"); stopWatch.Start(); foreach (var jsonData in data) { if (SelectedFilesType.Contains(jsonData.Type) && jsonData.Host.Contains(SelectedFilesHost)) { dataGridFiles.Rows.Add(jsonData.Type, jsonData.Name, StringExtensions.BytesToPrefix(jsonData.Size), StringExtensions.TimeSpanAge(jsonData.DateUploaded), jsonData.Host, jsonData.URL); if (!(comboBoxHost.Items.Contains(jsonData.Host))) { comboBoxHost.Items.Add(jsonData.Host); } } } stopWatch.Stop(); SetStatus(string.Format("Successfully returned search results - {0} Results ({2} seconds)", StringExtensions.FormatNumber(dataGridFiles.Rows.Count.ToString()), StringExtensions.FormatNumber(DbOpenFiles.Count.ToString()), String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds))); stopWatch.Reset(); if (dataGridFiles.Rows.Count == 0) { labelNoResultsFound.Visible = true; } else { labelNoResultsFound.Visible = false; } Program.log.Info(toolStripStatus.Text); EnableSearchControls(true); // Sets selected item to host if (SelectedFilesHost == "") { comboBoxHost.SelectedIndex = 0; } else { comboBoxHost.SelectedItem = SelectedFilesHost; } } }); }
public void ShowFiles(List <WebFile> dataFiles) { EnableSearchControls(false); var stopWatch = new Stopwatch(); Program.log.Info("Searching files started"); imageSearchFiles.Image = Properties.Resources.loader; BackGroundWorker.RunWorkAsync <List <WebFile> >(() => Query.Search(dataFiles, textBoxSearchFiles.Text, SelectedFilesSort), (data) => { if (tabSearch.InvokeRequired) { var b = new loadFilesCallBack(ShowFiles); Invoke(b, new object[] { dataFiles }); } else { dataGridFiles.Rows.Clear(); comboBoxFilterFiles.Items.Clear(); comboBoxFilterFiles.Items.Add("Any"); stopWatch.Start(); foreach (var jsonData in data) { if (SelectedFilesType.Contains(jsonData.Type) && jsonData.Host.Contains(SelectedFilesHost)) { dataGridFiles.Rows.Add(jsonData.Type, jsonData.Name, TextExtensions.BytesToString(jsonData.Size), TextExtensions.GetTimeAgo(jsonData.DateUploaded), jsonData.Host, jsonData.URL); if (!(comboBoxFilterFiles.Items.Contains(jsonData.Host))) { comboBoxFilterFiles.Items.Add(jsonData.Host); } } } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; labelResultsInfo.Text = TextExtensions.GetFormattedNumber(dataGridFiles.Rows.Count.ToString()) + " / " + TextExtensions.GetFormattedNumber(dataFiles.Count.ToString()) + " Files (" + String.Format("{0:0.000}", ts.TotalSeconds) + " Seconds)"; stopWatch.Reset(); tab.SelectedTab = CurrentTab; comboBoxFilterFiles.DropDownWidth = ControlExtensions.DropDownWidth(comboBoxFilterFiles); imageSearchFiles.Image = Properties.Resources.magnify_orange; if (dataGridFiles.Rows.Count == 0) { labelNoResultsFound.Visible = true; } else { labelNoResultsFound.Visible = false; } EnableSearchControls(true); Program.log.Info("Successfully returned search results"); } }); }
private void LoadBookmarks() { try { Program.log.Info("Loading users bookmarks"); LabelStatus.Text = "Loading bookmarks..."; BackGroundWorker.RunWorkAsync <List <WebFile> >(() => Query.Search(UserBookmarks.BookmarkedFiles(), TextBoxSearchQuery.Text, SelectedFilesSort), (data) => { if (this.InvokeRequired) { var b = new LoadBookmarksCallBack(LoadBookmarks); Invoke(b, new object[] { }); } else { DataGridFiles.Rows.Clear(); ComboBoxHost.Items.Clear(); ComboBoxHost.Items.Add("Any"); foreach (var webFile in data) { if (SelectedFilesType.Contains(webFile.Type) && webFile.Host.Contains(SelectedFilesHost)) { DataGridFiles.Rows.Add(webFile.Type, webFile.Name, StringExtensions.BytesToPrefix(webFile.Size), StringExtensions.TimeSpanAge(webFile.DateUploaded), webFile.Host, webFile.URL); if (!(ComboBoxHost.Items.Contains(webFile.Host))) { ComboBoxHost.Items.Add(webFile.Host); } } } LabelStatus.Text = "Loaded"; if (DataGridFiles.Rows.Count == 0) { labelNoResultsFound.Visible = true; } else { labelNoResultsFound.Visible = false; } // Sets selected item to host if (SelectedFilesHost == "") { ComboBoxHost.SelectedIndex = 0; } else { ComboBoxHost.SelectedItem = SelectedFilesHost; } Program.log.Info("Successfully loaded users bookmarks"); } }); } catch (Exception ex) { Program.log.Error("Error getting users bookmarks", ex); } }
/*************************************************************************/ /* Form / Startup Events */ /*************************************************************************/ private void MainForm_Load(object sender, EventArgs e) { Program.Log.Info("Loading application tasks beginning"); Directory.CreateDirectory(LocalExtensions.PathRoot); Directory.CreateDirectory(LocalExtensions.PathData); Updates.CheckForUpdate(); LoadMostSearches(); BackGroundWorker.RunWorkAsync(() => Database.UpdateLocalDatabase(), InitializeFinished); }
public void showFiles(List <string> dataFiles) { BackGroundWorker.RunWorkAsync <List <string> >(() => searchFiles(dataFiles), (data) => { if (tabFiles.InvokeRequired) { loadFilesCallBack b = new loadFilesCallBack(showFiles); Invoke(b, new object[] { dataFiles }); } else { ComponentResourceManager resources = new ComponentResourceManager(typeof(MainForm)); cmboBoxFilesSort.SelectedIndex = 0; dataGridFiles.Rows.Clear(); cmboBoxFilesHost.Items.Clear(); cmboBoxFilesHost.Items.Add(resources.GetString("cmboBoxFilesHost.Items")); stopWatch.Start(); foreach (string jsonData in data) { var dataJson = JsonConvert.DeserializeObject <Models.WebFile>(jsonData); string formattedDate = dataJson.DateAdded; if (dataJson.DateAdded != "-") { formattedDate = UtilityTools.getTimeAgo(Convert.ToDateTime(dataJson.DateAdded)); } string formattedSize = dataJson.Size; if (dataJson.Size != "-") { formattedSize = UtilityTools.bytesToString(Convert.ToInt64(dataJson.Size)); } dataGridFiles.Rows.Add(dataJson.Type, dataJson.Title, formattedSize, formattedDate, dataJson.Host, dataJson.URL); if (!(cmboBoxFilesHost.Items.Contains(dataJson.Host))) { cmboBoxFilesHost.Items.Add(dataJson.Host); } } stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; lblFilesResultsInfo.Text = UtilityTools.getFormattedNumber(dataGridFiles.Rows.Count.ToString()) + " / " + UtilityTools.getFormattedNumber(dataFiles.Count.ToString()) + " Files (" + String.Format("{0:0.000}", ts.TotalSeconds) + " Seconds)"; stopWatch.Reset(); tab.SelectedTab = currentTab; cmboBoxFilesHost.DropDownWidth = UtilityTools.DropDownWidth(cmboBoxFilesHost); imgSpinner.Visible = false; } }); }
private void LoadTopSearches() { try { Program.log.Info("Getting top searches"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetTopSearches(), (data) => { if (tabHome.InvokeRequired) { var b = new LoadTopSearchesCallBack(LoadTopSearches); Invoke(b, new object[] { }); } else { int count = 0; foreach (var tag in data) { if (count <= 65) { flowLayoutTopSearches.Controls.Add(ControlExtensions.AddTopSearchTag(tag, count)); count++; } } // Add Credits Label to end of Top Searches panel var a = new Label { Text = "Powered by FileChef", Font = new Font(buttonFileType.Font.Name, 9, FontStyle.Regular), BackColor = Color.Transparent, ForeColor = Color.White, Margin = new Padding(0, 8, 0, 3), Cursor = Cursors.Hand, Name = "btnFileChef", AutoSize = true, }; a.Click += buttonFileChef_Click; flowLayoutTopSearches.Controls.Add(a); Program.log.Info("Top searches successful"); } }); } catch (Exception ex) { labelTopSearches.Visible = false; splitterHeaderTopSearches.Visible = false; flowLayoutTopSearches.Visible = false; Program.log.Error("Error getting top searches", ex); } /* Error occurred, so hide controls/skip... */ }
private void LoadBookmarks() { try { Program.Log.Info("Loading users bookmarks"); LabelStatus.Text = "Loading bookmarks..."; BackGroundWorker.RunWorkAsync <List <FtpFile> >(() => Query.Search(Bookmarks.BookmarkedFiles(), TextBoxSearchQuery.Text, SelectedFilesSort, SelectedFilesType, SelectedFilesHost), (List <FtpFile> data) => { if (InvokeRequired) { Invoke(new LoadBookmarksCallBack(LoadBookmarks), new object[] { }); } else { DataGridFiles.Rows.Clear(); ComboBoxHost.Items.Clear(); ComboBoxHost.Items.Add("Any"); foreach (var ftpFile in data) { DataGridFiles.Rows.Add(ftpFile.Name, StringExtensions.BytesToPrefix(ftpFile.Size), StringExtensions.TimeSpanAge(ftpFile.DateModified), new Uri(ftpFile.URL).Host, ftpFile.URL); if (!(ComboBoxHost.Items.Contains(new Uri(ftpFile.URL).Host))) { ComboBoxHost.Items.Add(new Uri(ftpFile.URL).Host); } } LabelStatus.Text = string.Format("{0} Bookmarks", StringExtensions.FormatNumber(DataGridFiles.Rows.Count.ToString())); // Sets selected item to host if (SelectedFilesHost == "") { ComboBoxHost.SelectedIndex = 0; } else { ComboBoxHost.SelectedItem = SelectedFilesHost; } Program.Log.Info("Successfully loaded users bookmarks"); } }); } catch (Exception ex) { Program.Log.Error("Error getting users bookmarks", ex); } }
/*************************************************************************/ /* Form / Startup Events */ /*************************************************************************/ private void MainForm_Load(object sender, EventArgs e) { Program.log.Info("Starting load events"); Directory.CreateDirectory(LocalExtensions.pathRoot); Directory.CreateDirectory(LocalExtensions.pathData); if (LocalExtensions.IsConnectionEnabled()) { Updates.CheckForUpdate(); LoadTopSearches(); BackGroundWorker.RunWorkAsync(() => Database.UpdateLocalDatabase(), InitializeFinished); } else { Controls.Remove(FrmSplashScreen); MessageBox.Show(this, "No Internet connection found. You need to be connected to the Internet to use FileMasta. Please check your connection and try again.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } Program.log.Info("Completed all load events"); }
private void LoadServers() { Program.log.Info("Loading ftp servers"); BackGroundWorker.RunWorkAsync <List <string> >(() => GetServers(), (data) => { if (this.InvokeRequired) { Invoke(new loadHostsCallBack(LoadServers), new object[] { }); } else { dataGridDiscover.Rows.Clear(); int count = 1; foreach (string url in data) { dataGridDiscover.Rows.Add(count.ToString(), url, "FTP", url); count += 1; } } }); Program.log.Info("Successfully loaded servers"); }
public static void Start() { bgWorker = new BackGroundWorker(TimeSpan.FromSeconds(300)); }
public void GetDirectoryListing() { Program.log.InfoFormat("Processing directory listing for URL : " + currentURL); BackGroundWorker.RunWorkAsync <List <WebFile> >(() => Query.SpecialSearch(currentURL), (data) => { if (tabDiscover.InvokeRequired) { var b = new loadDirectoryListingCallBack(GetDirectoryListing); Invoke(b, new object[] { }); } else { var foundItems = new List <string>(); foreach (var jsonData in data) { var removedStart = jsonData.URL.Remove(0, currentURL.Length); var splitItems = removedStart.Split('/'); var itemText = splitItems[0]; if (itemText != null) { if (!foundItems.Contains(itemText)) { var newItem = new List <string>(); if (Path.HasExtension(itemText)) { // File newItem.Add(jsonData.Type); newItem.Add(jsonData.Name + "." + jsonData.Type.ToLower()); newItem.Add(StringExtensions.BytesToPrefix(jsonData.Size)); newItem.Add(StringExtensions.TimeSpanAge(jsonData.DateUploaded)); } else { // Folder newItem.Add("Folder"); newItem.Add(Uri.UnescapeDataString(itemText)); newItem.Add("-"); newItem.Add("-"); } newItem.Add(jsonData.Host); newItem.Add(currentURL + itemText); dataGridDirectoryListing.Rows.Add(newItem.ToArray()); foundItems.Add(itemText); } } } labelDirectoryStatus.Text = "Completed"; if (dataGridDirectoryListing.Rows.Count == 0) { labelDirectoryEmptyResults.Visible = true; } else { labelDirectoryEmptyResults.Visible = false; } Program.log.Info("Successfully returned directory listing"); } }); }
private void ButtonRequestSize_Click(object sender, EventArgs e) { // Request file size from URL ButtonRequestSize.Visible = false; BackGroundWorker.RunWorkAsync <string>(() => StringExtensions.BytesToPrefix(WebExtensions.FtpFileSize(CurrentFile.URL)), (data) => { LabelValueSize.Text = data; }); }
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; }); }
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; }); }