Ejemplo n.º 1
0
        /// <summary>
        /// Gets a friendly header message to be shown to the user when a transfer successfully completes.
        /// </summary>
        /// <param name="transferType">Type of the transfer.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentException">Thrown when <paramref name="transferType" /> has an unexpected value.</exception>
        private static string GetTransferSuccessHeader(GalleryAssetTransferType transferType)
        {
            var hdr = Resources.GalleryServer.Task_Transfer_Objects_Transfer_Successful_Hdr;

            switch (transferType)
            {
            case GalleryAssetTransferType.Move:
                return(string.Format(hdr, Resources.GalleryServer.Task_Transfer_Objects_TransferType_Move_Text2));

            case GalleryAssetTransferType.Copy:
                return(string.Format(hdr, Resources.GalleryServer.Task_Transfer_Objects_TransferType_Copy_Text2));

            default:
                throw new ArgumentException($"Encountered unexpected GalleryAssetTransferType enum value '{transferType}'.");
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates a friendly message to be shown to the user when a transfer successfully completes.
        /// </summary>
        /// <param name="destinationAlbum">The destination album.</param>
        /// <param name="itemsTransferred">The items that were moved or copied.</param>
        /// <param name="transferType">Type of the transfer.</param>
        /// <returns>System.String.</returns>
        /// <exception cref="System.ArgumentException">Thrown when <paramref name="transferType" /> has an unexpected value.</exception>
        private static string GetTransferSuccessMessage(IAlbum destinationAlbum, Entity.GalleryItem[] itemsTransferred, GalleryAssetTransferType transferType)
        {
            // Ex: Graduation day.JPG was successfully copied to the album My Vacation.
            // Ex: The selected items were successfully copied to the album My Vacation.
            var destAlbumUrl   = Utils.GetUrl(PageId.album, "aid={0}", destinationAlbum.Id);
            var destAlbumTitle = Utils.RemoveHtmlTags(destinationAlbum.Title);

            string transferString;

            switch (transferType)
            {
            case GalleryAssetTransferType.Move:
                transferString = Resources.GalleryServer.Task_Transfer_Objects_TransferType_Move_Text1;
                break;

            case GalleryAssetTransferType.Copy:
                transferString = Resources.GalleryServer.Task_Transfer_Objects_TransferType_Copy_Text1;
                break;

            default:
                throw new ArgumentException($"Encountered unexpected GalleryAssetTransferType enum value '{transferType}'.");
            }

            if (itemsTransferred.Length == 1)
            {
                var url = (itemsTransferred[0].IsAlbum ? Utils.GetUrl(PageId.album, "aid={0}", itemsTransferred[0].Id) : Utils.GetUrl(PageId.mediaobject, "moid={0}", itemsTransferred[0].Id));

                return(string.Format(Resources.GalleryServer.Task_Transfer_Objects_Transfer_Successful_Single_Dtl, url, itemsTransferred[0].Title, transferString, destAlbumUrl, destAlbumTitle));
            }
            else
            {
                return(string.Format(Resources.GalleryServer.Task_Transfer_Objects_Transfer_Successful_Multiple_Dtl, transferString, destAlbumUrl, destAlbumTitle));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Moves or copies the <paramref name="itemsToTransfer" /> to the <paramref name="destinationAlbumId" />.
        /// </summary>
        /// <param name="destinationAlbumId">The ID of the destination album.</param>
        /// <param name="itemsToTransfer">The items to transfer.</param>
        /// <param name="transferType">Type of the transfer.</param>
        /// <returns>An instance of <see cref="ActionResult" />.</returns>
        /// <exception cref="HttpResponseException">Thrown when an unexpected error occurs.</exception>
        /// <exception cref="HttpResponseMessage">Thrown when an unexpected error occurs.</exception>
        private static ActionResult TransferTo(int destinationAlbumId, Entity.GalleryItem[] itemsToTransfer, GalleryAssetTransferType transferType)
        {
            try
            {
                Entity.GalleryItem[] createdGalleryItems;
                var destinationAlbum = AlbumController.TransferToAlbum(destinationAlbumId, itemsToTransfer, transferType, out createdGalleryItems);

                return(new ActionResult()
                {
                    Status = ActionResultStatus.Success.ToString(),
                    Title = GetTransferSuccessHeader(transferType),
                    Message = GetTransferSuccessMessage(destinationAlbum, itemsToTransfer, transferType),
                    ActionTarget = createdGalleryItems
                });
            }
            catch (GallerySecurityException)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_No_Permission_Msg_Hdr,
                    Message = Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_No_Permission_Msg_Dtl
                });
            }
            catch (InvalidAlbumException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_To_Nested_Album_Msg_Hdr,
                    Message = ex.Message
                });
            }
            catch (CannotTransferAlbumToNestedDirectoryException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_To_Nested_Album_Msg_Hdr,
                    Message = ex.Message
                });
            }
            catch (UnsupportedMediaObjectTypeException ex)
            {
                return(new ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_UnsupportedFileType_Msg_Hdr,
                    Message = String.Format(CultureInfo.InvariantCulture, Resources.GalleryServer.Task_Transfer_Objects_Cannot_Transfer_UnsupportedFileType_Msg_Dtl, System.IO.Path.GetExtension(ex.MediaObjectFilePath)),
                });
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)
                {
                    Content      = Utils.GetExStringContent(ex),
                    ReasonPhrase = "Server Error"
                });
            }
        }
        /// <summary>
        /// Moves or copies the <paramref name="itemsToTransfer" /> to the <paramref name="destinationAlbumId" />.
        /// </summary>
        /// <param name="destinationAlbumId">The ID of the destination album.</param>
        /// <param name="itemsToTransfer">The items to transfer.</param>
        /// <param name="transferType">Type of the transfer.</param>
        /// <returns>An instance of <see cref="IActionResult" />.</returns>
        private IActionResult TransferTo(int destinationAlbumId, Entity.GalleryItem[] itemsToTransfer, GalleryAssetTransferType transferType)
        {
            try
            {
                //TODO: Need to implement TransferToAlbum()
                var destinationAlbum = _albumController.TransferToAlbum(destinationAlbumId, itemsToTransfer, transferType, out var createdGalleryItems);

                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Success.ToString(),
                    Title = $"{transferType} Successful",
                    Message = "The items were transferred.",
                    ActionTarget = createdGalleryItems
                }));
            }
            catch (GallerySecurityException)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Transfer Aborted - Invalid Selection",
                    Message = "You do not have permission to move or copy media assets to the selected album or you selected an album in a read-only gallery. Review your selection."
                }));
            }
            catch (InvalidAlbumException ex)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Transfer Aborted - Invalid Selection",
                    Message = ex.Message
                }));
            }
            catch (CannotTransferAlbumToNestedDirectoryException ex)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Transfer Aborted - Invalid Selection",
                    Message = ex.Message
                }));
            }
            catch (UnsupportedMediaObjectTypeException ex)
            {
                return(new JsonResult(new Business.ActionResult()
                {
                    Status = ActionResultStatus.Error.ToString(),
                    Title = "Transfer Aborted - Disabled File Type",
                    Message = $"One or more media assets you selected is a disabled file type ({System.IO.Path.GetExtension(ex.MediaObjectFilePath)}). An administrator can enable this file type on the File Types page."
                }));
            }
            catch (Exception ex)
            {
                AppEventController.LogError(ex);

                return(StatusCode(500, _exController.GetExString(ex)));
            }
        }