Sign() публичный статический Метод

public static Sign ( OssHttpRequestMessage ossHttpRequestMessage, NetworkCredential networkCredential ) : void
ossHttpRequestMessage OssHttpRequestMessage
networkCredential System.Net.NetworkCredential
Результат void
Пример #1
0
        public async Task <ObjectListing> ListObjects(ListObjectsRequest listObjectsRequest)
        {
            ObjectListing         result             = null;
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                if (listObjectsRequest.Prefix != null)
                {
                    parameters.Add("prefix", listObjectsRequest.Prefix);
                }
                if (listObjectsRequest.Delimiter != null)
                {
                    parameters.Add("delimiter", listObjectsRequest.Delimiter);
                }
                if (listObjectsRequest.Marker != null)
                {
                    parameters.Add("marker", listObjectsRequest.Marker);
                }
                if (listObjectsRequest.MaxKeys != null)
                {
                    parameters.Add("maxKeys", listObjectsRequest.MaxKeys.ToString());
                }

                httpRequestMessage = new OssHttpRequestMessage(listObjectsRequest.BucketName, null, parameters);

                httpRequestMessage.Method       = HttpMethod.Get;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }

                var temp = DeserializerFactory.GetFactory().CreateListObjectsResultDeserializer();
                result = await temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(result);
        }
Пример #2
0
        public async Task <CompleteMultipartUploadResult> CompleteMultipartUpload(CompleteMultipartUploadModel completeMultipartUploadModel)
        {
            CompleteMultipartUploadResult result             = null;
            OssHttpRequestMessage         httpRequestMessage = null;
            HttpResponseMessage           response           = null;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("uploadId", completeMultipartUploadModel.UploadId);


                httpRequestMessage = new OssHttpRequestMessage(completeMultipartUploadModel.Bucket, completeMultipartUploadModel.Key, parameters);

                httpRequestMessage.Method       = HttpMethod.Post;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                XmlStreamSerializer <CompleteMultipartUploadModel> serializer = new XmlStreamSerializer <CompleteMultipartUploadModel>();
                //  FileStream fileStream = new FileStream("1.xml", FileMode.Open);

                //httpRequestMessage.Content = new StreamContent(fileStream);
                httpRequestMessage.Content = new StreamContent(serializer.Serialize(completeMultipartUploadModel));

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
                var temp = DeserializerFactory.GetFactory().CreateCompMultiUploadDeserializer();
                result = await temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(result);
        }
Пример #3
0
        public async Task <ListPartsResult> ListMultiUploadParts(string buketName, string key, string uploadId)
        {
            ListPartsResult       result             = null;
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("uploadId", uploadId);


                httpRequestMessage = new OssHttpRequestMessage(buketName, key, parameters);

                httpRequestMessage.Method       = HttpMethod.Get;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
                var temp = DeserializerFactory.GetFactory().CreateListPartsDeserialzer();
                result = await temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(result);
        }
Пример #4
0
        public async Task <IEnumerable <Bucket> > ListBuckets()
        {
            IEnumerable <Bucket>  result             = null;
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                httpRequestMessage = new OssHttpRequestMessage(OssHttpRequestMessage.NONEEDBUKETNAME, null);

                httpRequestMessage.Method       = HttpMethod.Get;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);


                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }

                var temp = DeserializerFactory.GetFactory().CreateListBucketResultDeserializer();
                result = await temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }

            return(result);
        }
Пример #5
0
        public async Task <ObjectMetadata> GetObjectMetadata(string bucketName, string key)
        {
            ObjectMetadata        result             = null;
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                httpRequestMessage = new OssHttpRequestMessage(bucketName, key);

                httpRequestMessage.Method       = HttpMethod.Head;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }

                var temp = DeserializerFactory.GetFactory().CreateGetObjectMetadataResultDeserializer();
                result = temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(result);
        }
Пример #6
0
        public async Task DeleteMultipartUpload(MultiUploadRequestData multiUploadObject)
        {
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("partNumber", multiUploadObject.PartNumber);
                parameters.Add("uploadId", multiUploadObject.UploadId);

                httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters);

                httpRequestMessage.Method       = HttpMethod.Delete;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
Пример #7
0
        public async Task SetBucketAcl(string bucketName, CannedAccessControlList acl)
        {
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("acl", null);
                httpRequestMessage = new OssHttpRequestMessage(bucketName, null, parameters);

                httpRequestMessage.Method       = HttpMethod.Put;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;
                httpRequestMessage.Headers.Add("x-oss-acl", acl.GetStringValue());
                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
Пример #8
0
        public async Task DeleteBucket(string bucketName)
        {
            OssHttpRequestMessage httpRequestMessage = null;
            HttpResponseMessage   response           = null;

            try
            {
                httpRequestMessage = new OssHttpRequestMessage(bucketName, null);

                httpRequestMessage.Method       = HttpMethod.Delete;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                response = await httpClient.SendAsync(httpRequestMessage);

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }

                if (response != null)
                {
                    response.Dispose();
                }
            }
        }
Пример #9
0
        public async Task <MultipartUploadResult> MultipartUpload(MultiUploadRequestData multiUploadObject,
                                                                  Action <HttpProcessData> uploadProcessCallback = null, CancellationToken?cancellationToken = null)
        {
            MultipartUploadResult result = null;

            HttpClientHandler      hand = null;
            ProgressMessageHandler processMessageHander = null;
            HttpClient             localHttpClient      = null;
            OssHttpRequestMessage  httpRequestMessage   = null;
            HttpResponseMessage    response             = null;

            try
            {
                hand = new HttpClientHandler();
                processMessageHander     = new ProgressMessageHandler(hand);
                localHttpClient          = new HttpClient(processMessageHander);
                localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour);

                Dictionary <string, string> parameters = new Dictionary <string, string>();
                parameters.Add("partNumber", multiUploadObject.PartNumber);
                parameters.Add("uploadId", multiUploadObject.UploadId);

                httpRequestMessage = new OssHttpRequestMessage(multiUploadObject.Bucket, multiUploadObject.Key, parameters);

                httpRequestMessage.Method       = HttpMethod.Put;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;
                httpRequestMessage.Content      = new StreamContent(multiUploadObject.Content);

                if (uploadProcessCallback != null)
                {
                    processMessageHander.HttpSendProgress += (sender, e) =>
                    {
                        uploadProcessCallback(new HttpProcessData()
                        {
                            TotalBytes         = e.TotalBytes,
                            BytesTransferred   = e.BytesTransferred,
                            ProgressPercentage = e.ProgressPercentage
                        });
                    };
                }


                OssRequestSigner.Sign(httpRequestMessage, networkCredential);

                if (cancellationToken != null)
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken);
                }
                else
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage);
                }

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }
                var deseserializer = DeserializerFactory.GetFactory().CreateMultipartUploadDeserializer();
                result = deseserializer.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (hand != null)
                {
                    hand.Dispose();
                }

                if (processMessageHander != null)
                {
                    processMessageHander.Dispose();
                }

                if (localHttpClient != null)
                {
                    localHttpClient.Dispose();
                }

                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }


                if (response != null)
                {
                    response.Dispose();
                }
            }
            return(result);
        }
Пример #10
0
        public async Task <OssObject> GetObject(GetObjectRequest getObjectRequest,
                                                Action <HttpProcessData> downloadProcessCallback = null, CancellationToken?cancellationToken = null)
        {
            OssObject result = null;

            HttpClientHandler      hand = null;
            ProgressMessageHandler processMessageHander = null;
            HttpClient             localHttpClient      = null;
            OssHttpRequestMessage  httpRequestMessage   = null;
            HttpResponseMessage    response             = null;

            try
            {
                hand = new HttpClientHandler();
                processMessageHander     = new ProgressMessageHandler(hand);
                localHttpClient          = new HttpClient(processMessageHander);
                localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour);

                httpRequestMessage = new OssHttpRequestMessage(getObjectRequest.BucketName, getObjectRequest.Key);
                getObjectRequest.ResponseHeaders.Populate(httpRequestMessage.Headers);
                getObjectRequest.Populate(httpRequestMessage.Headers);

                httpRequestMessage.Method       = HttpMethod.Get;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;

                OssRequestSigner.Sign(httpRequestMessage, networkCredential);
                if (downloadProcessCallback != null)
                {
                    processMessageHander.HttpReceiveProgress += (sender, e) =>
                    {
                        downloadProcessCallback(new HttpProcessData()
                        {
                            TotalBytes         = e.TotalBytes,
                            BytesTransferred   = e.BytesTransferred,
                            ProgressPercentage = e.ProgressPercentage
                        });;
                    };
                }

                if (cancellationToken != null)
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken);
                }
                else
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage);
                }


                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }

                var temp = DeserializerFactory.GetFactory().CreateGetObjectResultDeserializer(getObjectRequest);
                result = await temp.Deserialize(response);
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (hand != null)
                {
                    hand.Dispose();
                }

                if (processMessageHander != null)
                {
                    processMessageHander.Dispose();
                }

                if (localHttpClient != null)
                {
                    localHttpClient.Dispose();
                }

                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }
            }


            return(result);
        }
Пример #11
0
        public async Task <PutObjectResult> PutObject(string bucketName, string key, Stream content, ObjectMetadata metadata,
                                                      Action <HttpProcessData> uploadProcessCallback = null, CancellationToken?cancellationToken = null)
        {
            PutObjectResult        result = null;
            HttpClientHandler      hand   = null;
            ProgressMessageHandler processMessageHander = null;
            HttpClient             localHttpClient      = null;
            OssHttpRequestMessage  httpRequestMessage   = null;
            HttpResponseMessage    response             = null;

            try
            {
                hand = new HttpClientHandler();
                processMessageHander     = new ProgressMessageHandler(hand);
                localHttpClient          = new HttpClient(processMessageHander);
                localHttpClient.Timeout += new TimeSpan(2 * TimeSpan.TicksPerHour);
                httpRequestMessage       = new OssHttpRequestMessage(bucketName, key);



                httpRequestMessage.Method       = HttpMethod.Put;
                httpRequestMessage.Headers.Date = DateTime.UtcNow;
                httpRequestMessage.Content      = new StreamContent(content);


                OssClientHelper.initialHttpRequestMessage(httpRequestMessage, metadata);



                OssRequestSigner.Sign(httpRequestMessage, networkCredential);

                if (uploadProcessCallback != null)
                {
                    processMessageHander.HttpSendProgress += (sender, e) =>
                    {
                        uploadProcessCallback(new HttpProcessData()
                        {
                            TotalBytes         = e.TotalBytes,
                            BytesTransferred   = e.BytesTransferred,
                            ProgressPercentage = e.ProgressPercentage
                        });
                    };
                }


                if (cancellationToken != null)
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage, (CancellationToken)cancellationToken);
                }
                else
                {
                    response = await localHttpClient.SendAsync(httpRequestMessage);
                }

                if (response.IsSuccessStatusCode == false)
                {
                    await ErrorResponseHandler.Handle(response);
                }

                var temp = DeserializerFactory.GetFactory().CreatePutObjectReusltDeserializer();
                result = temp.Deserialize(response);
                //localHttpClient.Dispose();
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (hand != null)
                {
                    hand.Dispose();
                }

                if (processMessageHander != null)
                {
                    processMessageHander.Dispose();
                }

                if (localHttpClient != null)
                {
                    localHttpClient.Dispose();
                }

                if (httpRequestMessage != null)
                {
                    httpRequestMessage.Dispose();
                }


                if (response != null)
                {
                    response.Dispose();
                }
            }

            return(result);
        }