예제 #1
0
        public bool Save(MediaResourceCreateCommand command, User createdByUser, out string failureReason, out MediaResource mediaResource)
        {
            failureReason = string.Empty;
            mediaResource = null;

            if (!_documentSession.Load <AppRoot>(Constants.AppRootId).AudioServiceStatus)
            {
                failureReason = "Audio files cannot be uploaded at the moment. Please try again later.";
                return(false);
            }

            bool returnValue;

            try
            {
                var audio = AudioUtility.Load(command.FileStream, command.FileName, command.FileMimeType);

                mediaResource = _mediaResourceFactory.MakeContributionAudio(
                    command.Key,
                    createdByUser,
                    command.UploadedOn,
                    command.FileName,
                    new Object(),
                    command.FileMimeType,
                    GetAudioMetadata(audio));

                string filePath = _mediaFilePathFactory.MakeMediaFilePath(mediaResource.Id, "Original", MediaTypeUtility.GetStandardExtensionForMimeType(command.FileMimeType));

                audio.SaveAs(filePath);

                returnValue = true;
            }
            catch (Exception exception)
            {
                _logger.ErrorException("Error saving audio", exception);

                failureReason = "The file is corrupted or not a valid audio file and could not be saved. Please check the file and try again.";
                returnValue   = false;
            }

            return(returnValue);
        }