Update_8_32.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. }
  69. provider.Save(events);
  70. Logger.Send(LogType.Information, "", $"Initialised Event.Enabled to true");
  71. }
  72. public override bool Update()
  73. {
  74. DoKanbanNotes();
  75. DoEventEnabled();
  76. return true;
  77. }
  78. }