/// By Ryan Moe /// Edited: Julian Nguyen(4/27/13) /// <summary> /// This method returns a list of Album objects to the callback given by the parameter. /// </summary> /// <param name="guiCallback">The callback for the GUI.</param> public void getAllAlbums(getAllAlbumNames_callback guiCallback) { ErrorReport errReport = null; ReadOnlyObservableCollection<SimpleAlbumData> readOnlyAlbumList = null; errReport = _photoBombDatabase.getAllAlbums_backend(out readOnlyAlbumList); guiCallback(errReport, readOnlyAlbumList); }
//----------------------------------------------------------------- // By: Bill Sanders, based on Ryan Moe's earlier function // last edited: 3/24/13 /// <summary> /// Retrieves a list of all albums in the albums.xml file, sent back via the callback. /// </summary> /// <param name="guiCallback">The callback to send the data back to the GUI</param> private void getAllAlbums_backend(getAllAlbumNames_callback guiCallback) { ErrorReport error = new ErrorReport(); // Ensure the database is valid before proceeding if (!util_checkAlbumDatabase(error)) { error.reportID = ErrorReport.FAILURE; error.description = "The album database was determined to be not valid."; guiCallback(error, null); return; } // An object to enumerate over the album XML nodes IEnumerable<XElement> _albumSearchIE; try { // get all the albums _albumSearchIE = (from c in _albumsDatabase.Elements() select c); } catch { error.reportID = ErrorReport.FAILURE; error.description = "PhotoBomb.getAllAlbumsByID_backend():Failed at finding albums in the database."; guiCallback(error, null); return; } foreach (XElement thisAlbum in _albumSearchIE) { SimpleAlbumData userAlbum = new SimpleAlbumData(); userAlbum.UID = (int)thisAlbum.Attribute("uid"); try { // Throws an exception if there is not exactly one albumName for a given album. userAlbum.albumName = thisAlbum.Descendants("albumName").Single().Value; } catch { // This is ugly. If we're upgrading to .net 4.5 anyway we can replace all error code with a tracking class: // http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.callermembernameattribute.aspx error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS; StringBuilder sb = new StringBuilder(); sb.AppendFormat("{0}.{1} : {2}", this.GetType().Name, MethodBase.GetCurrentMethod().Name, "Found an album with more than one name, or invalid name." ); error.warnings.Add(sb.ToString()); continue; // We'll keep going if one album is invalid } _albumsToReturn.Add(userAlbum); } ReadOnlyObservableCollection<SimpleAlbumData> readOnlyAlbumList = new ReadOnlyObservableCollection<SimpleAlbumData>(_albumsToReturn); guiCallback(error, readOnlyAlbumList); }
//----------------------------------------------- //By: Ryan Moe //Edited Last: // //This method returns a list of Album objects to the //callback given by the parameter. //PARAM 1 = a gui callback (see PhotoBombDelegates.cs). public void getAllAlbums(getAllAlbumNames_callback guiCallback) { getAllAlbums_backend(guiCallback); }