예제 #1
0
        public async Task CreateApprovalVersion()
        {
            Printer.PrintStepTitle("Creates A New Version Of An Existing Approval");
            Console.Write("Enter Approval ID:");
            string id = Console.ReadLine();

            if (id == "-1")
            {
                return;
            }

            Console.Write("Enter Number of Decisions Required:");
            string numberOfDecisionsRequiredInput = Console.ReadLine();

            int.TryParse(numberOfDecisionsRequiredInput, out int numberOfDecisionsRequired);

            var filePath = Path.Combine("dummy.pdf");

            var parameters = new ApprovalCreateVersionParameters
            {
                ApprovalId = id,
                NumberOfDecisionsRequired = numberOfDecisionsRequired,
            };

            Console.WriteLine("Creating new approval...");
            var approvalResult = await _apiClient.Approvals.CreateVersion(filePath, parameters);

            Console.WriteLine($"New approval created:{approvalResult.Id} - Version {approvalResult.Version}");
        }
예제 #2
0
        public static async Task CreateApprovalVersion()
        {
            Printer.PrintStepTitle("Creates A New Version Of An Existing Approval");

            var filePath = Path.Combine("dummy.pdf");

            var parameters = new ApprovalCreateVersionParameters
            {
                ApprovalId = TestContainer.Approval.Id,
                NumberOfDecisionsRequired = 3,
            };

            Console.WriteLine("Creating new approval...");

            var approvalResult = await ApiClient.Approvals.CreateVersion(filePath, parameters);

            Printer.Print($"New approval created:{approvalResult.Id} - Version {approvalResult.Version}");
        }
예제 #3
0
        /// <inheritdoc />
        public async Task <ApprovalCreateVersionResult> CreateVersion(string filename, byte[] fileContent, ApprovalCreateVersionParameters parameters)
        {
            // Basic client side validation to prevent unnesessary round trips on basic errors

            if (String.IsNullOrWhiteSpace(parameters.ApprovalId))
            {
                throw new ArgumentException("Approvals.CreateVersion: Approval Id not specified.");
            }

            var fileExtension = Path.GetExtension(filename);

            if (string.IsNullOrWhiteSpace(fileExtension))
            {
                throw new ArgumentException("Approvals.CreateVersion: File must have an extension.");
            }

            if (fileContent.Length <= 0)
            {
                throw new ArgumentException("Approvals.CreateVersion: File length muct be greater than zero");
            }

            using (var content = new MultipartFormDataContent())
            {
                content.Add(new StreamContent(new MemoryStream(fileContent)), "file", WebUtility.UrlEncode(filename));

                var values = new[]
                {
                    new KeyValuePair <string, string>("approvalId", parameters.ApprovalId),
                    new KeyValuePair <string, string>("lockPreviousVersion", parameters.LockPreviousVersion.ToString().ToLower()),
                    new KeyValuePair <string, string>("copyApprovalGroups", parameters.CopyApprovalGroups.ToString().ToLower()),
                    new KeyValuePair <string, string>("numberOfDecisionsRequired", (parameters.NumberOfDecisionsRequired ?? 0).ToString()),
                    new KeyValuePair <string, string>("addOwnerToInitialApprovalGroup", (parameters.AddOwnerToInitialApprovalGroup ?? false).ToString()),
                    new KeyValuePair <string, string>("deadline", parameters.Deadline?.ToString("O") ?? ""),
                    new KeyValuePair <string, string>("reviewers", parameters.Reviewers.ToJson())
                };

                foreach (var keyValuePair in values)
                {
                    content.Add(new StringContent(keyValuePair.Value), $"\"{keyValuePair.Key}\"");
                }

                var response = await ApiClient.PostAsync("Approvals/CreateVersion/", content);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsJsonAsync <ApprovalCreateVersionResult>());
                }

                throw new ApiException("Approvals.CreateVersion", response.StatusCode, await response.Content.ReadAsStringAsync());
            }
        }
예제 #4
0
        /// <inheritdoc />
        public async Task <ApprovalCreateVersionResult> CreateVersion(string filePath, ApprovalCreateVersionParameters parameters)
        {
            var filename = Path.GetFileName(filePath);

            var fileContent = File.ReadAllBytes(filePath);

            return(await CreateVersion(filename, fileContent, parameters));
        }
예제 #5
0
        /// <inheritdoc />
        public async Task <ApprovalCreateVersionResult> CreateVersion(string filename, byte[] fileContent, ApprovalCreateVersionParameters parameters)
        {
            // Basic client side validation to prevent unnesessary round trips on basic errors

            if (String.IsNullOrWhiteSpace(parameters.ApprovalId))
            {
                throw new ArgumentException("Approvals.CreateVersion: Approval Id not specified.");
            }

            var fileExtension = Path.GetExtension(filename);

            if (string.IsNullOrWhiteSpace(fileExtension))
            {
                throw new ArgumentException("Approvals.CreateVersion: File must have an extension.");
            }

            if (fileContent.Length <= 0)
            {
                throw new ArgumentException("Approvals.CreateVersion: File length muct be greater than zero");
            }

            using (var content = new MultipartFormDataContent())
            {
                var fileFormContent = new ByteArrayContent(fileContent, 0, fileContent.Length);
                fileFormContent.Headers.ContentDisposition = new ContentDispositionHeaderValue("form-data")
                {
                    Name = "file", FileName = filename
                };
                fileFormContent.Headers.ContentLength = fileContent.Length;

                content.Add(fileFormContent);

                var values = new[]
                {
                    new KeyValuePair <string, string>("approvalId", parameters.ApprovalId),
                    new KeyValuePair <string, string>("CopyApprovalGroups", false.ToString()),
                    new KeyValuePair <string, string>("SendNotifications", false.ToString()),
                    new KeyValuePair <string, string>("LockPreviousVersion", false.ToString())
                };

                foreach (var keyValuePair in values)
                {
                    content.Add(new StringContent(keyValuePair.Value), $"\"{keyValuePair.Key}\"");
                }


                ApiClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("multipart/form-data"));
                var response = await ApiClient.PostAsync($"approvals/{parameters.ApprovalId}/versions", content);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsJsonAsync <ApprovalCreateVersionResult>());
                }

                throw new ApiException("Approvals.CreateVersion", response.StatusCode, await response.Content.ReadAsStringAsync());
            }
        }