private void itunes_OnDatabaseChangedEvent(object deletedObjectIDs, object changedObjectIDs) { // NOTE: this event is both expensive and blocking, so it is not advised to // wire up a handler to OnDatabaseChanged. Debug.WriteLine("OnDatabaseChangedEvent(deletedObjectIDs, changedObjectIDs)"); if (deletedObjectIDs == null) { Debug.WriteLine("DeletedObjectIDs is null"); } else { ObjectIDCollection deleteIDs = new ObjectIDCollection(); Array deleted = deletedObjectIDs as Array; for (int i = deleted.GetLowerBound(0); i <= deleted.GetUpperBound(0); i++) { deleteIDs.Add(new ObjectID( (int)deleted.GetValue(i, 0), (int)deleted.GetValue(i, 1), (int)deleted.GetValue(i, 2), (int)deleted.GetValue(i, 3))); } if (deleteIDs.Count > 0) { DumpChanges("Deleted", deleteIDs); } } if (deletedObjectIDs == null) { Debug.WriteLine("ChangedObjectIDs is null"); } else { ObjectIDCollection changeIDs = new ObjectIDCollection(); Array changed = changedObjectIDs as Array; for (int i = changed.GetLowerBound(0); i <= changed.GetUpperBound(0); i++) { changeIDs.Add(new ObjectID( (int)changed.GetValue(i, 0), (int)changed.GetValue(i, 1), (int)changed.GetValue(i, 2), (int)changed.GetValue(i, 3))); } if (changeIDs.Count > 0) { DumpChanges("Changes", changeIDs); } } }
/// <summary> /// Instantiate a new maintenance action only if the safe array describes a recognizable /// activity pattern. /// </summary> /// <param name="safeArray"></param> /// <returns></returns> public static MaintenanceAction Create(object safeArray) { Array array = safeArray as Array; ObjectIDCollection list = new ObjectIDCollection(); StringBuilder builder = new StringBuilder(); ObjectID oid; // convert the safe array to a collection and construct the pattern map int lower = array.GetLowerBound(0); int upper = array.GetUpperBound(0); for (int i = lower; i <= upper; i++) { oid = new ObjectID( (int)array.GetValue(i, 0), // source (int)array.GetValue(i, 1), // playlist (int)array.GetValue(i, 2), // trackid (int)array.GetValue(i, 3)); // databaseid list.Add(oid); if (oid.IsPlaylist) { builder.Append("P"); } else if (oid.IsSource) { builder.Append("S"); } else if (oid.IsTrack) { builder.Append("T"); } else { builder.Append("X"); } } // recognize pattern to instantiate new MaintenanceAction string map = builder.ToString(); if (Regex.IsMatch(map, AddPlaylistPattern)) { return(new MaintenanceAction(ActionType.AddPlaylist, list)); } else if (Regex.IsMatch(map, AddTracksPattern)) { return(new MaintenanceAction(ActionType.AddTracksToPlaylist, list)); } else if (Regex.IsMatch(map, RemovePlaylistPattern)) { return(new MaintenanceAction(ActionType.RemovePlaylist, list)); } else if (Regex.IsMatch(map, RemoveTracksPattern)) { return(new MaintenanceAction(ActionType.RemoveTracksFromPlaylist, list)); } // Not a recognizable pattern, return null list.Clear(); return(null); }
private void itunes_OnDatabaseChangedEvent(object deletedObjectIDs, object changedObjectIDs) { // NOTE: this event is both expensive and blocking, so it is not advised to // wire up a handler to OnDatabaseChanged. Debug.WriteLine("OnDatabaseChangedEvent(deletedObjectIDs, changedObjectIDs)"); if (deletedObjectIDs == null) { Debug.WriteLine("DeletedObjectIDs is null"); } else { ObjectIDCollection deleteIDs = new ObjectIDCollection(); Array deleted = deletedObjectIDs as Array; for (int i = deleted.GetLowerBound(0); i <= deleted.GetUpperBound(0); i++) { deleteIDs.Add(new ObjectID( (int)deleted.GetValue(i, 0), (int)deleted.GetValue(i, 1), (int)deleted.GetValue(i, 2), (int)deleted.GetValue(i, 3))); } if (deleteIDs.Count > 0) { DumpChanges("Deleted", deleteIDs); } } if (deletedObjectIDs == null) { Debug.WriteLine("ChangedObjectIDs is null"); } else { ObjectIDCollection changeIDs = new ObjectIDCollection(); Array changed = changedObjectIDs as Array; for (int i = changed.GetLowerBound(0); i <= changed.GetUpperBound(0); i++) { changeIDs.Add(new ObjectID( (int)changed.GetValue(i, 0), (int)changed.GetValue(i, 1), (int)changed.GetValue(i, 2), (int)changed.GetValue(i, 3))); } if (changeIDs.Count > 0) { DumpChanges("Changes", changeIDs); } } }
/// <summary> /// Instantiate a new maintenance action only if the safe array describes a recognizable /// activity pattern. /// </summary> /// <param name="safeArray"></param> /// <returns></returns> public static MaintenanceAction Create(object safeArray) { Array array = safeArray as Array; ObjectIDCollection list = new ObjectIDCollection(); StringBuilder builder = new StringBuilder(); ObjectID oid; // convert the safe array to a collection and construct the pattern map int lower = array.GetLowerBound(0); int upper = array.GetUpperBound(0); for (int i = lower; i <= upper; i++) { oid = new ObjectID( (int)array.GetValue(i, 0), // source (int)array.GetValue(i, 1), // playlist (int)array.GetValue(i, 2), // trackid (int)array.GetValue(i, 3)); // databaseid list.Add(oid); if (oid.IsPlaylist) { builder.Append("P"); } else if (oid.IsSource) { builder.Append("S"); } else if (oid.IsTrack) { builder.Append("T"); } else { builder.Append("X"); } } // recognize pattern to instantiate new MaintenanceAction string map = builder.ToString(); if (Regex.IsMatch(map, AddPlaylistPattern)) { return new MaintenanceAction(ActionType.AddPlaylist, list); } else if (Regex.IsMatch(map, AddTracksPattern)) { return new MaintenanceAction(ActionType.AddTracksToPlaylist, list); } else if (Regex.IsMatch(map, RemovePlaylistPattern)) { return new MaintenanceAction(ActionType.RemovePlaylist, list); } else if (Regex.IsMatch(map, RemoveTracksPattern)) { return new MaintenanceAction(ActionType.RemoveTracksFromPlaylist, list); } // Not a recognizable pattern, return null list.Clear(); return null; }