using Comal.Classes; using InABox.Core; using InABox.Database; 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); public override bool Update() { 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"); return true; } }