Update_7_43.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using InABox.Configuration;
  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
  10. {
  11. public class Update_7_43 : DatabaseUpdateScript
  12. {
  13. public override VersionNumber Version => new VersionNumber(7, 43);
  14. public override bool Update()
  15. {
  16. var filters = DbFactory.Provider.Query(
  17. new InABox.Core.Filter<GlobalSettings>(x => x.Section).IsEqualTo("CoreFilterDefinitions"),
  18. new InABox.Core.Columns<GlobalSettings>(x => x.ID, x => x.Contents)).ToObjects<GlobalSettings>().ToList();
  19. foreach(var filter in filters)
  20. {
  21. var defs = Serialization.Deserialize<CoreFilterDefinitions>(filter.Contents) ?? new CoreFilterDefinitions();
  22. var nextSequence = 0L;
  23. foreach(var def in defs)
  24. {
  25. if(def.Sequence < nextSequence)
  26. {
  27. def.Sequence = nextSequence;
  28. }
  29. nextSequence = def.Sequence + 1;
  30. }
  31. filter.Contents = Serialization.Serialize(defs);
  32. }
  33. DbFactory.Provider.Save(filters);
  34. return true;
  35. }
  36. }
  37. }