Esempio n. 1
0
        internal PutImageResponse PutImage(PutImageRequest request)
        {
            var marshaller   = new PutImageRequestMarshaller();
            var unmarshaller = PutImageResponseUnmarshaller.Instance;

            return(Invoke <PutImageRequest, PutImageResponse>(request, marshaller, unmarshaller));
        }
Esempio n. 2
0
        /// <summary>
        /// Initiates the asynchronous execution of the PutImage operation.
        /// </summary>
        ///
        /// <param name="request">Container for the necessary parameters to execute the PutImage operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/ecr-2015-09-21/PutImage">REST API Reference for PutImage Operation</seealso>
        public Task <PutImageResponse> PutImageAsync(PutImageRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller   = new PutImageRequestMarshaller();
            var unmarshaller = PutImageResponseUnmarshaller.Instance;

            return(InvokeAsync <PutImageRequest, PutImageResponse>(request, marshaller,
                                                                   unmarshaller, cancellationToken));
        }
Esempio n. 3
0
        /// <summary>
        /// Replaces the image or if it doesn't exist, creates it.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>PutImageResponse</c> with a image id.
        /// </returns>
        public PutImageResponse Put(PutImageRequest request)
        {
            IEnumerable <MediaFolder> parentFolderFuture = null;

            if (request.Data.FolderId.HasValue)
            {
                parentFolderFuture = repository.AsQueryable <MediaFolder>()
                                     .Where(c => c.Id == request.Data.FolderId.Value && !c.IsDeleted)
                                     .ToFuture();
            }

            var mediaImage = repository.AsQueryable <MediaImage>()
                             .Where(file => file.Id == request.Id)
                             .ToFuture()
                             .FirstOrDefault();

            MediaFolder parentFolder = null;

            if (parentFolderFuture != null)
            {
                parentFolder = parentFolderFuture.First();
                if (parentFolder.Type != Module.MediaManager.Models.MediaType.Image)
                {
                    throw new CmsApiValidationException("Folder must be type of an image.");
                }
            }

            var createImage = mediaImage == null;

            if (createImage)
            {
                mediaImage = new MediaImage
                {
                    Id   = request.Id.GetValueOrDefault(),
                    Type = Module.MediaManager.Models.MediaType.Image
                };
            }
            else if (request.Data.Version > 0)
            {
                mediaImage.Version = request.Data.Version;
            }

            unitOfWork.BeginTransaction();

            if (!createImage)
            {
                repository.Save(mediaImage.CreateHistoryItem());
            }

            mediaImage.Title                 = request.Data.Title;
            mediaImage.Description           = request.Data.Description;
            mediaImage.Caption               = request.Data.Caption;
            mediaImage.Size                  = request.Data.FileSize;
            mediaImage.PublicUrl             = request.Data.ImageUrl;
            mediaImage.Width                 = request.Data.Width;
            mediaImage.Height                = request.Data.Height;
            mediaImage.PublicThumbnailUrl    = request.Data.ThumbnailUrl;
            mediaImage.ThumbnailWidth        = request.Data.ThumbnailWidth;
            mediaImage.ThumbnailHeight       = request.Data.ThumbnailHeight;
            mediaImage.ThumbnailSize         = request.Data.ThumbnailSize;
            mediaImage.Folder                = parentFolder;
            mediaImage.PublishedOn           = request.Data.PublishedOn;
            mediaImage.OriginalFileName      = request.Data.OriginalFileName;
            mediaImage.OriginalFileExtension = request.Data.OriginalFileExtension;
            mediaImage.OriginalWidth         = request.Data.OriginalWidth;
            mediaImage.OriginalHeight        = request.Data.OriginalHeight;
            mediaImage.OriginalSize          = request.Data.OriginalSize;
            mediaImage.PublicOriginallUrl    = request.Data.OriginalUrl;

            mediaImage.FileUri      = new Uri(request.Data.FileUri);
            mediaImage.IsUploaded   = request.Data.IsUploaded;
            mediaImage.IsTemporary  = request.Data.IsTemporary;
            mediaImage.IsCanceled   = request.Data.IsCanceled;
            mediaImage.OriginalUri  = new Uri(request.Data.OriginalUri);
            mediaImage.ThumbnailUri = new Uri(request.Data.ThumbnailUri);

            var archivedMedias   = new List <Media>();
            var unarchivedMedias = new List <Media>();

            if (mediaImage.IsArchived != request.Data.IsArchived)
            {
                if (request.Data.IsArchived)
                {
                    archivedMedias.Add(mediaImage);
                    mediaService.ArchiveSubMedias(mediaImage, archivedMedias);
                }
                else
                {
                    unarchivedMedias.Add(mediaImage);
                    mediaService.UnarchiveSubMedias(mediaImage, unarchivedMedias);
                }
            }

            mediaImage.IsArchived = request.Data.IsArchived;

            repository.Save(mediaImage);

            IList <Tag> newTags = null;

            if (request.Data.Tags != null)
            {
                tagService.SaveMediaTags(mediaImage, request.Data.Tags, out newTags);
            }

            unitOfWork.Commit();

            // Fire events.
            Events.RootEvents.Instance.OnTagCreated(newTags);
            if (createImage)
            {
                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(mediaImage);
            }
            else
            {
                Events.MediaManagerEvents.Instance.OnMediaFileUpdated(mediaImage);
            }

            foreach (var archivedMedia in archivedMedias.Distinct())
            {
                Events.MediaManagerEvents.Instance.OnMediaArchived(archivedMedia);
            }

            foreach (var archivedMedia in unarchivedMedias.Distinct())
            {
                Events.MediaManagerEvents.Instance.OnMediaUnarchived(archivedMedia);
            }

            return(new PutImageResponse
            {
                Data = mediaImage.Id
            });
        }
Esempio n. 4
0
        /// <summary>
        /// Replaces the image or if it doesn't exist, creates it.
        /// </summary>
        /// <param name="request">The request.</param>
        /// <returns>
        ///   <c>PutImageResponse</c> with a image id.
        /// </returns>
        public PutImageResponse Put(PutImageRequest request)
        {
            IEnumerable<MediaFolder> parentFolderFuture = null;
            if (request.Data.FolderId.HasValue)
            {
                parentFolderFuture = repository.AsQueryable<MediaFolder>()
                    .Where(c => c.Id == request.Data.FolderId.Value && !c.IsDeleted)
                    .ToFuture();
            }

            var mediaImage = repository.AsQueryable<MediaImage>()
                .Where(file => file.Id == request.Id)
                .ToFuture()
                .FirstOrDefault();

            MediaFolder parentFolder = null;
            if (parentFolderFuture != null)
            {
                parentFolder = parentFolderFuture.First();
                if (parentFolder.Type != Module.MediaManager.Models.MediaType.Image)
                {
                    throw new CmsApiValidationException("Folder must be type of an image.");
                }
            }

            var createImage = mediaImage == null;
            if (createImage)
            {
                mediaImage = new MediaImage
                                 {
                                     Id = request.Id.GetValueOrDefault(),
                                     Type = Module.MediaManager.Models.MediaType.Image
                                 };
            }
            else if (request.Data.Version > 0)
            {
                mediaImage.Version = request.Data.Version;
            }

            unitOfWork.BeginTransaction();

            if (!createImage)
            {
                repository.Save(mediaImage.CreateHistoryItem());
            }

            mediaImage.Title = request.Data.Title;
            mediaImage.Description = request.Data.Description;
            mediaImage.Caption = request.Data.Caption;
            mediaImage.Size = request.Data.FileSize;
            mediaImage.PublicUrl = request.Data.ImageUrl;
            mediaImage.Width = request.Data.Width;
            mediaImage.Height = request.Data.Height;
            mediaImage.PublicThumbnailUrl = request.Data.ThumbnailUrl;
            mediaImage.ThumbnailWidth = request.Data.ThumbnailWidth;
            mediaImage.ThumbnailHeight = request.Data.ThumbnailHeight;
            mediaImage.ThumbnailSize = request.Data.ThumbnailSize;
            mediaImage.Folder = parentFolder;
            mediaImage.PublishedOn = request.Data.PublishedOn;
            mediaImage.OriginalFileName = request.Data.OriginalFileName;
            mediaImage.OriginalFileExtension = request.Data.OriginalFileExtension;
            mediaImage.OriginalWidth = request.Data.OriginalWidth;
            mediaImage.OriginalHeight = request.Data.OriginalHeight;
            mediaImage.OriginalSize = request.Data.OriginalSize;
            mediaImage.PublicOriginallUrl = request.Data.OriginalUrl;

            mediaImage.FileUri = new Uri(request.Data.FileUri);
            mediaImage.IsUploaded = request.Data.IsUploaded;
            mediaImage.IsTemporary = request.Data.IsTemporary;
            mediaImage.IsCanceled = request.Data.IsCanceled;
            mediaImage.OriginalUri = new Uri(request.Data.OriginalUri);
            mediaImage.ThumbnailUri = new Uri(request.Data.ThumbnailUri);

            var archivedMedias = new List<Media>();
            var unarchivedMedias = new List<Media>();
            if (mediaImage.IsArchived != request.Data.IsArchived)
            {
                if (request.Data.IsArchived)
                {
                    archivedMedias.Add(mediaImage);
                    mediaService.ArchiveSubMedias(mediaImage, archivedMedias);
                }
                else
                {
                    unarchivedMedias.Add(mediaImage);
                    mediaService.UnarchiveSubMedias(mediaImage, unarchivedMedias);
                }
            }

            mediaImage.IsArchived = request.Data.IsArchived;

            repository.Save(mediaImage);

            IList<Tag> newTags = null;
            if (request.Data.Tags != null)
            {
                tagService.SaveMediaTags(mediaImage, request.Data.Tags, out newTags);
            }

            unitOfWork.Commit();

            // Fire events.
            Events.RootEvents.Instance.OnTagCreated(newTags);
            if (createImage)
            {
                Events.MediaManagerEvents.Instance.OnMediaFileUploaded(mediaImage);
            }
            else
            {
                Events.MediaManagerEvents.Instance.OnMediaFileUpdated(mediaImage);
            }

            foreach (var archivedMedia in archivedMedias.Distinct())
            {
                Events.MediaManagerEvents.Instance.OnMediaArchived(archivedMedia);
            }

            foreach (var archivedMedia in unarchivedMedias.Distinct())
            {
                Events.MediaManagerEvents.Instance.OnMediaUnarchived(archivedMedia);
            }

            return new PutImageResponse
                       {
                           Data = mediaImage.Id
                       };
        }