public async Task SaveOneDriveDocumentToFileAsync(string targetFilePath,
                                                          string restoreSessionId,
                                                          string oneDriveId,
                                                          string oneDriveDocumentId,
                                                          bool?asZip           = null,
                                                          CancellationToken ct = default)
        {
            ParameterValidator.ValidateNotNull(targetFilePath, nameof(targetFilePath));
            ParameterValidator.ValidateNotNull(restoreSessionId, nameof(restoreSessionId));
            ParameterValidator.ValidateNotNull(oneDriveId, nameof(oneDriveId));
            ParameterValidator.ValidateNotNull(oneDriveDocumentId, nameof(oneDriveDocumentId));

            var bodyParameters = new BodyParameters();

            if (asZip != null)
            {
                bodyParameters.AddMandatoryParameter("save", new { asZip = asZip.ToString() });
            }
            else
            {
                bodyParameters.AddNullParameter("save");
            }

            var url = $"restoresessions/{restoreSessionId}/organization/onedrives/{oneDriveId}/documents/{oneDriveDocumentId}/action";
            await _baseClient.DownloadToFilePostAsync(targetFilePath, url, bodyParameters, ct);
        }
Exemple #2
0
        /// <summary>
        /// Converts parameters, that are domain objects into their corresponding DTOs.
        /// </summary>
        /// <param name="parameters">Parameters with domain objects.</param>
        /// <returns></returns>
        private BodyParameters ConvertToDtoBodyParameters(BodyParameters parameters)
        {
            if (parameters == null)
            {
                return(null);
            }

            var convertedParameters = new BodyParameters();

            foreach (var bodyParameter in parameters.GetParameters())
            {
                var parameter = bodyParameter.Value;

                if (parameter == null)
                {
                    convertedParameters.AddNullParameter(bodyParameter.Key);
                    continue;
                }

                if (_dtoResolver.HasDataTransferObjectAssociated(parameter.GetType()))
                {
                    var dtoType    = _dtoResolver.GetDataTransferObjectRecursive(parameter.GetType());
                    var methodInfo = _mapper.GetType().GetMethods()
                                     .Single(x => x.Name == "Map" &&
                                             x.GetParameters().Length == 1 &&
                                             x.GetGenericArguments().Length == 1);
                    var method = methodInfo.MakeGenericMethod(dtoType);
                    parameter = Convert.ChangeType(
                        method.Invoke(_mapper, new object[] { parameter }),
                        dtoType);
                }

                convertedParameters.AddOptionalParameter(bodyParameter.Key, parameter);
            }

            return(convertedParameters);
        }