示例#1
0
        //-------------------------------------------------------------
        //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);
        }
        // Commenting this out, its functionality has been merged with util_getNextUID()
        // to replicate: util_getNextUID(_albumsDatabase, "album", 1)
        //------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //Returns a new VALID uid for a new album.
        //NOTE: this is the slow way of doing it, but
        //      it does not leave holes in the uids.
        //      Ex: if an album is deleted, we reuse it's uid
        //      when a new album is added.
        //RETURNS -1 if there was a problem getting a new uid.
        //private int util_getNewAlbumUID(ErrorReport error)
        //{
        //    int newUID = 1;
        //    Boolean uidNotFound = true;
        //    while (uidNotFound && newUID < UID_MAX_SIZE)
        //    {
        //        try
        //        {
        //            //if one or more (hope not more!) uid's are found
        //            //to match our testing uid, then incriment the testing
        //            //uid and try again.
        //            (from c in _albumsDatabase.Elements("album")
        //             where (int)c.Attribute("uid") == newUID
        //             select c).First();
        //            ++newUID;
        //        }
        //        //we found a unique one!
        //        catch
        //        {
        //            uidNotFound = false;
        //        }
        //    }//while
        //    if (newUID < UID_MAX_SIZE)
        //        return newUID;
        //    return -1;
        //}
        //-------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //add an album to the database in memory ONLY.
        private void util_addAlbumToAlbumDB(ErrorReport errorReport, SimpleAlbumData albumData)
        {
            //make sure the album database is valid.
            if (!util_checkAlbumDatabase(errorReport))
            {
                return;
            }

            //construct the object we will be adding to the database.
            XElement newAlbum = new XElement("album",
                                            new XAttribute("uid", albumData.UID),
                                            new XElement("albumName", albumData.albumName),
                                            new XElement("albumPhotos"));

            //add to the database in memory.
            _albumsDatabase.Add(newAlbum);
        }
示例#3
0
        //-----------------------------------------------------------------
        // 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);
        }
示例#4
0
 /// 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);
 }
示例#5
0
        /*********************************************************************************************
        * 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);
        }
示例#6
0
 //----------------------------------------------
 //By: Ryan Moe
 //Edited Last:
 //
 //Adds a new album to the album database.
 //PARAM 2 = 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.
 public void addNewAlbum(generic_callback guiCallback, SimpleAlbumData albumData)
 {
     addNewAlbum_backend(guiCallback, albumData);
 }
        //-------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //add an album to the database in memory ONLY.
        private void addAlbumNodeToAlbumsXml__(SimpleAlbumData albumData)
        {
            //construct the object we will be adding to the database.
            XElement newAlbum = new XElement("album",
                new XAttribute("uid", albumData.UID),
                new XElement("thumbnailPath", new XAttribute("thumbAlbumID", albumData.thumbAlbumID), albumData.thumbnailPath),
                new XElement("albumName", albumData.albumName),
                new XElement("albumPhotos"));

            //add to the database in memory.
            _albumsRootXml.Add(newAlbum);
        }
示例#8
0
        /**************************************************************************************************************************
         * Author: Ryan Causey
         * Created on: 4/3/13
         * Function for creating a new album name. Only to be called after the album name is validated.
         * @Param: albumName = the name for the new album being created
         * Last Edited By:
         * Last Edited Date:
         **************************************************************************************************************************/
        private void guiCreateNewAlbum(String albumName)
        {
            SimpleAlbumData newAlbum = new SimpleAlbumData();

            newAlbum.albumName = albumName;

            masterAndCommander.addNewAlbum(new generic_callback(guiCreateNewAlbum_Callback), newAlbum);
        }
示例#9
0
        /// By: Ryan Moe
        /// Edited: Julian Nguyen(4/28/13)
        /// <summary>
        /// This function blows out the existing database(normally due to it being corrupted)
        /// and creates a new one, consolidating all the photos into a Recovery Album.
        /// </summary>
        /// <returns>The error report of this action.</returns>
        public ErrorReport rebuildBackendOnFilesystem_backend()
        {
            ErrorReport errorReport = new ErrorReport();
            bool recover = true;

            //if the library folder does not exist, we are not recovering because there is nothing to recover. Sorry =(
            if (!Directory.Exists(_imagelibraryDirPath))
            {
                //now make a new library folder
                try
                {
                    Directory.CreateDirectory(_imagelibraryDirPath);
                }
                catch
                {
                    setErrorReportToFAILURE("Unable to create the new library folder.", ref errorReport);

                    return errorReport;
                }
                recover = false;
            }

            createDefaultXML(errorReport);

            // Check the XML creation for bugs
            if (errorReport.reportStatus == ReportStatus.FAILURE)
            {
                return errorReport;
            }

            //Load the new databases into memory.
            // BS: These functions are being slated for merging together
            _photoBomb_xml.loadXmlRootElement(_albumsXmlPath, out _albumsRootXml);
            _photoBomb_xml.loadXmlRootElement(_albumsXmlPath, out _imagesRootXml);
            //util_openAlbumsXML(errorReport);
            //util_openImagesXML(errorReport);

            if (errorReport.reportStatus == ReportStatus.FAILURE)
            {
                return errorReport;
            }

            // Not needed, createDefaultXML() saves these.
            //saveAlbumsXML_backend();
            //saveImagesXML_backend();

            //build the backup album and add all the photos to that album if we can
            if (recover)
            {
                addPhotoBackup(errorReport, buildBackupAlbum(errorReport));
            }
            else
            {
                SimpleAlbumData firstAlbum = new SimpleAlbumData();
                firstAlbum.albumName = "My First Album";
                addNewAlbum_backend(firstAlbum);
            }
            return errorReport;
        }
示例#10
0
        /// By: Bill Sanders, based on Ryan Moe's earlier function.
        /// Edited: Julian Nguyen(5/1/13)
        /// <summary>
        /// Retrieves a list of all albums in the albums.xml file, sent back via the callback.
        /// </summary>
        /// <param name="readOnlyAlbumList">A passback list of SimpleAlbumData.</param>
        /// <returns>The error report of this action.</returns>
        public ErrorReport getAllAlbums_backend(out ReadOnlyObservableCollection<SimpleAlbumData> readOnlyAlbumList)
        {
            ErrorReport error = new ErrorReport();

            //clear the collection as we are refreshing it
            _albumsCollection.Clear();
            //Null for safely.
            readOnlyAlbumList = null;

            // Ensure the database is valid before proceeding
            if (!util_checkAlbumDatabase(error))
            {
                setErrorReportToFAILURE("The album database was determined to be not valid", ref error);
                return error;
            }

            // An object to enumerate over the album XML nodes
            IEnumerable<XElement> _albumSearchIE;
            try
            {
                // get all the albums
                _albumSearchIE = (from c in _albumsRootXml.Elements() select c);
            }
            catch
            {
                setErrorReportToFAILURE("PhotoBomb.getAllAlbums_backend():Failed at finding albums in the database.", ref error);
                return error;
            }
            foreach (XElement thisAlbum in _albumSearchIE)
            {
                SimpleAlbumData userAlbum = new SimpleAlbumData();

                userAlbum.UID = (Guid)thisAlbum.Attribute("uid");

                // Get the thumbnail path...
                userAlbum.thumbnailPath = thisAlbum.Element("thumbnailPath").Value;
                // An album may legally have an empty thumbnail path (if for example it is empty)...

                // Get the idInAlbum of the thumbnail
                try
                {
                    userAlbum.thumbAlbumID = Convert.ToInt32(thisAlbum.Element("thumbnailPath").Attribute("thumbAlbumID").Value);
                }
                catch
                {
                    userAlbum.thumbAlbumID = -1;
                }

                // Here we're going to check if we need to regenerate the album thumbnail
                // First check to make sure the album's thumbnail is NOT set to empty string (an empty album) AND
                // Check to see if the file specified by thumbnailPath does NOT exist
                if ((userAlbum.thumbnailPath != string.Empty) && (!File.Exists(userAlbum.thumbnailPath)))
                {
                    // if the thumbnail doesn't exist... does the image itself?

                    XElement thumbnailPhoto = _photoBomb_xml.getAlbumImageNodeFromAlbumXml(userAlbum.UID, userAlbum.thumbAlbumID, _albumsRootXml);
                    ComplexPhotoData albumImageNodej = _photoBomb_xml.getComplexPhotoDataFromAlbumImageNode(thumbnailPhoto, _imagesRootXml);

                    if (albumImageNodej == null)
                    {
                        setErrorReportToFAILURE("Cannot get complexPhotoData", ref error);
                        return error;
                    }

                    if (!File.Exists(albumImageNodej.fullPath))
                    {
                        // if the image does not exist, remove all references of it from the whole DB
                        util_purgePhotoFromDB(error, ByteArrayToString(albumImageNodej.hash));
                    }

                    // get the first photo in the album and set it as the thumbnail
                    XElement firstAlbumImageNode = (from c in thisAlbum.Descendants("picture") select c).FirstOrDefault();

                    if (firstAlbumImageNode != null)
                    {
                        // ... and set it to be the thumbnail (generating it, if necessary)
                        util_setAlbumThumbnail(thisAlbum, _photoBomb_xml.getComplexPhotoDataFromAlbumImageNode(firstAlbumImageNode, _imagesRootXml));
                    }
                }

                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.reportStatus = ReportStatus.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
                }

                _albumsCollection.Add(userAlbum);
            }
            readOnlyAlbumList = new ReadOnlyObservableCollection<SimpleAlbumData>(_albumsCollection);
            return error;
        }
示例#11
0
        /// By: Ryan Moe
        /// Edited Julian Nguyen
        /// <summary>
        /// Will add a new Album to the database.
        /// Note: The UID of the albumData will not be used!!
        /// </summary>
        /// <param name="albumData">The data for the new album. The UID will not be used.</param>
        /// <returns>The error Report of this action.</returns>
        public ErrorReport addNewAlbum_backend(SimpleAlbumData albumData)
        {
            ErrorReport errorReport = new ErrorReport();

            //get a new uid for the new album.
            albumData.UID = Guid.NewGuid(); //util_getNextUID(_albumsRootXml, "album", "uid", 1);

            //add the album to the memory database.
            try
            {
                _photoBomb_xml.addAlbumNodeToAlbumsXml(albumData.UID, albumData.thumbAlbumID, albumData.thumbnailPath, albumData.albumName, _albumsRootXml);

            }
            catch (NullReferenceException)
            {
                setErrorReportToFAILURE("Failed to add an album to the albums xml.", ref errorReport);
                return errorReport;
            }
            //need to update the _albumsCollection observableCollection to reflect this addition in the GUI
            _albumsCollection.Add(albumData); //adds to end of collection

            // Save the albums xml to disk.
            return saveAlbumsXML_backend();
        }
示例#12
0
        /*
         * Created By: Ryan Causey
         * Created Date: 4/4/13
         * Last Edited By:
         * Last Edited Date:
         */
        /// <summary>
        /// will clear the existing album collection and create a new Recovery Album
        /// and add it to the previously cleared collection.
        /// </summary>
        /// <param name="errorReport">ErrorReport object to be updated</param>
        /// <returns>ErrorReport</returns>
        private Guid buildBackupAlbum(ErrorReport errorReport)
        {
            //empty the existing album collection
            _albumsCollection.Clear();

            //create the backup album
            SimpleAlbumData backupAlbum = new SimpleAlbumData();

            //set the name
            backupAlbum.albumName = Settings.PhotoLibraryBackupName;

            //get a new uid for the new album.
            backupAlbum.UID = Guid.NewGuid();

            try
            {
                _photoBomb_xml.addAlbumNodeToAlbumsXml(backupAlbum.UID, backupAlbum.thumbAlbumID, backupAlbum.thumbnailPath, backupAlbum.albumName, _albumsRootXml);

            }
            catch (NullReferenceException)
            {
                //if adding to the album database failed
                return Guid.Empty;
            }

            //save to disk.
            errorReport = saveAlbumsXML_backend();
            if (errorReport.reportStatus == ReportStatus.FAILURE)
                return Guid.Empty;

            return backupAlbum.UID;
        }