Execute() публичный Метод

Opens the connection to the {OPEN} API, assembles the signing headers and uploads any files.
public Execute ( WebRequest request, ClientCredential credential, Stream uploadStream = null ) : Stream
request System.Net.WebRequest the
credential ClientCredential
uploadStream Stream
Результат Stream
        public void TestAPIActionExecute()
        {
            string clientToken = "clientToken";
            string accessToken = "accessToken";
            string secret      = "secret-shh";
            var    credential  = new ClientCredential(clientToken, accessToken, secret);

            var    signer          = new EdgeGridV1Signer();
            string TestURIProtocol = "asdf";

            WebRequest.RegisterPrefix(TestURIProtocol, new WebRequestTestCreate());
            var request = (HttpWebRequestTest)WebRequest.Create("asdf://www.example.com/");

            var response = request.CreateResponse(HttpStatusCode.OK);

            request.NextResponse = response;

            Assert.AreSame(signer.Execute(request, credential), response.GetResponseStream());
            Assert.AreEqual(request.Method, "GET");
            Assert.AreEqual(request.Headers.Count, 1);

            request.Method = "PUT";
            signer.Execute(request, credential);
            Assert.AreEqual(request.ContentLength, 0);

            request.Method = "POST";
            var data         = "Lorem ipsum dolor sit amet, an sea putant quaeque, homero aperiam te eos.".ToByteArray();
            var uploadStream = new MemoryStream(data);

            signer.Execute(request, credential, uploadStream);
            Assert.AreEqual(request.ContentLength, 73);
            CollectionAssert.AreEqual(request.RequestStream.ToArray(), data);
        }
        static void execute(string httpMethod, string apiurl, List<string> headers, string clientToken, string accessToken, string secret, string data, string uploadfile, string outputfile, int? maxBodySize, string contentType, bool verbose = false)
        {
            if (apiurl == null || clientToken == null || accessToken == null || secret == null)
            {
                help();
                return;
            }

            EdgeGridV1Signer signer = new EdgeGridV1Signer(null, maxBodySize);
            ClientCredential credential = new ClientCredential(clientToken, accessToken, secret);

            Stream uploadStream = null;
            if (uploadfile != null)
                uploadStream = new FileInfo(uploadfile).OpenRead();
            else if (data != null)
                uploadStream = new MemoryStream(data.ToByteArray());

            var uri = new Uri(apiurl);
            var request = WebRequest.Create(uri);

            foreach (string header in headers) request.Headers.Add(header);
            request.Method = httpMethod;

            Stream output = Console.OpenStandardOutput();
            if (outputfile != null)
                output = new FileInfo(outputfile).OpenWrite();

            if (verbose)
            {
                signer.Sign(request, credential, uploadStream);
                Console.WriteLine("Authorization: {0}", request.Headers.Get("Authorization"));
                Console.WriteLine();
            }

            using (var result = signer.Execute(request, credential, uploadStream))
            {
                using (output)
                {
                    using (result)
                    {
                        byte[] buffer = new byte[1024*1024];
                        int bytesRead = 0;

                        while ((bytesRead = result.Read(buffer, 0, buffer.Length)) != 0)
                        {
                            output.Write(buffer, 0, bytesRead);
                        }
                    }
                }
            }
        }