NoChangeExporterDao.cs

Description du code

NoChangeExporterDao.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;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Data.Common;
  6. using System.Data;
  7. using System.Runtime.Serialization.Formatters.Binary;
  8. using System.IO;
  9. using System.Drawing;
  10.  
  11. using be.gaudry.observer;
  12. using be.gaudry.model.enums;
  13. using be.gaudry.model;
  14. using be.gaudry.model.exceptions;
  15.  
  16. namespace be.gaudry.bibliobrol.model.dao.mysql
  17. {
  18. public sealed class NoChangeExporterDao : Observable, IExporterDao
  19. {
  20. private String conStr;
  21. private enum MBCOMPAR { existingItem, newItem, conflictItem };
  22.  
  23. #region singleton
  24. static NoChangeExporterDao instance = null;
  25. static readonly object padlock = new object();
  26. private DbProviderFactory dbpf;
  27. NoChangeExporterDao()
  28. {
  29. notify(new Notification(Notification.VERBOSE.debug, "AccessImportExporter singleton call", this));
  30. dbpf = ((MySQLFactory)MySQLFactory.Instance).getDbpf();
  31. conStr = ((MySQLFactory)MySQLFactory.Instance).getConnectionString();
  32. }
  33. public static NoChangeExporterDao Instance
  34. {
  35. get
  36. {
  37. lock (padlock)
  38. {
  39. if (instance == null)
  40. {
  41. instance = new NoChangeExporterDao();
  42. }
  43. return instance;
  44. }
  45. }
  46. }
  47. #endregion
  48.  
  49. #region private methods
  50. /// <summary>
  51. /// Used to decorate FileStream constructor.
  52. /// Add exceptions catching and notifications on errors.
  53. /// </summary>
  54. /// <param name="path">(String) Path of the file</param>
  55. /// <param name="fMode">FileMode</param>
  56. /// <param name="fAccess">FileAccess</param>
  57. /// <returns>new FileStream or null</returns>
  58. internal FileStream getFileStream(String path, FileMode fMode, FileAccess fAccess)
  59. {
  60. String internEx = null;
  61. try
  62. {
  63. FileStream fs = new FileStream(path, fMode, fAccess);
  64. return fs;
  65. }
  66. catch (System.IO.IOException ioe)
  67. {
  68. internEx = ioe.Message;
  69. notify(new Notification(Notification.VERBOSE.criticalError, "Importation", "Erreur avec le fichier à importer", ioe, this));
  70. }
  71. catch (System.Security.SecurityException sex)
  72. {
  73. internEx = sex.Message;
  74. notify(new Notification(Notification.VERBOSE.criticalError, "Importation", "Erreur de sécurité avec le fichier d'importation", sex, this));
  75. }
  76. catch (System.UnauthorizedAccessException uae)
  77. {
  78. internEx = uae.Message;
  79. notify(new Notification(Notification.VERBOSE.criticalError, "Importation", "Accès non autorisé", uae, this));
  80. }
  81. catch (Exception fSer)
  82. {
  83. internEx = fSer.Message;
  84. notify(new Notification(Notification.VERBOSE.criticalError, "Importation", fSer, this));
  85. }
  86. //internalNotification to send msg to the import/export observer
  87. notify(new Notification(Notification.VERBOSE.internalNotification, "Importation", internEx, this));
  88. return null;
  89. }
  90. #endregion
  91.  
  92. #region binary
  93. /// <summary>
  94. /// Serialize itemms list of Brols or Mediabrols
  95. /// </summary>
  96. /// <param name="mediabrolIds">(int[]) array of mediabrol's ids</param>
  97. /// <param name="path">(String) path of binary export file</param>
  98. /// <param name="exportMediabrol">(bool) true if mediabrols must be exported, false if only brols must be exported</param>
  99. /// <param name="exportAllBrols">(bool) true if non selected brols must be also exported</param>
  100. /// <param name="anonymous">(bool) true if owner info may not be exported</param>
  101. public void exportBinaryMediaBrol(int[] ids, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous)
  102. {
  103. notify(new Notification(Notification.VERBOSE.debug, "Exportation params",
  104. "exportMediabrol : "+exportMediabrol+" "+
  105. "\nexportAllBrols : "+exportAllBrols+" "+
  106. "\nanonymous : "+anonymous, this));
  107. if (ids == null)
  108. {
  109. notify(new Notification(Notification.VERBOSE.opsResult, "Exportation", "Aucun élément à exporter", this));
  110. return;
  111. }
  112. if (path == null)
  113. {
  114. notify(new Notification(Notification.VERBOSE.criticalError, "Exportation", "Aucun chemin sélectionné pour exporter", this));
  115. return;
  116. }
  117. DateTime startDateTime = DateTime.Now;
  118. List<Brol> brols = null;
  119. List<MediaBrol> mediabrols = null;
  120. List<Image> images = new List<Image>();
  121. DbConnection dbCon = dbpf.CreateConnection();
  122. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  123. dbDa.SelectCommand = dbCon.CreateCommand();
  124. dbCon.ConnectionString = conStr;
  125. if (exportMediabrol)
  126. {
  127. mediabrols = loadSelectedMediaBrols(ids, anonymous, dbCon, dbDa);
  128. }
  129. else
  130. {
  131. brols = loadSelectedBrols(ids, dbCon, dbDa, true);
  132. Image img = null;
  133. foreach (Brol brol in brols)
  134. {
  135. try
  136. {
  137. img = Image.FromFile(be.gaudry.bibliobrol.view.utils.Img.getBrolImgPath(brol));
  138. images.Add(img);
  139. }
  140. catch (Exception) { }
  141. }
  142. }
  143. dbCon.Close();
  144.  
  145. BinaryFormatter bf = new BinaryFormatter();
  146. FileStream fs = getFileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
  147. if(fs==null)
  148. {
  149. notify(new Notification(Notification.VERBOSE.internalNotification, "End", "Impossible de terminer le traitement", this));
  150. return;
  151. }
  152. try
  153. {
  154. notify(new Notification(Notification.VERBOSE.internalNotification, "Info", "Début de la sauvegarde", this));
  155. if (exportMediabrol) bf.Serialize(fs, mediabrols);
  156. else
  157. {
  158. bf.Serialize(fs, brols);
  159. fs.Close();
  160. fs = getFileStream(path.Replace(".bed",".bif"), FileMode.OpenOrCreate, FileAccess.Write);
  161. bf.Serialize(fs, images);
  162. }
  163. notify(new Notification(Notification.VERBOSE.internalNotification, "Info", "Fin de la sauvegarde", this));
  164. }
  165. catch (Exception eSer)
  166. {
  167. notify(new Notification(Notification.VERBOSE.criticalError, "Exportation", eSer, this));
  168. notify(new Notification(Notification.VERBOSE.internalNotification, "End", "Impossible de terminer le traitement : " + eSer.Message, this));
  169. return;
  170. }
  171. finally
  172. {
  173. fs.Close();
  174. }
  175. //exportImgs(exportMediabrol, ibrols);
  176. notify(new Notification(Notification.VERBOSE.internalNotification, "End", String.Format("Fin de tous les traitements ({0})", Units.getDelay(startDateTime)), this));
  177. }
  178.  
  179. /*private void exportImgs(bool exportMediabrol, List<IBrol> ibrols)
  180.   {
  181.   List<Brol> brols = new List<Brol>();
  182.   if (exportMediabrol)
  183.   {
  184.   }
  185.   else
  186.   {
  187.   }
  188.   }
  189.   private void exportBrolImgs(List<Brol> brols)
  190.   {
  191.  
  192.   }*/
  193.  
  194.  
  195. /// <summary>
  196. /// Serialize mediabrols
  197. /// </summary>
  198. /// <param name="mediabrolIds">(int[]) array of mediabrol's ids</param>
  199. /// <param name="path">(String) path of binary export file</param>
  200. /// <param name="exportMediabrol">(bool) true if mediabrols must be exported, false if only brols must be exported</param>
  201. /// <param name="exportAllBrols">(bool) true if non selected brols must be also exported</param>
  202. /// <param name="anonymous">(bool) true if owner info may not be exported</param>
  203. public void exportBinaryMediaBrolTest(int[] mediabrolIds, String path, bool exportMediabrol, bool exportAllBrols, bool anonymous)
  204. {
  205. DateTime startDateTime = DateTime.Now;
  206. if (mediabrolIds == null)return;
  207. if (path == null)return;
  208. List<MediaBrol> mediabrols = new List<MediaBrol>();
  209. DbConnection dbCon = dbpf.CreateConnection();
  210. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  211. dbDa.SelectCommand = dbCon.CreateCommand();
  212. dbCon.ConnectionString = conStr;
  213. StringBuilder str = new StringBuilder("SELECT i.*, p.*, m.* FROM ");
  214. str.Append("(itemBiblio AS i");
  215. str.Append(" LEFT JOIN person AS p ON i.ownerId = p.id)");
  216. str.Append(" LEFT JOIN media AS m ON i.mediaId = m.id");
  217. str.Append(" WHERE i.id IN (0");
  218. foreach (int id in mediabrolIds)
  219. {
  220. str.Append(",");
  221. str.Append(id);
  222. }
  223. str.Append(")");
  224. dbDa.SelectCommand.CommandText = str.ToString();
  225. DataTable brolDt = new DataTable();
  226. MediaBrol mediabrol;
  227. try
  228. {
  229. dbDa.Fill(brolDt);
  230. int mbCount = brolDt.Rows.Count;
  231. int brolId;
  232. foreach (DataRow brolRow in brolDt.Rows)
  233. {
  234. mediabrol = msaccess.AccessMediaBrolDao.Instance.getMediaBrol(brolRow, anonymous);
  235. try
  236. {
  237. brolId = (int)brolRow["itemId"];
  238. mediabrol.Brol = NoChangeBrolDao.Instance.loadBrol(brolId, false);
  239. }
  240. catch (Exception){}
  241. try
  242. {
  243. mediabrol.Qualities = msaccess.AccessMediaBrolDao.Instance.loadQualitiesCommand(mediabrol.Id, dbDa);
  244. mediabrols.Add(mediabrol);
  245. }
  246. catch (Exception){}
  247. }
  248. }
  249. catch (Exception){}
  250. finally
  251. {
  252. brolDt.Dispose();
  253. dbCon.Close();
  254. }
  255. BinaryFormatter bf = new BinaryFormatter();
  256. FileStream fs = getFileStream(path, FileMode.OpenOrCreate, FileAccess.Write);
  257. if (fs == null) return;
  258. try
  259. {
  260. bf.Serialize(fs, mediabrols);
  261. }
  262. catch (Exception){}
  263. fs.Close();
  264. notify(new Notification(Notification.VERBOSE.internalNotification, "End", String.Format("Fin de tous les traitements ({0})", Units.getDelay(startDateTime)), this));
  265. }
  266.  
  267.  
  268.  
  269. #endregion
  270.  
  271. #region xml
  272. /// <summary>
  273. /// Export mediabrols into xml file
  274. /// </summary>
  275. /// <param name="mediabrolIds">(int[]) array of mediabrol's ids</param>
  276. /// <param name="path">(String) path of xml export file</param>
  277. public void exportXMLMediaBrol(int[] mediabrolIds, String path)
  278. {
  279. if (mediabrolIds == null)
  280. {
  281. notify(new Notification(Notification.VERBOSE.opsResult, "Exportation des exemplaires", "Aucun exemplaire à exporter", this));
  282. return;
  283. }
  284. if (path == null)
  285. {
  286. notify(new Notification(Notification.VERBOSE.criticalError, "Exportation des exemplaires", "Aucun chemin sélectionné pour exporter", this));
  287. return;
  288. }
  289.  
  290. DbConnection dbCon = dbpf.CreateConnection();
  291. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  292. dbDa.SelectCommand = dbCon.CreateCommand();
  293. dbCon.ConnectionString = conStr;
  294. StringBuilder str = new StringBuilder("SELECT i.*, p.*, m.* FROM ");
  295. str.Append("(itemBiblio AS i");
  296. str.Append(" LEFT JOIN person AS p ON i.ownerId = p.id)");
  297. str.Append(" LEFT JOIN media AS m ON i.mediaId = m.id");
  298. str.Append(" WHERE i.id IN (0");
  299. foreach (int id in mediabrolIds)
  300. {
  301. str.Append(",");
  302. str.Append(id);
  303. }
  304. str.Append(")");
  305.  
  306. dbDa.SelectCommand.CommandText = str.ToString();
  307. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  308. DataSet ds = new DataSet();
  309. try
  310. {
  311. dbDa.Fill(ds);
  312. ds.WriteXml(path);
  313. notify(new Notification(Notification.VERBOSE.opsResult, "Exportation des données", "Les données ont bien été exportées dans le fichier " + path, this));
  314. }
  315. catch (Exception e)
  316. {
  317. notify(new Notification(Notification.VERBOSE.criticalError, "Impossible d'exporter les données", e, this));
  318. }
  319. finally
  320. {
  321. ds.Dispose();
  322. dbCon.Close();
  323. }
  324.  
  325. }
  326. #endregion
  327.  
  328. #region MS Excel
  329. /// <summary>
  330. /// Export mediabrols into CSV or MS Excel Stylesheet file
  331. /// </summary>
  332. /// <param name="mediabrolIds">(int[]) array of mediabrol's ids</param>
  333. /// <param name="path">(String) path of the export file</param>
  334. /// <param name="type">(int) type of export (CSV or MS Excel)</param>
  335. public void exportExcelMediaBrol(int[] mediabrolIds, String path, int type)
  336. {
  337. if (mediabrolIds == null)
  338. {
  339. notify(new Notification(Notification.VERBOSE.opsResult, "Exportation des exemplaires", "Aucun exemplaire à exporter", this));
  340. return;
  341. }
  342. if (path == null)
  343. {
  344. notify(new Notification(Notification.VERBOSE.criticalError, "Exportation des exemplaires", "Aucun chemin sélectionné pour exporter", this));
  345. return;
  346. }
  347. String[] headers = new String[]
  348. {
  349. //"n°", //0
  350. "nom d'exemplaire", //1
  351. "n° d'ouvrage", //2
  352. //"n° de propriétaire", //3
  353. //"n° de support", //4
  354. "Date d'insertion", //5
  355. "Commentaire", //6
  356. "Localisation", //7
  357. //"n° de propriétaire", //8
  358. "Nom de propriétaire", //9
  359. "Prénom de propriétaire", //10
  360. //"Date de naissance proprio",//11
  361. //"Sexe proprio", //12
  362. //"Verrou proprio", //13
  363. //"Pseudonyme propriétaire", //14
  364. //"n° de support", //15
  365. "Support", //16
  366. "Type d'ouvrage" //17
  367. };
  368. int[] cols = new int[] { 1,2,5,6,7,9,10,16,17};
  369. DbConnection dbCon = dbpf.CreateConnection();
  370. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  371. dbDa.SelectCommand = dbCon.CreateCommand();
  372. dbCon.ConnectionString = conStr;
  373. StringBuilder str = new StringBuilder("SELECT i.*, p.*, m.* FROM ");
  374. str.Append("(itemBiblio AS i");
  375. str.Append(" LEFT JOIN person AS p ON i.ownerId = p.id)");
  376. str.Append(" LEFT JOIN media AS m ON i.mediaId = m.id");
  377. str.Append(" WHERE i.id IN (0");
  378. foreach (int id in mediabrolIds)
  379. {
  380. str.Append(",");
  381. str.Append(id);
  382. }
  383. str.Append(")");
  384.  
  385. dbDa.SelectCommand.CommandText = str.ToString();
  386. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  387. DataTable dt = new DataTable();
  388. try
  389. {
  390. dbDa.Fill(dt);
  391. if (type == 1) exportCSV(dt, path, headers, cols);
  392. else exportExcel(dt, path, headers, cols);
  393.  
  394. notify(new Notification(Notification.VERBOSE.opsResult, "Exportation des données", "Les données ont bien été exportées dans le fichier " + path, this));
  395. }
  396. catch (Exception e)
  397. {
  398. notify(new Notification(Notification.VERBOSE.criticalError, "Impossible d'exporter les données", e, this));
  399. }
  400. finally
  401. {
  402. dt.Dispose();
  403. dbCon.Close();
  404. }
  405.  
  406. }
  407. private void exportExcel(DataTable dt, String path, string[] headers, int[] cols)
  408. {
  409. // Export all the details
  410. try
  411. {
  412. // Export the details of specified columns to CSV
  413. Export objExport = new Export();
  414. objExport.ExportDetails(dt, cols, headers, BROL_EXPORT_FORMAT.Excel, path);
  415. }
  416. catch (Exception e)
  417. {
  418. notify(new Notification(Notification.VERBOSE.criticalError, "Impossible d'exporter les données", e, this));
  419. }
  420. }
  421.  
  422. private void exportCSV(DataTable dt, String path, string[] headers, int[] cols)
  423. {
  424. // Export all the details
  425. try
  426. {
  427. // Specify the column list to export
  428. /*int c = dt.Columns.Count-1;
  429.   int[] iColumns = new int[c];
  430.   for (int i = 0; i <= c; i++) { iColumns[i] = i; }
  431.   */
  432. // Export the details of specified columns to CSV
  433. Export objExport = new Export();
  434. objExport.ExportDetails(dt, cols, headers, BROL_EXPORT_FORMAT.CSV, path);
  435. }
  436. catch (Exception e)
  437. {
  438. notify(new Notification(Notification.VERBOSE.criticalError, "Impossible d'exporter les données", e, this));
  439. }
  440. }
  441. #endregion
  442.  
  443. #region load brols and mediabrols
  444.  
  445. /// <summary>
  446. /// Load a list with selected mediabrols with an existing connection.
  447. /// </summary>
  448. /// <param name="ids">(int[]) mediabrols identifiers</param>
  449. /// <param name="dbCon">DbConnection</param>
  450. /// <param name="dbDa">DbDataAdapter</param>
  451. /// <returns>List of mediabrols</returns>
  452. private List<MediaBrol> loadSelectedMediaBrols(int[] ids, bool anonymous, DbConnection dbCon, DbDataAdapter dbDa)
  453. {
  454. List<MediaBrol> mediabrols = new List<MediaBrol>();
  455. StringBuilder str = new StringBuilder("SELECT i.*, p.*, m.* FROM ");
  456. str.Append("(itemBiblio AS i");
  457. str.Append(" LEFT JOIN person AS p ON i.ownerId = p.id)");
  458. str.Append(" LEFT JOIN media AS m ON i.mediaId = m.id");
  459. str.Append(" WHERE i.id IN (0");
  460. foreach (int id in ids)
  461. {
  462. str.Append(",");
  463. str.Append(id);
  464. }
  465. str.Append(")");
  466. dbDa.SelectCommand.CommandText = str.ToString();
  467. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  468. DataTable brolDt = new DataTable();
  469. MediaBrol mediabrol;
  470. try
  471. {
  472. dbDa.Fill(brolDt);
  473. int mbCur = 0;
  474. int mbCount = brolDt.Rows.Count;
  475. notify(new Notification(Notification.VERBOSE.internalNotification, "count", mbCount.ToString(), this));
  476. notify(new Notification(Notification.VERBOSE.internalNotification, "Chargement des ouvrages", String.Format("{0} exemplaires chargés(s) sur {0} demandé(s)", mbCount, ids.Length), this));
  477. int[] brolIds = new int[1];
  478. foreach (DataRow brolRow in brolDt.Rows)
  479. {
  480. notify(new Notification(Notification.VERBOSE.internalNotification, "count2", "3", this));
  481. mediabrol = msaccess.AccessMediaBrolDao.Instance.getMediaBrol(brolRow, anonymous);
  482. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 1", this));
  483. try
  484. {
  485. brolIds[0] = (int)brolRow["itemId"];
  486. //mediabrol.Brol = AccessBrolDao.Instance.loadBrol(brolId, false);
  487. mediabrol.Brol = (loadSelectedBrols(brolIds, dbCon, dbDa, false))[0];
  488. notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", String.Format("Chargement de l'ouvrage {0}/{1} : {2}", ++mbCur, mbCount, mediabrol.Brol.Title), this));
  489. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 2", this));
  490. }
  491. catch (Exception eBrol)
  492. {
  493. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 2", this));
  494. notify(new Notification(Notification.VERBOSE.error, "Chargement des éléments", eBrol, this));
  495. }
  496. try
  497. {
  498. mediabrol.Qualities = msaccess.AccessMediaBrolDao.Instance.loadQualitiesCommand(mediabrol.Id, dbDa);
  499. mediabrols.Add(mediabrol);
  500. }
  501. catch (Exception eBrol)
  502. {
  503. notify(new Notification(Notification.VERBOSE.error, "Chargement des éléments", eBrol, this));
  504. }
  505. finally
  506. {
  507. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 3", this));
  508. notify(new Notification(Notification.VERBOSE.internalNotification, "brolEnd", "", this));
  509. }
  510. }
  511. notify(new Notification(Notification.VERBOSE.internalNotification, "lastBrol", String.Format("Fin des {0} chargements", mbCount), this));
  512. }
  513. catch (Exception eMedia)
  514. {
  515. notify(new Notification(Notification.VERBOSE.advancedOperation, "Chargement des ouvrages", eMedia, this));
  516.  
  517. }
  518. finally
  519. {
  520. brolDt.Dispose();
  521. }
  522. return mediabrols;
  523. }
  524. /// <summary>
  525. /// Load a list with selected brols
  526. /// </summary>
  527. /// <param name="ids">(int[]) brol identifiers</param>
  528. /// <returns>List of Brols</returns>
  529. internal List<Brol> loadSelectedBrols(int[] ids)
  530. {
  531. if (ids.Length < 1)
  532. {
  533. notify(new Notification(Notification.VERBOSE.lowError, "Chargement des ouvrages", "Aucun ouvrage à charger", this));
  534. return new List<Brol>();
  535. }
  536. DbConnection dbCon = dbpf.CreateConnection();
  537. DbDataAdapter dbDa = dbpf.CreateDataAdapter();
  538. List<Brol> brols = loadSelectedBrols(ids, dbCon, dbDa, false);
  539. dbCon.Close();
  540. return brols;
  541. }
  542. /// <summary>
  543. /// Load a list with selected brols with an existing connection.
  544. /// </summary>
  545. /// <param name="ids">(int[]) brol identifiers</param>
  546. /// <param name="dbCon">DbConnection</param>
  547. /// <param name="dbDa">DbDataAdapter</param>
  548. /// <param name="internalNotification">(bool) True if we use a progress bar</param>
  549. /// <returns>List of Brols</returns>
  550. internal List<Brol> loadSelectedBrols(int[] ids, DbConnection dbCon, DbDataAdapter dbDa, bool internalNotification)
  551. {
  552. List<Brol> brols = new List<Brol>();
  553. DataSet ds = new DataSet();
  554. dbDa.SelectCommand = dbCon.CreateCommand();
  555. dbCon.ConnectionString = conStr;
  556. //build brols datatable
  557. StringBuilder str = new StringBuilder("SELECT item.*, type.name AS tName FROM type");
  558. str.Append(" RIGHT JOIN item ON type.id = item.typeId");
  559. str.Append(" WHERE item.id IN (0");
  560. List<int> idslist = new List<int>();
  561. foreach (int id in ids)
  562. {
  563. str.Append(",");
  564. str.Append(id);
  565. idslist.Add(id);
  566. }
  567. idslist.Sort();
  568. str.Append(")");
  569. dbDa.SelectCommand.CommandText = str.ToString();
  570. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  571. try
  572. {
  573. dbDa.Fill(ds, "brolsDT");
  574. int mbCur = 0;
  575. int mbCount = ds.Tables["brolsDT"].Rows.Count;//ids.Length;
  576. if (internalNotification)
  577. {
  578. notify(new Notification(Notification.VERBOSE.internalNotification, "count", (mbCount+1).ToString(), this));
  579. notify(new Notification(Notification.VERBOSE.internalNotification, "Chargement des ouvrages", String.Format("{0} ouvrages chargé(s) sur {0} demandé(s)", mbCount, ids.Length), this));
  580. notify(new Notification(Notification.VERBOSE.internalNotification, "count2", "3", this));
  581. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 1", this));
  582. notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", "Chargement des catégories", this));
  583. }
  584.  
  585. //load categories
  586. str = new StringBuilder("SELECT category.*,categoryItemRelation.* FROM category");
  587. str.Append(" LEFT JOIN categoryItemRelation ON categoryItemRelation.categoryId = category.id");
  588. str.Append(" WHERE itemId IN (0");
  589. foreach (int id in ids)
  590. {
  591. str.Append(",");
  592. str.Append(id);
  593. }
  594. str.Append(")");
  595. dbDa.SelectCommand.CommandText = str.ToString();
  596. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  597. dbDa.Fill(ds, "categoriesDT");
  598. //build relation
  599. DataRelation dr = new DataRelation(
  600. "media-catégorie",
  601. ds.Tables["brolsDT"].Columns["id"],
  602. ds.Tables["categoriesDT"].Columns["itemId"]
  603. );
  604. NoChangeBrolDao.Instance.tryToAddRelation(ds, dr);
  605. if (internalNotification)
  606. {
  607. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 2", this));
  608. notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", "Chargement des acteurs", this));
  609. }
  610.  
  611. //load serie
  612. str = new StringBuilder("SELECT serie.*,serieItemRelation.* FROM serie");
  613. str.Append(" LEFT JOIN serieItemRelation ON serieItemRelation.serieId = serie.id");
  614. str.Append(" WHERE itemId IN (0");
  615. foreach (int id in ids)
  616. {
  617. str.Append(",");
  618. str.Append(id);
  619. }
  620. str.Append(")");
  621. dbDa.SelectCommand.CommandText = str.ToString();
  622. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  623. dbDa.Fill(ds, "seriesDT");
  624. //build relation
  625. DataRelation drSerie = new DataRelation(
  626. "media-serie",
  627. ds.Tables["brolsDT"].Columns["id"],
  628. ds.Tables["seriesDT"].Columns["itemId"]
  629. );
  630. NoChangeBrolDao.Instance.tryToAddRelation(ds, drSerie);
  631. /*if (internalNotification)
  632.   {
  633.   notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 2", this));
  634.   notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", "Chargement des acteurs", this));
  635.   } */
  636.  
  637. //load actors
  638. str = new StringBuilder("SELECT p.*, role.roleName, a.itemId, a.roleId, a.roleValue");
  639. str.Append(" FROM role RIGHT JOIN");
  640. str.Append(" (person AS p INNER JOIN actor AS a ON p.id=a.personId)");
  641. str.Append(" ON role.id=a.roleId");
  642. str.Append(" WHERE a.itemId IN (0");
  643. foreach (int id in ids)
  644. {
  645. str.Append(",");
  646. str.Append(id);
  647. }
  648. str.Append(")");
  649. dbDa.SelectCommand.CommandText = str.ToString();
  650. notify(new Notification(Notification.VERBOSE.persistentOperation, dbDa.SelectCommand.CommandText, this));
  651. if (internalNotification)
  652. {
  653. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 3", this));
  654. notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", "Chargement des acteurs", this));
  655. notify(new Notification(Notification.VERBOSE.internalNotification, "brolEnd", "", this));
  656. }
  657. try
  658. {
  659. dbDa.Fill(ds, "actorsDT");
  660.  
  661. //build relation
  662. DataRelation drActors = new DataRelation(
  663. "media-personnes",
  664. ds.Tables["brolsDT"].Columns["id"],
  665. ds.Tables["actorsDT"].Columns["itemId"]
  666. );
  667. NoChangeBrolDao.Instance.tryToAddRelation(ds, drActors);
  668. //build person objects
  669. foreach (DataRow brolRow in ds.Tables["brolsDT"].Rows)
  670. {
  671. try
  672. {
  673. if (internalNotification)
  674. notify(new Notification(Notification.VERBOSE.internalNotification, "count2", "3", this));
  675. Brol brol = NoChangeBrolDao.Instance.getBrol(brolRow);
  676. if (internalNotification)
  677. {
  678. notify(new Notification(Notification.VERBOSE.internalNotification, "brolStart", String.Format("Chargement de l'ouvrage {0}/{1} : {2}", ++mbCur, mbCount, brol.Title), this));
  679. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 1", this));
  680. }
  681. foreach (DataRow catRow in brolRow.GetChildRows(dr))
  682. {
  683. brol.addCategory(NoChangeBrolDao.Instance.getCategory(catRow));
  684. }
  685. if (internalNotification)
  686. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 2", this));
  687. foreach (DataRow actorRow in brolRow.GetChildRows(drActors))
  688. {
  689. brol.addActor(NoChangeBrolDao.Instance.getActor(actorRow));
  690. }
  691. foreach (DataRow serieRow in brolRow.GetChildRows(drSerie))
  692. {
  693. brol.addSerieItem(NoChangeBrolDao.Instance.getSerieItem(serieRow));
  694. }
  695. if (internalNotification)
  696. notify(new Notification(Notification.VERBOSE.internalNotification, "pb2", "step 3", this));
  697. brols.Add(brol);
  698. }
  699. catch (BuildObjectException boe)
  700. {
  701. notify(new Notification(Notification.VERBOSE.error, "Chargement d'un media", boe, this));
  702. }
  703. finally
  704. {
  705. if (internalNotification)
  706. notify(new Notification(Notification.VERBOSE.internalNotification, "brolEnd", "", this));
  707. }
  708. }
  709. }
  710. catch (Exception eAddAct)
  711. {
  712. notify(new Notification(Notification.VERBOSE.error, "Chargement des acteurs", eAddAct, this));
  713. }
  714. if (internalNotification)
  715. notify(new Notification(Notification.VERBOSE.internalNotification, "lastBrol", String.Format("Fin des {0} chargements", mbCount), this));
  716. }
  717. catch (Exception fillMediaEx)
  718. {
  719. notify(new Notification(Notification.VERBOSE.error, "Chargement des media", fillMediaEx, this));
  720. }
  721. return brols;
  722. }
  723. #endregion
  724. }
  725. }

Structure et Fichiers du projet

Afficher/masquer...


Répertoires contenus dans /var/www/bin/sniplets/bibliobrol/src/model/dao/mysql/ 
IcôneNomTailleModification
IcôneNomTailleModification
| _ Répertoire parent0 octets1731754294 16/11/2024 11:51:34
| _utils0 octets1541007203 31/10/2018 18:33:23
Fichiers contenus dans /var/www/bin/sniplets/bibliobrol/src/model/dao/mysql/ 
IcôneNomTailleModificationAction
IcôneNomTailleModificationAction
Afficher le fichier .cs|.csNoChangeImporterDao.cs27.14 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeExporterDao.cs33.69 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeSerieDao.cs6.22 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLFactory.cs3.75 Ko31/10/2018 18:33:17-refusé-
Afficher le fichier .cs|.csNoChangeConfigDao.cs12.25 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangePersonDao.cs59.9 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeTaskDao.cs8.92 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csNoChangeBrolDao.cs58.25 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLStatsDao.cs10.63 Ko31/10/2018 18:33:18-refusé-
Afficher le fichier .cs|.csMySQLMediaBrolDao.cs50.51 Ko31/10/2018 18:33:18-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.

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 16/10/2009, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/cs-bibliobrol-source-rf-model/dao/mysql/NoChangeExporterDao.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.