Example #1
0
        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");
                }
            });
        }
Example #2
0
        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;
                    }
                }
            });
        }
Example #3
0
        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); }
        }