Esempio n. 1
0
        /// <summary>
        /// Internal method to attach a file for the Parature entity
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="pc"></param>
        /// <param name="attachment"></param>
        /// <returns></returns>
        internal static Attachment UploadFile <TEntity>(ParaCredentials pc, System.Net.Mail.Attachment attachment)
            where TEntity : ParaEntity
        {
            var postUrlR     = ApiCallFactory.FileUploadGetUrl <TEntity>(pc);
            var uploadUrlDoc = postUrlR.XmlReceived;
            var postUrl      = AttachmentGetUrlToPost(uploadUrlDoc);

            var upresp = ApiCallFactory.FilePerformUpload(postUrl, attachment);

            var attaDoc = upresp.XmlReceived;

            var attach = ParaEntityParser.EntityFill <Attachment>(attaDoc);

            return(attach);
        }
Esempio n. 2
0
        /// <summary>
        /// Internal method to handle the upload of a file to Parature.
        /// </summary>
        internal static Attachment UploadFile <TEntity>(ParaCredentials pc, Byte[] attachment,
                                                        String contentType, String fileName) where TEntity : ParaEntity
        {
            Attachment attach;
            var        postUrl = "";

            postUrl = AttachmentGetUrlToPost(ApiCallFactory.FileUploadGetUrl <TEntity>(pc).XmlReceived);

            if (String.IsNullOrEmpty(postUrl) == false)
            {
                var uploadResponse =
                    ApiCallFactory.FilePerformUpload(postUrl, attachment, contentType, fileName)
                    .XmlReceived;

                attach = new Attachment();

                var uploadResult = ParaEntityParser.EntityFill <UploadResult>(uploadResponse);

                if (!string.IsNullOrEmpty(uploadResult.Error))
                {
                    //There was an error uploading
                    attach.HasException = true;
                    attach.Error        = uploadResult.Error;
                }
                else
                {
                    attach.Name = uploadResult.Result.File.FileName;
                    attach.Guid = uploadResult.Result.File.Guid;
                }
            }
            else
            {
                attach = new Attachment();
            }
            return(attach);
        }