Example #1
0
        /*********************************************************************************************
        * Author: Alejandro Sosa
        * parameters: reference to main window, and a complexphotodata containing info of the photo
        *   to be displayed
        * return type: none
        * purpose: creates a new instance of PhotoViewWindow object
        *********************************************************************************************/
        public PhotoViewWindow(mainGUI localMainWindowRef, ComplexPhotoData wantedPhoto, string myName)
        {
            mainWindowRef = localMainWindowRef;

            photoToDisplay = wantedPhoto;

            InitializeComponent();

            this.Text = myName;

            int appropriateHeight = (int)((SystemParameters.PrimaryScreenHeight)/3)*2;

            int appropriateWidth= (int)((SystemParameters.PrimaryScreenWidth)/3)*2;

            photoboxPanel1.MaximumSize = new System.Drawing.Size(appropriateWidth, appropriateHeight);

            //displayPhoto();

            photoBox.LoadAsync(wantedPhoto.path);
        }
Example #2
0
        // BS: Is this function at all used given that we don't add photos one at a time?
        // Added by Bill 4/1/13: This function is used only by frontend to add a single photo at a time
        // Commenting it out
        // This function doesn't take that param but starts hardcoded at 1
        // So I added a default parameter of 1 to the below function.
        //-------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //private void addNewPicture_backend(generic_callback guiCallback,
        //    String photoUserPath,
        //    String photoExtension,
        //    int albumUID,
        //    String pictureNameInAlbum)
        //{
        //    ErrorReport errorReport = new ErrorReport();
        //    ComplexPhotoData newPicture = new ComplexPhotoData();
        //    newPicture.hash = util_getHashOfFile(photoUserPath);
        //    // get an ID number for the picture.
        //    // Note that a photo may have two different ID numbers in albumsdb and picturesdb
        //    newPicture.UID = util_getNextUID(_picturesDatabase, "picture", 1);
        //    // error checking the call
        //    if (!util_checkUIDIsValid(newPicture.UID))
        //    {
        //        errorReport.reportID = ErrorReport.FAILURE;
        //        errorReport.description = "Failed to get a UID for a new picture.";
        //        guiCallback(errorReport);
        //        return;
        //    }
        //    //Change me if you want to start naming the pictures differently in the library.
        //    String picNameInLibrary = newPicture.UID.ToString() + photoExtension;
        //    //Change me if you want the default image name to be different.
        //    if (pictureNameInAlbum == "")
        //    {
        //        pictureNameInAlbum = Properties.Settings.Default.DefaultImageName + " " + newPicture.UID.ToString();
        //    }
        //    //Move picture and get a new path for the picture in our storage.
        //    newPicture.path = util_copyPicToLibrary(errorReport, photoUserPath, picNameInLibrary);
        //    //error checking
        //    if (errorReport.reportID == ErrorReport.FAILURE)
        //    {
        //        guiCallback(errorReport);
        //        return;
        //    }
        //    newPicture.extension = photoExtension;
        //    util_addPicToPhotoDB(errorReport, newPicture);
        //    //if adding to the picture database failed
        //    if (errorReport.reportID == ErrorReport.FAILURE)
        //    {
        //        guiCallback(errorReport);
        //        return;
        //    }
        //    util_addPicToAlbumDB(errorReport, newPicture, albumUID, pictureNameInAlbum);
        //    //if adding to the album database failed
        //    if (errorReport.reportID == ErrorReport.FAILURE)
        //    {
        //        guiCallback(errorReport);
        //        return;
        //    }
        //    //add to disk.
        //    savePicturesXML_backend(null);
        //    saveAlbumsXML_backend(null);
        //    guiCallback(errorReport);
        //}
        //-------------------------------------------------------------------
        //By: Ryan Moe
        //Edited Last:
        //NOTE: this is an overloaded function call FOR BACKEND USE ONLY.
        //      It does not have a gui callback and instead returns the
        //      Error report directly, for use in the backend.
        /// <summary>
        /// Create a photo object and its metadata, then adds it to both databases and the library.
        /// </summary>
        /// <param name="errorReport">An error report</param>
        /// <param name="photoUserPath">The path where the photo is originally from</param>
        /// <param name="photoExtension">The extension of the photo's filename</param>
        /// <param name="albumUID">The ID of the album to add this picture to</param>
        /// <param name="pictureNameInAlbum">The name the picture will have in the album</param>
        /// <param name="searchStartingPoint">Where to start looking for a new UID; defaults to 1</param>
        /// <returns></returns>
        private ErrorReport addNewPicture_backend(ErrorReport errorReport,
            String photoUserPath,
            String photoExtension,
            int albumUID,
            String pictureNameInAlbum,
            int searchStartingPoint = 1)
        {
            ComplexPhotoData newPicture = new ComplexPhotoData();

            // Compute the hash for this picture, and then check to make sure it is unique
            newPicture.hash = util_getHashOfFile(photoUserPath);
            if (!util_checkPhotoIsUniqueToAlbum(albumUID, ByteArrayToString(newPicture.hash)))
            {
                errorReport.reportID = ErrorReport.SUCCESS_WITH_WARNINGS;
                errorReport.description = "Picture is not unique.";
                errorReport.warnings.Add("Picture is not unique: " + photoUserPath);
                return errorReport;
            }

            //get a unique ID for this photo and update its
            //data object to reflect this new UID.
            newPicture.UID = util_getNextUID(_picturesDatabase, "picture", searchStartingPoint);
            // error checking the call
            if (!util_checkUIDIsValid(newPicture.UID))
            {
                errorReport.reportID = ErrorReport.FAILURE;
                errorReport.description = "Failed to get a UID for a new picture.";
                return errorReport;
            }

            //Change me if you want to start naming the pictures differently in the library.
            String picNameInLibrary = newPicture.UID.ToString() + photoExtension;

            //Change me if you want the default album name to be different.
            if (pictureNameInAlbum == "")
            {
                pictureNameInAlbum = Properties.Settings.Default.DefaultImageName + " " + newPicture.UID.ToString();
            }

            //Move picture and get a new path for the picture in our storage.
            newPicture.path = util_copyPicToLibrary(errorReport, photoUserPath, picNameInLibrary);
            //error checking
            if (errorReport.reportID == ErrorReport.FAILURE)
            {
                return errorReport;
            }

            newPicture.extension = photoExtension;

            // Get the refcount (will get zero if the pic is brand new) and increment it.
            newPicture.refCount = util_getPicRefCount(ByteArrayToString(newPicture.hash));
            newPicture.refCount++;
            // if this is a new picture, we add it to the db
            if (newPicture.refCount == 1)
            {
                util_addPicToPhotoDB(errorReport, newPicture);
            }
            else
            {
                // Otherwise, incremented the refcount, change the xml object in memory and it'll be saved shortly.
                XElement thisPic = util_getPhotoDBNode(errorReport, ByteArrayToString(newPicture.hash));
                thisPic.Attribute("refCount").Value = newPicture.refCount.ToString();
            }

            //if adding to the picture database failed
            if (errorReport.reportID == ErrorReport.FAILURE)
            {
                return errorReport;
            }

            util_addPicToAlbumDB(errorReport, newPicture, albumUID, pictureNameInAlbum);

            //if adding to the album database failed
            if (errorReport.reportID == ErrorReport.FAILURE)
            {
                return errorReport;
            }

            //save to disk.
            savePicturesXML_backend(null);
            saveAlbumsXML_backend(null);

            return errorReport;
        }
Example #3
0
        /*********************************************************************************************
        * Author: Alejandro Sosa
        * parameters: int that specifies the UID of an album to add pictures to
        * return type: void
        * purpose:
        *********************************************************************************************/
        private void addPicturesToAlbum(int albumId)
        {
            if (photoOpenFileDialog.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                List<string> fullFileNames = new List<string>();

                List<string> photoExtensions = new List<string>();
                //--fills up both lists that will be passed to bombaDeFotos.addNewPictures
                foreach (string picFile in photoOpenFileDialog.FileNames)
                {
                    fullFileNames.Add(picFile);

                    photoExtensions.Add(".jpg");
                }

                progressForm photoImportProgress;

                pictureImportProgress = new progressForm(photoOpenFileDialog.FileNames.Length, bombaDeFotos);

                ComplexPhotoData newPicture = new ComplexPhotoData();

                bombaDeFotos.addNewPictures(guiPictureAdded, fullFileNames, photoExtensions, albumChosenbyUser, null, new ProgressChangedEventHandler(guiUpdateImportProgress), 1);
                pictureImportProgress.ShowDialog();
        }
Example #4
0
        /*********************************************************************************************
        * Author: Alejandro Sosa
        * parameters: an object of ErrorReport which will be used to check if backend was successful
        *   a complexPhoto object containing the info about a previously requested photo
        * return type: void
        * purpose:
        *********************************************************************************************/
        public void photoInfoRetrieved(ErrorReport status, ComplexPhotoData thePhoto)
        {
            if (status.reportID == ErrorReport.SUCCESS)
            {

                    //check to see if photo exists.
                    if (File.Exists(thePhoto.path) == true)
                    {
                        PhotoViewWindow photoDisplayer = new PhotoViewWindow(this, thePhoto, photoListView.SelectedItems[firstListViewItemIndex].Text);
                        photoDisplayer.ShowDialog();
                    }
                    else
                    {
                        showError("Error: Photograph missing.");
                    }
            }
            else if(status.reportID == ErrorReport.FAILURE)
            {
                showError("Error: Photograph missing.");
            }
        }
Example #5
0
        /// By: Bill Sanders
        /// Edited Ryan Causey(4/5/13)
        /// This function replaces the function util_convertPhotoNodeToComplexPhotoData() below.
        /// <summary>
        /// Combines the data from both databases for a specific photo instance.
        /// </summary>
        /// <param name="errorReport"></param>
        /// <param name="albumImageNode">An XElement of a picture from the Album DB</param>
        /// <param name="albumUID">The unique ID number of the album the photo instance is in</param>
        /// <returns>Returns a ComplexPhotoData object, or null if the object could not be created.</returns>
        public ComplexPhotoData getComplexPhotoDataFromAlbumImageNode(XElement albumImageNode, XElement _imagesRootXml)
        {
            // We have all the data we need from the AlbumDB,
            // but the PhotoDB has important data as well.
            XElement imageNode = null;
            if (!getImageNodeFromImageXml((string)albumImageNode.Attribute("sha1"), _imagesRootXml, out imageNode))
                return null;

            ComplexPhotoData imageData = new ComplexPhotoData();

            //TRANSFER ALL DATA TO THE DATA CLASS HERE.
            try
            {
                // PhotoDB data
                imageData.UID = (int)imageNode.Attribute("uid");
                imageData.hash = stringToByteArray((string)imageNode.Attribute("sha1"));
                imageData.refCount = (int)imageNode.Attribute("refCount");
                imageData.fullPath = imageNode.Element("filePath").Value;
                imageData.lgThumbPath = imageNode.Element("lgThumbPath").Value;
                imageData.addedDate = stringToDateTime(imageNode.Element("dateAdded").Value);

                imageData.extension = (String)imageNode.Element("filePath").Attribute("extension");

                // AlbumDB data
                imageData.idInAlbum = (int)albumImageNode.Attribute("idInAlbum");
                imageData.name = albumImageNode.Element("name").Value;
                if (imageData.name == string.Empty)
                {
                    string defaultPhotoName = albumImageNode.Parent.Parent.Element("albumName").Value
                        + " "
                        + Settings.DefaultImageName
                        + " "
                        + imageData.idInAlbum;
                    imageData.name = defaultPhotoName;
                    albumImageNode.Element("name").Value = defaultPhotoName;
                }
                imageData.caption = albumImageNode.Element("caption").Value;

            }
            catch (Exception)
            {
                return null;
            }

            return imageData;
        }
        //--------------------------------------------------------
        // By: Bill Sanders
        // Edited Last By: Ryan Causey
        // Edited Last Date: 4/6/13
        /// <summary>
        /// Sets the thumbnail path for an album.
        /// </summary>
        /// <param name="albumNode">An XElement of the album to change the thumbnail of</param>
        /// <param name="photoObject">A ComplexPhotoData object which contains the path information</param>
        private void util_setAlbumThumbnail(XElement albumNode, ComplexPhotoData photoObject)
        {
            ErrorReport errorReport = new ErrorReport();
            String thumbPath;
            // If the objects look good, set up the (long...) path.
            if ((albumNode != null) && (photoObject != null))
            {
                thumbPath = System.IO.Path.Combine(
                    Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData),
                    Settings.OrgName,
                    Settings.PhotoLibraryName,
                    Settings.PhotoLibraryThumbsDir,
                    Settings.lrgThumbDir,
                    photoObject.UID.ToString() +
                    photoObject.extension
                    );

                thumbPath = util_generateThumbnail(
                    errorReport,
                    photoObject.fullPath,
                    photoObject.UID.ToString() + photoObject.extension,
                    Settings.lrgThumbSize);
            }
            // If either of these objects is null, just invalidate the path
            else
            {
                thumbPath = String.Empty;
            }

            albumNode.Element("thumbnailPath").Value = thumbPath;
            albumNode.Element("thumbnailPath").Attribute("thumbAlbumID").Value = photoObject.idInAlbum.ToString();
        }
Example #7
0
        /*
         * Created By: Ryan Causey
         * Created Date: 4/4/13
         * Last Edited By:
         * Last Edited Date:
         */
        /// By: Ryan Causey
        /// Edited Julian Nguyen(5/1/13)
        /// <summary>
        /// Adds all the photos from the library into the *hopefully* already created
        /// Recovery Album.
        /// </summary>
        /// <param name="errorReport">ErrorReport object to be updated</param>
        /// <param name="albumUID">UID of the Recovery Album</param>
        /// <returns>The ErrorReport of this action. </returns>
        private ErrorReport addPhotoBackup(ErrorReport errorReport, Guid albumUID)
        {
            if (albumUID == Guid.Empty)
            {
                setErrorReportToFAILURE("Failed to create recovery album", ref errorReport);
                return errorReport;
            }

            // This method of moving the folder to a new path and copying it back into the library works too
            // I'm not yet able to tell which is faster --BS
            // If you use this method, be sure to uncomment out the directory.delete function at the end of the foreach
            // Note also that DirectoryInfo.*() does not guarantee any order to the files
            //String tmpDir = Path.Combine(libraryPath, "..", "backup");
            //Directory.Move(libraryPath, tmpDir);
            //Directory.CreateDirectory(libraryPath);
            //set up a directory info object from the path
            //FileInfo[] files = new DirectoryInfo(tmpDir).GetFiles();

            IEnumerable<FileInfo> libraryDir = new DirectoryInfo(_imagelibraryDirPath).EnumerateFiles();
            // The files in libraryDir will not be sorted...

            //so we'll sort them here by removing the extension and then sorting them numerically
            IEnumerable<FileInfo> sortedFiles = libraryDir.OrderBy(
                fi => int.Parse(Path.GetFileNameWithoutExtension(fi.Name))
                );

            //set up an array of files
            foreach (FileInfo fi in sortedFiles)
            {
                ComplexPhotoData newPicture = new ComplexPhotoData();

                // Compute the hash for this picture, and then check to make sure it is unique
                newPicture.hash = util_getHashOfFile(fi.FullName);
                if (!util_isImageUniqueToAlbum(albumUID, ByteArrayToString(newPicture.hash)))
                {
                    errorReport.reportStatus = ReportStatus.SUCCESS_WITH_WARNINGS;
                    errorReport.description = "Picture is not unique.";
                    errorReport.warnings.Add("Picture is not unique: " + fi.FullName);
                    return errorReport;
                }

                //probably should check that the file extension is supported...
                newPicture.extension = fi.Extension;

                //get a unique ID for this photo and update its
                //data object to reflect this new UID.
                newPicture.UID = util_getNextUID(_imagesRootXml, "picture", "uid", 1);
                // error checking the call
                if (!util_checkIDIsValid(newPicture.UID))
                {
                    setErrorReportToFAILURE("Failed to get a UID for a new picture.", ref errorReport);
                    return errorReport;
                }

                //Change me if you want to start naming the pictures differently in the library.
                String picNameInLibrary = newPicture.UID.ToString() + fi.Extension;

                // Get the refcount (will get zero if the pic is brand new) and increment it.
                newPicture.refCount = _photoBomb_xml.getPhotoRefCount(ByteArrayToString(newPicture.hash), _imagesRootXml);
                newPicture.refCount++;
                // if this is a new picture, we add it to the db
                if (newPicture.refCount == 1)
                {
                    //rename the file
                    fi.MoveTo(Path.Combine(_imagelibraryDirPath, picNameInLibrary));

                    newPicture.fullPath = fi.FullName;

                    util_addImageToImageDB(errorReport, newPicture);
                }
                else
                {
                    // Otherwise, incremented the refcount, change the xml object in memory and it'll be saved shortly.
                    XElement imageNode = null;
                    if (!_photoBomb_xml.getImageNodeFromImageXml(ByteArrayToString(newPicture.hash), _imagesRootXml, out imageNode))
                    {
                        setErrorReportToFAILURE("Failed to get the image node.", ref errorReport);
                        return errorReport;
                    }
                    imageNode.Attribute("refCount").Value = newPicture.refCount.ToString();
                }

                //if adding to the picture database failed
                if (errorReport.reportStatus == ReportStatus.FAILURE)
                {
                    return errorReport;
                }

                util_addImageToAlbumDB(errorReport, newPicture, albumUID);

                //if adding to the album database failed
                if (errorReport.reportStatus == ReportStatus.FAILURE)
                {
                    return errorReport;
                }

                //save to disk.
                saveImagesXML_backend();
                saveAlbumsXML_backend();

                //when we have the photos collection implemented need to update it here and
                //if necessary blow it out up above.
            }

            //Directory.Delete(tmpDir, true);
            return errorReport;
        }
        //--------------------------------------------------------
        //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;
        }
Example #9
0
 /**************************************************************************************************************************
  * Author: Alejandro Sosa
  **************************************************************************************************************************/
 public void guiConvertToGreyscale(addNewPictures_callback guiGrayscaleCallback, ComplexPhotoData desiredImage, Guid albumGuid)
 {
     masterAndCommander.addImageAsGrayscale(guiGrayscaleCallback, albumGuid, desiredImage.fullPath);
 }
Example #10
0
 /**************************************************************************************************************************
  * Author: Bill Sanders
  * Created on: 4/7/13
  **************************************************************************************************************************/
 /// <summary>
 /// Copies the selected photos to the background clipboard.
 /// </summary>
 private void guiCopySelectedPhotosToClipboard()
 {
     //make sure an item is selected
     if (mainWindowAlbumList.SelectedItems != null)
     {
         // if the clipboard is currently empty, we're in copy-mode
         ComplexPhotoData[] clipArray = new ComplexPhotoData[mainWindowAlbumList.SelectedItems.Count];
         mainWindowAlbumList.SelectedItems.CopyTo(clipArray, 0);
         _clipboardOfPhotos = clipArray.ToList();
         _clipboardAlbumSrcID = _currentAlbumUID;
     }
 }
Example #11
0
 /*
  * Created By: Ryan Causey
  * Created Date: 4/7/13
  * Last Edited By:
  * Last Edited Date:
  */
 /// <summary>
 /// Function to transition to previous image.
 /// </summary>
 private void getPreviousImage()
 {
     _imageCollection.MoveCurrentToPrevious();
     if (_imageCollection.IsCurrentBeforeFirst == true)
     {
         _imageCollection.MoveCurrentToLast();
     }
     currentPicture = _imageCollection.CurrentItem as ComplexPhotoData;
     //get the current index
     //int index = _picturesCollection.IndexOf(currentPicture);
     ////set the current picture to the next one
     //if (index == 0)
     //{
     //    index = _picturesCollection.Count - 1;
     //    currentPicture = _picturesCollection.ElementAt(index);
     //}
     //else
     //{
     //    currentPicture = _picturesCollection.ElementAt(--index);
     //}
 }
Example #12
0
        /*
         * Created By: Ryan Causey
         * Created Date: 4/7/13
         * Last Edited By:
         * Last Edited Date:
         */
        /// <summary>
        /// Function to transition to next image.
        /// </summary>
        private void getNextImage()
        {
            _imageCollection.MoveCurrentToNext();

            if (_imageCollection.IsCurrentAfterLast == true)
            {
                _imageCollection.MoveCurrentToFirst();
            }
            currentPicture = _imageCollection.CurrentItem as ComplexPhotoData;

            ////get the current index
            //int index = _picturesCollection.IndexOf(currentPicture);
            ////set the current picture to the next one
            //if (!(index < _picturesCollection.Count - 1))
            //{
            //    index = 0;
            //    currentPicture = _picturesCollection.ElementAt(index);
            //}
            //else
            //{
            //    currentPicture = _picturesCollection.ElementAt(++index);
            //}
        }
Example #13
0
        /**************************************************************************************************************************
        * Author: Alejandro Sosa
        **************************************************************************************************************************/
        public void temp_guiGrayscaleCallback(ErrorReport isUseless, Guid albumGuid)
        {
            if (isUseless.reportStatus == ReportStatus.SUCCESS)
            {
                _imageCollection.MoveCurrentToLast();

                currentPicture = _imageCollection.CurrentItem as ComplexPhotoData;
            }
        }
Example #14
0
        /// By Ryan Moe
        /// Edited: Julian Nguyen(5/1/13)
        /// <summary>
        /// Will get an Image from an Album.
        /// </summary>
        /// <param name="guiCallback"></param>
        /// <param name="imageIDinAlbum">The ID of the image.</param>
        /// <param name="albumUID">The ID of the Album to look in. </param>
        /// <param name="imageData">The pass back of the image's ComplexPhotoData</param>
        /// <returns>The errorReport of this Action.</returns>
        public ErrorReport getImage_backend(int imageIDinAlbum, Guid albumUID, out ComplexPhotoData imageData)
        {
            ErrorReport error = new ErrorReport();
            imageData = null;

            // To get a photo from the photoDB knowing only an albumID and its ID in that album
            // We have to first retrieve the album...
            XElement albumNode = null;
            if (!_photoBomb_xml.getAlbumNodeFromAlbumXml(albumUID, _albumsRootXml, out albumNode))
            {
                setErrorReportToFAILURE("failed to find the albumNode.", ref error);
                return error;
            }

            // ... then with that, we can get the picture element from that album...
            XElement albumImageNode = null;
            if (!_photoBomb_xml.getAlbumImageNodeFromAlbumNode(albumNode, imageIDinAlbum, out albumImageNode))
            {
                setErrorReportToFAILURE("failed to find the albumImageNode.", ref error);
                return error;
            }

            // ... which we use to get the hash of the photo to do a lookup in the PhotoDB!
            XElement imageNode = null;
            if (!_photoBomb_xml.getImageNodeFromImageXml((string)albumImageNode.Attribute("sha1").Value, _imagesRootXml, out imageNode))
            {
                setErrorReportToFAILURE("failed to find the imageNode.", ref error);
                return error;
            }

            try
            {
                // TODO: fun!

                imageData = new ComplexPhotoData();
                imageData.hash = stringToByteArray((string)imageNode.Attribute("sha1"));
                imageData.UID = (int)imageNode.Attribute("uid");
                imageData.refCount = (int)imageNode.Attribute("refCount");
                imageData.fullPath = (string)imageNode.Element("filePath").Value;
                imageData.addedDate = _photoBomb_xml.stringToDateTime(imageNode.Element("dateAdded").Value.ToString());
            }
            catch
            {
                setErrorReportToFAILURE("PhotoBomb.getPictureByUID():Photo info could not be loaded.", ref error);
            }

            return error;
        }
Example #15
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;
            }
        }
        /// By Ryan Moe
        /// Edited Julian Nguyen(5/1/13)
        /// <summary>
        /// Adds a image to a specific album in the album database 
        /// </summary>
        /// <param name="errorReport"></param>
        /// <param name="newImage">An object with all the data necessary to create the Image in both DBs</param>
        /// <param name="albumUID">The unique ID of the album</param>
        private void util_addImageToAlbumDB(ErrorReport errorReport, ComplexPhotoData newImage, Guid albumUID)
        {
            //Get the specific album we will be adding to.
            XElement specificAlbum = _photoBomb_xml.getAlbumNodeFromAlbumXml(albumUID, _albumsRootXml);
            // 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)
            {
                setErrorReportToFAILURE("Found more than one album with that UID or none at all.", ref errorReport);
                return;
            }

            // idInAlbum for a photo is unique to an album in the albums database.
            newImage.idInAlbum = util_getNextUID(specificAlbum.Element("albumPhotos"), "picture", "idInAlbum", 1);
            // check to make sure we got a valid number back...
            if (!util_checkIDIsValid(newImage.idInAlbum))
            {
                setErrorReportToFAILURE("Photo id for album is not valid.", ref errorReport);
                return;
            }

            // check to see if this is going to be the first photo in an otherwise empty library...
            XElement photoNeighbor = (from c in specificAlbum.Descendants("picture") select c).FirstOrDefault();
            // ... If there are no neighbors, this is the solo photo in the album, and thus the first...
            if (photoNeighbor == null)
            {
                // ... so set it to be the album thumbnail
                util_setAlbumThumbnail(specificAlbum, newImage);
            }

            // Note as per requirements, the default photo name is the name of the album, plus its id number
            string nameInAlbum = specificAlbum.Element("albumName").Value + " Image " + newImage.idInAlbum;
            while (!_photoBomb_xml.isImageNameUniqueToAlbum(nameInAlbum, specificAlbum))
            {
                newImage.idInAlbum = util_getNextUID(specificAlbum.Element("albumPhotos"), "picture", "idInAlbum", newImage.idInAlbum + 1);
                nameInAlbum = specificAlbum.Element("albumName").Value + " Image " + newImage.idInAlbum;
            }

             //construct the object we will be adding to the album.
            XElement newAlbumImageNode = _photoBomb_xml.newAlbumImageNode(newImage.idInAlbum, ByteArrayToString(newImage.hash), nameInAlbum, newImage.caption);

            // Now add it to the albums database in memory
            specificAlbum.Element("albumPhotos").Add(newAlbumImageNode);
        }
        //--------------------------------------------------------
        //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: Julan nguyen(5/1/13)
        /// <summary>
        /// This adds a picture to JUST the picture database.
        /// </summary>
        /// <param name="errorReport">Why is this being passed in??</param>
        /// <param name="newPictureData">The data of the new image to be added. </param>
        /// <returns>The errorReport of this action.</returns>
        private ErrorReport util_addImageToImageDB(ErrorReport errorReport, ComplexPhotoData newPictureData)
        {
            // TODO: Test the incoming errorReport for failure.

            //if picture extension is not valid
            if (!util_checkPhotoExtension(newPictureData.extension))
            {
                setErrorReportToFAILURE("Extension is not valid.", ref errorReport);
                return errorReport;
            }

            //if path is not valid
            if (!util_checkFilePath(newPictureData.fullPath))
            {
                setErrorReportToFAILURE("Path is not valid", ref errorReport);
                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.fullPath),
                new XElement("lgThumbPath", newPictureData.lgThumbPath),
                new XElement("dateAdded", newPictureData.addedDate.ToString("yyyy-MM-dd"))
                );

            //add to the database (in memory, not on disk).
            _imagesRootXml.Add(newPicRoot);
            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;
        }
Example #20
0
        /// By: Ryan Moe
        /// Edited Julian Nguyen(5/1/13)
        /// NOTE: this is an overloaded function call FOR BACKEND USE ONLY.
        ///      It does not have a gui callback and instead returns the
        ///      Error report directly, for use in the backend.
        /// <summary>
        /// Create a photo object and its metadata, then adds it to both databases and the library.
        /// </summary>
        /// <param name="errorReport">An error report</param>
        /// <param name="photoUserPath">The path where the photo is originally from</param>
        /// <param name="photoExtension">The extension of the photo's filename</param>
        /// <param name="albumUID">The ID of the album to add this picture to</param>
        /// <param name="pictureNameInAlbum">The name the picture will have in the album</param>
        /// <param name="searchStartingPoint">Where to start looking for a new UID; defaults to 1</param>
        /// <returns></returns>
        private ComplexPhotoData addNewImage_backend(ErrorReport errorReport,
            String photoUserPath,
            String photoExtension,
            Guid albumUID,
            int searchStartingPoint = 1)
        {
            ComplexPhotoData imageData = new ComplexPhotoData();

            imageData.addedDate = DateTime.Now;

            // Compute the hash for this picture, and then check to make sure it is unique
            imageData.hash = util_getHashOfFile(photoUserPath);
            if (!util_isImageUniqueToAlbum(albumUID, ByteArrayToString(imageData.hash)))
            {
                errorReport.reportStatus = ReportStatus.SUCCESS_WITH_WARNINGS;
                errorReport.description = "Picture is not unique.";
                errorReport.warnings.Add("Picture is not unique: " + photoUserPath);
                return null;
            }

            // Get the refcount (will get zero if the pic is brand new) and increment it.
            imageData.refCount = _photoBomb_xml.getPhotoRefCount(ByteArrayToString(imageData.hash), _imagesRootXml);
            imageData.refCount++;

            imageData.extension = photoExtension;

            // if this is a new picture, we add it to the db
            if (imageData.refCount == 1)
            {
                //get a unique ID for this photo and update its
                //data object to reflect this new UID.
                imageData.UID = util_getNextUID(_imagesRootXml, "picture", "uid", searchStartingPoint);
                // error checking the call
                if (!util_checkIDIsValid(imageData.UID))
                {
                    setErrorReportToFAILURE("Failed to get a UID for a new picture.", ref errorReport);
                    return null;
                }

                //Change me if you want to start naming the pictures differently in the library.
                String picNameInLibrary = imageData.UID.ToString() + photoExtension;

                imageData.fullPath = util_copyImageToLibrary(errorReport, photoUserPath, picNameInLibrary);
                //error checking
                if (errorReport.reportStatus == ReportStatus.FAILURE)
                {
                    return null;
                }
                util_addImageToImageDB(errorReport, imageData);
                //Move picture and get a new path for the picture in our storage.
                //generate the thumbnails and get their path.
                imageData.lgThumbPath = util_generateThumbnail(errorReport, imageData.fullPath, picNameInLibrary, Settings.lrgThumbSize);
            }
            else
            {
                // Otherwise, incremented the refcount, change the xml object in memory and it'll be saved shortly.
                XElement imageNode =_photoBomb_xml.getImageNodeFromImageXml(ByteArrayToString(imageData.hash), _imagesRootXml);

                // Assign this new refcount
                imageNode.Attribute("refCount").Value = imageData.refCount.ToString();

                // fetch the uid and put it in the complex photo data, we'll need it later too
                imageData.UID = (int)imageNode.Attribute("uid");

                // make sure the photo still exists on the filesystem
                if (!File.Exists(imageNode.Element("filePath").Value))
                {
                    // good thing we checked!  Copy it to the filesystem again.
                    imageData.fullPath = util_copyImageToLibrary(
                        errorReport,
                        imageNode.Element("filePath").Value,
                        imageData.UID.ToString() + photoExtension);
                }
                else
                {
                    imageData.fullPath = imageNode.Element("filePath").Value;
                }
            }

            //if adding to the picture database failed
            if (errorReport.reportStatus == ReportStatus.FAILURE)
            {
                return null;
            }

            // Now add it to the albums database
            //_photoBomb_xml.a

            util_addImageToAlbumDB(errorReport, imageData, albumUID);

            //if adding to the album database failed
            if (errorReport.reportStatus == ReportStatus.FAILURE)
            {
                return null;
            }

            //save to disk.
            saveImagesXML_backend();
            saveAlbumsXML_backend();

            //update the photosCollection
            //_imagesCollection.Add(imageData);

            return imageData;
        }