Beispiel #1
0
 /*********************************************************************************************
 * Author: Alejandro Sosa
 * parameters: ErrorReport to check if back end successful
 * return type: void
 * purpose:
 *********************************************************************************************/
 public void albumAdded(ErrorReport status)
 {
     if (status.reportID != ErrorReport.SUCCESS)
     {
         // no error specified in srs.
         finishButton.Enabled = true;
     }
     else
     {
         DialogResult = DialogResult.OK;
         this.Close();
     }
 }
Beispiel #2
0
        /*********************************************************************************************
        * Author: Alejandro Sosa
        * parameters: ErrorReport to check if back end successful
        * return type: void
        * purpose: determines course of action depending on whether name is valid and unique
        *********************************************************************************************/
        public void albumNameAccepted(ErrorReport status)
        {
            if (status.reportID != ErrorReport.SUCCESS)
            {
                showError("Invalid album name.");

                finishButton.Enabled = true;
            }
            else
            {
                mainWindowRef.guiCreateThisAlbum(albumNameTextBox.Text, albumAdded);
            }
        }
Beispiel #3
0
        /*********************************************************************************************
        * Author: Alejandro Sosa
        * parameters: an object of ErrorReport which will be used to check if backend was successful,
        *   and a list <type is SimpleAlbumData> containing data to identify all albums requested
        * return type: void
        * purpose: list of albums returned from the backend
        *********************************************************************************************/
        public void guiAlbumsRetrieved(ErrorReport status, ReadOnlyObservableCollection<SimpleAlbumData> albumsRetrieved)
        {
            if (status.reportID == ErrorReport.SUCCESS)
            {
                listOfAlbums = albumsRetrieved;

                mainWindowAlbumList.ItemsSource = listOfAlbums;

                //mainWindowAlbumList.listItemsControl.DataContext = listOfAlbums;

            }
            else
            {
                //show an Error
            }

                /*
                //--stops the drawing of albumListView
                albumListView.BeginUpdate();

                ListViewItem itemHolder = null;
                ListViewItem.ListViewSubItem[] itemHolderSubitems;

                foreach (SimpleAlbumData singleAlbum in albumsRetrieved)
                {
                    try
                    {
                        itemHolderSubitems = new ListViewItem.ListViewSubItem[]{
                            new ListViewItem.ListViewSubItem(itemHolder, singleAlbum.albumName),
                            new ListViewItem.ListViewSubItem(itemHolder, singleAlbum.UID.ToString() )
                            };

                        itemHolder = new ListViewItem(itemHolderSubitems, defaultAlbumImageListIndex);
                        albumListView.Items.Add(itemHolder);
                    }
                    catch (Exception)
                    {
                        showError("Error: Album Missing");
                    }
                }

                //--resumes drawing of albumListView
                albumListView.EndUpdate();
            }
            else if (status.reportID == ErrorReport.FAILURE)
            {
                showError("Error: Album Missing");
            }
            */
        }
Beispiel #4
0
        //-------------------------------------------------------------
        //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:
        //load the database from disk into memory.
        // BS: This function is being slated for merging with util_openAlbumXML
        private void util_openPicturesXML(ErrorReport error)
        {
            try
            {
                _picturesDatabase = XDocument.Load(picturesDatabasePath).Element(Properties.Settings.Default.XMLRootElement);
            }
            catch
            {
                error.reportID = ErrorReport.FAILURE;
                error.description = "PhotoBomb.openPicturesXML():failed to load the pictures xml file: " + picturesDatabasePath;
                return;
            }

            //The loading of the xml was nominal.
            error.description = "great success!";
        }
        //----------------------------------------------------------
        //By: Ryan Moe
        //Edited Last: Bill Sanders, 3/29/13
        /// <summary>
        /// Query the Photo DB for a photo by hash
        /// </summary>
        /// <param name="error"></param>
        /// <param name="photoUID"></param>
        /// <returns>An XElement object representing the photo in the PhotoDB</returns>
        private XElement util_getPhotoDBNode(ErrorReport error, int photoUID)
        {
            if (util_checkPhotoDBIntegrity(error))
            {
                //Try searching for the album with the uid specified.
                XElement specificPicture;
                try
                {
                    //for(from) every c in the database's children (all albums),
                    //see if it's attribute uid is the one we want,
                    //and if so return the first instance of a match.
                    specificPicture = (from c in _picturesDatabase.Elements()
                                       where (int)c.Attribute("uid") == photoUID
                                       select c).Single();//NOTE: this will throw error if more than one OR none at all.
                }
                //failed to find the picture
                catch
                {
                    error.reportID = ErrorReport.FAILURE;
                    error.description = "Failed to find the picture specified.";
                    return null;
                }
                //success!
                return specificPicture;
            }

            //database is not clean!
            else
            {
                //error object already filled out by integrity checker.
                return null;
            }
        }
        //--------------------------------------------------------
        // By: Bill Sanders
        // Edited Last: 3/28/13
        /// <summary>
        /// Retrieves a specific photo instance from a combination of the AlbumID and its Photo ID in that album
        /// </summary>
        /// <param name="albumID">The unique ID of the album</param>
        /// <param name="photoID">The unique ID of the image in that album</param>
        /// <returns>Returns an xml node of the photo from the AlbumDB, or null.</returns>
        private XElement util_getAlbumDBPhotoNode(int albumID, int photoID)
        {
            ErrorReport errorReport = new ErrorReport();

            // first get the album by albumID
            XElement albumNode = util_getAlbum(errorReport, albumID);

            // Then get the photo node from that.
            XElement photoInstance = null;
            try
            {
                photoInstance = util_getAlbumDBPhotoNode(errorReport, albumNode, photoID);
            }
            catch
            {
                return null;
            }
            return photoInstance;
        }
        //-------------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //copies a picture into our picture library.
        //DOES NOT CHECK picturePath or picName, please do before hand.
        private String util_copyPicToLibrary(ErrorReport errorReport, String picturePath, String picNameInLibrary)
        {
            //check if file exists first!!!
            //if the picture does NOT exist.
            if (!File.Exists(picturePath))
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Can't find the new picture to import to the library.";
                return "";
            }

            //check if the library is ok.
            if (!util_checkLibraryDirectory())
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Something is wrong with the photo library.";
                return "";
            }

            //make the full picture path.
            String newPath = System.IO.Path.Combine(libraryPath, picNameInLibrary);

            // I haven't thought much about whether or not this is the right place to put this
            Imazen.LightResize.ResizeJob resizeJob = new Imazen.LightResize.ResizeJob();
            // specifies a maximum height resolution constraint
            resizeJob.Height = 120;
            // Actually processes the image, copying it to the new location, should go in a try/catch for IO
            // One of Build's overloads allows you to use file streams instead of filepaths.
            // If images have to be resized on-the-fly instead of stored, that may work as well.
            resizeJob.Build(
                picturePath,
                System.IO.Path.Combine(
                    libraryPath,
                    Properties.Settings.Default.PhotoLibraryThumbsDir,
                    picNameInLibrary),
                Imazen.LightResize.JobOptions.CreateParentDirectory
            );

            try
            {
                //copy the photo to the library.
                System.IO.File.Copy(picturePath, newPath, true);
            }
            catch
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Unable to make a copy of the photo in the library.";
                return "";
            }

            //new library path
            return newPath;
        }
        //----------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //use this to convert a photo element into a simplePhotoData data class.
        //Try and keep this updated if new fields are added to simplePhotoData.
        private SimplePhotoData util_convertPhotoElemToSimpleStruct(ErrorReport errorReport, XElement elem)
        {
            SimplePhotoData data = new SimplePhotoData();

            //TRANSFER ALL DATA TO THE DATA CLASS HERE.
            try
            {
                data.UID = (int)elem.Attribute("UID");
                data.picturesNameInAlbum = elem.Element("name").Value;

            }
            catch
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Error getting required data from photo element.";
                return null;
            }

            return data;
        }
 //-------------------------------------------------------------------------
 //By: Ryan Moe
 //Edited Last:
 //check if the library is ok, with ErrorReport param.
 private void util_checkLibraryDirectory(ErrorReport error)
 {
     //anything else we need to check?
     if (!Directory.Exists(libraryPath))
     {
         error.reportID = ErrorReport.FAILURE;
         error.description = "Library folder not found.";
     }
 }
Beispiel #11
0
        //-------------------------------------------------------------------
        //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;
        }
Beispiel #12
0
        //-----------------------------------------------------------------
        //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);
        }
Beispiel #13
0
        //-----------------------------------------------------------------
        //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);
        }
Beispiel #14
0
        //----------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        private void getPhoto_backend(getPhotoByUID_callback guiCallback, int photoUID, int albumUID)
        {
            ErrorReport error = new ErrorReport();

            // beware: this function assumes uid in album.xml == uid in photo.xml
            // change to lookup by hash?
            //get the picture from the picture database.
            XElement albumNode = util_getAlbum(error, albumUID);
            XElement albumPicElement = util_getAlbumDBPhotoNode(error, albumNode, photoUID);
            XElement picElement = util_getPhotoDBNode(error, (string)albumPicElement.Attribute("sha1").Value);

            //if the picture finding function reported success.
            if (error.reportID == ErrorReport.SUCCESS || error.reportID == ErrorReport.SUCCESS_WITH_WARNINGS)
            {
                ComplexPhotoData photo = new ComplexPhotoData();
                //ComplexPhotoData MOE MARKER MOE MARKER MOE MARKER MOE MARKER!!!!!!
                try
                {
                    photo.hash = StringToByteArray((string)picElement.Attribute("sha1"));
                    photo.UID = (int)picElement.Attribute("uid");
                    photo.refCount = (int)picElement.Attribute("refCount");
                    photo.path = (string)picElement.Element("filePath").Value;
                }
                catch
                {
                    error.reportID = ErrorReport.FAILURE;
                    error.description = "PhotoBomb.getPictureByUID():Photo info could not be loaded.";
                    guiCallback(error, null);
                    return;
                }
                //Success!
                guiCallback(error, photo);
                return;
            }
            //picture failed to be found.
            else
            {
                guiCallback(error, null);
                return;
            }
        }
Beispiel #15
0
        // 3/24/2013, BS: Commenting this function out,
        // having replaced it with the one above: getAllAlbums_backend()
        //By: Ryan Moe
        //Edited Last:
        //NOTE: This function is up for replacement by new logic that uses
        //the select/from/where style of code.
        //This is not in the style of code this file wants.
        //private void getAllUserAlbumNames_backend(getAllUserAlbumNames_callback guiCallback)
        //{
        //    ErrorReport error = new ErrorReport();
        //    //if the database is NOT valid.
        //    if (!util_checkAlbumDatabase(error))
        //    {
        //        error.reportID = ErrorReport.FAILURE;
        //        error.description = "The album database was determined to be not valid.";
        //        guiCallback(error, null);
        //        return;
        //    }
        //    //the list of all albums to return to the gui.
        //    List<SimpleAlbumData> _albumsToReturn = new List<SimpleAlbumData>();
        //    //get all the albums AND their children.
        //    List<XElement> _albumSearch;
        //    try
        //    {
        //        _albumSearch = xmlParser.searchForElements(_albumsDatabase.Element(Properties.Settings.Default.XMLRootElement), "album");
        //    }
        //    catch
        //    {
        //        error.reportID = ErrorReport.FAILURE;//maybe every error should be SHIT_JUST_GOT_REAL?  Decisions, decisions...
        //        error.description = "PhotoBomb.getAllUserAlbumNames():Failed at finding albums in the database.";
        //        guiCallback(error, null);
        //        return;
        //    }
        //    //go through each album and get data from its children to add to the list.
        //    foreach (XElement thisAlbum in _albumSearch)
        //    {
        //        //this custom data class gets sent back to the gui.
        //        SimpleAlbumData userAlbum = new SimpleAlbumData();
        //        List<XElement> _nameSearch;
        //        try
        //        {
        //            //get the name(s) of this album.
        //            _nameSearch = xmlParser.searchForElements(thisAlbum, "albumName");
        //        }
        //        catch
        //        {
        //            error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
        //            error.warnings.Add("PhotoBomb.getAllUserAlbumNames():Had an error finding the name of an album.");
        //            continue;
        //        }
        //        //make sure we have at least one name for the album.
        //        if (_nameSearch.Count == 1)
        //        {
        //            //get the value of the album name and add to list.
        //            try
        //            {
        //                userAlbum.albumName = _nameSearch.ElementAt(0).Value;
        //                userAlbum.UID = (int)thisAlbum.Attribute("uid");
        //            }
        //            catch
        //            {
        //                error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
        //                error.warnings.Add("PhotoBomb.getAllUserAlbumNames():Had an error trying to get either the name or uid value from an album.");
        //                continue;
        //            }
        //            _albumsToReturn.Add(userAlbum);
        //        }
        //        else if (_nameSearch.Count > 1)
        //        {
        //            error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
        //            error.warnings.Add("PhotoBomb.getAllUserAlbumNames():Found an album with more than one name.");
        //        }
        //        else if (_nameSearch.Count == 0)
        //        {
        //            error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
        //            error.warnings.Add("PhotoBomb.getAllUserAlbumNames():Found an album with no name.");
        //        }
        //    }//foreach
        //    guiCallback(error, _albumsToReturn);
        //}
        //-----------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last: Bill Sanders, 3/27/13
        private void getAllPhotosInAlbum_backend(getAllPhotosInAlbum_callback guiCallback, int AlbumUID)
        {
            ErrorReport error = new ErrorReport();

            //make sure the album database is valid.
            if (!util_checkAlbumDatabase(error))
            {
                guiCallback(error, null);
                return;
            }

            //Try searching for the album with the uid specified.
            XElement specificAlbum;
            specificAlbum = util_getAlbum(error, AlbumUID);
            // Commenting out the below in favor of a util class. - BillSanders
            //try
            //{
            //    //for(from) every c in the database's children (all albums),
            //    //see if it's attribute uid is the one we want,
            //    //and if so return the first instance of a match.
            //    specificAlbum = (from c in _albumsDatabase.Elements()
            //                     where (int)c.Attribute("uid") == AlbumUID
            //                     select c).Single();//NOTE: this will throw error if more than one OR none at all.
            //}
            //catch
            //{
            //    error.reportID = ErrorReport.FAILURE;
            //    error.description = "PhotoBomb.getAllPhotosInAlbum():Failed to find the album specified.";
            //    guiCallback(error, null);
            //    return;
            //}

            //Now lets get all the picture data from
            //the album and fill out the picture object list.
            List<SimplePhotoData> _list = new List<SimplePhotoData>();
            foreach (XElement subElement in specificAlbum.Element("albumPhotos").Elements("picture"))
            {
                SimplePhotoData pic = new SimplePhotoData();
                try
                {
                    pic.UID = (int)subElement.Attribute("uid");
                    pic.picturesNameInAlbum = (string)subElement.Element("name").Value;
                    _list.Add(pic);
                }
                catch
                {
                    error.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
                    error.warnings.Add("PhotoBomb.getAllPhotosInAlbum():A Picture in the album is missing either a name or an id.");
                }
            }//foreach

            guiCallback(error, _list);
        }
        //--------------------------------------------------------
        //By: Ryan Moe
        //Edited Last: Bill Sanders (4/1/13, removed inline linq, replaced with lookup function; added comments)
        /// <summary>
        /// Adds a photo to a specific album in the album database 
        /// </summary>
        /// <param name="errorReport"></param>
        /// <param name="newPicture"></param>
        /// <param name="albumUID"></param>
        /// <param name="albumName"></param>
        private void util_addPicToAlbumDB(ErrorReport errorReport, ComplexPhotoData newPicture, int albumUID, String albumName)
        {
            //Get the specific album we will be adding to.
            XElement specificAlbum = util_getAlbum(errorReport, albumUID);
            // If the lookup returns null, the album doesn't exist, or there's more than one album with that UID (db error)
            if (specificAlbum == null)
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Found more than one album with that UID or none at all.";
                return;
            }

            // UID for a photo is unique to an album in the albums database.
            newPicture.UID = util_getNextUID(specificAlbum.Element("albumPhotos"), "picture", 1);
            // check to make sure we got a valid number back...
            if (!util_checkUIDIsValid(newPicture.UID))
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Photo UID is not valid.";
                return;
            }

            //construct the object we will be adding to the album.
            XElement newPhotoElem = new XElement("picture",
                                            new XAttribute("uid", newPicture.UID),
                                            new XAttribute("sha1", ByteArrayToString(newPicture.hash)),
                                            new XElement("name", albumName),
                                            new XElement("caption", newPicture.caption));

            // Now add it to the albums database
            specificAlbum.Element("albumPhotos").Add(newPhotoElem);
        }
        //--------------------------------------------------------
        //By: Ryan Moe
        //Edited Last: Bill Sanders, 3/29/13
        //This adds a picture to JUST the picture database.
        //Does not use the UID or the albumName from the newPictureData.
        private ErrorReport util_addPicToPhotoDB(ErrorReport errorReport, ComplexPhotoData newPictureData)
        {
            //if picture extension is not valid
            if (!util_checkPictureExtension(newPictureData.extension))
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Extension is not valid.";
                return errorReport;
            }

            //if path is not valid
            if (!util_checkPicturePath(newPictureData.path))
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Path is not valid.";
                return errorReport;
            }

            //make the object that will go into the xml database.
            XElement newPicRoot = new XElement("picture",
                new XAttribute("uid", newPictureData.UID),
                new XAttribute("sha1", ByteArrayToString(newPictureData.hash)),
                new XAttribute("refCount", newPictureData.refCount),
                new XElement("filePath", new XAttribute("extension", newPictureData.extension), newPictureData.path)
                );

            //add to the database (in memory, not on disk).
            _picturesDatabase.Add(newPicRoot);
            return errorReport;
        }
Beispiel #18
0
        //-------------------------------------------------------------------
        //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:
        //returns true if the picture database is ok.
        private Boolean util_checkPhotoDBIntegrity(ErrorReport errorReport)
        {
            if (_picturesDatabase == null)
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "PhotoBomb: The album database has not been loaded yet!";
                return false;
            }

            //put more checks here.

            return true;
        }
Beispiel #20
0
        //-------------------------------------------------------------------
        //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: Ryan Moe
        //Edited Last:
        //use this to convert a photo element into a complexPhotoData data class.
        //Try and keep this updated if new fields are added to complexPhotoData.
        private ComplexPhotoData util_convertPhotoNodeToComplexPhotoData(ErrorReport errorReport, XElement elem)
        {
            ComplexPhotoData data = new ComplexPhotoData();

            //TRANSFER ALL DATA TO THE DATA CLASS HERE.
            try
            {
                data.UID = (int)elem.Attribute("UID");
                data.hash = StringToByteArray((string)elem.Attribute("SHA1"));
                data.refCount = (int)elem.Attribute("refCount");
                data.path = elem.Element("filePath").Value;
                data.extension = (String)elem.Element("filePath").Attribute("extension");
            }
            catch
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Error converting XElement to struct.";
                return null;
            }

            return data;
        }
Beispiel #22
0
        //-------------------------------------------------------------------
        //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: Ryan Moe
 //Edited Last: Bill Sanders, 3/29/13
 /// <summary>
 /// Queries the Album database for the specified album.
 /// </summary>
 /// <param name="error"></param>
 /// <param name="albumUID">The Unique ID of the album</param>
 /// <returns>An XElement object referring to the specified album, or null if not found.</returns>
 private XElement util_getAlbum(ErrorReport error, int albumUID)
 {
     try
     {
         //find and return an album whos uid is the one we are looking for.
         //Throws exception if none or more than one match is found.
         return (from c in _albumsDatabase.Elements("album")
                 where (int)c.Attribute("uid") == albumUID
                 select c).Single();
     }
     catch
     {
         error.reportID = ErrorReport.FAILURE;
         error.description = "Failed to find a single album by UID.";
         return null;
     }
 }
Beispiel #24
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);
        }
 //--------------------------------------------------------------------------
 //By: Ryan Moe, comments by Bill Sanders
 //Edited Last: 3/24/13
 /// <summary>
 /// Searches for a photo by UID in the specified album.
 /// </summary>
 /// <param name="error"></param>
 /// <param name="albumNode"></param>
 /// <param name="photoUID"></param>
 /// <returns>Returns an xml node of the photo from the AlbumDB, or null.</returns>
 private XElement util_getAlbumDBPhotoNode(ErrorReport error, XElement albumNode, int photoUID)
 {
     try
     {
         // Search through a specific album for a specific photo by ID
         // Return an (XElement) picture with the matching uid if it exists
         // Throws exception if it doesn't find exactly 1 match
         return (from c in albumNode.Element("albumPhotos").Elements("picture")
                 where (int)c.Attribute("uid") == photoUID
                 select c).Single();
     }
     catch
     {
         error.reportID = ErrorReport.FAILURE;
         error.description = "Failed to find a single picture by UID.";
         return null;
     }
 }
Beispiel #26
0
        //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);
        }
        /// <summary>
        /// Looks up the photo by hash in the Photos XML database, returns the number of appearances in the Album database.
        /// </summary>
        /// <param name="hash">A string representing the hash value of the file.</param>
        /// <returns>An integer representing the number of times this photo appears in the the Album database</returns>
        private int util_getPicRefCount(string hash)
        {
            ErrorReport errorReport = new ErrorReport();

            XElement specificPhoto = util_getPhotoDBNode(errorReport, hash);

            int refCount;
            if (specificPhoto == null)
            {
                refCount = 0;
            }
            else
            {
                refCount = (int)specificPhoto.Attribute("refCount");
            }

            return refCount;
        }
Beispiel #28
0
        //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: Ryan Moe
 //Edited Last: Bill Sanders 4/1/13 (renamed function, added comments)
 /// <summary>
 /// Renames an instance of a photo in an album
 /// </summary>
 /// <param name="error"></param>
 /// <param name="photoElem">An XElement representation of the photo from the album DB</param>
 /// <param name="newName">The new name for the photo</param>
 private void util_renamePhoto(ErrorReport error, XElement photoElem, String newName)
 {
     try
     {
         photoElem.Element("name").Value = newName;
     }
     catch
     {
         // this probably means they passed in a XElem from the pictures library...?
         error.reportID = ErrorReport.FAILURE;
         error.description = "Failed to change the name of a photo.";
     }
 }
        // 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);
        }