using Comal.Classes; using InABox.Core; using InABox.Database; using InABox.DynamicGrid; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace PRS.Shared.Database_Update_Scripts; internal class Update_8_32 : DatabaseUpdateScript { public override VersionNumber Version => new(8, 32); private static void DoKanbanNotes() { var provider = DbFactory.NewProvider(Logger.Main); Logger.Send(LogType.Information, "", $"Process Kanban Notes..."); var tasks = provider.Query( null, Columns.None().Add(x => x.ID).Add(x => x.Notes)) .ToArray(); Utils.Utils.ProcessInChunks(tasks, chunk => { foreach(var kanban in chunk) { if (kanban.Notes is not null && kanban.Notes.Any(x => x?.Contains("===================================") != false)) { var notes = new List>() { new() }; foreach (var line in kanban.Notes) { if(line is not null) { if (line.Equals("===================================")) { notes.Add(new()); } else { notes[^1].Add(line); } } else { notes[^1].Add(""); } } kanban.Notes = notes.Select(x => string.Join('\n', x)).Where(x => !x.IsNullOrWhiteSpace()).ToArray(); } } provider.Save(chunk.Where(x => x.IsChanged())); }, 1000, percent => { Logger.Send(LogType.Information, "", $"Processing Kanban Notes: {percent:F2}%"); }); Logger.Send(LogType.Information, "", $"Processing Kanban Notes complete"); } private static void DoEventEnabled() { var provider = DbFactory.NewProvider(Logger.Main); Logger.Send(LogType.Information, "", $"Initialising Event.Enabled to true..."); var events = provider.Query( null, Columns.None().Add(x => x.ID).Add(x => x.Enabled)) .ToArray(); foreach(var ev in events) { ev.Enabled = true; ev.Visible = true; } provider.Save(events); Logger.Send(LogType.Information, "", $"Initialised Event.Enabled to true"); } public override bool Update() { DoKanbanNotes(); DoEventEnabled(); return true; } }