BrolFileStatsControl.cs
Description du code
BrolFileStatsControl.cs est un fichier du projet BrolFileStats.Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/brolfilestats/.
Projet BrolFileStats :
Statistiques en CSharp.
Code source ou contenu du fichier
Code c# (BrolFileStatsControl.cs) (441 lignes)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Drawing; using System.Data; using System.Text; using System.Windows.Forms; using System.IO; using be.gaudry.explorer.filestats.model; using be.gaudry.model.enums; using be.gaudry.view; using be.gaudry.events; using be.gaudry.model; namespace be.gaudry.explorer.filestats.view.controls { public partial class BrolFileStatsControl : UserControl { #region declarations and constructors private FileStatsParser fileParser; private Stat stat; private string startProcessStr, stopProcessStr; public BrolFileStatsControl() { startProcessStr = "Actualiser"; stopProcessStr = "Arrêter"; InitializeComponent(); //setStartBtn(false); startParseBtn.Text = startProcessStr; progressGB.Dock = DockStyle.Fill; startPathLbl.Text = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments); initStatsTypeCB(); initNbResultsToDisplayCB(); } private void initNbResultsToDisplayCB() { nbResultsToDisplayCB.Items.Add("Tous"); nbResultsToDisplayCB.Items.Add(5); nbResultsToDisplayCB.Items.Add(10); nbResultsToDisplayCB.Items.Add(15); nbResultsToDisplayCB.SelectedIndex = 0; } private void initStatsTypeCB() { statsTypeCB.DisplayMember = "Value"; statsTypeCB.ValueMember = "Key"; statsTypeCB.SelectedValue = FILE_SEARCHTYPE.DirSize; setSearchType((FILE_SEARCHTYPE)statsTypeCB.SelectedValue); } #endregion #region display and set parameters public void addContextMenuItems(ContextMenu menu) { /* //menu.MenuItems.Add(ToolStripSeparator); menu.MenuItems. Add(searchInSubDirsTsMi); menu.MenuItems.Add(searchInHiddenFilesTsMi); menu.MenuItems.Add(searchInSystemFilesTsMi); menu.MenuItems.Add(searchKeySensitiveTsMi); menu.MenuItems.Add(searchTypeTsCB); //menu.MenuItems.Add(ToolStripSeparator); menu.MenuItems.Add(displayChartTsMi); menu.MenuItems.Add(displayDGVTsMi); menu.MenuItems.Add(displaySearchOptionsTsMi); menu.MenuItems.Add(displayTop10TsMi); * */ } public void setStartPath(string currentDirPath) { startPathLbl.Text = currentDirPath; } public void parse(string currentDirPath) { startPathLbl.Text = currentDirPath; search(); } private void setStartBtn(bool started) { if(started) { startParseBtn.Text = stopProcessStr; startParseBtn.Image = global::be.gaudry.explorer.filestats.Properties.Resources.stopProcess; } else { startParseBtn.Text = startProcessStr; startParseBtn.Image = global::be.gaudry.explorer.filestats.Properties.Resources.startProcess; } startParseBtn.ImageAlign = ContentAlignment.MiddleRight; startParseBtn.TextAlign = ContentAlignment.MiddleLeft; startParseBtn.TextImageRelation = TextImageRelation.TextBeforeImage; startParseBtn.AutoSize = true; } private void browseStartPathBtn_Click(object sender, EventArgs e) { folderBrowserDialog.SelectedPath = startPathLbl.Text; folderBrowserDialog.Description = "Sélectionnez le répertoire dans lequel se trouve les fichiers à renommer..."; folderBrowserDialog.ShowNewFolderButton = false; if (DialogResult.OK == folderBrowserDialog.ShowDialog()) { startPathLbl.Text = folderBrowserDialog.SelectedPath; } } private void statsTypeCB_SelectionChangeCommitted(object sender, EventArgs e) { FILE_SEARCHTYPE searchType = (FILE_SEARCHTYPE)EnumHelper.getEnum(statsTypeCB.SelectedItem); setSearchType(searchType); search(); } private void setSearchType(FILE_SEARCHTYPE searchType) { fileParser.SearchType = searchType; chartControl.FormatString -= this.formatPathString; chartControl.FormatValue -= this.formatDirectoryLength; keySensitiveChkB.Visible = false; switch (searchType) { case FILE_SEARCHTYPE.Extension: stat.LabelFormat = "{0:0.0%} des fichiers ({1}) pour l'extension \"{2}\""; chartControl.Title = "Répartition des fichiers par extensions."; chartControl.setColumnTitle(1, "Extension"); keySensitiveChkB.Visible = true; chartControl.FormatString += this.formatPathString; break; case FILE_SEARCHTYPE.Count: stat.LabelFormat = "{0:0.0%} de fichiers ({1}) pour le répertoire {2}"; chartControl.Title = "Répartition par nombre de fichiers."; chartControl.setColumnTitle(1, "Répertoire"); chartControl.FormatString += this.formatPathString; break; case FILE_SEARCHTYPE.FileSize: stat.LabelFormat = "{0:0.0%} de la taille pour le fichier {2} ({1} octets)"; chartControl.Title = "Répartition par taille de fichiers."; chartControl.setColumnTitle(1, "Fichier"); chartControl.FormatString += this.formatPathString; chartControl.FormatValue += this.formatDirectoryLength; break; case FILE_SEARCHTYPE.DirSize: stat.LabelFormat = "{0:0.0%} de la taille totale ({1} octets) pour le répertoire {2}"; chartControl.Title = "Répartition par taille de répertoires."; chartControl.setColumnTitle(1, "Répertoire"); chartControl.FormatString += this.formatPathString; chartControl.FormatValue += this.formatDirectoryLength; break; case FILE_SEARCHTYPE.LastAccess: stat.LabelFormat = "{0:0.0%} de fichiers ({1}) accédés {2}"; chartControl.Title = "Répartition des fichiers par date d'accès."; chartControl.setColumnTitle(1, "Dernier accès"); break; case FILE_SEARCHTYPE.Attribute: stat.LabelFormat = "{0:0.0%}({1} fichiers avec l'attribut {2})"; chartControl.Title = "Répartition des fichiers par attributs."; chartControl.setColumnTitle(1, "Attribut"); break; default: chartControl.Title = ""; chartControl.setColumnTitle(1, ""); break; } } #endregion #region chart format events private string formatPathString(string stringToFormat) { return stringToFormat.Substring(stringToFormat.LastIndexOf(Path.DirectorySeparatorChar)+1); } private string formatDirectoryLength(double value) { return Units.getLengthString((long)value); } #endregion #region search private void search() { if (startParseBtn.Text.Equals(startProcessStr)) { setStartBtn(true); startSearch(); } else { mediaBrowserBgWorker.CancelAsync(); setStartBtn(false); //browsePgB.ParameterValue = 0; } } private void startSearch() { String error = null; String startPath = startPathLbl.Text; if (!Directory.Exists(startPath)) { error = String.Format("\n{0} n'est pas un chemin valide.", startPath); } else { setStartBtn(true); if (mediaBrowserBgWorker.IsBusy) { error = "Impossible de lancer le traitement car un traitement est déjà en cours..."; } else { fileParser.StartPath = startPath; fileParser.PreCalcProgress = false; displayProgressGB(); stat.clear(); fileParser.Stat = stat; mediaBrowserBgWorker.RunWorkerAsync(); } } if (error != null) { MessageBox.Show( this, error, "Impossible de démarrer le traitement", MessageBoxButtons.OK, MessageBoxIcon.Stop ); } } #endregion #region progress methods private void displayProgressGB() { browsePgB.Value = 0; browsePgB.Style = ProgressBarStyle.Marquee; curDirValLbl.Text = ""; progressGB.Visible = true; } /// <summary> /// Reinit the progress max value /// (this value depends of the quantity of files into the directory to scan) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void reinitProgressMaxValue(object sender, EventArgs e) { searchResultsLbl.Visible = false; } /// <summary> /// Start asynchroneous search /// </summary> /// <remarks> /// In this method, do not modify any graphic component /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void mediaBrowserBgWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker bgw = sender as BackgroundWorker; // Call the model asynchroneous search e.Result = fileParser.parse(bgw, e); } /// <summary> /// Display results throws by the search /// </summary> /// <remarks> /// The graphic components may here react at the results /// </remarks> /// <param name="sender"></param> /// <param name="e"></param> private void mediaBrowserBgWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { switch (e.ProgressPercentage) { case (int)BGWORKER.currentInfo: { String s = e.UserState as String; if (s != null) curDirValLbl.Text = s; break; } case (int)BGWORKER.progressBarStyle_Block: { browsePgB.Style = ProgressBarStyle.Blocks; break; } default: { if (e.ProgressPercentage > 0) { browsePgB.Value = e.ProgressPercentage; } break; } } } /* private void increaseDirSize(FileInfo fi, ProgressChangedEventArgs e) { if (!stat.Dictionary.ContainsKey(fi.DirectoryName)) { double size = (double)BrolFile.getDirectoryLength(mediaBrowserBgWorker, e, fi.Directory, true); stat.increase(fi.DirectoryName, size); } }*/ private void mediaBrowserBgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { setStartBtn(false); browsePgB.Value = 0; /*try { if (e.Result != null) { previousMaxResult = (float)e.Result; } } catch (System.Reflection.TargetInvocationException) { }*/ if (e.Error != null) { searchResultsLbl.Text = "Erreur : " + e.Error.Message; } else if (e.Cancelled) { searchResultsLbl.Text = "La recherche a été stoppée avant sa fin... Tous les résultats ne sont pas présents."; } else { //string columnTitle, chartTitle; try { chartControl.TopCountToDisplay = (int)nbResultsToDisplayCB.SelectedItem; } catch { chartControl.TopCountToDisplay = 0; } chartControl.setBrolChart(stat/*, chartTitle, columnTitle*/); chartControl.Visible = true; searchResultsLbl.Text = String.Format("Taille du répertoire : {0}", Units.getLengthString((long)e.Result)); } progressGB.Visible = false; } #endregion #region display and search options private void includeHiddenFilesChkB_Click(object sender, EventArgs e) { } private void includeHiddenFilesTsMi_Click(object sender, EventArgs e) { } private void includeSystemFilesChkB_Click(object sender, EventArgs e) { } private void searchInSystemFilesTsMi_Click(object sender, EventArgs e) { } private void includeSubDirChkB_Click(object sender, EventArgs e) { } private void searchInSubDirsTsMi_Click(object sender, EventArgs e) { } private void displaySearchOptionsTsMi_Click(object sender, EventArgs e) { } private void nbResultsToDisplayCB_SelectionChangeCommitted(object sender, EventArgs e) { if (this.Visible) { try { chartControl.TopCountToDisplay = (int)nbResultsToDisplayCB.SelectedItem; Console.WriteLine("nb items to display : " + chartControl.TopCountToDisplay); } catch { chartControl.TopCountToDisplay = 0; } chartControl.setBrolChart(stat/*, chartTitle, columnTitle*/); } } #endregion private void BrolFileStatsControl_Load(object sender, EventArgs e) { startParseBtn.Text = startProcessStr; } private void startParseBtn_Click(object sender, EventArgs e) { search(); } } }
Structure et Fichiers du projet
Afficher/masquer...Icône | Nom | Taille | Modification |
Pas de sous-répertoires. | |||
Icône | Nom | Taille | Modification |
| _ | Répertoire parent | 0 octets | 1731590509 14/11/2024 14:21:49 |
Utilisation de l'explorateur de code
- Navigation :
- Un clic sur une icône de répertoire ouvre ce répertoire pour en afficher les fichiers.
- Lorsque le répertoire en cours ne contient pas de sous-répertoires il est possible de remonter vers le répertoire parent.
- La structure de répertoires en treetable (tableau en forme d'arborescence) n'est plus possibledans cette version.
- Un clic sur une icône de fichier ouvre ce fichier pour en afficher le code avec la coloration syntaxique adaptée en fonction du langage principal utilisé dans le fichier.
- Affichage :
- Il est possible de trier les répertoires ou les fichiers selon certains critères (nom, taille, date).
- Actions :
- Les actions possible sur les fichiers dépendent de vos droits d'utilisateur sur le site. Veuillez activer le mode utilisateur pour activer les actions.
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-brolfilestats-source-rf-view/controls//BrolFileStatsControl.cs.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.