示例#1
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;
                    }
                }
            });
        }
示例#2
0
        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);
                }
            });
        }
示例#3
0
        public void ShowFiles(List <WebFile> dataFiles)
        {
            EnableSearchControls(false);
            var stopWatch = new Stopwatch();

            Program.log.InfoFormat("Starting query. Preferences - Sort: {0}, Type: {1}, Host: {2}", SelectedFilesSort.ToString(), SelectedFilesType.ToString(), SelectedFilesHost);
            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, StringExtensions.BytesToPrefix(jsonData.Size), StringExtensions.TimeSpanAge(jsonData.DateUploaded), jsonData.Host, jsonData.URL);
                            if (!(comboBoxFilterFiles.Items.Contains(jsonData.Host)))
                            {
                                comboBoxFilterFiles.Items.Add(jsonData.Host);
                            }
                        }
                    }

                    stopWatch.Stop();
                    labelResultsInfo.Text = string.Format("{0} Results ({2} seconds)", StringExtensions.FormatNumber(dataGridFiles.Rows.Count.ToString()), StringExtensions.FormatNumber(dataFiles.Count.ToString()), String.Format("{0:0.000}", stopWatch.Elapsed.TotalSeconds));
                    stopWatch.Reset();

                    tab.SelectedTab = CurrentTab;

                    comboBoxFilterFiles.DropDownWidth = ControlExtensions.GetMaxDropDownWidth(comboBoxFilterFiles);

                    imageSearchFiles.Image = Properties.Resources.magnify_orange;

                    if (dataGridFiles.Rows.Count == 0)
                    {
                        labelNoResultsFound.Visible = true;
                    }
                    else
                    {
                        labelNoResultsFound.Visible = false;
                    }

                    Program.log.Info("Successfully returned search results - " + labelResultsInfo.Text);
                }

                EnableSearchControls(true);
            });
        }