Exemplo n.º 1
0
        public async Task <StatusInfo> UploadContentAsync(UploadScoInfo uploadScoInfo)
        {
            var(xml, status) = await this.requestProcessor.ProcessUploadAsync(Commands.Sco.Upload,
                                                                              string.Format(CommandParams.ScoUpload, uploadScoInfo.scoId, UrlEncode(uploadScoInfo.summary), UrlEncode(uploadScoInfo.title)), uploadScoInfo);

            return(status);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Uploads contents by SCO id.
        /// </summary>
        /// <param name="uploadScoInfo">
        /// The upload SCO Info.
        /// </param>
        /// <returns>
        /// The <see cref="ScoContentCollectionResult"/>.
        /// </returns>
        public StatusInfo UploadContent(UploadScoInfo uploadScoInfo)
        {
            StatusInfo status;

            this.requestProcessor.ProcessUpload(Commands.Sco.Upload,
                                                string.Format(CommandParams.ScoUpload, uploadScoInfo.scoId, UrlEncode(uploadScoInfo.summary), UrlEncode(uploadScoInfo.title)), uploadScoInfo, out status);
            return(status);
        }
Exemplo n.º 3
0
        private static FileDto Create(string fileScoId, string fileName, string fileContentType, byte[] content, IAdobeConnectProxy ac)
        {
            if (string.IsNullOrWhiteSpace(fileName))
            {
                throw new ArgumentException("fileName can't be empty", nameof(fileName));
            }
            if (string.IsNullOrWhiteSpace(fileContentType))
            {
                throw new ArgumentException("fileContentType can't be empty", nameof(fileContentType));
            }
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var uploadScoInfo = new UploadScoInfo
            {
                scoId           = fileScoId,
                fileContentType = fileContentType,
                fileName        = fileName,
                fileBytes       = content,
                title           = fileName,
            };

            try
            {
                StatusInfo uploadResult = ac.UploadContent(uploadScoInfo);
            }
            catch (AdobeConnectException ex)
            {
                // Status.Code: invalid. Status.SubCode: format. Invalid Field: file
                if (ex.Status.Code == Esynctraining.AC.Provider.Entities.StatusCodes.invalid && ex.Status.SubCode == StatusSubCodes.format && ex.Status.InvalidField == "file")
                {
                    throw new Exception("Invalid file format selected.");
                }

                throw new Exception("Error occured during file uploading.", ex);
            }

            return(new FileDto
            {
                Id = fileScoId,
                Name = fileName,
                Size = content.Length,
            });
        }
Exemplo n.º 4
0
        public async Task <(XmlDocument, StatusInfo)> ProcessUploadAsync(
            string action,
            string parameters,
            UploadScoInfo uploadData)
        {
            var status = new StatusInfo();

            if (parameters == null)
            {
                parameters = string.Empty;
            }

            try
            {
                var url  = BuildUrl(action, parameters) + $"&session={sessionCookie.Value}";
                var form = new MultipartFormDataContent
                {
                    { new ByteArrayContent(uploadData.fileBytes, 0, uploadData.fileBytes.Length), "file", uploadData.fileName }
                };

                HttpResponseMessage response = null;
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromMilliseconds(connectionDetails.HttpContentRequestTimeout);

                    response = await httpClient.PostAsync(url, form);
                }

                response.EnsureSuccessStatusCode();

                var result = await response.Content.ReadAsStringAsync();

                return(ProcessXmlResult(status, result), status);
            }
            catch (Exception ex)
            {
                status.UnderlyingExceptionInfo = ex;
                TraceTool.TraceException(ex);

                return(null, status);
            }
        }
Exemplo n.º 5
0
        public XmlDocument ProcessUpload(
            string action,
            string parameters,
            UploadScoInfo uploadData,
            out StatusInfo status)
        {
            status = new StatusInfo();

            if (parameters == null)
            {
                parameters = string.Empty;
            }

            try
            {
                HttpResponseMessage response = null;
                var url = BuildUrl(action, parameters) + $"&session={sessionCookie.Value}";
                // ReSharper disable once UseObjectOrCollectionInitializer
                var form = new MultipartFormDataContent();
                form.Add(new ByteArrayContent(uploadData.fileBytes, 0, uploadData.fileBytes.Length), "file",
                         uploadData.fileName);
                using (var httpClient = new HttpClient())
                {
                    httpClient.Timeout = TimeSpan.FromMilliseconds(connectionDetails.HttpContentRequestTimeout);

                    response = httpClient.PostAsync(url, form).Result;
                }

                response.EnsureSuccessStatusCode();
                var result = response.Content.ReadAsStringAsync().Result;
                return(ProcessXmlResult(status, result));
            }
            catch (Exception ex)
            {
                status.UnderlyingExceptionInfo = ex;
                TraceTool.TraceException(ex);
                return(null);
            }
        }
Exemplo n.º 6
0
        public ScoInfoResult UploadFile(string folderScoId, string name, string description, string customUrl,
                                        string fileName, string fileContentType, Stream fileStream,
                                        out int fileSize)
        {
            try
            {
                var createFile = new ContentUpdateItem
                {
                    FolderId    = folderScoId,
                    Name        = name,
                    Description = description,
                    UrlPath     = customUrl,
                    Type        = ScoType.content,
                };

                ScoInfoResult createdFile = _acProxy.CreateSco(createFile);

                if (!createdFile.Success || createdFile.ScoInfo == null)
                {
                    if ((createdFile.Status.SubCode == StatusSubCodes.duplicate) && (createdFile.Status.InvalidField == "name"))
                    {
                        throw new WarningMessageException(Resources.Messages.NameNotUnique);
                    }

                    if ((createdFile.Status.SubCode == StatusSubCodes.duplicate) && (createdFile.Status.InvalidField == "url-path"))
                    {
                        throw new WarningMessageException(Resources.Messages.UrlPathNotUnique);
                    }

                    if ((createdFile.Status.SubCode == StatusSubCodes.illegal_operation) && (createdFile.Status.InvalidField == "url-path"))
                    {
                        throw new WarningMessageException(Resources.Messages.UrlPathReserved);
                    }

                    if ((createdFile.Status.SubCode == StatusSubCodes.format) && (createdFile.Status.InvalidField == "url-path"))
                    {
                        throw new WarningMessageException(Resources.Messages.UrlPathInvalidFormat);
                    }

                    _logger.Error("UploadFile.CreateSco error. " + createdFile.Status.GetErrorInfo());
                    throw new WarningMessageException(createdFile.Status.Code.ToString() + " " + createdFile.Status.SubCode.ToString());
                }

                var uploadScoInfo = new UploadScoInfo
                {
                    scoId           = createdFile.ScoInfo.ScoId,
                    fileContentType = fileContentType,
                    fileName        = fileName,
                    fileBytes       = fileStream.ReadToEnd(),
                    title           = fileName,
                };

                // TRICK:
                fileSize = uploadScoInfo.fileBytes.Length;

                try
                {
                    StatusInfo uploadResult = _acProxy.UploadContent(uploadScoInfo);
                }
                catch (AdobeConnectException ex)
                {
                    try
                    {
                        _acProxy.DeleteSco(createdFile.ScoInfo.ScoId);
                    }
                    catch
                    {
                    }

                    // Status.Code: invalid. Status.SubCode: format. Invalid Field: file
                    if (ex.Status.Code == StatusCodes.invalid && ex.Status.SubCode == StatusSubCodes.format && ex.Status.InvalidField == "file")
                    {
                        throw new WarningMessageException(Resources.Messages.FileInvalidFormat);
                    }

                    throw new WarningMessageException("Error occured during file uploading.", ex);
                }

                return(createdFile);
            }
            catch (Exception ex)
            {
                _logger.Error("UploadFile", ex);
                throw;
            }
        }