internal static CreateAttachmentRequest CreateAttachmentRequest(ItemId parentItemId, string fileName, int size, string contentType, byte[] content, bool isInline, string cancellationId)
        {
            CreateAttachmentRequest createAttachmentRequest = new CreateAttachmentRequest();
            FileAttachmentType      fileAttachmentType      = new FileAttachmentType();

            fileAttachmentType.Name              = fileName;
            fileAttachmentType.Size              = size;
            fileAttachmentType.ContentType       = contentType;
            fileAttachmentType.Content           = content;
            fileAttachmentType.IsInline          = isInline;
            createAttachmentRequest.ParentItemId = parentItemId;
            createAttachmentRequest.Attachments  = new AttachmentType[]
            {
                fileAttachmentType
            };
            createAttachmentRequest.RequireImageType           = fileAttachmentType.IsInline;
            createAttachmentRequest.IncludeContentIdInResponse = fileAttachmentType.IsInline;
            createAttachmentRequest.ClientSupportsIrm          = true;
            createAttachmentRequest.CancellationId             = cancellationId;
            return(createAttachmentRequest);
        }
예제 #2
0
        private string PostAttachment(string endpoint, CreateAttachmentRequest request)
        {
            var client = InitHttpClient();

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var jsonPayload = JsonConvert.SerializeObject(request, _serializerSettings);

            HttpResponseMessage response = client.PostAsync(BaseUrl + endpoint, new StringContent(jsonPayload, Encoding.UTF8, "application/json")).Result;
            string body = response.Content.ReadAsStringAsync().Result;

            if (response.IsSuccessStatusCode)
            {
                dynamic file = JsonConvert.DeserializeObject(body);

                return(file.item.hash);
            }

            var error = JsonConvert.DeserializeObject <HelpScoutError>(body);

            throw new HelpScoutApiException(error, body);
        }
예제 #3
0
        // Token: 0x06001999 RID: 6553 RVA: 0x0005A2D8 File Offset: 0x000584D8
        internal static CreateAttachmentResponse CreateAttachment(CallContext callContext, CreateAttachmentRequest translatedRequest)
        {
            CreateAttachmentHelper.UpdateContentType(callContext);
            CreateAttachmentResponse result;

            using (CreateAttachment createAttachment = new CreateAttachment(callContext, translatedRequest))
            {
                if (!createAttachment.PreExecute())
                {
                    result = null;
                }
                else
                {
                    ServiceResult <AttachmentType> currentStepResult;
                    try
                    {
                        currentStepResult = createAttachment.Execute();
                    }
                    catch (LocalizedException exception)
                    {
                        currentStepResult = ExceptionHandler <AttachmentType> .GetServiceResult <AttachmentType>(exception, null);
                    }
                    createAttachment.SetCurrentStepResult(currentStepResult);
                    result = (CreateAttachmentResponse)createAttachment.PostExecute();
                }
            }
            return(result);
        }
예제 #4
0
 public CreateAttachmentFromLocalFile(CallContext callContext, CreateAttachmentRequest request) : base(callContext)
 {
     this.request = request;
 }
        public async Task <string> CreateAttachment(CreateAttachmentRequest request)
        {
            string endpoint = "attachments.json";

            return(await PostAttachment(endpoint, request));
        }
예제 #6
0
        public string CreateAttachment(CreateAttachmentRequest request)
        {
            string endpoint = "attachments.json";

            return(PostAttachment(endpoint, request));
        }