Пример #1
0
        /// <summary>
        /// Executes WOPI request at given WOPI endpoint address against provided wopi FileRep.
        /// </summary>
        public override IResponseData Execute(string endpointAddress,
                                              string accessToken,
                                              long accessTokenTtl,
                                              ITestCase testCase,
                                              Dictionary <string, string> savedState,
                                              IResourceManager resourceManager,
                                              string userAgent,
                                              RSACryptoServiceProvider proofKeyProviderNew,
                                              RSACryptoServiceProvider proofKeyProviderOld)
        {
            // Get the url of the WOPI endpoint that we'll call - either the normal endpoint, or a SavedState override.
            // If it's an override it might change the accessToken that we're using because it probably already has a token on it.
            Uri uri = GetRequestUri(endpointAddress, ref accessToken, accessTokenTtl, savedState);

            // Run any access token mutators defined on this request.
            string accessTokenToUse = GetMutatedAccessToken(accessToken);

            if (accessToken != accessTokenToUse)
            {
                // The access token changed so update our uri with the new one
                uri = new Uri(UrlHelper.AppendOrReplaceQueryParameter(uri.AbsoluteUri, "access_token", accessTokenToUse));
            }
            // At this point we have the final uri and accessTokenToUse values.  We'll use them later in proof key signing

            List <KeyValuePair <string, string> >        headers       = DefaultHeaders.ToList();
            IEnumerable <KeyValuePair <string, string> > customHeaders = GetCustomHeaders(savedState, resourceManager);

            if (customHeaders != null)
            {
                headers.AddRange(customHeaders);
            }

            if (!string.IsNullOrEmpty(WopiOverrideValue))
            {
                headers.Add(new KeyValuePair <string, string>(Constants.Headers.Override, WopiOverrideValue));
            }

            if (proofKeyProviderNew != null && proofKeyProviderOld != null)
            {
                Dictionary <string, string> originalProofKeyHeaders =
                    GetProofKeyHeaders(accessTokenToUse, uri, proofKeyProviderNew, proofKeyProviderOld);
                Dictionary <string, string> proofKeyHeadersToUse =
                    GetMutatedProofKeyHeaders(originalProofKeyHeaders, timestamp => GetProofKeyHeaders(accessTokenToUse, uri, proofKeyProviderNew, proofKeyProviderOld, timestamp));
                headers.AddRange(proofKeyHeadersToUse);
            }

            headers.Add(new KeyValuePair <string, string>(Constants.Headers.Authorization, "Bearer " + accessTokenToUse));

            MemoryStream         contentStream = HasRequestContent ? GetRequestContent(resourceManager) : null;
            RequestExecutionData executionData = new RequestExecutionData(uri, headers, contentStream);

            return(ExecuteRequest(executionData, userAgent));
        }