コード例 #1
0
        /// <summary>
        /// Create new navigation property to versions for me
        /// <param name="body"></param>
        /// <param name="requestConfiguration">Configuration for the request such as headers, query parameters, and middleware options.</param>
        /// </summary>
        public RequestInformation CreatePostRequestInformation(ListItemVersion body, Action <VersionsRequestBuilderPostRequestConfiguration> requestConfiguration = default)
        {
            _ = body ?? throw new ArgumentNullException(nameof(body));
            var requestInfo = new RequestInformation {
                HttpMethod     = Method.POST,
                UrlTemplate    = UrlTemplate,
                PathParameters = PathParameters,
            };

            requestInfo.SetContentFromParsable(RequestAdapter, "application/json", body);
            if (requestConfiguration != null)
            {
                var requestConfig = new VersionsRequestBuilderPostRequestConfiguration();
                requestConfiguration.Invoke(requestConfig);
                requestInfo.AddRequestOptions(requestConfig.Options);
                requestInfo.AddHeaders(requestConfig.Headers);
            }
            return(requestInfo);
        }
コード例 #2
0
        /// <summary>
        /// Method to retrieve the old version document content
        /// </summary>
        /// <param name="clientContext">SPO Client Context</param>
        /// <param name="searchDocumentRequest">Request model for search operation</param>
        /// <param name="requestedVersion">Specific version number to be fetched from SPO</param>
        /// <param name="LoggerId">Message Id used for logging information</param>
        /// <returns></returns>
        private SearchDocumentResponse SearchDocumentByVersion(ClientContext clientContext, SearchDocumentRequest searchDocumentRequest, int requestedVersion, string LoggerId)
        {
            SearchDocumentResponse searchDocumentResponse = new SearchDocumentResponse();

            try
            {
                Log.DebugFormat("In SearchDocumentByVersion method for MessageId - {0}", LoggerId);
                //Retrieve file based on DocumentId
                Microsoft.SharePoint.Client.File file = clientContext.Web.GetFileById(searchDocumentRequest.DocumentId);
                //Load list item version to fetch the previous version metadata
                ListItemVersion listItemVersions = file.ListItemAllFields.Versions.GetById(requestedVersion);
                //Get the content of specific file version
                FileVersion           fileVersions = file.Versions.GetById(requestedVersion);
                ClientResult <Stream> clientResult = fileVersions.OpenBinaryStream();
                clientContext.Load(file);
                //Load specific metadata of the file
                clientContext.Load(listItemVersions, item => item[SpoConstants.Name],
                                   item => item[SpoConstants.DealerNumber],
                                   item => item[SpoConstants.RequestUser],
                                   item => item[SpoConstants.Version]);
                clientContext.Load(fileVersions);
                clientContext.ExecuteQueryWithRetry(Convert.ToInt32(ConfigurationManager.AppSettings.Get(ExecuteQueryConstants.RetryCount)),
                                                    Convert.ToInt32(ConfigurationManager.AppSettings.Get(ExecuteQueryConstants.RetryDelayTime)),
                                                    LoggerId);
                Log.DebugFormat("In SearchDocumentByVersion method after ExecuteQueryWithRetry method for MessageId - {0}", LoggerId);
                using (MemoryStream mStream = new MemoryStream())
                {
                    if (clientResult != null)
                    {
                        clientResult.Value.CopyTo(mStream);
                        //Read the file content and assign to response model
                        searchDocumentResponse.DocumentContent = mStream.ToArray();

                        foreach (var item in listItemVersions.FieldValues)
                        {
                            if (item.Key == SpoConstants.Name && item.Value != null)
                            {
                                searchDocumentResponse.DocumentName = item.Value.ToString();
                            }
                            if (item.Key == SpoConstants.DealerNumber && item.Value != null)
                            {
                                searchDocumentResponse.DealerNumber = item.Value.ToString();
                            }
                            if (item.Key == SpoConstants.RequestUser && item.Value != null)
                            {
                                searchDocumentResponse.RequestUser = item.Value.ToString();
                            }
                            if (item.Key == SpoConstants.Version && item.Value != null)
                            {
                                searchDocumentResponse.Version = item.Value.ToString();
                            }
                        }
                    }
                }
                Log.DebugFormat("Out of SearchDocumentByVersion method for MessageId - {0}", LoggerId);
            }
            catch (WebException e) when(e.Status == WebExceptionStatus.NameResolutionFailure)
            {
                Log.ErrorFormat("WebException in SearchDocumentByVersion method for MessageId - {0} :{1}", LoggerId, e.Message);
                searchDocumentResponse.ErrorMessage = ErrorMessage.RemoteName;
            }
            catch (ServerException ex)
            {
                Log.ErrorFormat("ServerException in SearchDocumentByVersion method for MessageId - {0} :{1}", LoggerId, ex.Message);
                if (ex.ServerErrorTypeName == ErrorException.SystemIoFileNotFound)
                {
                    searchDocumentResponse.ErrorMessage = ErrorMessage.FileNotFound;
                }
                if (ex.ServerErrorTypeName == ErrorException.ClientServiceException && ex.Message.Contains(ErrorException.CannotRetrieveNullObject))
                {
                    searchDocumentResponse.ErrorMessage = ErrorMessage.FileNotFound;
                }
                else
                {
                    searchDocumentResponse.ErrorMessage = ex.Message;
                }
            }
            catch (Exception ex)
            {
                Log.ErrorFormat("Exception in SearchDocumentByVersion method for MessageId - {0} :{1}", LoggerId, ex.Message);
                searchDocumentResponse.ErrorMessage = ex.Message;
            }
            return(searchDocumentResponse);
        }