Update_8_32.cs 2.1 KB

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