예제 #1
0
        /// <summary>
        /// Show details/info for a WebFile
        /// </summary>
        /// <param name="File">WebFile object</param>
        /// <param name="createNewInstance">Whether to create a new instance</param>
        public void ShowFileDetails(WebFile File, bool createNewInstance = true)
        {
            Program.log.Info("Showing file details dialog : " + File.URL);

            if (createNewInstance)
            {
                FrmFileDetails = new FileDetails();
            }

            FrmFileDetails.currentFile       = File;
            FrmFileDetails.infoFileName.Text = File.Name;
            FrmFileDetails.infoName.Text     = File.Name;
            FrmFileDetails.infoReferrer.Text = File.Host;
            FrmFileDetails.infoType.Text     = File.Type;
            FrmFileDetails.infoFileURL.Text  = Uri.UnescapeDataString(File.URL);

            // Builds parts of the URL into a better presented string, simply replaces '/' with '>' and no filename
            var url         = new Uri(File.URL);
            var directories = new StringBuilder();

            if (!File.URL.StartsWith(LocalExtensions.userDownloadsDirectory))
            {
                directories.Append(File.Host);
            }
            else
            {
                FrmFileDetails.infoReferrer.Text = "Local";
            }                                                                                                                                                        // Appends the Host at the start if not Local, else it will be named 'Local'
            foreach (string path in url.LocalPath.Split('/', '\\'))
            {
                if (!Path.HasExtension(path))
                {
                    directories.Append(path + "> ");
                }
            }
            FrmFileDetails.infoDirectory.Text = directories.ToString();

            FrmFileDetails.infoSize.Text = TextExtensions.BytesToString(File.Size);
            FrmFileDetails.infoAge.Text  = TextExtensions.GetTimeAgo(File.DateUploaded);

            FrmFileDetails.Dock = DockStyle.Fill;
            if (!createNewInstance)
            {
                FrmFileDetails.CheckFileEvents();
            }
            if (createNewInstance)
            {
                tabBlank.Controls.Clear(); tabBlank.Controls.Add(FrmFileDetails);
            }
            tab.SelectedTab = tabBlank;

            Program.log.Info("Successfully loaded file details dialog");
        }
예제 #2
0
        /// <summary>
        /// Show file details for a WebFile
        /// </summary>
        /// <param name="file">WebFile object</param>
        /// <param name="createNewInstance">Whether to create a new instance</param>
        public void ShowFileDetails(WebFile file, bool createNewInstance = true)
        {
            Program.log.Info("Showing file details dialog : " + file.URL);

            if (createNewInstance)
            {
                FrmFileDetails = new FileDetails();
            }

            FrmFileDetails.currentFile       = file;
            FrmFileDetails.infoFileName.Text = file.Name;
            FrmFileDetails.infoName.Text     = file.Name;
            FrmFileDetails.infoReferrer.Text = file.Host;
            FrmFileDetails.infoType.Text     = file.Type;
            FrmFileDetails.infoFileURL.Text  = Uri.UnescapeDataString(file.URL);

            // Build all parts of the URL into a better presented string
            var url         = new Uri(file.URL);
            var directories = new StringBuilder(file.Host);

            foreach (string path in url.LocalPath.Split('/'))
            {
                if (!Path.HasExtension(path))
                {
                    directories.Append(path + "> ");
                }
            }
            FrmFileDetails.infoDirectory.Text = directories.ToString();

            FrmFileDetails.infoSize.Text = TextExtensions.BytesToString(file.Size);
            FrmFileDetails.infoAge.Text  = TextExtensions.GetTimeAgo(file.DateUploaded);

            FrmFileDetails.Dock = DockStyle.Fill;
            if (!createNewInstance)
            {
                FrmFileDetails.CheckFileEvents();
            }
            if (createNewInstance)
            {
                tabBlank.Controls.Clear(); tabBlank.Controls.Add(FrmFileDetails);
            }
            tab.SelectedTab = tabBlank;

            Program.log.Info("Successfully loaded file details dialog");
        }
예제 #3
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");
                }
            });
        }
예제 #4
0
        /// <summary>
        /// Gets recently added files in the database by checking if file was uploaded in the last two weeks
        /// </summary>
        public void LoadRecentlyAddedFiles()
        {
            try
            {
                int itemCount  = 1;
                var addedHosts = new List <string>();
                Program.log.Info("Getting recently added files");
                var copiedItems = new List <WebFile>(FilesOpenDatabase);
                copiedItems.Shuffle();
                foreach (var jsonData in copiedItems)
                {
                    if (DateTime.Today < jsonData.DateUploaded.Date.AddDays(14) && jsonData.Size > 0 && !addedHosts.Contains(jsonData.Host) && itemCount <= 6)
                    {
                        itemCount++;
                        addedHosts.Add(jsonData.Host);
                        dataGridRecentlyAdded.Rows.Add(jsonData.Type, jsonData.Name, TextExtensions.BytesToString(jsonData.Size), TextExtensions.GetTimeAgo(jsonData.DateUploaded), jsonData.Host, jsonData.URL);
                    }
                }

                Program.log.Info("Recently added files successful");
            }
            catch (Exception ex) { labelRecentlyAdded.Visible = false; splitterHeaderRecentlyAdded.Visible = false; dataGridRecentlyAdded.Visible = false; Program.log.Error("Error getting recently added files", ex); } /* Error occurred, so hide controls/skip... */
        }