// ---------- #endregion #region Events // ------ #endregion #region Constructors // ------------ /// <summary> /// Called once the constructor has filled all the properties /// </summary> //partial void onConstruct() { //} /// <summary> /// Called once the cloning constructor has filled all the properties. Clones have no children data. /// </summary> //partial void onCloned(PlaylistTrack clone) { //} /// <summary> /// Called once the CSV-constructor who reads the data from a CSV file has filled all the properties /// </summary> //partial void onCsvConstruct() { //} #endregion #region Methods // ------- /// <summary> /// Called before {ClassName}.Store() gets executed /// </summary> //partial void onStoring(ref bool isCancelled) { //} /// <summary> /// Called after PlaylistTrack.Store() is executed /// </summary> //partial void onStored() { //} /// <summary> /// Called before PlaylistTrack gets written to a CSV file /// </summary> //partial void onCsvWrite() { //} /// <summary> /// Called after all properties of PlaylistTrack are updated, but before the HasChanged event gets raised /// </summary> //partial void onUpdating(Playlist playlist, Track track, ref bool isCancelled){ //} /// <summary> /// Called after all properties of PlaylistTrack are updated, but before the HasChanged event gets raised /// </summary> //partial void onUpdated(PlaylistTrack old) { //} /// <summary> /// Called after an update for PlaylistTrack is read from a CSV file /// </summary> //partial void onCsvUpdate() { //} /// <summary> /// Called before PlaylistTrack.Release() gets executed /// </summary> partial void onReleasing() { if (DC.Data.PlayinglistTracksByPlaylistTrackKey.TryGetValue(Key, out var playinglistTrack)) { playinglistTrack.Release(); //playinglistTrack.Release() does not remove playinglistTrack from Playinglist.ToPlayTracks DC.Data.Playinglists[Playlist].Remove(playinglistTrack); } Playlist.RemoveFromPlaylistTracks(this); Playlist = null !; Track.RemoveFromPlaylistTracks(this); Track = null !; }
public void Update(Playlist playlist, Track track, int trackNo) { if (Key >= 0) { if (playlist.Key < 0) { throw new Exception($"PlaylistTrack.Update(): It is illegal to add stored PlaylistTrack '{this}'" + Environment.NewLine + $"to Playlist '{playlist}', which is not stored."); } if (track.Key < 0) { throw new Exception($"PlaylistTrack.Update(): It is illegal to add stored PlaylistTrack '{this}'" + Environment.NewLine + $"to Track '{track}', which is not stored."); } } var clone = new PlaylistTrack(this); var isCancelled = false; onUpdating(playlist, track, trackNo, ref isCancelled); if (isCancelled) { return; } //remove not yet updated item from parents which will be removed by update var hasPlaylistChanged = Playlist != playlist; if (hasPlaylistChanged) { Playlist.RemoveFromPlaylistTracks(this); } var hasTrackChanged = Track != track; if (hasTrackChanged) { Track.RemoveFromPlaylistTracks(this); } //update properties and detect if any value has changed var isChangeDetected = false; if (Playlist != playlist) { Playlist = playlist; isChangeDetected = true; } if (Track != track) { Track = track; isChangeDetected = true; } if (TrackNo != trackNo) { TrackNo = trackNo; isChangeDetected = true; } //add updated item to parents which have been newly added during update if (hasPlaylistChanged) { Playlist.AddToPlaylistTracks(this); } if (hasTrackChanged) { Track.AddToPlaylistTracks(this); } if (isChangeDetected) { onUpdated(clone); if (Key >= 0) { DC.Data._PlaylistTracks.ItemHasChanged(clone, this); } else if (DC.Data.IsTransaction) { DC.Data.AddTransaction(new TransactionItem(3, TransactionActivityEnum.Update, Key, this, oldItem: clone)); } HasChanged?.Invoke(clone, this); } }