Keine Cache-Version

Caching deaktiviert Standardeinstellung für diese Seite:aktiviert (code LNG204)
Wenn die Anzeige zu langsam ist, können Sie den Benutzermodus deaktivieren, um die zwischengespeicherte Version anzuzeigen.

Console.cs

Description du code

Console.cs est un fichier du projet BiblioBrol.
Ce fichier est situé dans /var/www/bin/sniplets/bibliobrol/src/.

Projet BiblioBrol :

Gestion de media en CSharp.

Pour plus d'infos, vous pouvez consulter la brève analyse.

Code source ou contenu du fichier

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing;
  4. using System.Text;
  5. using System.Windows.Forms;
  6. using be.gaudry.bibliobrol.config;
  7. using be.gaudry.bibliobrol.view.dialogs;
  8. using be.gaudry.observer;
  9. using be.gaudry.view.dialogs;
  10. using be.gaudry.view;
  11.  
  12. namespace be.gaudry.bibliobrol.view.utils
  13. {
  14. internal delegate void UpdateDelegateHandler(Notification notification);
  15. public partial class Console : UserControl, be.gaudry.observer.IObserver
  16. {
  17. #region declarations
  18. private int lineNbr, maxLines;
  19. private Font fontNormal, fontAvert;
  20. private UpdateDelegateHandler UpdateDelegate;
  21.  
  22.  
  23. private bool buffered;
  24. private List<Exception> exBuffer = new List<Exception>();
  25. #endregion
  26.  
  27. #region constructors and destructors
  28. public Console()
  29. {
  30. buffered = false;
  31. InitializeComponent();
  32. UpdateDelegate = new UpdateDelegateHandler(safeWrite);
  33. lineNbr = 0;
  34. maxLines = 200;
  35. fontNormal = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  36. fontAvert = new System.Drawing.Font(fontNormal, ((System.Drawing.FontStyle)(System.Drawing.FontStyle.Bold)));
  37. subscribeToObservables();
  38. }
  39. ~Console()
  40. {
  41. unsubscribeToObservables();
  42. Dispose(false);
  43. }
  44.  
  45. #endregion
  46.  
  47. #region IObserver Members
  48.  
  49. public void update(Notification notification)
  50. {
  51. try
  52. {
  53. cleanTsStatus();
  54. StringBuilder str;
  55. switch (notification.Level)
  56. {
  57. case Notification.VERBOSE.persistentOperation:
  58. if (Config.ConsolePersistentOps)
  59. {
  60. consoleRTB.SelectionColor = System.Drawing.Color.Orchid;
  61. write(notification);
  62. }
  63. break;
  64. case Notification.VERBOSE.internalNotification:
  65. if (Config.ConsoleDebug)
  66. {
  67. consoleRTB.SelectionColor = System.Drawing.Color.DarkViolet;
  68. write(notification);
  69. }
  70. break;
  71. case Notification.VERBOSE.showErrors:
  72. if (exBuffer.Count > 0)
  73. {
  74. new ExceptionDialog(exBuffer).Show();
  75. exBuffer.Clear();
  76. }
  77. buffered = true;
  78. break;
  79. case Notification.VERBOSE.showNewErrors:
  80. exBuffer.Clear();
  81. buffered = false;
  82. break;
  83. case Notification.VERBOSE.hideErrors:
  84. buffered = true;
  85. break;
  86. case Notification.VERBOSE.advancedOperation:
  87. if (Config.ConsoleAdvancedOps)
  88. {
  89. consoleRTB.SelectionColor = System.Drawing.Color.LightSeaGreen;
  90. write(notification);
  91. }
  92. break;
  93. case Notification.VERBOSE.basicOperation:
  94. if (Config.ConsoleBasicOps)
  95. {
  96. consoleRTB.SelectionColor = System.Drawing.Color.ForestGreen;
  97. write(notification);
  98. }
  99. break;
  100. case Notification.VERBOSE.criticalError:
  101. if (this.ParentForm is IMDIParent)
  102. {
  103. ((IMDIParent)this.ParentForm).setStatusMessage(
  104. global::be.gaudry.bibliobrol.Properties.Resources.brolLevel4,
  105. "Erreur critique : " + notification.Title,
  106. notification.Msg
  107. );
  108. }
  109. if (Config.ConsoleCriticalError)
  110. {
  111. consoleRTB.SelectionColor = System.Drawing.Color.Crimson;
  112. consoleRTB.SelectionFont = fontAvert;
  113. write(notification);
  114. consoleRTB.SelectionFont = fontNormal;
  115. }
  116. if (Config.PopupCriticalError)
  117. {
  118. if (buffered)
  119. {
  120. exBuffer.Add(notification.NotificationException);
  121. }
  122. else
  123. {
  124. ExceptionDialog.ShowDialog(notification.NotificationException, this.ParentForm);
  125. }
  126. /*str = new StringBuilder(notification.Msg);
  127.   appendException(str, notification.NotificationException);
  128.   MessageBox.Show(
  129.   str.ToString(),
  130.   "ERREUR CRITIQUE : " + notification.Title,
  131.   MessageBoxButtons.OK,
  132.   MessageBoxIcon.Stop,
  133.   MessageBoxDefaultButton.Button1);*/
  134. }
  135. break;
  136. case Notification.VERBOSE.debug:
  137. if (Config.ConsoleDebug)
  138. {
  139. consoleRTB.SelectionColor = System.Drawing.Color.DarkOrange;
  140. write(notification);
  141. }
  142. break;
  143. case Notification.VERBOSE.lowError:
  144. if (Config.ConsoleLowError)
  145. {
  146. consoleRTB.SelectionColor = System.Drawing.Color.Crimson;
  147. write(notification);
  148. }
  149. break;
  150. case Notification.VERBOSE.error:
  151. if (this.ParentForm is IMDIParent)
  152. {
  153. ((IMDIParent)this.ParentForm).setStatusMessage(
  154. global::be.gaudry.bibliobrol.Properties.Resources.brolLevel3,
  155. "Erreur : " + notification.Title,
  156. notification.Msg
  157. );
  158. }
  159. str = new StringBuilder(notification.Msg);
  160. if (Config.ConsoleOpsResult)
  161. {
  162. consoleRTB.SelectionColor = System.Drawing.Color.Crimson;
  163. consoleRTB.SelectionFont = fontAvert;
  164. write(notification);
  165. consoleRTB.SelectionFont = fontNormal;
  166. if (notification.NotificationException != null)
  167. {
  168. str.Append(notification.NotificationException.Message);
  169. str.Append("\n\nVous pouvez consulter la console pour un rapport détaillé de l'erreur.");
  170. }
  171. }
  172. if (Config.PopupOpsResult)
  173. {
  174. if (notification.NotificationException != null)
  175. {
  176. if (buffered)
  177. {
  178. exBuffer.Add(notification.NotificationException);
  179. }
  180. else
  181. {
  182. ExceptionDialog.ShowDialog(notification.NotificationException, this.ParentForm);
  183. }
  184. }
  185. else MessageBox.Show(
  186. this.ParentForm,
  187. str.ToString(),
  188. "ERREUR : " + notification.Title,
  189. MessageBoxButtons.OK,
  190. MessageBoxIcon.Error,
  191. MessageBoxDefaultButton.Button1
  192. );
  193. }
  194. break;
  195. case Notification.VERBOSE.opsResult:
  196. if (!notification.Title.Equals(String.Empty) && this.ParentForm is IMDIParent)
  197. {
  198. ((IMDIParent)this.ParentForm).setStatusMessage(
  199. global::be.gaudry.bibliobrol.Properties.Resources.brolLevel1,
  200. notification.Title,
  201. notification.Msg
  202. );
  203. }
  204. if (Config.ConsoleOpsResult)
  205. {
  206. consoleRTB.SelectionColor = System.Drawing.Color.SteelBlue;
  207. write(notification);
  208. }
  209. if (Config.PopupOpsResult)
  210. {
  211. MessageBox.Show(
  212. notification.Msg,
  213. String.Empty.Equals(notification.Title) ? "Information" : notification.Title,
  214. MessageBoxButtons.OK,
  215. MessageBoxIcon.Information,
  216. MessageBoxDefaultButton.Button1
  217. );
  218. }
  219. break;
  220. default:
  221. consoleRTB.SelectionColor = System.Drawing.Color.Black;
  222. write(notification);
  223. break;
  224. }
  225. if (lineNbr != 0 && (lineNbr % maxLines == 0))
  226. {
  227. DialogResult r = MessageBox.Show(
  228. this,
  229. String.Format("La console contient actuellement {0} notifications.Toutes les {1} notifications il est préférable de supprimer les anciens message afin de maintenir un niveau de performances acceptable.\nDésirez-vous vider la console ?", lineNbr, maxLines),
  230. "Console",
  231. MessageBoxButtons.YesNo,
  232. MessageBoxIcon.Exclamation,
  233. MessageBoxDefaultButton.Button1);
  234. if (r == DialogResult.Yes)
  235. {
  236. Clear();
  237. }
  238. }
  239. }
  240. catch (Exception ex)
  241. {
  242. StringBuilder str = new StringBuilder("Tentative d'écriture dans la console depuis un autre thread : ");
  243. appendException(str, ex);
  244. System.Console.WriteLine(str.ToString());
  245. }
  246. }
  247.  
  248. #endregion
  249.  
  250. #region private methods
  251. private void cleanTsStatus()
  252. {
  253. if (this.ParentForm is IMDIParent)
  254. {
  255. ((IMDIParent)this.ParentForm).setStatusMessage(
  256. global::be.gaudry.bibliobrol.Properties.Resources.brolConsole,
  257. String.Format("{0} message(s) dans la console", Count),
  258. ""
  259. );
  260. }
  261. }
  262. private void subscribeToObservables()
  263. {
  264. Config.instanceAddObserver(this);
  265. //model
  266. model.dao.DAOFactory.Instance.getConfigDao().addObserver(this);
  267. model.dao.DAOFactory.Instance.getPersonDao().addObserver(this);
  268. model.dao.DAOFactory.Instance.getBrolDao().addObserver(this);
  269. model.dao.DAOFactory.Instance.getMediaBrolDao().addObserver(this);
  270. model.dao.DAOFactory.Instance.getTaskDao().addObserver(this);
  271. model.dao.DAOFactory.Instance.getExporterDao().addObserver(this);
  272. model.dao.DAOFactory.Instance.getImporterDao().addObserver(this);
  273. model.dao.DAOFactory.Instance.getStatsDao().addObserver(this);
  274. model.dao.DAOFactory.Instance.getSerieDao().addObserver(this);
  275. //other views
  276. StaticObservable.addObserver(this);
  277. }
  278. private void unsubscribeToObservables()
  279. {
  280. Config.instanceRemoveObserver(this);
  281. //model
  282. model.dao.DAOFactory.Instance.getConfigDao().removeObserver(this);
  283. model.dao.DAOFactory.Instance.getPersonDao().removeObserver(this);
  284. model.dao.DAOFactory.Instance.getBrolDao().removeObserver(this);
  285. model.dao.DAOFactory.Instance.getMediaBrolDao().removeObserver(this);
  286. model.dao.DAOFactory.Instance.getTaskDao().removeObserver(this);
  287. model.dao.DAOFactory.Instance.getExporterDao().removeObserver(this);
  288. model.dao.DAOFactory.Instance.getImporterDao().removeObserver(this);
  289. model.dao.DAOFactory.Instance.getStatsDao().removeObserver(this);
  290. model.dao.DAOFactory.Instance.getSerieDao().removeObserver(this);
  291. //other views
  292. StaticObservable.removeObserver(this);
  293. }
  294.  
  295. private void appendException(StringBuilder str, Exception e)
  296. {
  297. if (e != null)
  298. {
  299. str.Append("\nDétails de l'erreur : \nSource : ");
  300. str.Append(e.Source);
  301. str.Append("\nException : ");
  302. str.Append(e.GetType().ToString());
  303. str.Append("\nTargetSite : ");
  304. str.Append(e.TargetSite);
  305. str.Append("\nInnerException : ");
  306. str.Append(e.InnerException);
  307. str.Append("\nStackTrace :\n");
  308. str.Append(e.StackTrace);
  309. str.Append("\n\nAide : http://www.gaudry.be/infobrol.html");
  310. }
  311. }
  312. private String getInfo(Notification n)
  313. {
  314. StringBuilder str = new StringBuilder("\n\n");
  315. str.Append(++lineNbr);
  316. str.Append("\t");
  317. str.Append(String.Empty.Equals(n.Title) ? "Sans titre" : n.Title);
  318. if (!String.Empty.Equals(n.Msg))
  319. {
  320. str.Append("\nMessage : ");
  321. str.Append(n.Msg);
  322. }
  323. str.Append("\nNiveau de notification : ");
  324. str.Append(Enum.GetName(typeof(Notification.VERBOSE), n.Level));
  325. if (n.Sender != null)
  326. {
  327. str.Append("\nEnvoyé par ");
  328. str.Append(n.Sender);
  329. }
  330. if (n.NotificationException != null)
  331. {
  332. appendException(str, n.NotificationException);
  333. }
  334. return str.ToString();
  335. }
  336. private void safeWrite(Notification n)
  337. {
  338. consoleRTB.AppendText(getInfo(n));
  339. consoleRTB.ScrollToCaret();
  340. }
  341. private void write(Notification n)
  342. {
  343. if (consoleRTB.InvokeRequired)
  344. {
  345. consoleRTB.Invoke(UpdateDelegate, n);
  346. }
  347. else
  348. {
  349. safeWrite((n));
  350. }
  351. }
  352. #endregion
  353.  
  354. #region public methods
  355. /// <summary>
  356. /// Cleans all displayed text on the console and resets notifications counter.
  357. /// </summary>
  358. public void Clear()
  359. {
  360. consoleRTB.Clear();
  361. lineNbr = 0;
  362. }
  363. #endregion
  364.  
  365. #region properties
  366. /// <summary>
  367. /// Number of notifications in the console
  368. /// </summary>
  369. public int Count
  370. {
  371. get { return this.lineNbr; }
  372. }
  373. #endregion
  374.  
  375. /// <summary>
  376. /// Cleans all displayed text on the console and resets notifications counter.
  377. /// </summary>
  378. /// <param name="sender"></param>
  379. /// <param name="e"></param>
  380. private void cleanConsole_Click(object sender, EventArgs e)
  381. {
  382. Clear();
  383. }
  384. /// <summary>
  385. /// Displays an option dialog to select verbose level of the console
  386. /// (allows to select the kinds of notification to display).
  387. /// </summary>
  388. /// <param name="sender"></param>
  389. /// <param name="e"></param>
  390. public void selectVerbose_Click(object sender, EventArgs e)
  391. {
  392. SelectConsoleVerboseDialog dialog = new SelectConsoleVerboseDialog();
  393. dialog.ShowDialog(ParentForm);
  394. }
  395. }
  396. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/view/utils/ 
IcôneNomTailleModification
Pas de sous-répertoires.
IcôneNomTailleModification
| _ Répertoire parent0 octets1719422285 26/06/2024 19:18:05
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/view/utils/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csExportControl.cs27.1 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csMultiWebInfoControl.cs2.13 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csImagesImporter.Designer.cs3.64 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csImg.cs3.45 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .resx|.resxMediabrolInfoControl.resx5.68 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .resx|.resxExportControl.resx5.68 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csConsole.Designer.cs4.25 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .resx|.resxConsole.resx6.06 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csMediabrolInfoControl.Designer.cs12.57 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csMultiWebInfoControl.Designer.cs1.46 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csImagesImporter.cs1.89 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csExportControl.Designer.cs42.38 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .resx|.resxMultiWebInfoControl.resx5.68 Ko31/10/2018 18:33:04-refusé-
Afficher le fichier .cs|.csMediabrolInfoControl.cs1.9 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .resx|.resxImagesImporter.resx5.68 Ko31/10/2018 18:33:03-refusé-
Afficher le fichier .cs|.csConsole.cs16.89 Ko31/10/2018 18:33:03-refusé-

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.

Deutsche Übersetzung

Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.

Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.

Vielen Dank im Voraus.

Dokument erstellt 16/10/2009, zuletzt geändert 26/10/2018
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/cs-bibliobrol-source-rf-view/utils//Console.cs.html

Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.