protected virtual async Task SortItemsByScript(string script, bool descending) { using (var transaction = this.Database.BeginTransaction(this.Database.PreferredIsolationLevel)) { var set = this.Database.Set <PlaylistItem>(transaction); var playlistItems = set.ToArray(); using (var comparer = new PlaylistItemScriptComparer(script)) { comparer.InitializeComponent(this.Core); Array.Sort(playlistItems, comparer); if (descending) { Array.Reverse(playlistItems); } } for (var a = 0; a < playlistItems.Length; a++) { playlistItems[a].Sequence = a; } await EntityHelper <PlaylistItem> .Create( this.Database, this.Database.Tables.PlaylistItem, transaction ).UpdateAsync( playlistItems, new[] { nameof(PlaylistItem.Sequence) } ).ConfigureAwait(false); if (transaction.HasTransaction) { transaction.Commit(); } } }
protected virtual async Task SortItemsByScript(string script, bool descending) { using (var comparer = new PlaylistItemScriptComparer(script)) { comparer.InitializeComponent(this.Core); await this.SortItems(comparer, descending).ConfigureAwait(false); } }