コード例 #1
0
        /// <summary>
        /// Get information of all the images
        /// </summary>
        /// <returns>Information for each image</returns>
        public static List <AllImagesInfo> getAllImageInfo()
        {
            AllImagesInfo        imageInfo;
            List <AllImagesInfo> allImageInfo = new List <AllImagesInfo>();

            string[] albums = Directory.GetFiles(Directory.GetCurrentDirectory() + "\\Users", "*.album", SearchOption.AllDirectories);
            foreach (string album in albums)
            {
                XDocument xdoc = new XDocument();
                try
                {
                    xdoc = XDocument.Load(album);
                    var Albums = from AlbumInfo in xdoc.Descendants("AlbumInfo")
                                 select new
                    {
                        Header   = AlbumInfo.Attribute("name").Value,
                        Children = AlbumInfo.Descendants("PictureInfo")
                    };

                    foreach (var albumInfo in Albums)
                    {
                        foreach (var PictureInfo in albumInfo.Children)
                        {
                            imageInfo.MD5  = PictureInfo.Attribute("md5").Value;
                            imageInfo.path = PictureInfo.Attribute("path").Value;
                            allImageInfo.Add(imageInfo);
                        }
                    }
                }
                catch { }
            }
            return(allImageInfo);
        }
コード例 #2
0
        /// <summary>
        /// Loads the album information from a .abm(XML format) file and adds information to a query
        /// then, the datalist vector will get each pictures information
        /// Zach
        /// </summary>
        /// <param name="albumName">Name of album to open</param>
        /// <returns>Whether album was successfuly opened</returns>
        public bool loadAlbum(string albumName)
        {
            pictureData PicData = new pictureData();
            //if fails to get or read file
            //return false;
            XDocument xdoc = new XDocument();

            try
            {
                xdoc = XDocument.Load(albumName);
            }catch
            {
                return(false);
            }
            //Run query, only header item is the album name. children contains all pciture information
            var Albums = from AlbumInfo in xdoc.Descendants("AlbumInfo")
                         select new
            {
                Header   = AlbumInfo.Attribute("name").Value,
                Children = AlbumInfo.Descendants("PictureInfo")
            };

            //Loop through results and add the info to the datalist for each picture
            foreach (var albumInfo in Albums)
            {
                foreach (var PictureInfo in albumInfo.Children)
                {
                    PicData.id           = PictureInfo.Attribute("id").Value;
                    PicData.path         = PictureInfo.Attribute("path").Value;
                    PicData.name         = PictureInfo.Attribute("name").Value;
                    PicData.description  = PictureInfo.Attribute("description").Value;
                    PicData.MD5          = PictureInfo.Attribute("md5").Value;
                    PicData.dateAdded    = PictureInfo.Attribute("dateAdded").Value;
                    PicData.dateModified = PictureInfo.Attribute("dateModified").Value;
                    PicData.albumPath    = albumName;
                    dataList.Add(PicData);
                }
            }
            //read and load xml data into dataList
            _filePath         = albumName;
            _currentAlbumName = albumName;

            return(true);
        }