/// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null.
        /// Only media objects the user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(m =>
                                     m.Album.FKGalleryId == SearchOptions.GalleryId &&
                                     m.Metadata.Any(md => md.MetaName == TagType && md.MetadataTags.Any(mdt => SearchOptions.Tags.Contains(mdt.FKTagName))), m => m.Metadata);

                foreach (var moDto in RestrictForCurrentUser(qry))
                {
                    var mediaObject = Factory.GetMediaObjectFromDto(moDto, null);

                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return(galleryObjects);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates an instance of <see cref="CacheItemAlbum" /> from <paramref name="album" />. This instance is suitable for storing in cache.
        /// If <paramref name="album" /> is not inflated, a call to the data store is made to retrieve the child albums and media assets.
        /// </summary>
        /// <param name="album">The album.</param>
        /// <returns>An instance of <see cref="CacheItemAlbum" />.</returns>
        public static CacheItemAlbum CreateFrom(IAlbum album)
        {
            ConcurrentDictionary <int, byte> childAlbumIds;
            ConcurrentDictionary <int, byte> childMediaObjectIds;

            if (album.AreChildrenInflated)
            {
                childAlbumIds       = new ConcurrentDictionary <int, byte>(album.GetChildGalleryObjects(GalleryObjectType.Album).ToDictionary(k => k.Id, v => (byte)0));
                childMediaObjectIds = new ConcurrentDictionary <int, byte>(album.GetChildGalleryObjects(GalleryObjectType.MediaObject).ToDictionary(k => k.Id, v => (byte)0));
            }
            else
            {
                using (var repo = new AlbumRepository())
                {
                    childAlbumIds = new ConcurrentDictionary <int, byte>(repo.Where(a => a.FKAlbumParentId == album.Id).ToDictionary(k => k.AlbumId, v => (byte)0));
                }

                using (var repo = new MediaObjectRepository())
                {
                    childMediaObjectIds = new ConcurrentDictionary <int, byte>(repo.Where(a => a.FKAlbumId == album.Id).ToDictionary(k => k.MediaObjectId, v => (byte)0));
                }
            }

            return(new CacheItemAlbum(album.Id, album.GalleryId, album.Parent.Id, album.GalleryObjectType, album.Sequence, album.DateAdded, CacheItemMetaItem.FromMetaItems(album.MetadataItems, album.Id, album.GalleryObjectType), album.CreatedByUserName, album.LastModifiedByUserName, album.DateLastModified, album.IsPrivate, album.DirectoryName, album.ThumbnailMediaObjectId, album.SortByMetaName, album.SortAscending, album.OwnerUserName, album.OwnerRoleName, childAlbumIds, childMediaObjectIds));
        }
Ejemplo n.º 3
0
        private IEnumerable <IGalleryObject> FindItemsMatchingKeywords()
        {
            var results = new GalleryObjectCollection();

            using (var repo = new AlbumRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(a =>
                                                                                                      a.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      a.Metadata.Any(md => md.Value.Contains(searchTerm))));

                foreach (var album in qry)
                {
                    results.Add(Factory.GetAlbumFromDto(album));
                }
            }

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                                                                                                      mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      mo.Metadata.Any(md => md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    results.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(results);
        }
        /// <summary>
        /// Delete the object to which this behavior belongs from the data store and optionally the file system.
        /// </summary>
        /// <param name="deleteFromFileSystem">Indicates whether to delete the original file from the hard drive in addition
        /// to deleting it from the data store. When true, the object is deleted from both the data store and hard drive. When
        /// false, only the record in the data store and the thumbnail and optimized images are deleted; the original file
        /// is untouched.</param>
        public void Delete(bool deleteFromFileSystem)
        {
            DeleteFromFileSystem(this._galleryObject, deleteFromFileSystem);

            //Factory.GetDataProvider().MediaObject_Delete(this._galleryObject);
              using (var repo = new MediaObjectRepository())
              {
            repo.Delete(this._galleryObject);
              }
        }
        /// <summary>
        /// Delete the object to which this behavior belongs from the data store and optionally the file system.
        /// </summary>
        /// <param name="deleteFromFileSystem">Indicates whether to delete the original file from the hard drive in addition
        /// to deleting it from the data store. When true, the object is deleted from both the data store and hard drive. When
        /// false, only the record in the data store and the thumbnail and optimized images are deleted; the original file
        /// is untouched.</param>
        public void Delete(bool deleteFromFileSystem)
        {
            DeleteFromFileSystem(this._galleryObject, deleteFromFileSystem);

            //Factory.GetDataProvider().MediaObject_Delete(this._galleryObject);
            using (var repo = new MediaObjectRepository())
            {
                repo.Delete(this._galleryObject);
            }
        }
Ejemplo n.º 6
0
        public Dictionary <int, DtoMediaObject> GetMediaObjectByIdList(List <int> ids, bool isText = false)
        {
            List <DtoMediaObject> objectList = new List <DtoMediaObject>();

            if (isText)
            {
                objectList = MediaObjectRepository.GetMediaObjectByIdList(ids);
            }
            else
            {
                objectList = MediaObjectRepository.GetMediaObjectByIdListExceptText(ids);
            }
            var objectDic = objectList.ToDictionary(s => s.MediaId, v => new DtoMediaObject {
                MediaId = v.MediaId, MediaName = v.MediaName, MediaUrl = v.MediaUrl.ToOssPath(), ImgId = v.ImgId, ImgUrl = v.ImgUrl.ToOssPath(), TextId = v.TextId, TextContent = v.TextContent, Description = v.Description
            });

            return(objectDic);
        }
Ejemplo n.º 7
0
        public int AddMediaObject(int objectType, string url, int imageCoverId, int textObjectId, string description, int creator)
        {
            Yw_MediaObject mediaObject = new Yw_MediaObject()
            {
                Yme_MediaType    = objectType,
                Yme_Url          = url,
                Yme_ImageCoverId = imageCoverId,
                Yme_TextObjectId = textObjectId,
                Yme_Description  = description,
                Yme_Status       = 1,
                Yme_Creator      = creator,
                Yme_CreateTime   = DateTime.Now,
                Yme_Editor       = creator,
                Yme_UpdateTime   = DateTime.Now
            };

            return(MediaObjectRepository.Add(mediaObject));
        }
        /// <summary>
        /// Gets the <paramref name="top" /> most recently added media objects, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> GetRecentlyAddedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = RestrictForCurrentUser(repo.Where(mo => mo.Album.FKGalleryId == SearchOptions.GalleryId)
                                                 .OrderByDescending(m => m.DateAdded))
                          .Skip(skip).Take(top)
                          .Include(m => m.Metadata);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// 音频关联图片
        /// </summary>
        /// <param name="paging"></param>
        /// <param name="grade"></param>
        /// <param name="mediaType"></param>
        /// <param name="nameOrKey"></param>
        /// <returns></returns>
        public List <Yw_MediaResource> GetImgList(PagingObject paging, int grade, string nameOrKey)
        {
            List <Yw_MediaResource> mediaList = new List <Yw_MediaResource>();

            if (!string.IsNullOrEmpty(nameOrKey))
            {
                if (nameOrKey.IsNumberic() && nameOrKey.Length >= 5)
                {
                    mediaList = MediaObjectRepository.GetPagingImgList(paging, grade, nameOrKey._ToInt32());
                }
                else
                {
                    var resourceIds = ResourceIndexRepository.GetResourceIndexIds(paging, grade, (int)MediaResourceTypeEnum.图片, 0, nameOrKey, ResourceTypeEnum.多媒体资源);
                    Dictionary <int, int> orderDic = resourceIds.ToOrderDic();
                    mediaList = MediaResourceRepository.GetMediaListByIds(resourceIds).ToList();
                    mediaList = mediaList.OrderBy(x => orderDic[x.Ymr_Id]).ToList();
                }
            }
            else
            {
                mediaList = MediaObjectRepository.GetPagingImgList(paging, grade, nameOrKey._ToInt32());
            }
            return(mediaList);
        }
        private IEnumerable <IGalleryObject> GetMediaObjectsHavingTitleOrCaption()
        {
            var galleryObjects = new GalleryObjectCollection();

            var metaTagsToSearch = new[] { MetadataItemName.Title, MetadataItemName.Caption };

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = RestrictForCurrentUser(qry);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                                                                                                      mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                                                      mo.Metadata.Any(md => metaTagsToSearch.Contains(md.MetaName) && md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null. Only media objects the
        /// user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IEnumerable <IGalleryObject> GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                foreach (var mediaObjectId in GetMediaObjectIdsHavingTags(repo))
                {
                    var mediaObject = Factory.LoadMediaObjectInstance(mediaObjectId);
                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return(galleryObjects);
        }
        /// <summary>
        /// Gets the <paramref name="top" /> media objects having the specified rating, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned. Albums cannot be rated and are thus not returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> GetRatedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                IQueryable <MediaObjectDto> qry;

                switch (SearchOptions.SearchTerms[0].ToLowerInvariant())
                {
                case "highest":                         // Highest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderByDescending(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "lowest":                         // Lowest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                                                            //&& mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && md.Value == "5"))
                                                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "none":                         // Having no rating
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.DateAdded)
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                default:                         // Look for a specific rating
                    var r = ParseRating(SearchOptions.SearchTerms[0]);
                    if (r != null)
                    {
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                                                                mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && r.Contains(md.Value)))
                                                     .OrderBy(mo => mo.DateAdded)
                                                     .Include(mo => mo.Metadata)
                                                     .Skip(skip).Take(top));
                    }
                    else
                    {
                        // The search term is a string other than highest, lowest, none or a decimal. Don't return anything.
                        qry = repo.Where(mo => false);
                    }
                    break;
                }

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            SyncFilenameToMetadataFilename();

            // Save the data to the data store
            //Factory.GetDataProvider().MediaObject_Save(this._galleryObject);
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (IGalleryObjectMetadataItem item in this._galleryObject.MetadataItems)
            {
                item.HasChanges = false;
            }
        }
Ejemplo n.º 14
0
 public int UpdatePropogue(int id, string description, string url)
 {
     return(MediaObjectRepository.UpdatePropogue(id, description, url));
 }
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            var mediaItemsAreWritable = !Factory.LoadGallerySetting(_galleryObject.GalleryId).MediaObjectPathIsReadOnly;

            if (mediaItemsAreWritable)
            {
                SyncFilenameToMetadataFilename();
            }

            var isNew = this._galleryObject.IsNew;

            // Save the data to the data store
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (var item in this._galleryObject.MetadataItems)
            {
                if (mediaItemsAreWritable && !isNew && item.HasChanges && item.PersistToFile)
                {
                    // Persist meta property to original file, but only in writable galleries and for existing media objects
                    // (new ones have their meta extracted from the file so it doesn't make sense to write it back right away).
                    this._galleryObject.MetadataReadWriter.SaveMetaValue(item.MetadataItemName);
                }

                item.HasChanges = false;
            }
        }
Ejemplo n.º 16
0
 /// <overloads>Determine the type of the media object (image, video, audio, generic, etc) specified by the parameter(s). 
 /// This method returns GalleryObjectType.Unknown if no matching MIME type can be found. Guaranteed to not 
 /// return null.</overloads>
 /// <summary>
 /// Determine the type of the media object (image, video, audio, generic, etc) based on its ID. 
 /// This method returns GalleryObjectType.Unknown if no matching MIME type can be found. Guaranteed to not 
 /// return null.
 /// </summary>
 /// <param name="mediaObjectId">An integer representing a media object that exists in the data store. If no 
 /// matching media object is found, an InvalidMediaObjectException is thrown. (this will occur when no 
 /// matching record exists in the data store, or the ID actually represents an album ID). If a media object 
 /// is found, but no MIME type is declared in the configuration file that matches the file's extension, 
 /// GalleryObjectType.Unknown is returned.</param>
 /// <returns>Returns a GalleryObjectType enum indicating the type of media object specified by the 
 /// mediaObjectId parameter. Guaranteed to not return null.</returns>
 /// <remarks>Use this method for existing objects that have previously been added to the data store. </remarks>
 /// <exception cref="GalleryServerPro.Events.CustomExceptions.InvalidMediaObjectException">Thrown 
 /// when the mediaObjectId parameter does not represent an existing media object in the data store.</exception>
 public static GalleryObjectType DetermineMediaObjectType(int mediaObjectId)
 {
     using (var repo = new MediaObjectRepository())
     {
         return DetermineMediaObjectType(repo.Find(mediaObjectId));
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Gets the <paramref name="top" /> most recently added media objects, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable<IGalleryObject> GetRecentlyAddedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = RestrictForCurrentUser(repo.Where(mo => mo.Album.FKGalleryId == SearchOptions.GalleryId)
                    .OrderByDescending(m => m.DateAdded))
                    .Skip(skip).Take(top)
                    .Include(m => m.Metadata);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Gets the <paramref name="top" /> media objects having the specified rating, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned. Albums cannot be rated and are thus not returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable<IGalleryObject> GetRatedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                IQueryable<MediaObjectDto> qry;

                switch (SearchOptions.SearchTerms[0].ToLowerInvariant())
                {
                    case "highest": // Highest rated objects
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                            .OrderByDescending(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    case "lowest": // Lowest rated objects
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                                //&& mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && md.Value == "5"))
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                            .OrderBy(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    case "none": // Having no rating
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && String.IsNullOrEmpty(md.Value)))
                            .OrderBy(mo => mo.DateAdded)
                            .Include(mo => mo.Metadata)
                            .Skip(skip).Take(top));
                        break;

                    default: // Look for a specific rating
                        var r = ParseRating(SearchOptions.SearchTerms[0]);
                        if (r != null)
                        {
                            qry = RestrictForCurrentUser(repo.Where(mo =>
                                mo.Album.FKGalleryId == SearchOptions.GalleryId
                                && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && r.Contains(md.Value)))
                                .OrderBy(mo => mo.DateAdded)
                                .Include(mo => mo.Metadata)
                                .Skip(skip).Take(top));
                        }
                        else
                        {
                            // The search term is a string other than highest, lowest, none or a decimal. Don't return anything.
                            qry = repo.Where(mo => false);
                        }
                        break;
                }

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
Ejemplo n.º 19
0
 public DtoMediaResourceAndObject GetMediaResource(int id)
 {
     return(MediaObjectRepository.GetMedia(id));
 }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the media objects having all tags specified in the search options. Guaranteed to not return null. 
        /// Only media objects the user has permission to view are returned.
        /// </summary>
        /// <returns>An instance of <see cref="IGalleryObjectCollection" />.</returns>
        private IGalleryObjectCollection GetMediaObjectsHavingTags()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(m =>
                    m.Album.FKGalleryId == SearchOptions.GalleryId &&
                    m.Metadata.Any(md => md.MetaName == TagType && md.MetadataTags.Any(mdt => SearchOptions.Tags.Contains(mdt.FKTagName))), m => m.Metadata);

                foreach (var moDto in RestrictForCurrentUser(qry))
                {
                    var mediaObject = Factory.GetMediaObjectFromDto(moDto, null);

                    // We have a media object that contains at least one of the tags. If we have multiple tags, do an extra test to ensure
                    // media object matches ALL of them. (I wasn't able to write the LINQ to do this for me, so it's an extra step.)
                    if (SearchOptions.Tags.Length == 1)
                    {
                        galleryObjects.Add(mediaObject);
                    }
                    else if (MetadataItemContainsAllTags(mediaObject.MetadataItems.First(md => md.MetadataItemName == TagType)))
                    {
                        galleryObjects.Add(mediaObject);
                    }
                }
            }

            return galleryObjects;
        }
        /// <summary>
        /// Persist the object to which this behavior belongs to the data store. Also persist to the file system, if
        /// the object has a representation on disk, such as albums (stored as directories) and media objects (stored
        /// as files). New objects with ID = int.MinValue will have a new <see cref="IGalleryObject.Id"/> assigned
        /// and <see cref="IGalleryObject.IsNew"/> set to false.
        /// All validation should have taken place before calling this method.
        /// </summary>
        public void Save()
        {
            // If the user requested a rotation, then rotate and save the original. If no rotation is requested,
            // the following line does nothing.
            this._galleryObject.Original.GenerateAndSaveFile();

            // Generate the thumbnail and optimized versions. These must run after the previous statement because when
            // the image is rotated, these methods assume the original has already been rotated.
            try
            {
                this._galleryObject.Thumbnail.GenerateAndSaveFile();
                this._galleryObject.Optimized.GenerateAndSaveFile();

                try
                {
                    // Now delete the temp file, but no worries if an error happens. The file is in the temp directory
                    // which is cleaned out each time the app starts anyway.
                    if (File.Exists(_galleryObject.Original.TempFilePath))
                    {
                        File.Delete(_galleryObject.Original.TempFilePath);
                    }
                }
                catch (IOException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (NotSupportedException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
                catch (UnauthorizedAccessException ex)
                {
                    Events.EventController.RecordError(ex, AppSetting.Instance, this._galleryObject.GalleryId, Factory.LoadGallerySettings());
                }
            }
            catch (UnsupportedImageTypeException)
            {
                // We'll get here when there is a corrupt image or the server's memory is not sufficient to process the image.
                // When this happens, replace the thumbnail creator object with a GenericThumbnailCreator. That one uses a
                // hard-coded thumbnail image rather than trying to generate a thumbnail from the original image.
                // Also, null out the Optimized object and don't bother to try to create an optimized image.
                this._galleryObject.Thumbnail.DisplayObjectCreator = new GenericThumbnailCreator(this._galleryObject);
                this._galleryObject.Thumbnail.GenerateAndSaveFile();

                this._galleryObject.Optimized = new NullObjects.NullDisplayObject();
            }

            SyncFilenameToMetadataFilename();

            // Save the data to the data store
            //Factory.GetDataProvider().MediaObject_Save(this._galleryObject);
            using (var repo = new MediaObjectRepository())
            {
                repo.Save(this._galleryObject);
            }

            foreach (IGalleryObjectMetadataItem item in this._galleryObject.MetadataItems)
            {
                item.HasChanges = false;
            }
        }
Ejemplo n.º 22
0
		private static void AddChildObjects(IAlbum album)
		{
			if (album == null)
				throw new ArgumentNullException("album");

			#region Add child albums

			using (var repo = new AlbumRepository())
			{
				//foreach (int albumId in GetDataProvider().Album_GetChildAlbumIdsById(album.Id))
				foreach (int albumId in repo.Where(a => a.FKAlbumParentId == album.Id).Select(a => a.AlbumId))
				{
					album.AddGalleryObject(CreateAlbumInstance(albumId, album.GalleryId));
				}
			}

			#endregion

			#region Add child media objects

			using (var repo = new MediaObjectRepository())
			{
				//foreach (MediaObjectDto moDto in GetDataProvider().Album_GetChildMediaObjectsById(album.Id, album.AllowMetadataLoading))
				IQueryable<MediaObjectDto> moDtos;
				if (album.AllowMetadataLoading)
					moDtos = repo.Where(m => m.FKAlbumId == album.Id, m => m.Metadata);
				else
					moDtos = repo.Where(m => m.FKAlbumId == album.Id);

				foreach (MediaObjectDto moDto in moDtos)
				{
					var mediaObject = GetMediaObjectFromDto(moDto, album);

					AddToMediaObjectCache(mediaObject);

					album.AddGalleryObject(mediaObject);
				}
			}

			#endregion

			album.AreChildrenInflated = true;
		}
Ejemplo n.º 23
0
		private static MediaObjectDto GetMediaObjectById(int mediaObjectId, bool includeMetadata)
		{
			using (var repo = new MediaObjectRepository())
			{
				return (includeMetadata ? repo.Where(m => m.MediaObjectId == mediaObjectId, m => m.Metadata).FirstOrDefault() : repo.Find(mediaObjectId));
			}
		}
Ejemplo n.º 24
0
 public DtoMediaResourceToCourse GetMediaDetailToCourse(int id)
 {
     return(MediaObjectRepository.GetMediaDetailToCourse(id));
 }
Ejemplo n.º 25
0
        private IEnumerable<IGalleryObject> GetMediaObjectsHavingTitleOrCaption()
        {
            var galleryObjects = new GalleryObjectCollection();

            var metaTagsToSearch = new[] { MetadataItemName.Title, MetadataItemName.Caption };

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = RestrictForCurrentUser(qry);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                    mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                    mo.Metadata.Any(md => metaTagsToSearch.Contains(md.MetaName) && md.Value.Contains(searchTerm))));

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }
Ejemplo n.º 26
0
        public void UpdateMediaResource(DtoResourceRequest resource)
        {
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    var words = GetWords(resource.Name, resource.Keyword, resource.Grade);
                    Yw_MediaResource mediaResource = MediaResourceRepository.GetMediaResource(resource.Id);
                    if (mediaResource != null)
                    {
                        mediaResource.Ymr_Name       = resource.Name;
                        mediaResource.Ymr_Grade      = resource.Grade;
                        mediaResource.Ymr_Status     = resource.Status;
                        mediaResource.Ymr_Keywords   = resource.Keyword;
                        mediaResource.Ymr_UpdateTime = DateTime.Now;
                        mediaResource.Ymr_Editor     = resource.Editor;
                        MediaResourceRepository.Update(mediaResource);
                    }

                    Yw_MediaObject mediaObject = MediaObjectRepository.GetMediaObject(mediaResource.Ymr_MediaObjectId);
                    if (mediaObject != null)
                    {
                        mediaObject.Yme_Url          = resource.Url;
                        mediaObject.Yme_ImageCoverId = resource.ImgId;
                        mediaObject.Yme_Description  = resource.Description;
                        mediaObject.Yme_Editor       = resource.Editor;
                        mediaObject.Yme_UpdateTime   = DateTime.Now;
                        if (!string.IsNullOrEmpty(resource.AudioContent))
                        {
                            if (mediaObject.Yme_TextObjectId > 0)
                            {
                                Yw_TextObject textObject = TextObjectRepository.GeTextObject(mediaObject.Yme_TextObjectId);
                                textObject.Yxo_Content    = resource.AudioContent;
                                textObject.Yxo_Editor     = resource.Editor;
                                textObject.Yxo_UpdateTime = DateTime.Now;
                                TextObjectRepository.Update(textObject);
                            }
                            else
                            {
                                Yw_TextObject textObject = new Yw_TextObject()
                                {
                                    Yxo_Content    = resource.AudioContent,
                                    Yxo_Status     = 1,
                                    Yxo_CreateTime = DateTime.Now,
                                    Yxo_Creator    = resource.Creator,
                                    Yxo_Editor     = resource.Editor,
                                    Yxo_UpdateTime = DateTime.Now
                                };
                                int textObjectId = TextObjectRepository.Add(textObject);
                                mediaObject.Yme_TextObjectId = textObjectId;
                            }
                        }
                        MediaObjectRepository.Update(mediaObject);
                    }


                    UpdateResourceIndex(resource.Name, resource.Grade, (int)resource.MediaType, (int)ResourceTypeEnum.多媒体资源, mediaResource.Ymr_Id, words, resource.Creator);

                    scope.Complete();
                }
                catch (Exception ex)
                {
                    RollbackTran();
                    throw ex;
                }
            }
        }
        /// <summary>
        /// Gets the <paramref name="top" /> media objects having the specified rating, skipping the first
        /// <paramref name="skip" /> objects. Only media objects the current user is authorized to
        /// view are returned. Albums cannot be rated and are thus not returned.
        /// </summary>
        /// <param name="top">The number of items to retrieve.</param>
        /// <param name="skip">The number of items to skip over in the data store.</param>
        /// <returns><see cref="IEnumerable&lt;IGalleryObject&gt;" />.</returns>
        private IEnumerable <IGalleryObject> GetRatedMediaObjects(int top, int skip = 0)
        {
            var galleryObjects = new GalleryObjectCollection();

            if (AppSetting.Instance.ProviderDataStore == ProviderDataStore.SqlCe)
            {
                // SQL CE does not support the queries below, so throw an error. We should never get here because Utils.GetTopRatedUrl()
                // only generates an URL for SQL Server DB's, but better safe than sorry. FYI, these are the errors SQL CE generates:
                // Caused by String.IsNullOrEmpty(md.Value): "The specified argument value for the function is not valid. [ Argument # = 1,Name of function(if known) = LEN ]"
                // Caused by using md.Value in OrderBy: "Large objects (ntext and image) cannot be used in ORDER BY clauses."
                // One way to make these queries work is to change Metadata.Value from NTEXT to NVARCHAR(4000), but this is undesirable because we
                // want the max length to handle long meta values, especially in SQL Server, where these queries work fine. I looked into adding
                // conditional logic to change the column definition for SQL CE but leaving it unchanged for SQL Server, but it was complex and had risk.
                throw new NotSupportedException("SQL CE does not support the query syntax used in GalleryObjectSearcher.GetRatedMediaObjects(). Use SQL Server instead.");
            }

            using (var repo = new MediaObjectRepository())
            {
                IQueryable <MediaObjectDto> qry;

                switch (SearchOptions.SearchTerms[0].ToLowerInvariant())
                {
                case "highest": // Highest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderByDescending(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "lowest": // Lowest rated objects
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId
                                                            //&& mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && md.Value == "5"))
                                                            && mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && !String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.Metadata.Where(md => md.MetaName == MetadataItemName.Rating).Select(md => md.Value).FirstOrDefault())
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                case "none": // Having no rating
                    qry = RestrictForCurrentUser(repo.Where(mo =>
                                                            mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                            mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && String.IsNullOrEmpty(md.Value)))
                                                 .OrderBy(mo => mo.DateAdded)
                                                 .Include(mo => mo.Metadata)
                                                 .Skip(skip).Take(top));
                    break;

                default: // Look for a specific rating
                    var r = ParseRating(SearchOptions.SearchTerms[0]);
                    if (r != null)
                    {
                        qry = RestrictForCurrentUser(repo.Where(mo =>
                                                                mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                                                                mo.Metadata.Any(md => md.MetaName == MetadataItemName.Rating && r.Contains(md.Value)))
                                                     .OrderBy(mo => mo.DateAdded)
                                                     .Include(mo => mo.Metadata)
                                                     .Skip(skip).Take(top));
                    }
                    else
                    {
                        // The search term is a string other than highest, lowest, none or a decimal. Don't return anything.
                        qry = repo.Where(mo => false);
                    }
                    break;
                }

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return(galleryObjects);
        }
Ejemplo n.º 28
0
        private IEnumerable<IGalleryObject> GetMediaObjectsMatchingKeywords()
        {
            var galleryObjects = new GalleryObjectCollection();

            using (var repo = new MediaObjectRepository())
            {
                var qry = repo.Where(a => true, a => a.Metadata);

                qry = SearchOptions.SearchTerms.Aggregate(qry, (current, searchTerm) => current.Where(mo =>
                    mo.Album.FKGalleryId == SearchOptions.GalleryId &&
                    mo.Metadata.Any(md => md.Value.Contains(searchTerm))));

                qry = RestrictForCurrentUser(qry);

                foreach (var mediaObject in qry)
                {
                    galleryObjects.Add(Factory.GetMediaObjectFromDto(mediaObject, null));
                }
            }

            return galleryObjects;
        }