//------------------------------------------------------------- //By: Ryan Moe //Edited Last: //UNTESTED/UNFINISHED private void addExistingPictureToAlbum_backend(generic_callback guiCallback, int pictureUID, int albumUID, String SimplePhotoData) { ErrorReport errorReport = new ErrorReport(); XElement picture = util_getPhotoDBNode(errorReport, pictureUID); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } util_addPicToAlbumDB(errorReport, null, albumUID, SimplePhotoData); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } guiCallback(errorReport); }
//------------------------------------------------------------- //By: Ryan Moe //Edited Last: private void addNewAlbum_backend(generic_callback guiCallback, SimpleAlbumData albumData) { ErrorReport errorReport = new ErrorReport(); //get a new uid for the new album. albumData.UID = util_getNextUID(_albumsDatabase, "album", 1); //add the album to the memory database. util_addAlbumToAlbumDB(errorReport, albumData); //if adding to the album database failed if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } //save to disk. saveAlbumsXML_backend(null); guiCallback(errorReport); }
// BS (4/1/13) Commenting this out: we never add a single picture at a time! //---------------------------------------------- //By: Ryan Moe //Edited Last: // //Adds a picture to the picture database AND the album database. //Also this makes a copy of the photo in the Library. //PARAM 1 = gui callback. //PARAM 2 = the path to the photo that is being imported. //PARAM 3 = extension of the photo (ex: ".jpg") //PARAM 4 = uid of the album that the photo is being added to. //PARAM 5 = the name of the photo in the album. NOTE: you can // send in "" and the backend will give the photo a default name. //public void addNewPicture(generic_callback guiCallback, String photoUserPath, String photoExtension, int albumUID, String pictureNameInAlbum) //{ // addNewPicture_backend(guiCallback, photoUserPath, photoExtension, albumUID, pictureNameInAlbum); //} //---------------------------------------------- //By: Bill Sanders //Edited Last: 3/26/13 /// <summary> /// This function removes the specified photo from the specified album. /// </summary> /// <param name="guiCallback"></param> /// <param name="uid">The UID of the photo</param> /// <param name="albumUID">The UID of the album</param> public void removePictureFromAlbum(generic_callback guiCallback, int uid, int albumUID) { removePictureFromAlbum_backend(guiCallback, uid, albumUID); }
//BS: Commenting this function out: its never used 03/23/13 //----------------------------------------------------------------- //By: Ryan Moe //Edited Last: //private void reopenAlbumsXML_backend(generic_callback guiCallback) //{ // //use this to inform the calling gui of how things went. // ErrorReport error = new ErrorReport(); // util_openAlbumsXML(error); // guiCallback(error); //} //----------------------------------------------------------------- //By: Ryan Moe //Edited Last: private void saveAlbumsXML_backend(generic_callback guiCallback) { ErrorReport error = new ErrorReport(); //make sure the album database is valid. if (!util_checkAlbumDatabase(error)) { guiCallback(error); return; } _albumsDatabase.Document.Save(albumsDatabasePath); if (guiCallback != null) guiCallback(error); }
//------------------------------------------------------------------- //By: Bill Sanders //Edited Last: 3/28/13 /// <summary> /// Removes the specified photo from the specified album /// </summary> /// <param name="guiCallback"></param> /// <param name="pictureElement"></param> /// <returns></returns> private ErrorReport removePictureFromPicsDB_backend(generic_callback guiCallback, XElement pictureElement) { ErrorReport errorReport = new ErrorReport(); try { File.Delete(pictureElement.Element("filePath").Value); } catch { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Failed to delete the photo file from the filesystem"; return errorReport; } // Delete this instance of the photo from the in-memory xml database try { pictureElement.Remove(); // TODO: move these calls out of here for efficiency in removing multiple files! saveAlbumsXML_backend(null); savePicturesXML_backend(null); } catch // the photo mysteriously disappeared (from the xml!) before removing it..? { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Failed to remove the photo instance from the xml database"; return errorReport; } return errorReport; }
//------------------------------------------------------------------- //By: Bill Sanders //Edited Last: 3/28/13 /// <summary> /// Removes the specified photo from the specified album /// </summary> /// <param name="guiCallback"></param> /// <param name="pictureElement"></param> /// <returns></returns> private ErrorReport removePictureElement_backend(generic_callback guiCallback, XElement pictureElement) { ErrorReport errorReport = new ErrorReport(); XElement picFromPicsDB = util_getPhotoDBNode(errorReport, (string)pictureElement.Attribute("sha1")); int refCount = (int)picFromPicsDB.Attribute("refCount"); refCount--; // Delete this instance of the photo from the in-memory xml database try { // delete this instance of the picture from the album db pictureElement.Remove(); if (refCount == 0) { // This was the last reference to the picture. removePictureFromPicsDB_backend(null, picFromPicsDB); } else { // update xml with new refcount picFromPicsDB.Attribute("refCount").Value = refCount.ToString(); } // TODO: move these two calls out of here for efficiency in removing multiple files! saveAlbumsXML_backend(null); savePicturesXML_backend(null); } catch // the photo mysteriously disappeared (from the xml!) before removing it..? { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Failed to remove the photo instance from the xml database"; } return errorReport; }
//----------------------------------------------------------------- //By: Ryan Moe //Edited Last: // I understand what this function does, but not entirely when/why it does it private void rebuildBackendOnFilesystem_backend(generic_callback guiCallback) { ErrorReport errorReport = new ErrorReport(); //if the library folder existed, rename it. if (Directory.Exists(libraryPath)) { //if a backup already exists, throw error. try { Directory.Move(libraryPath, (libraryPath + Properties.Settings.Default.PhotoLibraryBackupName)); } catch { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Couldn't backup (rename) the old library folder. If you have a library backup already, please remove it."; guiCallback(errorReport); return; } }//if //now make a new library folder try { Directory.CreateDirectory(libraryPath); } catch { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Unable to create the new library folder."; guiCallback(errorReport); return; } //make the new database xml files XDocument initDB = new XDocument(); XElement root = new XElement(Properties.Settings.Default.XMLRootElement); initDB.Add(root); try { initDB.Save(albumsDatabasePath); initDB.Save(picturesDatabasePath); } catch { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Unable to create the new database files."; guiCallback(errorReport); return; } //Load the new databases into memory. // BS: These functions are being slated for merging together util_openAlbumsXML(errorReport); util_openPicturesXML(errorReport); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } saveAlbumsXML_backend(null); savePicturesXML_backend(null); guiCallback(errorReport); }
//-------------------------------------------------------------- //By: Ryan Moe //Edited Last: private void changePhotoNameByUID_backend(generic_callback guiCallback, int albumUID, int photoUID, String newName) { ErrorReport errorReport = new ErrorReport(); //get the album that has the name of the photo we are changing. XElement album = util_getAlbum(errorReport, albumUID); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } //Get the photo from the album. XElement photo = util_getAlbumDBPhotoNode(errorReport, album, photoUID); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } //change the photo's name. util_renamePhoto(errorReport, photo, newName); if (errorReport.reportID == ErrorReport.FAILURE) { guiCallback(errorReport); return; } saveAlbumsXML_backend(null); }
//By: Bill Sanders //Edited: Julian Nguyen(4/30/13) /// <summary> /// Checks to see if a photo name is unique. /// This will return FAILED in the error report (in the callback) /// if the name is not unique. /// </summary> /// <param name="guiCallback">The callback to the GUI.</param> /// <param name="photoName">The name of the image to be tested.</param> /// <param name="albumUID">The ID of the Album that the Image is in.</param> public void isImageNameUnique(generic_callback guiCallback, String photoName, Guid albumUID) { ErrorReport errReport = null; bool isUnique = false; errReport = _photoBombDatabase.isImageNameUnique_backend(photoName, albumUID, out isUnique); guiCallback(errReport); }
/// By: Ryan Moe /// Edited: Julian Nguyen(4/28/13) /// <summary> /// initialize the backend object AND load the databases. DOES NOT re-initialize the databases if there is a problem. /// Error: Fails if any of the XML files is nissing or if the image folder does not exist. /// </summary> /// <param name="guiCallback">The callback to the GUI.</param> /// <param name="albumDatabasePathIn">The path to the album XML file.</param> /// <param name="imageDatabasePathIn">The path to the image XML file.</param> /// <param name="libraryPath">The path to the folder where all the images are stored.</param> public void init(generic_callback guiCallback, string albumDatabasePathIn, string imageDatabasePathIn, string libraryPath) { ErrorReport errReport = null; errReport = _photoBombDatabase.init_backend(_albumDatabasePath, _imageDatabasePath, _libraryPath); loadsettingsDatabase(_settingPath); guiCallback(errReport); }
/// By Ryan Moe /// Edited Julian Nguyen(4/27/13) /// <summary> /// Checks to see if an album name is unique. /// This will return FAILED in the error report (in the callback) /// </summary> /// <param name="guiCallback"></param> /// <param name="albumName"></param> public void checkIfAlbumNameIsUnique(generic_callback guiCallback, String albumName) { ErrorReport errReport = null; bool isUnique = false; errReport = _photoBombDatabase.isAlbumNameUnique_backend(albumName, out isUnique); guiCallback(errReport); }
/// By: Ryan Moe /// Edited Julian Nguyen(4/27/13) /// <summary> /// Adds a new album to the album database. /// </summary> /// <param name="guiCallback">The callback for the GUI.</param> /// <param name="albumData">a data class that you need to fill out with the new album's info. /// NOTE: you don't need to worry about the UID, that gets set in here.</param> public void addNewAlbum(generic_callback guiCallback, SimpleAlbumData albumData) { ErrorReport errReport = null; errReport = _photoBombDatabase.addNewAlbum_backend(albumData); guiCallback(errReport); }
//---------------------------------------------- //By: Ryan Moe //Edited Last: // //Adds a single existing picture (it exists in the picture database already) to //an album. //PARAM 4 = data class for you to fill out. //UNTESTED/UNFINISHED. public void addExistingPictureToAlbum(generic_callback guiCallback, int pictureUID, int albumUID, String SimplePhotoData) { addExistingPictureToAlbum_backend(guiCallback, pictureUID, albumUID, SimplePhotoData); }
//BS: Commenting this function out: its never used 03/23/13 //---------------------------------------------- //By: Ryan Moe //Edited Last: // //Open the pictures database (xml file). //PARAM 1 = a gui callback (see PhotoBombDelegates.cs). //ERROR CONDITIONS //1) if the xml file does not exist, an error will be returned. //2) if the xml file does not contain VALID xml, error. //public void reopenPicturesXML(generic_callback guiCallback) //{ // reopenPicturesXML_backend(guiCallback); //} //----------------------------------------------- //By: Ryan Moe //Edited Last: // //Save the pictures database (xml file). //PARAM 1 = a gui callback (see PhotoBombDelegates.cs). public void savePicturesXML(generic_callback guiCallback) { savePicturesXML_backend(guiCallback); }
//BS: Commenting this function out: its never used 03/23/13 //---------------------------------------------- //By: Ryan Moe //Edited Last: // //reopen the xml document (database) that represents the //user's albums in the program. //PARAM 1 = a callback (delegate) to a gui function (see PhotoBombDelegates.cs). //ERROR CONDITIONS //1) if the xml file does not exist, an error will be returned. //2) if the xml file does not contain VALID xml, error. //public void reopenAlbumsXML(generic_callback guiCallback) //{ // reopenAlbumsXML_backend(guiCallback); //} //---------------------------------------------- //By: Ryan Moe //Edited Last: // //Save the album data to an xml file. //PARAM 1 = a gui callback (see PhotoBombDelegates.cs). public void saveAlbumsXML(generic_callback guiCallback) { saveAlbumsXML_backend(guiCallback); }
/********************************************************************************************* * Author: Alejandro Sosa * parameters: * return type: void * purpose: *********************************************************************************************/ public void guiCreateThisAlbum(string userInput, generic_callback addNewAlbumDelegate) { SimpleAlbumData theNewAlbum = new SimpleAlbumData(); theNewAlbum.albumName = userInput; bombaDeFotos.addNewAlbum(addNewAlbumDelegate, theNewAlbum); }
//--------------------------------------------- //By: Ryan Moe //Edited Last: private void addNewPictures_backend(generic_callback guiCallback, List<String> photoUserPath, List<String> photoExtension, int albumUID, List<String> pictureNameInAlbum, ProgressChangedEventHandler updateCallback, int updateAmount) { addPhotosThread = new BackgroundWorker(); //transfer parameters into a data class to pass //into the photo thread. addPhotosThreadData data = new addPhotosThreadData(); data.errorReport = new ErrorReport(); data.guiCallback = guiCallback; data.photoUserPath = photoUserPath; data.photoExtension = photoExtension; data.albumUID = albumUID; data.pictureNameInAlbum = pictureNameInAlbum; data.updateAmount = updateAmount; //setup the worker. addPhotosThread.WorkerReportsProgress = true; addPhotosThread.WorkerSupportsCancellation = true; addPhotosThread.DoWork += new DoWorkEventHandler(addPhotosThread_DoWork); addPhotosThread.ProgressChanged += updateCallback; addPhotosThread.RunWorkerCompleted += new RunWorkerCompletedEventHandler(addPhotosThread_RunWorkerCompleted); addPhotosThread.RunWorkerAsync(data); }
/// By Ryan Moe /// Edited: Julian Nguyen(4/28/13) /// <summary> /// CAREFULL!!! This will blow out the databases and make a new library folder. /// Before making the new library folder, if an old folder was found, /// that old folder will be renamed to libraryName_backup. ///ERROR: This returns an error if it fails to create one of the database files or the folder. ///If libraryName_backup exists it also returns an error. /// </summary> /// <param name="guiCallback">The callback to the GUI.</param> public void rebuildBackendOnFilesystem(generic_callback guiCallback) { ErrorReport errReport = null; errReport = _photoBombDatabase.rebuildBackendOnFilesystem_backend(); guiCallback(errReport); }
//-------------------------------------------------------------- //By: Ryan Moe //Edited Last: private void checkIfAlbumNameIsUnique_backend(generic_callback guiCallback, String albumName) { ErrorReport errorReport = new ErrorReport(); //get uniqueness Boolean nameUnique = util_checkAlbumNameIsUnique(albumName); if (!nameUnique) { errorReport.reportID = ErrorReport.FAILURE; errorReport.description = "Album name is not unique."; guiCallback(errorReport); return; } guiCallback(errorReport); }
//By: Bill Sanders //Edited Last: 3/28/13 /// <summary> /// This function removes the specified album. /// </summary> /// <param name="guiCallback"></param> /// <param name="albumUID">The UID of the album</param> public void removeAlbum(generic_callback guiCallback, Guid albumUID) { ErrorReport errReport = null; errReport = _photoBombDatabase.removeAlbum_backend(albumUID); guiCallback(errReport); }
//----------------------------------------------------------------- //FUNCTIONS-------------------------------------------------------- //----------------------------------------------------------------- //By: Ryan Moe //Edited Last: 3/31/13 //Edited By: Ryan Causey private void init_backend(generic_callback guiCallback, string albumDatabasePathIn, string pictureDatabasePathIn, string libraryPathIn) { ErrorReport errorReport = new ErrorReport(); //keep the paths to databases and library. albumsDatabasePath = albumDatabasePathIn; picturesDatabasePath = pictureDatabasePathIn; libraryPath = libraryPathIn; //this might be depricated with the current backend design, //think about moving it into the utils class... //xmlParser = new XmlParser(); //try to open the databases. // BS: These functions are being slated for merging together // Ooops. If these functions fail, but the third check succeeds, it overwrites errorReport util_openAlbumsXML(errorReport); util_openPicturesXML(errorReport); //check the library directory. util_checkLibraryDirectory(errorReport); //the list of all albums to return to the gui. _albumsToReturn = new ObservableCollection<SimpleAlbumData>(); guiCallback(errorReport); }
/// By: Bill Sanders /// Edited Julian Nguyen(4/28/13) /// <summary> /// This function removes the specified photo from the specified album. /// </summary> /// <param name="guiCallback"></param> /// <param name="uid">The idInAlbum of the photo</param> /// <param name="albumUID">The UID of the album</param> public void removeImageFromAlbum(generic_callback guiCallback, int idInAlbum, Guid albumUID) { ErrorReport errReport = null; errReport = _photoBombDatabase.removeImageFromAlbum_backend(idInAlbum, albumUID); guiCallback(errReport); }
//------------------------------------------------------------------- //By: Bill Sanders //Edited Last: 3/28/13 /// <summary> /// Removes the specified album /// </summary> /// <param name="guiCallback"></param> /// <param name="albumUID">The album's UID</param> private ErrorReport removeAlbum_backend(generic_callback guiCallback, int albumUID) { ErrorReport errorReport = new ErrorReport(); XElement specificAlbum = util_getAlbum(errorReport, albumUID); List<XElement> pictureElements = specificAlbum.Element("albumPhotos").Elements("picture").ToList(); // linq returns a lazy evaluated ienumberable, which foreach apparently doesn't like, so we convert to a list. foreach (XElement subElement in pictureElements) { // remove the picture element removePictureElement_backend(null, subElement); } // now delete the album itself. // Since we're deleting every photo in the album, we can just remove the node. specificAlbum.Remove(); // now sync to the disk saveAlbumsXML_backend(null); savePicturesXML_backend(null); return errorReport; }
/// By Ryan Moe /// Edited: Julian Nguyen(4/28/13) /// <summary> /// Will save the Image XML to file. /// </summary> /// <param name="guiCallback">The call back to the GUI.</param> public void saveImagesXML(generic_callback guiCallback) { ErrorReport errReport = null; errReport = _photoBombDatabase.saveImagesXML_backend(); if(guiCallback != null) guiCallback(errReport); }
//------------------------------------------------------------------- //By: Bill Sanders //Edited Last: 3/29/13 /// <summary> /// Removes the specified photo from the specified album /// </summary> /// <param name="guiCallback"></param> /// <param name="PhotoID">The photo's ID</param> /// <param name="albumUID">The album's UID</param> private ErrorReport removePictureFromAlbum_backend(generic_callback guiCallback, int PhotoID, int albumUID) { ErrorReport errorReport = new ErrorReport(); // these two lines are kind of redundant, at the moment // First get the actual instance of the photo (from the pictures DB!) XElement thisPicture = util_getAlbumDBPhotoNode(albumUID, PhotoID); //util_getPhotoDBNode(errorReport, uid); // Now get that photo from the album DB! // thisPicture = util_getAlbumDBPhotoNode(albumUID, (string)thisPicture.Attribute("sha1")); //thisPicture = errorReport = removePictureElement_backend(null, thisPicture); return errorReport; }
//By: Bill Sanders //Edited Last: 4/6/13 /// <summary> /// This function renames the specified image in this album. /// </summary> /// <param name="guiCallback"></param> /// <param name="albumUID">The UID of the album the photo is in</param> /// <param name="idInAlbum">The id of the photo in this album</param> /// <param name="newName">The new name of the photo</param> public void setImageName(generic_callback guiCallback, Guid albumUID, int idInAlbum, string newName) { ErrorReport errReport = null; errReport = _photoBombDatabase.setImageName_backend(albumUID, idInAlbum, newName); guiCallback(errReport); }
//By: Ryan Moe //Edited Last: // //Change the name of a photo (its name in a single album) in the //database and save the change to disk. /// <summary> /// Will change the name of an Image in an album. /// </summary> /// <param name="guiCallback">The callback to the GUI.</param> /// <param name="albumUID">The ID of the album.</param> /// <param name="photoUID">The ID of Image (In Album ID)</param> /// <param name="newName"></param> public void setImageNameByUID(generic_callback guiCallback, Guid albumUID, int photoUID, String newName) { ErrorReport errReport = null; errReport = _photoBombDatabase.setImageNameByUID_backend( albumUID, photoUID, newName); guiCallback(errReport); }
/********************************************************************************************* * Author: Alejandro Sosa * parameters: * return type: void * purpose: *********************************************************************************************/ public void guiCheckAlbumNameIsUnique(string userInput, generic_callback addNewAlbumDelegate) { bombaDeFotos.checkIfAlbumNameIsUnique(addNewAlbumDelegate, userInput); }
//BS: Commenting this function out: its never used 03/23/13 //----------------------------------------------------------------- //By: Ryan Moe //Edited Last: //private void reopenPicturesXML_backend(generic_callback guiCallback) //{ // //use this to inform the calling gui of how things went. // ErrorReport error = new ErrorReport(); // try // { // _picturesDatabase = XDocument.Load(picturesDatabasePath); // } // catch // { // error.reportID = ErrorReport.FAILURE; // error.description = "PhotoBomb.openPicturesXML():failed to load the albums xml file: " + picturesDatabasePath; // guiCallback(error); // return; // } // //The loading of the xml was nominal, report back to the gui callback. // guiCallback(error); //} //----------------------------------------------------------------- //By: Ryan Moe //Edited Last: private void savePicturesXML_backend(generic_callback guiCallback) { ErrorReport error = new ErrorReport(); //if the database is NOT valid. if (!util_checkPhotoDBIntegrity(error)) { guiCallback(error); return; } _picturesDatabase.Document.Save(picturesDatabasePath); if (guiCallback != null) guiCallback(error); }
//By: Bill Sanders //Edited Last: 3/28/13 /// <summary> /// This function removes the specified album. /// </summary> /// <param name="guiCallback"></param> /// <param name="albumUID">The UID of the album</param> public void removeAlbum(generic_callback guiCallback, int albumUID) { removeAlbum_backend(guiCallback, albumUID); }