示例#1
0
        public async Task <GetInvitationLinkResponse> Execute(string documentId, GenerateConfirmationCodeRequest request, string url, string accessToken)
        {
            if (string.IsNullOrWhiteSpace(documentId))
            {
                throw new ArgumentNullException(nameof(documentId));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (string.IsNullOrWhiteSpace(url))
            {
                throw new ArgumentNullException(nameof(url));
            }

            var httpClient = _httpClientFactory.GetHttpClient();
            var serializedPostPermission = JsonConvert.SerializeObject(request);
            var body        = new StringContent(serializedPostPermission, Encoding.UTF8, "application/json");
            var httpRequest = new HttpRequestMessage
            {
                Method     = HttpMethod.Post,
                Content    = body,
                RequestUri = new Uri($"{url}/{documentId}/invitation")
            };

            if (!string.IsNullOrWhiteSpace(accessToken))
            {
                httpRequest.Headers.Add("Authorization", "Bearer " + accessToken);
            }

            var httpResponse = await httpClient.SendAsync(httpRequest).ConfigureAwait(false);

            var json = await httpResponse.Content.ReadAsStringAsync();

            try
            {
                httpResponse.EnsureSuccessStatusCode();
            }
            catch (Exception)
            {
                return(new GetInvitationLinkResponse
                {
                    HttpStatus = httpResponse.StatusCode,
                    ContainsError = true,
                    Error = TryGetError(json)
                });
            }

            return(new GetInvitationLinkResponse
            {
                ContainsError = false,
                Content = JsonConvert.DeserializeObject <OfficeDocumentConfirmationLinkResponse>(json)
            });
        }
示例#2
0
        public static GenerateConfirmationLinkParameter ToParameter(this GenerateConfirmationCodeRequest request)
        {
            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            return(new GenerateConfirmationLinkParameter
            {
                ExpiresIn = request.ExpiresIn,
                NumberOfConfirmations = request.NumberOfConfirmations
            });
        }
示例#3
0
        /// <summary>
        /// Create a shared link.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void HandleAddSharedLink(object sender, EventArgs e)
        {
            var activeDocument = Globals.ThisAddIn.Application.ActiveDocument;

            if (activeDocument == null)
            {
                return;
            }

            string sidDocumentIdValue;

            if (activeDocument.TryGetVariable(Constants.VariableName, out sidDocumentIdValue))
            {
                var request = new GenerateConfirmationCodeRequest
                {
                    ExpiresIn             = ViewModel.IsExpiresInEnabled ? (int?)ViewModel.ExpiresIn : null,
                    NumberOfConfirmations = ViewModel.IsNumberOfDownloadsEnabled ? (int?)ViewModel.NumberOfDownloads : null
                };
                DisplayLoading(true);
                AddSharedLink(sidDocumentIdValue, request).ContinueWith((gi) =>
                {
                    var result = gi.Result;
                    DisplayLoading(false);
                    if (result.ContainsError)
                    {
                        DisplayErrorMessage("An error occured while trying to generate the shared link");
                        return;
                    }

                    _window.Dispatcher.Invoke(new Action(() =>
                    {
                        ViewModel.SharedLinks.Add(new SharedLinkViewModel
                        {
                            ConfirmationCode = result.Content.ConfirmationCode,
                            IsSelected       = false,
                            RedirectUrl      = result.Content.Url
                        });
                    }));
                    DisplayInformationMessage("The shared link has been generated");
                }, TaskContinuationOptions.OnlyOnRanToCompletion).ContinueWith((gi) =>
                {
                    DisplayErrorMessage("An error occured while trying to interact with the DocumentApi");
                    DisplayLoading(false);
                }, TaskContinuationOptions.OnlyOnFaulted);
            }
        }
        public async Task <IActionResult> GetInvitationLink(string id, [FromBody] GenerateConfirmationCodeRequest request)
        {
            if (string.IsNullOrWhiteSpace(id))
            {
                return(GetError(ErrorCodes.InvalidRequest, string.Format(ErrorDescriptions.ParameterIsMissing, "id"), HttpStatusCode.BadRequest));
            }

            if (request == null)
            {
                return(GetError(ErrorCodes.InvalidRequest, ErrorDescriptions.NoRequest, HttpStatusCode.BadRequest));
            }

            var subject = GetSubject();

            try
            {
                var parameter = request.ToParameter();
                parameter.Subject = subject;
                var confirmationCode = await _officeDocumentActions.GenerateConfirmationLink(id, parameter);

                var result = new OfficeDocumentConfirmationLinkResponse
                {
                    ConfirmationCode = confirmationCode,
                    Url = $"{_options.DocumentManagementWebsiteBaseUrl}/confirm/{confirmationCode}"
                };
                return(new OkObjectResult(result));
            }
            catch (NotAuthorizedException ex)
            {
                return(GetError(ex.Code, ex.Message, HttpStatusCode.Unauthorized));
            }
            catch (DocumentNotFoundException)
            {
                return(GetError(ErrorCodes.InvalidRequest, "the document doesn't exist", HttpStatusCode.NotFound));
            }
        }
示例#5
0
        private Task <GetInvitationLinkResponse> AddSharedLink(string documentId, GenerateConfirmationCodeRequest request)
        {
            var officeDocumentClient = _documentManagementFactory.GetOfficeDocumentClient();

            return(officeDocumentClient.GetInvitationLinkResolve(documentId, request, Constants.DocumentApiConfiguration, _authenticationStore.AccessToken));
        }
 public Task <GetInvitationLinkResponse> GetInvitationLink(string documentId, GenerateConfirmationCodeRequest request, string url, string accessToken)
 {
     return(_getInvitationLinkOperation.Execute(documentId, request, url, accessToken));
 }
        public async Task <GetInvitationLinkResponse> GetInvitationLinkResolve(string documentId, GenerateConfirmationCodeRequest request, string configurationUrl, string accessToken)
        {
            var configuration = await _getConfigurationOperation.Execute(new Uri(configurationUrl)).ConfigureAwait(false);

            return(await _getInvitationLinkOperation.Execute(documentId, request, configuration.OfficeDocumentsEndpoint, accessToken).ConfigureAwait(false));
        }