Update_8_32.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using Comal.Classes;
  2. using InABox.Core;
  3. using InABox.Database;
  4. using InABox.DynamicGrid;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. namespace PRS.Shared.Database_Update_Scripts;
  11. internal class Update_8_32 : DatabaseUpdateScript
  12. {
  13. public override VersionNumber Version => new(8, 32);
  14. private static void DoKanbanNotes()
  15. {
  16. var provider = DbFactory.NewProvider(Logger.Main);
  17. Logger.Send(LogType.Information, "", $"Process Kanban Notes...");
  18. var tasks = provider.Query<Kanban>(
  19. null,
  20. Columns.None<Kanban>().Add(x => x.ID).Add(x => x.Notes))
  21. .ToArray<Kanban>();
  22. Utils.Utils.ProcessInChunks(tasks, chunk =>
  23. {
  24. foreach(var kanban in chunk)
  25. {
  26. if (kanban.Notes is not null && kanban.Notes.Any(x => x?.Contains("===================================") != false))
  27. {
  28. var notes = new List<List<string>>() { new() };
  29. foreach (var line in kanban.Notes)
  30. {
  31. if(line is not null)
  32. {
  33. if (line.Equals("==================================="))
  34. {
  35. notes.Add(new());
  36. }
  37. else
  38. {
  39. notes[^1].Add(line);
  40. }
  41. }
  42. else
  43. {
  44. notes[^1].Add("");
  45. }
  46. }
  47. kanban.Notes = notes.Select(x => string.Join('\n', x)).Where(x => !x.IsNullOrWhiteSpace()).ToArray();
  48. }
  49. }
  50. provider.Save(chunk.Where(x => x.IsChanged()));
  51. }, 1000, percent =>
  52. {
  53. Logger.Send(LogType.Information, "", $"Processing Kanban Notes: {percent:F2}%");
  54. });
  55. Logger.Send(LogType.Information, "", $"Processing Kanban Notes complete");
  56. }
  57. private static void DoEventEnabled()
  58. {
  59. var provider = DbFactory.NewProvider(Logger.Main);
  60. Logger.Send(LogType.Information, "", $"Initialising Event.Enabled to true...");
  61. var events = provider.Query(
  62. null,
  63. Columns.None<Event>().Add(x => x.ID).Add(x => x.Enabled))
  64. .ToArray<Event>();
  65. foreach(var ev in events)
  66. {
  67. ev.Enabled = true;
  68. ev.Visible = true;
  69. }
  70. provider.Save(events);
  71. Logger.Send(LogType.Information, "", $"Initialised Event.Enabled to true");
  72. }
  73. public override bool Update()
  74. {
  75. DoKanbanNotes();
  76. DoEventEnabled();
  77. return true;
  78. }
  79. }