//----------------------------------------------------------------------
        //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;
        }
Exemple #2
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);
        }