├── .gitignore ├── .travis.yml ├── CHANGELOG.md ├── LICENSE ├── README.md ├── aliyun-oss-sdk.sln ├── build └── Aliyun.OSS.dll ├── doc └── help.shfbproj ├── lib └── nunit.framework.dll ├── samples ├── Config.cs ├── Program.cs ├── Properties │ └── AssemblyInfo.cs ├── Samples │ ├── AppendObjectSample.cs │ ├── CNameSample.cs │ ├── CopyObjectSample.cs │ ├── CreateBucketSample.cs │ ├── CreateEmptyFolderSample.cs │ ├── DeleteBucketCorsSample.cs │ ├── DeleteBucketLoggingSample.cs │ ├── DeleteBucketSample.cs │ ├── DeleteBucketWetbsiteSample.cs │ ├── DeleteObjectsSample.cs │ ├── DoesBucketExistSample.cs │ ├── DoesObjectExistSample.cs │ ├── GetBucketAclSample.cs │ ├── GetBucketCorsSample.cs │ ├── GetBucketLifecycleSample.cs │ ├── GetBucketLoggingSample.cs │ ├── GetBucketRefererSample.cs │ ├── GetBucketWetbsiteSample.cs │ ├── GetObjectAclSample.cs │ ├── GetObjectByRangeSample.cs │ ├── GetObjectSample.cs │ ├── ImageProcessSample.cs │ ├── ListBucketsSample.cs │ ├── ListObjectsSample.cs │ ├── ModifyObjectMetaSample.cs │ ├── MultipartUploadSample.cs │ ├── PostPolicySample.cs │ ├── PutObjectSample.cs │ ├── ResumableSample.cs │ ├── SetBucketAclSample.cs │ ├── SetBucketCorsSample.cs │ ├── SetBucketLifecycleSample.cs │ ├── SetBucketLoggingSample.cs │ ├── SetBucketRefererSample.cs │ ├── SetBucketWetbsiteSample.cs │ ├── SetObjectAclSample.cs │ └── UrlSignatureSample.cs └── aliyun-oss-sdk-samples.csproj ├── sdk ├── Commands │ ├── AbortMultipartUploadCommand.cs │ ├── AppendObjectCommand.cs │ ├── CompleteMultipartUploadCommand.cs │ ├── CopyObjectCommand.cs │ ├── CreateBucketCommand.cs │ ├── DeleteBucketCommand.cs │ ├── DeleteBucketCorsCommand.cs │ ├── DeleteBucketLoggingCommand.cs │ ├── DeleteBucketWebsiteCommand.cs │ ├── DeleteObjectCommand.cs │ ├── DeleteObjectsCommand.cs │ ├── GetBucketAclCommand.cs │ ├── GetBucketCorsCommand.cs │ ├── GetBucketLifecycleCommand.cs │ ├── GetBucketLoggingCommand.cs │ ├── GetBucketRefererCommand.cs │ ├── GetBucketWebsiteCommand.cs │ ├── GetObjectAclCommand.cs │ ├── GetObjectCommand.cs │ ├── GetObjectMetadataCommand.cs │ ├── HeadObjectCommand.cs │ ├── InitiateMultipartUploadCommand.cs │ ├── ListBucketsCommand.cs │ ├── ListMultipartUploadsCommand.cs │ ├── ListObjectsCommand.cs │ ├── ListPartsCommand.cs │ ├── OssCommand.cs │ ├── PutObjectCommand.cs │ ├── SetBucketAclCommand.cs │ ├── SetBucketCorsCommand.cs │ ├── SetBucketLifecycleCommand.cs │ ├── SetBucketLoggingCommand.cs │ ├── SetBucketRefererCommand.cs │ ├── SetBucketWebsiteCommand.cs │ ├── SetObjectAclCommand.cs │ ├── UploadPartCommand.cs │ └── UploadPartCopyCommand.cs ├── Common │ ├── Authentication │ │ ├── DefaultCredentials.cs │ │ ├── DefaultCredentialsProvider.cs │ │ ├── HmacSHA1Signature.cs │ │ ├── ICredentials.cs │ │ ├── ICredentialsProvider.cs │ │ ├── IRequestSigner.cs │ │ └── ServiceSignature.cs │ ├── ClientConfiguration.cs │ ├── Communication │ │ ├── ExecutionContext.cs │ │ ├── HttpMethod.cs │ │ ├── IServiceClient.cs │ │ ├── RetryableServiceClient.cs │ │ ├── ServiceClient.cs │ │ ├── ServiceClientImpl.cs │ │ ├── ServiceMessage.cs │ │ ├── ServiceRequest.cs │ │ └── ServiceResponse.cs │ ├── Handlers │ │ ├── IResponseHandler.cs │ │ └── ResponseHandler.cs │ ├── OssErrorCode.cs │ ├── OssException.cs │ └── ServiceException.cs ├── Domain │ ├── AbortMultipartUploadRequest.cs │ ├── AccessControlList.cs │ ├── AppendObjectRequest.cs │ ├── AppendObjectResult.cs │ ├── Bucket.cs │ ├── BucketLoggingResult.cs │ ├── BucketWebsiteResult.cs │ ├── CORSRule.cs │ ├── CompleteMultipartUploadRequest.cs │ ├── CompleteMultipartUploadResult.cs │ ├── CopyObjectRequest.cs │ ├── CopyObjectResult.cs │ ├── DeleteObjectsRequest.cs │ ├── DeleteObjectsResult.cs │ ├── GeneratePresignedUriRequest.cs │ ├── GetObjectRequest.cs │ ├── Grant.cs │ ├── GroupGrantee.cs │ ├── IGrantee.cs │ ├── InitiateMultipartUploadRequest.cs │ ├── InitiateMultipartUploadResult.cs │ ├── LifecycleRule.cs │ ├── ListBucketsRequest.cs │ ├── ListBucketsResult.cs │ ├── ListMultipartUploadsRequest.cs │ ├── ListObjectsRequest.cs │ ├── ListPartsRequest.cs │ ├── MultipartUpload.cs │ ├── MultipartUploadListing.cs │ ├── ObjectListing.cs │ ├── ObjectMetadata.cs │ ├── OssObject.cs │ ├── OssObjectSummary.cs │ ├── OssResources.Designer.cs │ ├── OssResources.resx │ ├── Owner.cs │ ├── Part.cs │ ├── PartEtag.cs │ ├── PartListing.cs │ ├── PolicyConditions.cs │ ├── PutObjectResult.cs │ ├── RefererConfiguration.cs │ ├── ResponseHeaderOverrides.cs │ ├── ResumableContext.cs │ ├── SetBucketAclRequest.cs │ ├── SetBucketCorsRequest.cs │ ├── SetBucketLifecycleRequest.cs │ ├── SetBucketLoggingRequest.cs │ ├── SetBucketRefererRequest.cs │ ├── SetBucketWebsiteRequest.cs │ ├── SetObjectAclRequest.cs │ ├── UploadPartCopyRequest.cs │ ├── UploadPartCopyResult.cs │ ├── UploadPartRequest.cs │ └── UploadPartResult.cs ├── Enums │ ├── CannedAccessControlList.cs │ ├── Permission.cs │ ├── Protocol.cs │ └── SignHttpMethod.cs ├── IOss.cs ├── Model │ ├── AccessControlPolicy.cs │ ├── CompleteMultipartUploadRequestModel.cs │ ├── CompleteMultipartUploadResultModel.cs │ ├── CopyObjectResultModel.cs │ ├── DeleteObjectsRequestModel.cs │ ├── ErrorResult.cs │ ├── InitiateMultipartResult.cs │ ├── LifecycleConfiguration.cs │ ├── ListAllMyBucketsResult.cs │ ├── ListBucketResult.cs │ ├── ListMultipartUploadsResult.cs │ ├── ListPartsResult.cs │ ├── SetBucketCorsRequestModel.cs │ ├── SetBucketLoggingRequestModel.cs │ ├── SetBucketWebsiteRequestModel.cs │ └── UploadPartCopyRequestModel.cs ├── OssClient.cs ├── Properties │ ├── AssemblyInfo.cs │ └── Resources.cs ├── Resources │ └── MimeData.txt ├── Transform │ ├── AppendObjectResponseDeserializer.cs │ ├── CompleteMultipartUploadRequestSerializer.cs │ ├── CompleteMultipartUploadResultDeserializer.cs │ ├── CopyObjectResultDeserializer.cs │ ├── DeleteObjectsRequestSerializer.cs │ ├── DeleteObjectsResultDeserializer.cs │ ├── DeserializerFactory.cs │ ├── GetAclResponseDeserializer.cs │ ├── GetBucketLifecycleDeserializer.cs │ ├── GetBucketLoggingResultDeserializer.cs │ ├── GetBucketWebSiteResultDeserializer.cs │ ├── GetCorsResponseDeserializer.cs │ ├── GetObjectMetadataResponseDeserializer.cs │ ├── GetObjectResponseDeserializer.cs │ ├── IDeserializer.cs │ ├── ISerializer.cs │ ├── InitiateMultipartUploadResultDeserializer.cs │ ├── ListBucketsResultDeserializer.cs │ ├── ListMultipartUploadsResponseDeserializer.cs │ ├── ListObjectsResponseDeserializer.cs │ ├── ListPartsResultDeserializer.cs │ ├── PutObjectResponseDeserializer.cs │ ├── RequestSerializationException.cs │ ├── RequestSerializer.cs │ ├── ResponseDeserializationException.cs │ ├── ResponseDeserializer.cs │ ├── SerializerFactory.cs │ ├── SetBucketCorsRequestSerializer.cs │ ├── SetBucketLifecycleRequestSerializer.cs │ ├── SetBucketLoggingRequestSerializer.cs │ ├── SetBucketRefererRequestSerializer.cs │ ├── SetBucketWebsiteRequestSerializer.cs │ ├── SimpleResponseDeserializer.cs │ ├── UploadPartCopyResponseDeserializer.cs │ ├── UploadPartResponseDeserializer.cs │ ├── XmlStreamDeserializer.cs │ └── XmlStreamSerializer.cs ├── Util │ ├── AsyncResult.cs │ ├── DateUtils.cs │ ├── EnumUtils.cs │ ├── ErrorResponseHandler.cs │ ├── ExceptionFactory.cs │ ├── ExecutionContextBuilder.cs │ ├── HttpHeaders.cs │ ├── HttpUtils.cs │ ├── IOUtils.cs │ ├── OssHeaders.cs │ ├── OssRequestSigner.cs │ ├── OssUtils.cs │ ├── RequestParameters.cs │ ├── ServiceClientFactory.cs │ ├── SignUtils.cs │ └── StringValueAttribute.cs ├── aliyun-oss-sdk.csproj └── aliyun_sdk_net.snk └── test ├── ConcurrencyTestConfig.xml ├── Properties ├── AssemblyInfo.cs └── Settings.Designer.cs ├── TestCase ├── AccessKeyTestCase │ └── AccessKeyTest.cs ├── BucketTestCase │ ├── BucketAclSettingsTest.cs │ ├── BucketBasicOperationTest.cs │ ├── BucketCorsSettingsTest.cs │ ├── BucketLoggingSettingsTest.cs │ ├── BucketRefersSettingsTest.cs │ ├── BucketSettingsTest.cs │ └── BucketWebsiteSettingsTest.cs ├── ObjectTestCase │ ├── ObjectAclSettingsTest.cs │ ├── ObjectBasicOperationTest.cs │ ├── ObjectCopyTest.cs │ ├── ObjectEncodingTypeTest.cs │ ├── ObjectMultipartUploadTest.cs │ ├── ObjectProcessTest.cs │ └── ObjectSignedUriTest.cs └── OtherTestCase │ ├── ConcurrencyTest.cs │ ├── EpochTimeSettingTest.cs │ ├── HttpsTest.cs │ └── ProxyTest.cs ├── Util ├── AccountSettings.cs ├── Config.cs ├── FileUtils.cs ├── LogUtility.cs ├── OssClientFactory.cs └── OssTestUtils.cs ├── aliyun-oss-sdk-test.csproj ├── app.config └── example.jpg /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.suo 3 | *.user 4 | Backup* 5 | 6 | bin 7 | obj -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: csharp 2 | solution: aliyun-oss-sdk.sln 3 | mono: 4 | - latest 5 | - 4.2.1 6 | - 4.0.0 7 | - 3.12.0 8 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 aliyun.com 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 4 | documentation files (the "Software"), to deal in the Software without restriction, including without limitation the 5 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 6 | permit persons to whom the Software is furnished to do so, subject to the following conditions: 7 | 8 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the 9 | Software. 10 | 11 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE 12 | WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 13 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 14 | OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /build/Aliyun.OSS.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shirlman/aliyun-oss-unity-sdk/3ebf22bb46d1f0e149a0a380d0c50224d1e65ab7/build/Aliyun.OSS.dll -------------------------------------------------------------------------------- /lib/nunit.framework.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shirlman/aliyun-oss-unity-sdk/3ebf22bb46d1f0e149a0a380d0c50224d1e65ab7/lib/nunit.framework.dll -------------------------------------------------------------------------------- /samples/Config.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using Aliyun.OSS.Common; 3 | 4 | namespace Aliyun.OSS.Samples 5 | { 6 | internal class Config 7 | { 8 | public static string AccessKeyId = ""; 9 | 10 | public static string AccessKeySecret = ""; 11 | 12 | public static string Endpoint = ""; 13 | 14 | public static string DirToDownload = ""; 15 | 16 | public static string FileToUpload = ""; 17 | 18 | public static string BigFileToUpload = ""; 19 | } 20 | } -------------------------------------------------------------------------------- /samples/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | #region Using directives 3 | 4 | using System.Reflection; 5 | using System.Runtime.InteropServices; 6 | 7 | #endregion 8 | 9 | // General Information about an assembly is controlled through the following 10 | // set of attributes. Change these attribute values to modify the information 11 | // associated with an assembly. 12 | [assembly: AssemblyTitle("Aliyun.OSS.Samples")] 13 | [assembly: AssemblyDescription("Aliyun OSS SDK Samples for C#")] 14 | [assembly: AssemblyConfiguration("")] 15 | [assembly: AssemblyCompany("Alibaba Cloud Computing")] 16 | [assembly: AssemblyProduct("Aliyun.OSS.Samples")] 17 | [assembly: AssemblyCopyright("Copyright 2012")] 18 | [assembly: AssemblyTrademark("")] 19 | [assembly: AssemblyCulture("")] 20 | 21 | // This sets the default COM visibility of types in the assembly to invisible. 22 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. 23 | [assembly: ComVisible(false)] 24 | 25 | // The assembly version has following format : 26 | // 27 | // Major.Minor.Build.Revision 28 | // 29 | // You can specify all the values or you can use the default the Revision and 30 | // Build Numbers by using the '*' as shown below: 31 | [assembly: AssemblyVersion("2.4.0")] 32 | [assembly: NeutralResourcesLanguage("zh-CN")] 33 | [assembly: AssemblyFileVersion("2.4.0")] 34 | 35 | -------------------------------------------------------------------------------- /samples/Samples/CreateBucketSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for creating bucket. 15 | /// 16 | public static class CreateBucketSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void CreateBucket(string bucketName) 24 | { 25 | try 26 | { 27 | client.CreateBucket(bucketName); 28 | 29 | Console.WriteLine("Created bucket name:{0} succeeded ", bucketName); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /samples/Samples/CreateEmptyFolderSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using Aliyun.OSS.Common; 11 | 12 | namespace Aliyun.OSS.Samples 13 | { 14 | /// 15 | /// Sample for creating an empty folder. 16 | /// 17 | public static class CreateEmptyFolderSample 18 | { 19 | static string accessKeyId = Config.AccessKeyId; 20 | static string accessKeySecret = Config.AccessKeySecret; 21 | static string endpoint = Config.Endpoint; 22 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 23 | 24 | public static void CreateEmptyFolder(string bucketName) 25 | { 26 | // Note: key treats as a folder and must end with slash. 27 | const string key = "yourfolder/"; 28 | try 29 | { 30 | // put object with zero bytes stream. 31 | using (MemoryStream memStream = new MemoryStream()) 32 | { 33 | client.PutObject(bucketName, key, memStream); 34 | Console.WriteLine("Create dir:{0} succeeded", key); 35 | } 36 | } 37 | catch (OssException ex) 38 | { 39 | Console.WriteLine("CreateBucket Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 40 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /samples/Samples/DeleteBucketCorsSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket cors. 15 | /// 16 | public static class DeleteBucketCorsSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void DeleteBucketCors(string bucketName) 24 | { 25 | try 26 | { 27 | client.DeleteBucketCors(bucketName); 28 | 29 | Console.WriteLine("Delete bucket:{0} Cors succeeded ", bucketName); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/DeleteBucketLoggingSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for delete bucket logging. 15 | /// 16 | public static class DeleteBucketLoggingSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void DeleteBucketLogging(string bucketName) 24 | { 25 | try 26 | { 27 | client.DeleteBucketLogging(bucketName); 28 | 29 | Console.WriteLine("Delete bucket:{0} Logging succeeded ", bucketName); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/DeleteBucketWetbsiteSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for delete bucket wetbsite. 15 | /// 16 | public static class DeleteBucketWebsiteSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void DeleteBucketWebsite(string bucketName) 24 | { 25 | try 26 | { 27 | client.DeleteBucketWebsite(bucketName); 28 | 29 | Console.WriteLine("Delete bucket:{0} Wetbsite succeeded ", bucketName); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/DoesBucketExistSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for determining whether the specified bucket exists. 15 | /// 16 | public static class DoesBucketExistSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void DoesBucketExist(string bucketName) 24 | { 25 | try 26 | { 27 | var exist = client.DoesBucketExist(bucketName); 28 | Console.WriteLine("exist ? " + exist); 29 | } 30 | catch (OssException ex) 31 | { 32 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 33 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 34 | } 35 | catch (Exception ex) 36 | { 37 | Console.WriteLine("Failed with error info: {0}", ex.Message); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /samples/Samples/DoesObjectExistSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for determining whether the specified object exists in the specified bucket. 15 | /// 16 | public static class DoesObjectExistSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void DoesObjectExist(string bucketName) 24 | { 25 | const string key = "key1"; 26 | try 27 | { 28 | var exist = client.DoesObjectExist(bucketName, key); 29 | Console.WriteLine("exist ? " + exist); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketAclSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket acl. 15 | /// 16 | public static class GetBucketAclSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void GetBucketAcl(string bucketName) 24 | { 25 | try 26 | { 27 | var result = client.GetBucketAcl(bucketName); 28 | Console.WriteLine("Get Bucket Acl succeeded,Id:{0} Acl:{1} succeeded", 29 | result.Owner.Id, result.ACL.ToString()); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketCorsSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket cors. 15 | /// 16 | public static class GetBucketCorsSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void GetBucketCors(string bucketName) 24 | { 25 | try 26 | { 27 | var result = client.GetBucketCors(bucketName); 28 | 29 | Console.WriteLine("Get bucket:{0} Cors succeeded ", bucketName); 30 | 31 | foreach (var rule in result) 32 | { 33 | foreach (var origin in rule.AllowedOrigins) 34 | { 35 | Console.WriteLine("Allowed origin:{0}", origin); 36 | } 37 | 38 | } 39 | } 40 | catch (OssException ex) 41 | { 42 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 43 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 44 | } 45 | catch (Exception ex) 46 | { 47 | Console.WriteLine("Failed with error info: {0}", ex.Message); 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketLifecycleSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | using Aliyun.OSS.Common; 11 | 12 | namespace Aliyun.OSS.Samples 13 | { 14 | /// 15 | /// Sample for getting bucket lifecycle 16 | /// 17 | public static class GetBucketLifecycleSample 18 | { 19 | static string accessKeyId = Config.AccessKeyId; 20 | static string accessKeySecret = Config.AccessKeySecret; 21 | static string endpoint = Config.Endpoint; 22 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 23 | 24 | public static void GetBucketLifecycle(string bucketName) 25 | { 26 | try 27 | { 28 | var rules = client.GetBucketLifecycle(bucketName); 29 | 30 | Console.WriteLine("Get bucket:{0} Lifecycle succeeded ", bucketName); 31 | 32 | foreach (var rule in rules) 33 | { 34 | Console.WriteLine("ID: {0}", rule.ID); 35 | Console.WriteLine("Prefix: {0}", rule.Prefix); 36 | Console.WriteLine("Status: {0}", rule.Status); 37 | if (rule.ExpriationDays.HasValue) 38 | Console.WriteLine("ExpirationDays: {0}", rule.ExpriationDays); 39 | if (rule.ExpirationTime.HasValue) 40 | Console.WriteLine("ExpirationTime: {0}", FormatIso8601Date(rule.ExpirationTime.Value)); 41 | } 42 | } 43 | catch (OssException ex) 44 | { 45 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 46 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 47 | } 48 | catch (Exception ex) 49 | { 50 | Console.WriteLine("Failed with error info: {0}", ex.Message); 51 | } 52 | } 53 | 54 | private static string FormatIso8601Date(DateTime dateTime) 55 | { 56 | return dateTime.ToUniversalTime().ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'", 57 | CultureInfo.CreateSpecificCulture("en-US")); 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketLoggingSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for getting bucket cors. 15 | /// 16 | public static class GetBucketLoggingSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void GetBucketLogging(string bucketName) 24 | { 25 | try 26 | { 27 | var result = client.GetBucketLogging(bucketName); 28 | 29 | Console.WriteLine("Get bucket:{0} Logging succeeded, prefix:{1}", bucketName, result.TargetPrefix); 30 | } 31 | catch (OssException ex) 32 | { 33 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 34 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 35 | } 36 | catch (Exception ex) 37 | { 38 | Console.WriteLine("Failed with error info: {0}", ex.Message); 39 | } 40 | } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketRefererSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common; 11 | 12 | namespace Aliyun.OSS.Samples 13 | { 14 | /// 15 | /// Sample for getting bucket referer list. 16 | /// 17 | public static class GetBucketRefererSample 18 | { 19 | static string accessKeyId = Config.AccessKeyId; 20 | static string accessKeySecret = Config.AccessKeySecret; 21 | static string endpoint = Config.Endpoint; 22 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 23 | 24 | public static void GetBucketReferer(string bucketName) 25 | { 26 | try 27 | { 28 | var rc = client.GetBucketReferer(bucketName); 29 | 30 | Console.WriteLine("Get bucket:{0} Referer succeeded ", bucketName); 31 | 32 | Console.WriteLine("allow?" + (rc.AllowEmptyReferer ? "yes" : "no")); 33 | if (rc.RefererList.Referers != null) 34 | { 35 | for (var i = 0; i < rc.RefererList.Referers.Length; i++) 36 | Console.WriteLine(rc.RefererList.Referers[i]); 37 | } 38 | else 39 | { 40 | Console.WriteLine("Empty Referer List"); 41 | } 42 | } 43 | catch (OssException ex) 44 | { 45 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 46 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 47 | } 48 | catch (Exception ex) 49 | { 50 | Console.WriteLine("Failed with error info: {0}", ex.Message); 51 | } 52 | finally 53 | { 54 | client.SetBucketReferer(new SetBucketRefererRequest(bucketName)); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /samples/Samples/GetBucketWetbsiteSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for getting bucket website. 15 | /// 16 | public static class GetBucketWebsiteSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void GetBucketWebsite(string bucketName) 24 | { 25 | try 26 | { 27 | var result = client.GetBucketWebsite(bucketName); 28 | 29 | Console.WriteLine("Get bucket:{0} Wetbsite succeeded, index doc:{1}, error doc:{2}", 30 | bucketName, result.IndexDocument, result.ErrorDocument); 31 | } 32 | catch (OssException ex) 33 | { 34 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 35 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 36 | } 37 | catch (Exception ex) 38 | { 39 | Console.WriteLine("Failed with error info: {0}", ex.Message); 40 | } 41 | } 42 | } 43 | } -------------------------------------------------------------------------------- /samples/Samples/GetObjectAclSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket acl. 15 | /// 16 | public static class GetObjectAclSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void GetBucketAcl(string bucketName) 24 | { 25 | string key = "GetObjectSample"; 26 | 27 | try 28 | { 29 | var result = client.GetObjectAcl(bucketName, key); 30 | Console.WriteLine("Get Object Acl succeeded,Id:{0} Acl:{1} succeeded", 31 | result.Owner.Id, result.ACL.ToString()); 32 | } 33 | catch (OssException ex) 34 | { 35 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 36 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine("Failed with error info: {0}", ex.Message); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /samples/Samples/ModifyObjectMetaSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | using System.Text; 11 | using System.IO; 12 | 13 | namespace Aliyun.OSS.Samples 14 | { 15 | /// 16 | /// Sample for modify object meta 17 | /// 18 | public static class ModifyObjectMetaSample 19 | { 20 | static string accessKeyId = Config.AccessKeyId; 21 | static string accessKeySecret = Config.AccessKeySecret; 22 | static string endpoint = Config.Endpoint; 23 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 24 | 25 | public static void ModifyObjectMeta(string bucketName) 26 | { 27 | const string key = "key1"; 28 | try 29 | { 30 | byte[] binaryData = Encoding.ASCII.GetBytes("forked from aliyun/aliyun-oss-csharp-sdk "); 31 | var stream = new MemoryStream(binaryData); 32 | 33 | client.PutObject(bucketName, key, stream); 34 | 35 | var oldMeta = client.GetObjectMetadata(bucketName, key); 36 | 37 | var newMeta = new ObjectMetadata() 38 | { 39 | ContentType = "application/msword", 40 | ExpirationTime = oldMeta.ExpirationTime, 41 | ContentEncoding = null, 42 | CacheControl = "" 43 | }; 44 | 45 | client.ModifyObjectMeta(bucketName, key, newMeta); 46 | 47 | Console.WriteLine("Modify object meta succeeded"); 48 | } 49 | catch (OssException ex) 50 | { 51 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 52 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 53 | } 54 | catch (Exception ex) 55 | { 56 | Console.WriteLine("Failed with error info: {0}", ex.Message); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /samples/Samples/SetBucketCorsSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket cors. 15 | /// 16 | public static class SetBucketCorsSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void SetBucketCors(string bucketName) 24 | { 25 | try 26 | { 27 | var request = new SetBucketCorsRequest(bucketName); 28 | var rule1 = new CORSRule(); 29 | // Note: AllowedOrigin & AllowdMethod must not be empty. 30 | rule1.AddAllowedOrigin("http://www.a.com"); 31 | rule1.AddAllowedMethod("POST"); 32 | rule1.AddAllowedHeader("*"); 33 | rule1.AddExposeHeader("x-oss-test"); 34 | request.AddCORSRule(rule1); 35 | 36 | var rule2 = new CORSRule(); 37 | rule2.AddAllowedOrigin("http://www.b.com"); 38 | rule2.AddAllowedMethod("GET"); 39 | rule2.AddExposeHeader("x-oss-test2"); 40 | rule2.MaxAgeSeconds = 100; 41 | request.AddCORSRule(rule2); 42 | 43 | client.SetBucketCors(request); 44 | 45 | Console.WriteLine("Set bucket:{0} Cors succeeded ", bucketName); 46 | } 47 | catch (OssException ex) 48 | { 49 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 50 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 51 | } 52 | catch (Exception ex) 53 | { 54 | Console.WriteLine("Failed with error info: {0}", ex.Message); 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /samples/Samples/SetBucketLoggingSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket logging. 15 | /// 16 | public static class SetBucketLoggingSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void SetBucketLogging(string bucketName) 24 | { 25 | try 26 | { 27 | var request = new SetBucketLoggingRequest(bucketName, bucketName, "logging-"); 28 | 29 | client.SetBucketLogging(request); 30 | 31 | Console.WriteLine("Set bucket:{0} Logging succeeded ", bucketName); 32 | } 33 | catch (OssException ex) 34 | { 35 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 36 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine("Failed with error info: {0}", ex.Message); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /samples/Samples/SetBucketRefererSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common; 11 | 12 | namespace Aliyun.OSS.Samples 13 | { 14 | /// 15 | /// Sample for setting bucket referer list. 16 | /// 17 | public static class SetBucketRefererSample 18 | { 19 | static string accessKeyId = Config.AccessKeyId; 20 | static string accessKeySecret = Config.AccessKeySecret; 21 | static string endpoint = Config.Endpoint; 22 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 23 | 24 | public static void SetBucketReferer(string bucketName) 25 | { 26 | try 27 | { 28 | var refererList = new List(); 29 | refererList.Add(" http://www.aliyun.com"); 30 | refererList.Add(" http://www.*.com"); 31 | refererList.Add(" http://www.?.aliyuncs.com"); 32 | var srq = new SetBucketRefererRequest(bucketName, refererList); 33 | client.SetBucketReferer(srq); 34 | 35 | Console.WriteLine("Set bucket:{0} Referer succeeded ", bucketName); 36 | } 37 | catch (OssException ex) 38 | { 39 | Console.WriteLine("Failed with error code: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 40 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 41 | } 42 | catch (Exception ex) 43 | { 44 | Console.WriteLine("Failed with error info: {0}", ex.Message); 45 | } 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /samples/Samples/SetBucketWetbsiteSample.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common; 10 | 11 | namespace Aliyun.OSS.Samples 12 | { 13 | /// 14 | /// Sample for setting bucket website. 15 | /// 16 | public static class SetBucketWebsiteSample 17 | { 18 | static string accessKeyId = Config.AccessKeyId; 19 | static string accessKeySecret = Config.AccessKeySecret; 20 | static string endpoint = Config.Endpoint; 21 | static OssClient client = new OssClient(endpoint, accessKeyId, accessKeySecret); 22 | 23 | public static void SetBucketWebsite(string bucketName) 24 | { 25 | try 26 | { 27 | var request = new SetBucketWebsiteRequest(bucketName, "index.html", "error.html"); 28 | 29 | client.SetBucketWebsite(request); 30 | 31 | Console.WriteLine("Set bucket:{0} Wetbsite succeeded ", bucketName); 32 | } 33 | catch (OssException ex) 34 | { 35 | Console.WriteLine("Failed with error info: {0}; Error info: {1}. \nRequestID:{2}\tHostID:{3}", 36 | ex.ErrorCode, ex.Message, ex.RequestId, ex.HostId); 37 | } 38 | catch (Exception ex) 39 | { 40 | Console.WriteLine("Failed with error info: {0}", ex.Message); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sdk/Commands/CreateBucketCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | 12 | namespace Aliyun.OSS.Commands 13 | { 14 | internal class CreateBucketCommand : OssCommand 15 | { 16 | private readonly string _bucketName; 17 | 18 | protected override HttpMethod Method 19 | { 20 | get { return HttpMethod.Put; } 21 | } 22 | 23 | protected override string Bucket 24 | { 25 | get { return _bucketName; } 26 | } 27 | 28 | private CreateBucketCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 29 | string bucketName) 30 | : base(client, endpoint, context) 31 | { 32 | OssUtils.CheckBucketName(bucketName); 33 | _bucketName = bucketName; 34 | } 35 | 36 | public static CreateBucketCommand Create(IServiceClient client, Uri endpoint, 37 | ExecutionContext context, 38 | string bucketName) 39 | { 40 | return new CreateBucketCommand(client, endpoint, context, bucketName); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Commands/DeleteBucketCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | 12 | namespace Aliyun.OSS.Commands 13 | { 14 | internal class DeleteBucketCommand : OssCommand 15 | { 16 | private readonly string _bucketName; 17 | 18 | protected override HttpMethod Method 19 | { 20 | get { return HttpMethod.Delete; } 21 | } 22 | 23 | protected override string Bucket 24 | { 25 | get { return _bucketName; } 26 | } 27 | 28 | private DeleteBucketCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 29 | string bucketName) 30 | : base(client, endpoint, context) 31 | { 32 | OssUtils.CheckBucketName(bucketName); 33 | _bucketName = bucketName; 34 | } 35 | 36 | public static DeleteBucketCommand Create(IServiceClient client, Uri endpoint, 37 | ExecutionContext context, 38 | string bucketName) 39 | { 40 | return new DeleteBucketCommand(client, endpoint, context, bucketName); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Commands/DeleteBucketCorsCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | using System.Collections.Generic; 12 | namespace Aliyun.OSS.Commands 13 | { 14 | internal class DeleteBucketCorsCommand : OssCommand 15 | { 16 | private readonly string _bucketName; 17 | 18 | protected override HttpMethod Method 19 | { 20 | get { return HttpMethod.Delete; } 21 | } 22 | 23 | protected override string Bucket 24 | { 25 | get { return _bucketName; } 26 | } 27 | 28 | private DeleteBucketCorsCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 29 | string bucketName) 30 | : base(client, endpoint, context) 31 | { 32 | OssUtils.CheckBucketName(bucketName); 33 | _bucketName = bucketName; 34 | } 35 | 36 | public static DeleteBucketCorsCommand Create(IServiceClient client, Uri endpoint, 37 | ExecutionContext context, 38 | string bucketName) 39 | { 40 | return new DeleteBucketCorsCommand(client, endpoint, context, bucketName); 41 | } 42 | 43 | protected override IDictionary Parameters 44 | { 45 | get 46 | { 47 | return new Dictionary() 48 | { 49 | { RequestParameters.SUBRESOURCE_CORS, null } 50 | }; 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sdk/Commands/DeleteBucketLoggingCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | using System.Collections.Generic; 12 | 13 | namespace Aliyun.OSS.Commands 14 | { 15 | internal class DeleteBucketLoggingCommand : OssCommand 16 | { 17 | private readonly string _bucketName; 18 | 19 | protected override HttpMethod Method 20 | { 21 | get { return HttpMethod.Delete; } 22 | } 23 | 24 | protected override string Bucket 25 | { 26 | get { return _bucketName; } 27 | } 28 | 29 | private DeleteBucketLoggingCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 30 | string bucketName) 31 | : base(client, endpoint, context) 32 | { 33 | OssUtils.CheckBucketName(bucketName); 34 | _bucketName = bucketName; 35 | } 36 | 37 | public static DeleteBucketLoggingCommand Create(IServiceClient client, Uri endpoint, 38 | ExecutionContext context, 39 | string bucketName) 40 | { 41 | return new DeleteBucketLoggingCommand(client, endpoint, context, bucketName); 42 | } 43 | 44 | protected override IDictionary Parameters 45 | { 46 | get 47 | { 48 | return new Dictionary() 49 | { 50 | { RequestParameters.SUBRESOURCE_LOGGING, null } 51 | }; 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sdk/Commands/DeleteBucketWebsiteCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | using System.Collections.Generic; 12 | 13 | namespace Aliyun.OSS.Commands 14 | { 15 | internal class DeleteBucketWebsiteCommand : OssCommand 16 | { 17 | private readonly string _bucketName; 18 | 19 | protected override HttpMethod Method 20 | { 21 | get { return HttpMethod.Delete; } 22 | } 23 | 24 | protected override string Bucket 25 | { 26 | get 27 | { 28 | return _bucketName; 29 | } 30 | } 31 | 32 | private DeleteBucketWebsiteCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 33 | string bucketName) 34 | : base(client, endpoint, context) 35 | { 36 | OssUtils.CheckBucketName(bucketName); 37 | _bucketName = bucketName; 38 | } 39 | 40 | public static DeleteBucketWebsiteCommand Create(IServiceClient client, Uri endpoint, 41 | ExecutionContext context, 42 | string bucketName) 43 | { 44 | return new DeleteBucketWebsiteCommand(client, endpoint, context, bucketName); 45 | } 46 | 47 | protected override IDictionary Parameters 48 | { 49 | get 50 | { 51 | return new Dictionary() 52 | { 53 | { RequestParameters.SUBRESOURCE_WEBSITE, null } 54 | }; 55 | } 56 | } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sdk/Commands/DeleteObjectCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class DeleteObjectCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | private readonly string _key; 20 | 21 | protected override HttpMethod Method 22 | { 23 | get { return HttpMethod.Delete; } 24 | } 25 | 26 | protected override string Bucket 27 | { 28 | get { return _bucketName; } 29 | } 30 | 31 | protected override string Key 32 | { 33 | get { return _key; } 34 | } 35 | 36 | protected override IDictionary Parameters 37 | { 38 | get 39 | { 40 | return new Dictionary() 41 | { 42 | {RequestParameters.ENCODING_TYPE, HttpUtils.UrlEncodingType } 43 | }; 44 | } 45 | } 46 | 47 | private DeleteObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 48 | string bucketName, string key) 49 | : base(client, endpoint, context) 50 | { 51 | OssUtils.CheckBucketName(bucketName); 52 | OssUtils.CheckObjectKey(key); 53 | 54 | _bucketName = bucketName; 55 | _key = key; 56 | } 57 | 58 | public static DeleteObjectCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, 59 | string bucketName, string key) 60 | { 61 | return new DeleteObjectCommand(client, endpoint, context, bucketName, key); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketAclCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketAclCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketAclCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketAclCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketAclCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetAclResultDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_ACL, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketCorsCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketCorsCommand : OssCommand> 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketCorsCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer> deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketCorsCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketCorsCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetCorsResultDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_CORS, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketLifecycleCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketLifecycleCommand : OssCommand> 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketLifecycleCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer> deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketLifecycleCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketLifecycleCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetBucketLifecycleDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_LIFECYCLE, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketLoggingCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketLoggingCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketLoggingCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketLoggingCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketLoggingCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetBucketLoggingResultDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_LOGGING, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketRefererCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketRefererCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketRefererCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketRefererCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketRefererCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetBucketRefererResultDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_REFERER, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetBucketWebsiteCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetBucketWebsiteCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | 20 | protected override string Bucket 21 | { 22 | get { return _bucketName; } 23 | } 24 | 25 | private GetBucketWebsiteCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 26 | string bucketName, IDeserializer deserializer) 27 | : base(client, endpoint, context, deserializer) 28 | { 29 | OssUtils.CheckBucketName(bucketName); 30 | _bucketName = bucketName; 31 | } 32 | 33 | public static GetBucketWebsiteCommand Create(IServiceClient client, Uri endpoint, 34 | ExecutionContext context, 35 | string bucketName) 36 | { 37 | return new GetBucketWebsiteCommand(client, endpoint, context, bucketName, 38 | DeserializerFactory.GetFactory().CreateGetBucketWebSiteResultDeserializer()); 39 | } 40 | 41 | protected override IDictionary Parameters 42 | { 43 | get 44 | { 45 | return new Dictionary() 46 | { 47 | { RequestParameters.SUBRESOURCE_WEBSITE, null } 48 | }; 49 | } 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/GetObjectAclCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Transform; 13 | 14 | namespace Aliyun.OSS.Commands 15 | { 16 | internal class GetObjectAclCommand : OssCommand 17 | { 18 | private readonly string _bucketName; 19 | private readonly string _key; 20 | 21 | protected override string Bucket 22 | { 23 | get { return _bucketName; } 24 | } 25 | 26 | protected override string Key 27 | { 28 | get { return _key; } 29 | } 30 | 31 | protected override IDictionary Parameters 32 | { 33 | get 34 | { 35 | return new Dictionary() 36 | { 37 | { RequestParameters.SUBRESOURCE_ACL, null } 38 | }; 39 | } 40 | } 41 | 42 | private GetObjectAclCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 43 | string bucketName, string key, 44 | IDeserializer deserializer) 45 | : base(client, endpoint, context, deserializer) 46 | { 47 | OssUtils.CheckBucketName(bucketName); 48 | OssUtils.CheckObjectKey(key); 49 | 50 | _bucketName = bucketName; 51 | _key = key; 52 | } 53 | 54 | public static GetObjectAclCommand Create(IServiceClient client, Uri endpoint, 55 | ExecutionContext context, 56 | string bucketName, string key) 57 | { 58 | return new GetObjectAclCommand(client, endpoint, context, bucketName, key, 59 | DeserializerFactory.GetFactory().CreateGetAclResultDeserializer()); 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /sdk/Commands/GetObjectMetadataCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | using Aliyun.OSS.Transform; 12 | 13 | namespace Aliyun.OSS.Commands 14 | { 15 | internal class GetObjectMetadataCommand : OssCommand 16 | { 17 | private readonly string _bucketName; 18 | private readonly string _key; 19 | 20 | protected override HttpMethod Method 21 | { 22 | get { return HttpMethod.Head; } 23 | } 24 | 25 | protected override string Bucket 26 | { 27 | get { return _bucketName; } 28 | } 29 | 30 | protected override string Key 31 | { 32 | get { return _key; } 33 | } 34 | 35 | private GetObjectMetadataCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 36 | IDeserializer deserializer, 37 | string bucketName, string key) 38 | : base(client, endpoint, context, deserializer) 39 | { 40 | OssUtils.CheckBucketName(bucketName); 41 | OssUtils.CheckObjectKey(key); 42 | 43 | _bucketName = bucketName; 44 | _key = key; 45 | } 46 | 47 | public static GetObjectMetadataCommand Create(IServiceClient client, Uri endpoint, ExecutionContext context, 48 | string bucketName, string key) 49 | { 50 | return new GetObjectMetadataCommand(client, endpoint, context, 51 | DeserializerFactory.GetFactory().CreateGetObjectMetadataResultDeserializer(), 52 | bucketName, key); 53 | } 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /sdk/Commands/HeadObjectCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | 12 | namespace Aliyun.OSS.Commands 13 | { 14 | internal class HeadObjectCommand : OssCommand 15 | { 16 | private readonly string _bucketName; 17 | private readonly string _key; 18 | 19 | protected override HttpMethod Method 20 | { 21 | get { return HttpMethod.Head; } 22 | } 23 | 24 | protected override string Bucket 25 | { 26 | get { return _bucketName; } 27 | } 28 | 29 | protected override string Key 30 | { 31 | get { return _key; } 32 | } 33 | 34 | private HeadObjectCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 35 | string bucketName, string key) 36 | : base(client, endpoint, context) 37 | { 38 | OssUtils.CheckBucketName(bucketName); 39 | OssUtils.CheckObjectKey(key); 40 | 41 | _bucketName = bucketName; 42 | _key = key; 43 | } 44 | 45 | public static HeadObjectCommand Create(IServiceClient client, Uri endpoint, 46 | ExecutionContext context, 47 | string bucketName, string key) 48 | { 49 | return new HeadObjectCommand(client, endpoint, context, bucketName, key); 50 | } 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /sdk/Commands/SetBucketAclCommand.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS.Commands 14 | { 15 | internal class SetBucketAclCommand : OssCommand 16 | { 17 | private readonly string _bucketName; 18 | private readonly SetBucketAclRequest _request; 19 | 20 | protected override HttpMethod Method 21 | { 22 | get { return HttpMethod.Put; } 23 | } 24 | 25 | protected override string Bucket 26 | { 27 | get { return _bucketName; } 28 | } 29 | 30 | private SetBucketAclCommand(IServiceClient client, Uri endpoint, ExecutionContext context, 31 | string bucketName, SetBucketAclRequest request) 32 | : base(client, endpoint, context) 33 | { 34 | OssUtils.CheckBucketName(bucketName); 35 | 36 | _bucketName = bucketName; 37 | _request = request; 38 | } 39 | 40 | public static SetBucketAclCommand Create(IServiceClient client, Uri endpoint, 41 | ExecutionContext context, 42 | string bucketName, SetBucketAclRequest request) 43 | { 44 | return new SetBucketAclCommand(client, endpoint, context, bucketName, request); 45 | } 46 | 47 | protected override IDictionary Headers 48 | { 49 | get 50 | { 51 | return new Dictionary() 52 | { 53 | { OssHeaders.OssCannedAcl, EnumUtils.GetStringValue(_request.ACL) } 54 | }; 55 | } 56 | } 57 | 58 | protected override IDictionary Parameters 59 | { 60 | get 61 | { 62 | return new Dictionary() 63 | { 64 | { RequestParameters.SUBRESOURCE_ACL, null } 65 | }; 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/DefaultCredentials.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Authentication; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS.Common.Authentication 12 | { 13 | /// 14 | /// 默认鉴权类 15 | /// 16 | public class DefaultCredentials : ICredentials 17 | { 18 | /// 19 | public string AccessKeyId { get; private set; } 20 | 21 | /// 22 | public string AccessKeySecret { get; private set; } 23 | 24 | /// 25 | public string SecurityToken { get; private set; } 26 | 27 | /// 28 | public bool UseToken { get { return !string.IsNullOrEmpty(SecurityToken); } } 29 | 30 | /// 31 | /// 构造一个的实例 32 | /// 33 | /// OSS的访问ID 34 | /// OSS的访问密钥 35 | /// STS提供的安全令牌 36 | public DefaultCredentials(string accessKeyId, string accessKeySecret, string securityToken) 37 | { 38 | OssUtils.CheckCredentials(accessKeyId, accessKeySecret); 39 | 40 | AccessKeyId = accessKeyId.Trim(); 41 | AccessKeySecret = accessKeySecret.Trim(); 42 | SecurityToken = securityToken ?? string.Empty; 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/DefaultCredentialsProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Authentication; 10 | using Aliyun.OSS.Util; 11 | 12 | namespace Aliyun.OSS.Common.Authentication 13 | { 14 | /// 15 | /// 默认鉴权工厂类 16 | /// 17 | public class DefaultCredentialsProvider : ICredentialsProvider 18 | { 19 | private volatile ICredentials _creds; 20 | 21 | /// 22 | /// 构造一个的实例 23 | /// 24 | /// 接口的实例 25 | public DefaultCredentialsProvider(ICredentials creds) 26 | { 27 | SetCredentials(creds); 28 | } 29 | 30 | /// 31 | public void SetCredentials(ICredentials creds) 32 | { 33 | if (creds == null) 34 | throw new ArgumentNullException("creds"); 35 | 36 | OssUtils.CheckCredentials(creds.AccessKeyId, creds.AccessKeySecret); 37 | _creds = creds; 38 | } 39 | 40 | /// 41 | public ICredentials GetCredentials() 42 | { 43 | return _creds; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/HmacSHA1Signature.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Diagnostics; 10 | using System.Security.Cryptography; 11 | using System.Text; 12 | 13 | namespace Aliyun.OSS.Common.Authentication 14 | { 15 | internal class HmacSha1Signature : ServiceSignature 16 | { 17 | private static readonly Encoding Encoding = Encoding.UTF8; 18 | public override string SignatureMethod 19 | { 20 | get { return "HmacSHA1"; } 21 | } 22 | 23 | public override string SignatureVersion 24 | { 25 | get { return "1"; } 26 | } 27 | 28 | protected override string ComputeSignatureCore(string key, string data) 29 | { 30 | Debug.Assert(!string.IsNullOrEmpty(data)); 31 | 32 | using (var algorithm = KeyedHashAlgorithm.Create(SignatureMethod.ToUpperInvariant())) 33 | { 34 | algorithm.Key = Encoding.GetBytes(key.ToCharArray()); 35 | return Convert.ToBase64String( 36 | algorithm.ComputeHash(Encoding.GetBytes(data.ToCharArray()))); 37 | } 38 | } 39 | 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/ICredentials.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Common.Authentication 9 | { 10 | /// 11 | /// 鉴权的接口 12 | /// 13 | public interface ICredentials 14 | { 15 | /// 16 | /// OSS的访问ID 17 | /// 18 | string AccessKeyId { get; } 19 | 20 | /// 21 | /// OSS的访问密钥 22 | /// 23 | string AccessKeySecret { get; } 24 | 25 | /// 26 | /// STS提供的安全令牌 27 | /// 28 | string SecurityToken { get; } 29 | 30 | /// 31 | /// 是否使用了STS提供的安全令牌 32 | /// 33 | bool UseToken { get; } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/ICredentialsProvider.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Common.Authentication 9 | { 10 | /// 11 | /// 鉴权工厂的接口 12 | /// 13 | public interface ICredentialsProvider 14 | { 15 | /// 16 | /// 设置一个新的 17 | /// 18 | /// 新的 19 | void SetCredentials(ICredentials creds); 20 | 21 | /// 22 | /// 获取一个 23 | /// 24 | /// 实例 25 | ICredentials GetCredentials(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/IRequestSigner.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | 10 | namespace Aliyun.OSS.Common.Authentication 11 | { 12 | internal interface IRequestSigner 13 | { 14 | void Sign(ServiceRequest request, ICredentials credentials); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sdk/Common/Authentication/ServiceSignature.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Properties; 10 | 11 | namespace Aliyun.OSS.Common.Authentication 12 | { 13 | internal abstract class ServiceSignature 14 | { 15 | public abstract string SignatureMethod { get; } 16 | 17 | public abstract string SignatureVersion { get; } 18 | 19 | public string ComputeSignature(String key, String data) 20 | { 21 | if (string.IsNullOrEmpty(key)) 22 | throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "key"); 23 | if (string.IsNullOrEmpty(data)) 24 | throw new ArgumentException(Resources.ExceptionIfArgumentStringIsNullOrEmpty, "data"); 25 | 26 | return ComputeSignatureCore(key, data); 27 | } 28 | 29 | protected abstract string ComputeSignatureCore(string key, string data); 30 | 31 | public static ServiceSignature Create() 32 | { 33 | return new HmacSha1Signature(); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Common/Communication/ExecutionContext.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Collections.Generic; 9 | using Aliyun.OSS.Common.Authentication; 10 | using Aliyun.OSS.Common.Handlers; 11 | using Aliyun.OSS.Commands; 12 | 13 | namespace Aliyun.OSS.Common.Communication 14 | { 15 | internal class ExecutionContext 16 | { 17 | /// 18 | /// List of HTTP response handlers. 19 | /// 20 | private readonly IList _responseHandlers = new List(); 21 | 22 | /// 23 | /// Gets or sets the request signer. 24 | /// 25 | public IRequestSigner Signer { get; set; } 26 | 27 | /// 28 | /// Gets or sets the credentials. 29 | /// 30 | public ICredentials Credentials { get; set ;} 31 | 32 | /// 33 | /// Gets the list of . 34 | /// 35 | public IList ResponseHandlers 36 | { 37 | get { return _responseHandlers; } 38 | } 39 | 40 | /// 41 | /// Gets or sets a concrete command associate with this context. 42 | /// 43 | public OssCommand Command { get; set; } 44 | 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sdk/Common/Communication/HttpMethod.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Common.Communication 9 | { 10 | /// 11 | /// Represents a HTTP method. 12 | /// 13 | internal enum HttpMethod 14 | { 15 | /// 16 | /// Represents HTTP GET. Default value. 17 | /// 18 | Get = 0, 19 | 20 | /// 21 | /// Represents HTTP DELETE. 22 | /// 23 | Delete, 24 | 25 | /// 26 | /// Represents HTTP HEAD. 27 | /// 28 | Head, 29 | 30 | /// 31 | /// Represents HTTP POST. 32 | /// 33 | Post, 34 | 35 | /// 36 | /// Represents HTTP PUT. 37 | /// 38 | Put, 39 | 40 | /// 41 | /// Represents HTTP OPTIONS. 42 | /// 43 | Options, 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /sdk/Common/Communication/IServiceClient.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS.Common.Communication 11 | { 12 | /// 13 | /// Represent the channel that communicates with an Aliyun Open Service. 14 | /// 15 | internal interface IServiceClient 16 | { 17 | /// 18 | /// Sends a request to the service. 19 | /// 20 | /// The request data. 21 | /// The execution context. 22 | /// The response data. 23 | ServiceResponse Send(ServiceRequest request, ExecutionContext context); 24 | 25 | /// 26 | /// Begins to send a request to the service asynchronously. 27 | /// 28 | /// The request data. 29 | /// The execution context. 30 | /// User callback. 31 | /// User state. 32 | /// An instance of . 33 | IAsyncResult BeginSend(ServiceRequest request, ExecutionContext context, AsyncCallback callback, object state); 34 | 35 | /// 36 | /// Ends the asynchronous operation. 37 | /// 38 | /// An instance of . 39 | /// The response data. 40 | ServiceResponse EndSend(IAsyncResult asyncResult); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /sdk/Common/Communication/ServiceMessage.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | using System.IO; 11 | 12 | namespace Aliyun.OSS.Common.Communication 13 | { 14 | internal class ServiceMessage 15 | { 16 | private readonly IDictionary _headers = 17 | new Dictionary(StringComparer.OrdinalIgnoreCase); 18 | 19 | /// 20 | /// Gets the dictionary of HTTP headers. 21 | /// 22 | public virtual IDictionary Headers 23 | { 24 | get { return _headers; } 25 | } 26 | 27 | /// 28 | /// Gets or sets the content stream. 29 | /// 30 | public virtual Stream Content { get; set; } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sdk/Common/Communication/ServiceResponse.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Diagnostics; 10 | using System.Net; 11 | 12 | namespace Aliyun.OSS.Common.Communication 13 | { 14 | internal abstract class ServiceResponse : ServiceMessage, IDisposable 15 | { 16 | public abstract HttpStatusCode StatusCode { get; } 17 | 18 | public abstract Exception Failure { get; } 19 | 20 | public virtual bool IsSuccessful() 21 | { 22 | return (int)StatusCode / 100 == (int)HttpStatusCode.OK / 100; 23 | } 24 | 25 | /// 26 | /// Throws the exception from communication if the status code is not 2xx. 27 | /// 28 | public virtual void EnsureSuccessful() 29 | { 30 | if (!IsSuccessful()) 31 | { 32 | // Disposing the content should help users: If users call EnsureSuccessStatusCode(), an exception is 33 | // thrown if the response status code is != 2xx. I.e. the behavior is similar to a failed request (e.g. 34 | // connection failure). Users don't expect to dispose the content in this case: If an exception is 35 | // thrown, the object is responsible fore cleaning up its state. 36 | if (Content != null) 37 | { 38 | Content.Dispose(); 39 | } 40 | 41 | Debug.Assert(Failure != null); 42 | throw Failure; 43 | } 44 | } 45 | 46 | public void Dispose() 47 | { 48 | Dispose(true); 49 | GC.SuppressFinalize(this); 50 | } 51 | 52 | protected virtual void Dispose(bool disposing) 53 | { 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sdk/Common/Handlers/IResponseHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | 10 | namespace Aliyun.OSS.Common.Handlers 11 | { 12 | internal interface IResponseHandler 13 | { 14 | void Handle(ServiceResponse response); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /sdk/Common/Handlers/ResponseHandler.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Diagnostics; 9 | using Aliyun.OSS.Common.Communication; 10 | 11 | namespace Aliyun.OSS.Common.Handlers 12 | { 13 | internal class ResponseHandler : IResponseHandler 14 | { 15 | public virtual void Handle(ServiceResponse response) 16 | { 17 | Debug.Assert(response != null); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /sdk/Common/OssException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Runtime.Serialization; 10 | using System.Security.Permissions; 11 | 12 | namespace Aliyun.OSS.Common 13 | { 14 | /// 15 | /// 该异常在对对象存储服务(Object Storage Service)访问失败时抛出。 16 | /// 17 | /// 18 | [Serializable] 19 | public class OssException : ServiceException 20 | { 21 | /// 22 | /// 初始化新的实例。 23 | /// 24 | public OssException() 25 | { } 26 | 27 | /// 28 | /// 初始化新的实例。 29 | /// 30 | /// 解释异常原因的错误信息。 31 | public OssException(string message) 32 | : base(message) 33 | { } 34 | 35 | /// 36 | /// 初始化新的实例。 37 | /// 38 | /// 保存序列化对象数据的对象。 39 | /// 有关源或目标的上下文信息。 40 | protected OssException(SerializationInfo info, StreamingContext context) 41 | : base(info, context) 42 | { } 43 | 44 | /// 45 | /// 初始化新的实例。 46 | /// 47 | /// 解释异常原因的错误信息。 48 | /// 导致当前异常的异常。 49 | public OssException(string message, Exception innerException) 50 | : base(message, innerException) 51 | { } 52 | 53 | /// 54 | /// 重载方法。 55 | /// 56 | /// ,它存有有关所引发异常的序列化的对象数据。 57 | /// ,它包含有关源或目标的上下文信息。 58 | [SecurityPermission(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.SerializationFormatter)] 59 | public override void GetObjectData(SerializationInfo info, StreamingContext context) 60 | { 61 | base.GetObjectData(info, context); 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sdk/Domain/AbortMultipartUploadRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 指定中止Multipart Upload事件的请求参数 12 | /// 13 | public class AbortMultipartUploadRequest 14 | { 15 | /// 16 | /// 获取所在的名称。 17 | /// 18 | public string BucketName { get; private set; } 19 | 20 | /// 21 | /// 获取或者设置的值。 22 | /// 23 | public string Key { get; private set; } 24 | 25 | /// 26 | /// 获取或者设置需要取消的UploadId。 27 | /// 28 | public string UploadId { get; private set; } 29 | 30 | /// 31 | /// 通过bucket name, object key和upload id构造AbortMultipartUploadRequest对象 32 | /// 33 | /// bucket的名字 34 | /// object的名字 35 | /// 本次要取消的upload的id,由中获取 36 | public AbortMultipartUploadRequest(string bucketName, string key, string uploadId) 37 | { 38 | BucketName = bucketName; 39 | Key = key; 40 | UploadId = uploadId; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Domain/AppendObjectRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using System.Collections.Generic; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS 14 | { 15 | #pragma warning disable 618, 3005 16 | 17 | /// 18 | /// 指定追加Object的请求参数 19 | /// 20 | public class AppendObjectRequest 21 | { 22 | /// 23 | /// 获取或者设置Object所在的Bucket的名称。 24 | /// 25 | public string BucketName { get; set; } 26 | 27 | /// 28 | /// 获取或者设置Object的Key。 29 | /// 30 | public string Key { get; set; } 31 | 32 | /// 33 | /// 获取或者设置目标Object的Metadata信息。 34 | /// 35 | public ObjectMetadata ObjectMetadata { get; set; } 36 | 37 | /// 38 | /// 设置或获取追加的位置。第一次可以通过GetObjectMeta获取,后续可以从前一次的AppendObjectResult中获取 39 | /// 40 | public long Position { get; set; } 41 | 42 | /// 43 | /// 需要追加的内容 44 | /// 45 | public Stream Content { get; set; } 46 | 47 | /// 48 | /// 构造一个新的 实例 49 | /// 50 | /// 需要追加的所在的Bucket 51 | /// 需要追加的名称 52 | public AppendObjectRequest(string bucketName, string key) 53 | { 54 | BucketName = bucketName; 55 | Key = key; 56 | } 57 | 58 | internal void Populate(IDictionary headers) 59 | { 60 | ObjectMetadata.Populate(headers); 61 | } 62 | } 63 | 64 | #pragma warning restore 618, 3005 65 | } 66 | -------------------------------------------------------------------------------- /sdk/Domain/AppendObjectResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 表示追加时的请求结果。 12 | /// 13 | public class AppendObjectResult 14 | { 15 | /// 16 | /// 获取一个值表示与Object相关的hex编码的128位MD5摘要。 17 | /// 18 | public string ETag { get; internal set; } 19 | 20 | /// 21 | /// 指明下一次请求应当提供的position。 22 | /// 23 | public long NextAppendPosition { get; internal set; } 24 | 25 | /// 26 | /// 表明Object的64位CRC值。该64位CRC根据ECMA-182标准计算得出。 27 | /// 28 | public ulong HashCrc64Ecma { get; internal set; } 29 | 30 | internal AppendObjectResult() 31 | { } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/Domain/Bucket.cs: -------------------------------------------------------------------------------- 1 | /* 2 | ///Copyright (C) Alibaba Cloud Computing 3 | ///All rights reserved. 4 | /// 5 | ///版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | ///Bucket是OSS上的命名空间,可以理解为存储空间 15 | /// 16 | /// 17 | /// 18 | ///Bucket名在整个 OSS 中具有全局唯一性,且不能修改;存储在OSS上的每个Object必须都包含在某个Bucket中。 19 | ///一个应用,例如图片分享网站,可以对应一个或多个 Bucket。一个用户最多可创建 10 个Bucket, 20 | ///但每个Bucket 中存放的Object的数量和大小总和没有限制,用户不需要考虑数据的可扩展性。 21 | /// 22 | /// 23 | ///Bucket 命名规范 24 | /// 25 | /// 只能包括小写字母,数字和短横线(-) 26 | /// 必须以小写字母或者数字开头 27 | /// 长度必须在 3-63 字节之间 28 | /// 29 | /// 30 | /// 31 | public class Bucket 32 | { 33 | /// 34 | /// 获取/设置Bucket的Location。 35 | /// 36 | public string Location { get; internal set; } 37 | 38 | /// 39 | /// 获取/设置Bucket的名称。 40 | /// 41 | public string Name { get; internal set; } 42 | 43 | /// 44 | /// 获取/设置Bucket的 45 | /// 46 | public Owner Owner { get; internal set; } 47 | 48 | /// 49 | /// 获取/设置Bucket的创建时间。 50 | /// 51 | public DateTime CreationDate { get; internal set; } 52 | 53 | /// 54 | /// 使用指定的Bucket名称构造一个新的实例。 55 | /// 56 | /// Bucket的名称。 57 | internal Bucket(string name) 58 | { 59 | Name = name; 60 | } 61 | 62 | /// 63 | /// 返回该对象的字符串表示。 64 | /// 65 | /// 对象的字符串表示形式 66 | public override string ToString() 67 | { 68 | return string.Format(CultureInfo.InvariantCulture, 69 | "OSS Bucket [Name={0}], [Location={1}] [Owner={2}], [CreationTime={3}]", 70 | Name, Location, Owner, CreationDate); 71 | } 72 | 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /sdk/Domain/BucketLoggingResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// Get Bucket Logging 的请求结果。 12 | /// 13 | public class BucketLoggingResult 14 | { 15 | /// 16 | /// 访问日志记录要存入的bucket。 17 | /// 18 | public string TargetBucket { get; internal set; } 19 | 20 | /// 21 | /// 存储访问日志记录的object名字前缀,可以为空。 22 | /// 23 | public string TargetPrefix { get; internal set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/Domain/BucketWebsiteResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// Get Bucket Website 的请求结果。 12 | /// 13 | public class BucketWebsiteResult 14 | { 15 | /// 16 | /// 索引页面 17 | /// 18 | public string IndexDocument { get; internal set; } 19 | 20 | /// 21 | /// 错误页面 22 | /// 23 | public string ErrorDocument { get; internal set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/Domain/CompleteMultipartUploadRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Collections.Generic; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 指定完成Multipart Upload的请求参数。 14 | /// 15 | public class CompleteMultipartUploadRequest 16 | { 17 | private readonly IList _partETags = new List(); 18 | 19 | /// 20 | /// 获取或者设置所在的名称。 21 | /// 22 | public string BucketName { get; private set; } 23 | 24 | /// 25 | /// 获取或者设置的值。 26 | /// 27 | public string Key { get; private set; } 28 | 29 | /// 30 | /// 获取或设置上传Multipart上传事件的Upload ID。 31 | /// 32 | public string UploadId { get; private set; } 33 | 34 | /// 35 | /// 获取或者设置标识Part上传结果的对象列表。 36 | /// 37 | public IList PartETags 38 | { 39 | get { return _partETags; } 40 | } 41 | 42 | /// 43 | /// 通过bucket名称,object名称和upload id构造本对象 44 | /// 45 | /// bucket的名称 46 | /// object的名称 47 | /// 本次需要完成的上传的id,由中获得 48 | public CompleteMultipartUploadRequest(string bucketName, string key, string uploadId) 49 | { 50 | BucketName = bucketName; 51 | Key = key; 52 | UploadId = uploadId; 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /sdk/Domain/CompleteMultipartUploadResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// Complete Multipart Upload的请求结果。 12 | /// 13 | public class CompleteMultipartUploadResult 14 | { 15 | /// 16 | /// 获取所在的名称。 17 | /// 18 | public string BucketName { get; internal set; } 19 | 20 | /// 21 | /// 获取的Key。 22 | /// 23 | public string Key { get; internal set; } 24 | 25 | /// 26 | /// 获取新创建Object的URL。 27 | /// 28 | public string Location { get; internal set; } 29 | 30 | /// 31 | /// 获取新创建的Object的ETag 32 | /// 33 | public string ETag { get; internal set; } 34 | 35 | internal CompleteMultipartUploadResult() 36 | { } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sdk/Domain/CopyObjectResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 拷贝Object的请求结果。 14 | /// 15 | public class CopyObjectResult 16 | { 17 | /// 18 | /// 获取新Object最后更新时间。 19 | /// 20 | public DateTime LastModified { get; internal set; } 21 | 22 | /// 23 | /// 获取新Object的ETag值。 24 | /// 25 | public string ETag { get; internal set; } 26 | 27 | internal CopyObjectResult() 28 | { } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Domain/DeleteObjectsResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | /// Description of DeleteObjectsResult. 15 | /// 16 | [XmlRoot("DeleteResult")] 17 | public class DeleteObjectsResult 18 | { 19 | private DeletedObject[] _keys; 20 | 21 | /// 22 | /// Deleted部分的解析和获取 23 | /// 24 | [XmlElement("Deleted")] 25 | public DeletedObject[] Keys 26 | { 27 | get 28 | { 29 | if (EncodingType == null) 30 | return _keys; 31 | 32 | bool isUrlEncoding = EncodingType.ToLowerInvariant().Equals(HttpUtils.UrlEncodingType); 33 | foreach (var key in _keys) 34 | { 35 | key.Key = isUrlEncoding ? HttpUtils.DecodeUri(key.Key) : key.Key; 36 | } 37 | return _keys; 38 | } 39 | set 40 | { 41 | this._keys = value; 42 | } 43 | } 44 | 45 | /// 46 | /// EncodingType值的解析和获取 47 | /// 48 | [XmlElement("EncodingType")] 49 | public string EncodingType { get; set; } 50 | 51 | internal DeleteObjectsResult() 52 | { 53 | } 54 | 55 | /// 56 | /// Deleted部分的解析和获取 57 | /// 58 | [XmlRoot("Deleted")] 59 | public class DeletedObject 60 | { 61 | /// 62 | /// Deleted Key的解析和获取 63 | /// 64 | [XmlElement("Key")] 65 | public string Key { get; set; } 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /sdk/Domain/Grant.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 访问控制的授权信息。 14 | /// 15 | public class Grant { 16 | 17 | /// 18 | /// 获取被授权者信息。 19 | /// 20 | public IGrantee Grantee { get; private set; } 21 | 22 | /// 23 | /// 获取被授权的权限。 24 | /// 25 | public Permission Permission { get; private set; } 26 | 27 | /// 28 | /// 构造一个新的实体。 29 | /// 30 | /// 被授权者。目前只支持。 31 | /// 权限。 32 | public Grant(IGrantee grantee, Permission permission) 33 | { 34 | if (grantee == null) 35 | throw new ArgumentNullException("grantee"); 36 | 37 | Grantee = grantee; 38 | Permission = permission; 39 | } 40 | 41 | /// 42 | /// 判断两个是否相等 43 | /// 44 | /// 需要比较的 45 | /// 46 | public override bool Equals(Object obj) 47 | { 48 | var g = obj as Grant; 49 | if (g == null) 50 | return false; 51 | 52 | return Grantee.Identifier== g.Grantee.Identifier && 53 | Permission == g.Permission; 54 | } 55 | 56 | /// 57 | /// 获取HashCode值 58 | /// 59 | /// hash code值 60 | public override int GetHashCode() 61 | { 62 | return (Grantee.Identifier + ":" + Permission).GetHashCode(); 63 | } 64 | 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /sdk/Domain/GroupGrantee.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 定义了可以被授权的一组OSS用户。 14 | /// 15 | public sealed class GroupGrantee : IGrantee 16 | { 17 | private readonly string _identifier; 18 | 19 | /// 20 | /// 获取被授权者的标识。 21 | /// 22 | /// 23 | /// 不支持set操作,否则会抛出。 24 | /// 25 | public string Identifier 26 | { 27 | get { return _identifier; } 28 | set { throw new NotSupportedException(); } 29 | } 30 | 31 | private static readonly GroupGrantee _allUsers = 32 | new GroupGrantee("http://oss.service.aliyun.com/acl/group/ALL_USERS"); 33 | 34 | /// 35 | /// 表示为OSS的指定匿名访问的权限。 36 | /// 任何用户都可以根据被授予的权限进行访问。 37 | /// 38 | public static GroupGrantee AllUsers 39 | { 40 | get { return _allUsers; } 41 | } 42 | 43 | /// 44 | /// 设置授权者标识 45 | /// 46 | /// 授权者标识 47 | private GroupGrantee(string identifier) 48 | { 49 | _identifier = identifier; 50 | } 51 | 52 | /// 53 | /// 判断两个是否相等 54 | /// 55 | /// 需要判断的另一个 56 | /// 57 | public override bool Equals(object obj) 58 | { 59 | var grantee = obj as GroupGrantee; 60 | if (grantee == null) 61 | return false; 62 | 63 | return grantee.Identifier == Identifier; 64 | } 65 | 66 | /// 67 | /// 获取hash code值 68 | /// 69 | /// hash code值 70 | public override int GetHashCode() 71 | { 72 | return ("[GroupGrantee ID=" + Identifier + "]").GetHashCode(); 73 | } 74 | 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /sdk/Domain/IGrantee.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 表示被授权者的信息。 12 | /// 13 | public interface IGrantee 14 | { 15 | /// 16 | /// 获取或设置被授权者的标识。 17 | /// 18 | string Identifier { get; set; } 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /sdk/Domain/InitiateMultipartUploadResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 表示初始化MultipartUpload的结果。 12 | /// 13 | public class InitiateMultipartUploadResult 14 | { 15 | /// 16 | /// 获取所在的名称。 17 | /// 18 | public string BucketName { get; internal set; } 19 | 20 | /// 21 | /// 获取的Key。 22 | /// 23 | public string Key { get; internal set; } 24 | 25 | /// 26 | /// 获取上传Id 27 | /// 28 | public string UploadId { get; internal set; } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Domain/LifecycleRule.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// Lifecycle规则状态。 14 | /// 15 | public enum RuleStatus 16 | { 17 | /// 18 | /// 启用规则 19 | /// 20 | Enabled, 21 | 22 | /// 23 | /// 禁用规则 24 | /// 25 | Disabled 26 | }; 27 | 28 | /// 29 | /// 表示一条Lifecycle规则。 30 | /// 31 | public class LifecycleRule 32 | { 33 | /// 34 | /// 当前规则的标识符 35 | /// 36 | public string ID { get; set; } 37 | 38 | /// 39 | /// 当前规则适用的前缀 40 | /// 41 | public string Prefix { get; set; } 42 | 43 | /// 44 | /// 当前规则的状态 45 | /// 46 | public RuleStatus Status { get; set; } 47 | 48 | /// 49 | /// 当前规则的有效天数 50 | /// 51 | public int? ExpriationDays { get; set; } 52 | 53 | /// 54 | /// 当前规则的有效时间 55 | /// 56 | public DateTime? ExpirationTime { get; set; } 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /sdk/Domain/ListBucketsRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 包含获取列表的请求信息。 12 | /// 13 | public class ListBucketsRequest 14 | { 15 | /// 16 | /// 获取或设置一个值,限定返回的的Key必须以该值作为前缀。 17 | /// 18 | public string Prefix { get; set; } 19 | 20 | /// 21 | /// 获取或设置一个值,用户设定结果从该值之后按字母排序的第一个开始返回。 22 | /// 23 | public string Marker { get; set; } 24 | 25 | /// 26 | /// 获取或设置一个值,用于限定此次返回bucket的最大数。 27 | /// 如果不设定,默认为100。 28 | /// 29 | public int? MaxKeys { get; set; } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/Domain/ListBucketsResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Collections.Generic; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 列举Bucket的请求结果。 14 | /// 15 | public class ListBucketsResult 16 | { 17 | /// 18 | /// 获取一个值,限定返回的的Key必须以该值作为前缀。 19 | /// 20 | public string Prefix { get; internal set; } 21 | 22 | /// 23 | /// 获取一个值,用户设定结果从该值之后按字母排序的第一个开始返回。 24 | /// 25 | public string Marker { get; internal set; } 26 | 27 | /// 28 | /// 获取一个值,用于限定此次返回bucket的最大数。 29 | /// 如果不设定,默认为100。 30 | /// 31 | public int? MaxKeys { get; internal set; } 32 | 33 | /// 34 | /// 获取一个值,指明是否所有的结果都已经返回。 35 | /// 36 | public bool? IsTruncated { get; internal set; } 37 | 38 | /// 39 | /// 获取一个值,指明下一个Marker。 40 | /// 41 | public string NextMaker { get; internal set; } 42 | 43 | /// 44 | /// 获取一个值,指明Bucket请求列表。 45 | /// 46 | public IEnumerable Buckets { get; internal set; } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sdk/Domain/ListPartsRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 指定列出指定Upload ID所属的所有已经上传成功Part的请求参数。 12 | /// 13 | public class ListPartsRequest 14 | { 15 | /// 16 | /// 获取所在的名称。 17 | /// 18 | public string BucketName { get; private set; } 19 | 20 | /// 21 | /// 获取或者设置的值。 22 | /// 23 | public string Key { get; private set; } 24 | 25 | /// 26 | /// 获取或者设置响应中的最大Part数目。 27 | /// 28 | public int? MaxParts { get; set; } 29 | 30 | /// 31 | /// 获取或者设置List的起始位置,只有Part Number数目大于该参数的Part会被列出。 32 | /// 33 | public int? PartNumberMarker { get; set; } 34 | 35 | /// 36 | /// 获取encoding-type的值 37 | /// 38 | public string EncodingType { get; set; } 39 | 40 | /// 41 | /// 获取或者设置UploadId。 42 | /// 43 | public string UploadId { get; private set; } 44 | 45 | /// 46 | /// 构造一个新的实例。 47 | /// 48 | /// 所在的名称。 49 | /// 。 50 | /// 51 | public ListPartsRequest(string bucketName, string key, string uploadId) 52 | { 53 | BucketName = bucketName; 54 | Key = key; 55 | UploadId = uploadId; 56 | EncodingType = Util.HttpUtils.UrlEncodingType; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /sdk/Domain/MultipartUpload.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | /// 获取MultipartUpload事件的信息。 15 | /// 16 | public class MultipartUpload 17 | { 18 | /// 19 | /// 获取Object的key。 20 | /// 21 | public string Key { get; internal set; } 22 | 23 | /// 24 | /// 获取上传Id。 25 | /// 26 | public string UploadId { get; internal set; } 27 | 28 | /// 29 | /// 获取Object的存储类别。 30 | /// 31 | public string StorageClass {get; internal set; } 32 | 33 | /// 34 | /// Multipart Upload事件初始化的时间。 35 | /// 36 | public DateTime Initiated {get; internal set;} 37 | 38 | internal MultipartUpload() 39 | { } 40 | 41 | /// 42 | /// 获取该实例的字符串表示。 43 | /// 44 | /// 对象的字符串表示 45 | public override string ToString() 46 | { 47 | return string.Format(CultureInfo.InvariantCulture, 48 | "[MultipartUpload Key={0}, UploadId={1}]", Key, UploadId); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /sdk/Domain/OssObjectSummary.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | /// 的摘要信息。 15 | /// 16 | public class OssObjectSummary 17 | { 18 | /// 19 | /// 获取Object所在的的名称。 20 | /// 21 | public string BucketName { get; internal set; } 22 | 23 | /// 24 | /// 获取Object的Key。 25 | /// 26 | public string Key { get; internal set; } 27 | 28 | /// 29 | /// 获取一个值表示与Object相关的hex编码的128位MD5摘要。 30 | /// 31 | public string ETag { get; internal set; } 32 | 33 | /// 34 | /// 获取Object的文件字节数。 35 | /// 36 | public long Size { get; internal set; } 37 | 38 | /// 39 | /// 获取最后修改时间。 40 | /// 41 | public DateTime LastModified { get; internal set; } 42 | 43 | /// 44 | /// 获取Object的存储类别。 45 | /// 46 | public string StorageClass { get; internal set; } 47 | 48 | /// 49 | /// 获取Object的。 50 | /// 51 | public Owner Owner { get; internal set; } 52 | 53 | /// 54 | /// 初始化一个新的实例。 55 | /// 56 | internal OssObjectSummary() 57 | { } 58 | 59 | /// 60 | /// 获取该实例的字符串表示。 61 | /// 62 | /// 63 | public override string ToString() 64 | { 65 | return string.Format(CultureInfo.InvariantCulture, 66 | "[OSSObjectSummary Bucket={0}, Key={1}]", BucketName, Key); 67 | } 68 | 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sdk/Domain/Owner.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | using System.Xml.Serialization; 11 | 12 | namespace Aliyun.OSS 13 | { 14 | /// 15 | /// 表示OSS实体的所有者。 16 | /// 17 | [XmlRoot("Owner")] 18 | public class Owner : ICloneable 19 | { 20 | /// 21 | /// 获取或设置所有者的ID。 22 | /// 23 | [XmlElement("ID")] 24 | public string Id { get; set; } 25 | 26 | /// 27 | /// 获取或设置所有者的显示名称。 28 | /// 29 | [XmlElement("DisplayName")] 30 | public string DisplayName { get; set; } 31 | 32 | /// 33 | /// 构造一个新的实例。 34 | /// 35 | internal Owner() 36 | { } 37 | 38 | /// 39 | /// 使用给定的所有者ID和显示名称构造一个新的实例。 40 | /// 41 | /// 所有者的ID。 42 | /// 所有者的显示名称。 43 | internal Owner(string id, string displayName) 44 | { 45 | Id = id; 46 | DisplayName = displayName; 47 | } 48 | 49 | /// 50 | /// 的字符串表示形式 51 | /// 52 | /// 的字符串表示形式 53 | public override string ToString() 54 | { 55 | return string.Format(CultureInfo.InvariantCulture, 56 | "[Owner Id={0}, DisplayName={1}]", 57 | Id ?? string.Empty, 58 | DisplayName ?? string.Empty); 59 | } 60 | 61 | /// 62 | /// 克隆一个 63 | /// 64 | /// 新的对象 65 | public object Clone() 66 | { 67 | return new Owner(Id, DisplayName); 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /sdk/Domain/Part.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | /// 获取Multipart Upload事件中某块数据的信息。 15 | /// 16 | public class Part 17 | { 18 | internal Part() 19 | { } 20 | 21 | /// 22 | /// 获取分块的编号 23 | /// 24 | public int PartNumber { get; internal set; } 25 | 26 | /// 27 | /// 获取分块上传的时间 28 | /// 29 | public DateTime LastModified { get; internal set; } 30 | 31 | /// 32 | /// 获取分块内容的ETag 33 | /// 34 | public string ETag { get; internal set; } 35 | 36 | /// 37 | /// 获取分块的大小,单位字节 38 | /// 39 | public long Size { get; internal set; } 40 | 41 | /// 42 | /// 获取该实例的字符串表示。 43 | /// 44 | /// 实例的字符串形式 45 | public override string ToString() 46 | { 47 | return string.Format(CultureInfo.InvariantCulture, 48 | "[Part PartNumber={0}, ETag={1}, LastModified={2}, Size={3}]", 49 | PartNumber, ETag, LastModified, Size); 50 | } 51 | 52 | /// 53 | /// 获取包含Part标识号码和ETag值的对象 54 | /// 55 | public PartETag PartETag 56 | { 57 | get { return new PartETag(PartNumber, ETag); } 58 | } 59 | 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sdk/Domain/PartEtag.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 某块PartNumber和ETag的信息,用于Complete Multipart Upload请求参数的设置。 12 | /// 13 | public class PartETag 14 | { 15 | /// 16 | /// 获取或者设置一个值表示表示分块的标识 17 | /// 18 | public int PartNumber { get; set; } 19 | 20 | /// 21 | /// 获取或者设置一个值表示与Object相关的hex编码的128位MD5摘要。 22 | /// 23 | public string ETag { get; set; } 24 | 25 | /// 26 | /// 构造一个新的实例。 27 | /// 28 | /// 分片的id 29 | /// 分片的ETag值 30 | public PartETag(int partNumber, string eTag) 31 | { 32 | PartNumber = partNumber; 33 | ETag = eTag; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Domain/PutObjectResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 表示上传时的请求结果。 12 | /// 13 | public class PutObjectResult 14 | { 15 | /// 16 | /// 获取一个值表示与Object相关的hex编码的128位MD5摘要。 17 | /// 18 | public string ETag { get; internal set; } 19 | 20 | internal PutObjectResult() 21 | { } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sdk/Domain/RefererConfiguration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// Referer反盗链相关配置。 14 | /// 15 | [XmlRoot("RefererConfiguration")] 16 | public class RefererConfiguration 17 | { 18 | /// 19 | /// 指定是否允许referer字段为空的请求访问。 20 | /// 21 | [XmlElement("AllowEmptyReferer")] 22 | public bool AllowEmptyReferer { get; set; } 23 | 24 | /// 25 | /// 保存referer访问白名单列表。 26 | /// 27 | [XmlElement("RefererList")] 28 | public RefererListModel RefererList { get; set; } 29 | 30 | internal RefererConfiguration() 31 | { } 32 | 33 | /// 34 | /// referer列表的配置 35 | /// 36 | [XmlRoot("RefererList")] 37 | public class RefererListModel 38 | { 39 | /// 40 | /// referer列表 41 | /// 42 | [XmlElement("Referer")] 43 | public string[] Referers { get; set; } 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /sdk/Domain/SetBucketAclRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 存储空间ACL权限的请求 12 | /// 13 | public class SetBucketAclRequest 14 | { 15 | /// 16 | /// 获取所在的名称。 17 | /// 18 | public string BucketName { get; private set; } 19 | 20 | /// 21 | /// 获取用户访问权限。 22 | /// 23 | public CannedAccessControlList ACL { get; private set; } 24 | 25 | /// 26 | /// 构造一个新的实例。 27 | /// 28 | /// 所在的名称。 29 | /// 用户访问权限 30 | public SetBucketAclRequest(string bucketName, CannedAccessControlList acl) 31 | { 32 | BucketName = bucketName; 33 | ACL = acl; 34 | } 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /sdk/Domain/SetBucketLoggingRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 设置存储空间日志配置的请求 12 | /// 13 | public class SetBucketLoggingRequest 14 | { 15 | /// 16 | /// 获取或设置名称。 17 | /// 18 | public string BucketName { get; private set; } 19 | 20 | /// 21 | /// 获取或设置存放访问日志的Bucket。 22 | /// 23 | public string TargetBucket { get; private set; } 24 | 25 | /// 26 | /// 获取或设置存放访问日志的文件名前缀。 27 | /// 28 | public string TargetPrefix { get; private set; } 29 | 30 | /// 31 | /// 构造一个新的实例。 32 | /// 33 | /// 所在的名称 34 | /// 存放日志的存储空间名称 35 | /// 产生的日子的文件名前缀 36 | public SetBucketLoggingRequest(string bucketName, string targetBucket, string targetPrefix) 37 | { 38 | BucketName = bucketName; 39 | TargetBucket = targetBucket; 40 | TargetPrefix = targetPrefix; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Domain/SetBucketWebsiteRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 设置存储空间静态网页配置的请求 12 | /// 13 | public class SetBucketWebsiteRequest 14 | { 15 | /// 16 | /// 获取或者设置所在的名称。 17 | /// 18 | public string BucketName { get; private set; } 19 | 20 | /// 21 | /// 索引页面 22 | /// 23 | public string IndexDocument { get; private set; } 24 | 25 | /// 26 | /// 错误页面 27 | /// 28 | public string ErrorDocument { get; private set; } 29 | 30 | /// 31 | /// 构造一个新的实例。 32 | /// 33 | /// 所在的名称 34 | /// 存放索引的文件 35 | /// 产生错误时访问的文件 36 | public SetBucketWebsiteRequest(string bucketName, string indexDocument, string errorDocument) 37 | { 38 | BucketName = bucketName; 39 | IndexDocument = indexDocument; 40 | ErrorDocument = errorDocument; 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Domain/SetObjectAclRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using System.Collections.Generic; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS 14 | { 15 | /// 16 | /// 设置文件ACL权限的请求 17 | /// 18 | public class SetObjectAclRequest 19 | { 20 | /// 21 | /// 获取或获取所在的的名称。 22 | /// 23 | public string BucketName { get; private set; } 24 | 25 | /// 26 | /// 获取或者设置Object的Key。 27 | /// 28 | public string Key { get; private set; } 29 | 30 | /// 31 | /// 获取用户访问权限。 32 | /// 33 | public CannedAccessControlList ACL { get; private set; } 34 | 35 | /// 36 | /// 构造一个新的实例。 37 | /// 38 | /// bucket的名字 39 | /// object的名字 40 | /// 用户访问权限 41 | public SetObjectAclRequest(string bucketName, string key, CannedAccessControlList acl) 42 | { 43 | BucketName = bucketName; 44 | Key = key; 45 | ACL = acl; 46 | } 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /sdk/Domain/UploadPartCopyResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 获取以某一Object作为上传某分块数据源的结果。 12 | /// 13 | public class UploadPartCopyResult 14 | { 15 | /// 16 | /// 获取一个值表示与Object相关的hex编码的128位MD5摘要。 17 | /// 18 | public string ETag { get; internal set; } 19 | 20 | /// 21 | /// 获取一个值表示分块的标识 22 | /// 23 | public int PartNumber { get; internal set; } 24 | 25 | /// 26 | /// 获取包含Part标识号码和ETag值的对象 27 | /// 28 | public PartETag PartETag 29 | { 30 | get { return new PartETag(PartNumber, ETag); } 31 | } 32 | 33 | internal UploadPartCopyResult() 34 | { } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Domain/UploadPartRequest.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS 12 | { 13 | /// 14 | /// 指定上传某分块的请求。 15 | /// 16 | public class UploadPartRequest 17 | { 18 | /// 19 | /// 获取或者设置所在的名称。 20 | /// 21 | public string BucketName { get; private set; } 22 | 23 | /// 24 | /// 获取或者设置的值。 25 | /// 26 | public string Key { get; private set; } 27 | 28 | /// 29 | /// 获取或设置上传Multipart上传事件的Upload ID。 30 | /// 31 | public string UploadId { get; private set; } 32 | 33 | /// 34 | /// 获取或设置返回上传分块(Part)的标识号码(Part Number)。 35 | /// 每一个上传分块(Part)都有一个标识它的号码(范围1~10000)。 36 | /// 对于同一个Upload ID,该号码不但唯一标识这一块数据,也标识了这块数据在整个文件中的相对位置。 37 | /// 如果你用同一个Part号码上传了新的数据,那么OSS上已有的这个号码的Part数据将被覆盖。 38 | /// 39 | public int? PartNumber { get; set; } 40 | 41 | /// 42 | /// 获取或设置返回分块(Part)数据的字节数。 43 | /// 除最后一个Part外,其他Part最小为5MB。 44 | /// 45 | public long? PartSize { get; set; } 46 | 47 | /// 48 | /// 获取或设置分块(Part)数据的MD5校验值。 49 | /// 50 | public string Md5Digest { get; set; } 51 | 52 | /// 53 | /// 获取或设置包含上传分块内容的数据流。 54 | /// 55 | public Stream InputStream { get; set; } 56 | 57 | public UploadPartRequest(string bucketName, string key, string uploadId) 58 | { 59 | BucketName = bucketName; 60 | Key = key; 61 | UploadId = uploadId; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sdk/Domain/UploadPartResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 获取上传某分块的结果。 12 | /// 13 | public class UploadPartResult 14 | { 15 | /// 16 | /// 获取一个值表示与Object相关的hex编码的128位MD5摘要。 17 | /// 18 | public string ETag { get; internal set; } 19 | 20 | /// 21 | /// 获取一个值表示分块的标识 22 | /// 23 | public int PartNumber { get; internal set; } 24 | 25 | /// 26 | /// 获取包含Part标识号码和ETag值的对象 27 | /// 28 | public PartETag PartETag 29 | { 30 | get { return new PartETag(PartNumber, ETag); } 31 | } 32 | 33 | internal UploadPartResult() 34 | { } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Enums/CannedAccessControlList.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Util; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 表示一组常用的用户访问权限。 14 | /// 15 | /// 这一组常用权限相当于给所有用户指定权限的快捷方法。 16 | /// 17 | /// 18 | public enum CannedAccessControlList 19 | { 20 | /// 21 | /// 私有权限,有权限才可以读和写 22 | /// 23 | [StringValue("private")] 24 | Private = 0, 25 | 26 | /// 27 | /// 公共读,任何人都可以读,有权限才可以写 28 | /// 29 | [StringValue("public-read")] 30 | PublicRead, 31 | 32 | /// 33 | /// 公共读写,任何人都可以读和写 34 | /// 35 | [StringValue("public-read-write")] 36 | PublicReadWrite, 37 | 38 | /// 39 | /// 默认权限,仅用于文件,与存储空间的权限相同 40 | /// 41 | [StringValue("default")] 42 | Default 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sdk/Enums/Permission.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 表示访问控制权限。 12 | /// 13 | public enum Permission { 14 | /// 15 | /// 只读权限。 16 | /// 17 | Read = 0, 18 | 19 | /// 20 | /// 完全控制权限,即可读可写。 21 | /// 22 | FullControl 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /sdk/Enums/Protocol.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Util; 9 | 10 | namespace Aliyun.OSS 11 | { 12 | /// 13 | /// 表示请求OSS服务时采用的通信协议,默认值为HTTP。 14 | /// 15 | public enum Protocol 16 | { 17 | /// 18 | /// 超文本传输协议 19 | /// 20 | [StringValue("http")] 21 | Http = 0, 22 | 23 | /// 24 | /// 超文本安全传输协议 25 | /// 26 | [StringValue("https")] 27 | Https 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /sdk/Enums/SignHttpMethod.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS 9 | { 10 | /// 11 | /// 用于预签名URL的请求方法. 12 | /// 13 | public enum SignHttpMethod 14 | { 15 | /// 16 | /// Represents HTTP GET. Default value. 17 | /// 18 | Get = 0, 19 | 20 | /// 21 | /// Represents HTTP DELETE. 22 | /// 23 | Delete, 24 | 25 | /// 26 | /// Represents HTTP HEAD. 27 | /// 28 | Head, 29 | 30 | /// 31 | /// Represents HTTP POST. 32 | /// 33 | Post, 34 | 35 | /// 36 | /// Represents HTTP PUT. 37 | /// 38 | Put, 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /sdk/Model/AccessControlPolicy.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Collections.Generic; 9 | using System.Diagnostics.CodeAnalysis; 10 | using System.Xml.Serialization; 11 | 12 | namespace Aliyun.OSS.Model 13 | { 14 | [XmlRoot("AccessControlPolicy")] 15 | public class AccessControlPolicy 16 | { 17 | [XmlElement("Owner")] 18 | public Owner Owner { get; set; } 19 | 20 | [XmlArray("AccessControlList")] 21 | [XmlArrayItem("Grant")] 22 | [SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] 23 | public List Grants { get; set; } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /sdk/Model/CompleteMultipartUploadRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("CompleteMultipartUpload")] 13 | public class CompleteMultipartUploadRequestModel 14 | { 15 | [XmlElement("Part")] 16 | public CompletePart[] Parts { get; set; } 17 | 18 | [XmlRoot("Part")] 19 | public class CompletePart 20 | { 21 | [XmlElement("PartNumber")] 22 | public int PartNumber { get; set; } 23 | 24 | [XmlElement("ETag")] 25 | public string ETag { get; set; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/Model/CompleteMultipartUploadResultModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("CompleteMultipartUploadResult")] 13 | public class CompleteMultipartUploadResultModel 14 | { 15 | [XmlElement("Location")] 16 | public string Location { get; set; } 17 | 18 | [XmlElement("Bucket")] 19 | public string Bucket { get; set; } 20 | 21 | [XmlElement("Key")] 22 | public string Key { get; set; } 23 | 24 | [XmlElement("ETag")] 25 | public string ETag { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/Model/CopyObjectResultModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Xml.Serialization; 10 | 11 | namespace Aliyun.OSS.Model 12 | { 13 | [XmlRoot("CopyObjectResult")] 14 | public class CopyObjectResultModel 15 | { 16 | [XmlElement("LastModified")] 17 | public DateTime LastModified { get; set; } 18 | 19 | [XmlElement("ETag")] 20 | public string ETag { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sdk/Model/DeleteObjectsRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("Delete")] 13 | public class DeleteObjectsRequestModel 14 | { 15 | [XmlElement("Quiet")] 16 | public bool Quiet { get; set; } 17 | 18 | [XmlElement("Object")] 19 | public ObjectToDel[] Keys { get; set; } 20 | 21 | [XmlRoot("Object")] 22 | public class ObjectToDel 23 | { 24 | [XmlElement("Key")] 25 | public string Key { get; set; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/Model/ErrorResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("Error")] 13 | public class ErrorResult 14 | { 15 | [XmlElement("Code")] 16 | public string Code { get; set; } 17 | 18 | [XmlElement("Message")] 19 | public string Message { get; set; } 20 | 21 | [XmlElement("RequestId")] 22 | public string RequestId { get; set; } 23 | 24 | [XmlElement("HostId")] 25 | public string HostId { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/Model/InitiateMultipartResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("InitiateMultipartUploadResult")] 13 | public class InitiateMultipartResult 14 | { 15 | [XmlElement("Bucket")] 16 | public string Bucket { get; set; } 17 | 18 | [XmlElement("Key")] 19 | public string Key { get; set; } 20 | 21 | [XmlElement("UploadId")] 22 | public string UploadId { get; set; } 23 | 24 | [XmlElement("EncodingType")] 25 | public string EncodingType { get; set; } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/Model/LifecycleConfiguration.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Xml.Serialization; 10 | 11 | namespace Aliyun.OSS.Model 12 | { 13 | [XmlRoot("LifecycleConfiguration")] 14 | public class LifecycleConfiguration 15 | { 16 | [XmlElement("Rule")] 17 | public LifecycleRule[] LifecycleRules { get; set; } 18 | } 19 | 20 | [XmlRoot("Rule")] 21 | public class LifecycleRule 22 | { 23 | [XmlElement("ID")] 24 | public string ID { get; set; } 25 | 26 | [XmlElement("Prefix")] 27 | public String Prefix { get; set; } 28 | 29 | [XmlElement("Status")] 30 | public string Status { get; set; } 31 | 32 | [XmlElement("Expiration")] 33 | public Expiration Expiration { get; set; } 34 | } 35 | 36 | public class Expiration 37 | { 38 | [XmlElement("Days", IsNullable = true)] 39 | public int? Days { get; set; } 40 | 41 | public bool ShouldSerializeDays() 42 | { 43 | return Days.HasValue; 44 | } 45 | 46 | public bool IsSetDays() 47 | { 48 | return Days.HasValue; 49 | } 50 | 51 | [XmlElement("Date", IsNullable = true)] 52 | public string Date { get; set; } 53 | 54 | public bool ShouldSerializeDate() 55 | { 56 | return Date != null; 57 | } 58 | 59 | public bool IsSetDate() 60 | { 61 | return Date != null; 62 | } 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /sdk/Model/ListAllMyBucketsResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Diagnostics.CodeAnalysis; 9 | using System; 10 | using System.Collections.Generic; 11 | using System.Xml.Serialization; 12 | 13 | namespace Aliyun.OSS.Model 14 | { 15 | [XmlRoot("ListAllMyBucketsResult")] 16 | public class ListAllMyBucketsResult 17 | { 18 | [XmlElement("Prefix")] 19 | public string Prefix { get; set; } 20 | 21 | [XmlElement("Marker")] 22 | public string Marker { get; set; } 23 | 24 | [XmlElement("MaxKeys")] 25 | public int? MaxKeys { get; set; } 26 | 27 | [XmlElement("IsTruncated")] 28 | public bool? IsTruncated { get; set; } 29 | 30 | [XmlElement("NextMarker")] 31 | public string NextMarker { get; set; } 32 | 33 | [XmlElement("Owner")] 34 | public Owner Owner { get; set; } 35 | 36 | [XmlArrayItem("Bucket")] 37 | [SuppressMessage("Microsoft.Design", "CA1002:DoNotExposeGenericLists")] 38 | public List Buckets { get; set; } 39 | } 40 | 41 | [XmlRoot("Bucket")] 42 | public class BucketModel 43 | { 44 | [XmlElement("Location")] 45 | public string Location { get; set; } 46 | 47 | [XmlElement("Name")] 48 | public string Name { get; set; } 49 | 50 | [XmlElement("CreationDate")] 51 | public DateTime CreationDate { get; set; } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /sdk/Model/ListPartsResult.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Xml.Serialization; 10 | 11 | namespace Aliyun.OSS.Model 12 | { 13 | [XmlRoot("ListPartsResult")] 14 | public class ListPartsResult 15 | { 16 | [XmlElement("Bucket")] 17 | public string Bucket { get; set; } 18 | 19 | [XmlElement("Key")] 20 | public string Key { get; set; } 21 | 22 | [XmlElement("UploadId")] 23 | public string UploadId { get; set; } 24 | 25 | [XmlElement("PartNumberMarker")] 26 | public int PartNumberMarker { get; set; } 27 | 28 | [XmlElement("NextPartNumberMarker")] 29 | public String NextPartNumberMarker { get; set; } 30 | 31 | [XmlElement("MaxParts")] 32 | public int MaxParts { get; set; } 33 | 34 | [XmlElement("IsTruncated")] 35 | public bool IsTruncated { get; set; } 36 | 37 | [XmlElement("Part")] 38 | public PartResult[] PartResults { get; set; } 39 | 40 | [XmlElement("EncodingType")] 41 | public string EncodingType { get; set; } 42 | 43 | 44 | [XmlRoot("Part")] 45 | public class PartResult 46 | { 47 | [XmlElement("PartNumber")] 48 | public int PartNumber { get; set; } 49 | 50 | [XmlElement("LastModified")] 51 | public DateTime LastModified { get; set; } 52 | 53 | [XmlElement("ETag")] 54 | public string ETag { get; set; } 55 | 56 | [XmlElement("Size")] 57 | public long Size { get; set; } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /sdk/Model/SetBucketCorsRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Xml.Serialization; 10 | 11 | namespace Aliyun.OSS.Model 12 | { 13 | [XmlRoot("CORSConfiguration")] 14 | public class SetBucketCorsRequestModel 15 | { 16 | [XmlElement("CORSRule")] 17 | public CORSRuleModel[] CORSRuleModels { get; set; } 18 | 19 | [XmlRoot("CORSRule")] 20 | public class CORSRuleModel 21 | { 22 | [XmlElement("AllowedOrigin")] 23 | public String[] AllowedOrigins { get; set; } 24 | 25 | [XmlElement("AllowedMethod")] 26 | public String[] AllowedMethods { get; set; } 27 | 28 | [XmlElement("AllowedHeader")] 29 | public String[] AllowedHeaders { get; set; } 30 | 31 | [XmlElement("ExposeHeader")] 32 | public String[] ExposeHeaders { get; set; } 33 | 34 | [XmlElement("MaxAgeSeconds")] 35 | public Int32 MaxAgeSeconds { get; set; } 36 | } 37 | 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /sdk/Model/SetBucketLoggingRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("BucketLoggingStatus")] 13 | public class SetBucketLoggingRequestModel 14 | { 15 | [XmlElement("LoggingEnabled")] 16 | public SetBucketLoggingEnabled LoggingEnabled { get; set; } 17 | 18 | [XmlRoot("LoggingEnabled")] 19 | public class SetBucketLoggingEnabled 20 | { 21 | [XmlElement("TargetBucket")] 22 | public string TargetBucket { get; set; } 23 | 24 | [XmlElement("TargetPrefix")] 25 | public string TargetPrefix { get; set; } 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/Model/SetBucketWebsiteRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Xml.Serialization; 9 | 10 | namespace Aliyun.OSS.Model 11 | { 12 | [XmlRoot("WebsiteConfiguration")] 13 | public class SetBucketWebsiteRequestModel 14 | { 15 | [XmlElement("IndexDocument")] 16 | public IndexDocumentModel IndexDocument { get; set; } 17 | 18 | [XmlElement("ErrorDocument")] 19 | public ErrorDocumentModel ErrorDocument { get; set; } 20 | 21 | [XmlRoot("IndexDocument")] 22 | public class IndexDocumentModel 23 | { 24 | [XmlElement("Suffix")] 25 | public string Suffix { get; set; } 26 | } 27 | 28 | [XmlRoot("ErrorDocument")] 29 | public class ErrorDocumentModel 30 | { 31 | [XmlElement("Key")] 32 | public string Key { get; set; } 33 | } 34 | 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Model/UploadPartCopyRequestModel.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Xml.Serialization; 10 | 11 | namespace Aliyun.OSS.Model 12 | { 13 | [XmlRoot("CopyPartResult")] 14 | public class UploadPartCopyRequestModel 15 | { 16 | [XmlElement("LastModified")] 17 | public DateTime LastModified { get; set; } 18 | 19 | [XmlElement("ETag")] 20 | public string ETag { get; set; } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /sdk/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Runtime.CompilerServices; 2 | 3 | #region Using directives 4 | 5 | using System; 6 | using System.Reflection; 7 | using System.Resources; 8 | using System.Runtime.InteropServices; 9 | 10 | #endregion 11 | 12 | // General Information about an assembly is controlled through the following 13 | // set of attributes. Change these attribute values to modify the information 14 | // associated with an assembly. 15 | [assembly: AssemblyTitle("Aliyun.OSS.dll")] 16 | [assembly: AssemblyDescription("Aliyun OSS SDK for C#")] 17 | [assembly: AssemblyConfiguration("")] 18 | [assembly: AssemblyCompany("Alibaba Cloud Computing")] 19 | [assembly: AssemblyProduct("Aliyun OSS SDK for C#")] 20 | [assembly: AssemblyCopyright("Copyright 2012")] 21 | [assembly: AssemblyTrademark("")] 22 | [assembly: AssemblyCulture("")] 23 | 24 | [assembly: NeutralResourcesLanguage("zh-CN")] 25 | 26 | // This sets the default COM visibility of types in the assembly to invisible. 27 | // If you need to expose a type to COM, use [ComVisible(true)] on that type. 28 | [assembly: ComVisible(false)] 29 | 30 | // The assembly version has following format : 31 | // 32 | // Major.Minor.Build.Revision 33 | // 34 | [assembly: AssemblyVersion("2.4.0")] 35 | 36 | // The asembly is designed as CLS compliant to support CLS-compliant languages. 37 | //[assembly: CLSCompliant(true)] 38 | 39 | [assembly: InternalsVisibleTo("Aliyun.OSS.UnitTest, PublicKey=002400000480000094000000060200000024000052534131000400000100010045C2B8CBBFE7B414DEE24D990688805C04B57ABB8292CEC3CFBCF4C7F6BD8254C8DDEA76F8EA035D106914678AAE9DB8BA4BF1669637043DBE62E1DE2B978729CF6F3DD0080AC2209559371D26219B50309EFDA1D51800DE052B0A45C7C9238884EEA4E7DC3C595B4930785A33A90ED4A6869285C3C04AD95245C0DFC00D24CC")] 40 | [assembly: AssemblyFileVersion("2.4.0")] 41 | 42 | -------------------------------------------------------------------------------- /sdk/Transform/AppendObjectResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class AppendObjectResponseDeserializer : ResponseDeserializer 14 | { 15 | public AppendObjectResponseDeserializer() 16 | : base(null) 17 | { } 18 | 19 | public override AppendObjectResult Deserialize(ServiceResponse xmlStream) 20 | { 21 | var result = new AppendObjectResult(); 22 | if (xmlStream.Headers.ContainsKey(HttpHeaders.ETag)) 23 | result.ETag = OssUtils.TrimQuotes(xmlStream.Headers[HttpHeaders.ETag]); 24 | 25 | if (xmlStream.Headers.ContainsKey(HttpHeaders.NextAppendPosition)) 26 | { 27 | result.NextAppendPosition = long.Parse(xmlStream.Headers[HttpHeaders.NextAppendPosition]); 28 | } 29 | 30 | if (xmlStream.Headers.ContainsKey(HttpHeaders.HashCrc64Ecma)) 31 | { 32 | result.HashCrc64Ecma = ulong.Parse(xmlStream.Headers[HttpHeaders.HashCrc64Ecma]); 33 | } 34 | 35 | return result; 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sdk/Transform/CompleteMultipartUploadRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Model; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class CompleteMultipartUploadRequestSerializer 15 | : RequestSerializer 16 | { 17 | public CompleteMultipartUploadRequestSerializer(ISerializer contentSerializer) 18 | : base(contentSerializer) 19 | { } 20 | 21 | public override Stream Serialize(CompleteMultipartUploadRequest request) 22 | { 23 | var model = new CompleteMultipartUploadRequestModel(); 24 | var modelParts = new List(); 25 | foreach (var part in request.PartETags) 26 | { 27 | var modelPart = new CompleteMultipartUploadRequestModel.CompletePart 28 | { 29 | ETag = "\"" + part.ETag + "\"", 30 | PartNumber = part.PartNumber 31 | }; 32 | modelParts.Add(modelPart); 33 | } 34 | model.Parts = modelParts.ToArray(); 35 | return ContentSerializer.Serialize(model); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /sdk/Transform/CompleteMultipartUploadResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Model; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal class CompleteMultipartUploadResultDeserializer 16 | : ResponseDeserializer 17 | { 18 | public CompleteMultipartUploadResultDeserializer(IDeserializer contentDeserializer) 19 | : base(contentDeserializer) 20 | { } 21 | 22 | public override CompleteMultipartUploadResult Deserialize(ServiceResponse xmlStream) 23 | { 24 | var result = ContentDeserializer.Deserialize(xmlStream.Content); 25 | return new CompleteMultipartUploadResult 26 | { 27 | BucketName = result.Bucket, 28 | Key = result.Key, 29 | Location = result.Location, 30 | ETag = OssUtils.TrimQuotes(result.ETag) 31 | }; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /sdk/Transform/CopyObjectResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Model; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal class CopyObjectResultDeserializer : ResponseDeserializer 16 | { 17 | public CopyObjectResultDeserializer(IDeserializer contentDeserializer) 18 | : base(contentDeserializer) 19 | { 20 | } 21 | 22 | public override CopyObjectResult Deserialize(ServiceResponse xmlStream) 23 | { 24 | var result = ContentDeserializer.Deserialize(xmlStream.Content); 25 | return new CopyObjectResult 26 | { 27 | ETag = OssUtils.TrimQuotes(result.ETag), 28 | LastModified = result.LastModified 29 | }; 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sdk/Transform/DeleteObjectsRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Model; 10 | using System.Collections.Generic; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class DeleteObjectsRequestSerializer : RequestSerializer 15 | { 16 | public DeleteObjectsRequestSerializer(ISerializer contentSerializer) 17 | : base(contentSerializer) 18 | { 19 | } 20 | 21 | public override Stream Serialize(DeleteObjectsRequest request) 22 | { 23 | var newKeys = new List(); 24 | foreach (var key in request.Keys) 25 | { 26 | newKeys.Add(new DeleteObjectsRequestModel.ObjectToDel { Key = key }); 27 | } 28 | 29 | var model = new DeleteObjectsRequestModel 30 | { 31 | Quiet = request.Quiet, 32 | Keys = newKeys.ToArray() 33 | }; 34 | return ContentSerializer.Serialize(model); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sdk/Transform/DeleteObjectsResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class DeleteObjectsResultDeserializer : ResponseDeserializer 15 | { 16 | public DeleteObjectsResultDeserializer(IDeserializer contentDeserializer) 17 | : base(contentDeserializer) 18 | { } 19 | 20 | public override DeleteObjectsResult Deserialize(ServiceResponse xmlStream) 21 | { 22 | if (int.Parse(xmlStream.Headers[HttpHeaders.ContentLength]) == 0) 23 | return new DeleteObjectsResult(); 24 | 25 | return ContentDeserializer.Deserialize(xmlStream.Content); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /sdk/Transform/GetAclResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | using Aliyun.OSS.Model; 13 | 14 | namespace Aliyun.OSS.Transform 15 | { 16 | internal class GetAclResponseDeserializer : ResponseDeserializer 17 | { 18 | public GetAclResponseDeserializer(IDeserializer contentDeserializer) 19 | : base(contentDeserializer) 20 | { } 21 | 22 | public override AccessControlList Deserialize(ServiceResponse xmlStream) 23 | { 24 | var model = ContentDeserializer.Deserialize(xmlStream.Content); 25 | var acl = new AccessControlList {Owner = new Owner(model.Owner.Id, model.Owner.DisplayName)}; 26 | foreach(var grant in model.Grants) 27 | { 28 | if (grant == EnumUtils.GetStringValue(CannedAccessControlList.PublicRead)) 29 | { 30 | acl.GrantPermission(GroupGrantee.AllUsers, Permission.Read); 31 | acl.ACL = CannedAccessControlList.PublicRead; 32 | } 33 | else if (grant == EnumUtils.GetStringValue(CannedAccessControlList.PublicReadWrite)) 34 | { 35 | acl.GrantPermission(GroupGrantee.AllUsers, Permission.FullControl); 36 | acl.ACL = CannedAccessControlList.PublicReadWrite; 37 | } 38 | else if (grant == EnumUtils.GetStringValue(CannedAccessControlList.Private)) 39 | { 40 | acl.ACL = CannedAccessControlList.Private; 41 | } 42 | else if (grant == EnumUtils.GetStringValue(CannedAccessControlList.Default)) 43 | { 44 | acl.ACL = CannedAccessControlList.Default; 45 | } 46 | } 47 | return acl; 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /sdk/Transform/GetBucketLoggingResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Model; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class GetBucketLoggingResultDeserializer 15 | : ResponseDeserializer 16 | { 17 | public GetBucketLoggingResultDeserializer(IDeserializer contentDeserializer) 18 | : base(contentDeserializer) 19 | { } 20 | 21 | public override BucketLoggingResult Deserialize(ServiceResponse xmlStream) 22 | { 23 | var model = ContentDeserializer.Deserialize(xmlStream.Content); 24 | return new BucketLoggingResult 25 | { 26 | TargetBucket = model.LoggingEnabled.TargetBucket, 27 | TargetPrefix = model.LoggingEnabled.TargetPrefix 28 | }; 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/Transform/GetBucketWebSiteResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | using Aliyun.OSS.Model; 10 | using System.IO; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class GetBucketWebSiteResultDeserializer : ResponseDeserializer 15 | { 16 | public GetBucketWebSiteResultDeserializer(IDeserializer contentDeserializer) 17 | : base(contentDeserializer) 18 | { } 19 | 20 | public override BucketWebsiteResult Deserialize(ServiceResponse xmlStream) 21 | { 22 | var model = ContentDeserializer.Deserialize(xmlStream.Content); 23 | return new BucketWebsiteResult 24 | { 25 | IndexDocument = model.IndexDocument.Suffix, 26 | ErrorDocument = model.ErrorDocument.Key 27 | }; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Transform/GetCorsResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | using Aliyun.OSS.Model; 10 | using System.Collections.Generic; 11 | using System.IO; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal class GetCorsResponseDeserializer : ResponseDeserializer, SetBucketCorsRequestModel> 16 | { 17 | public GetCorsResponseDeserializer(IDeserializer contentDeserializer) 18 | : base(contentDeserializer) 19 | { } 20 | 21 | public override IList Deserialize(ServiceResponse xmlStream) 22 | { 23 | var model = ContentDeserializer.Deserialize(xmlStream.Content); 24 | 25 | IList corsRuleList = new List(); 26 | foreach (var corsRuleModel in model.CORSRuleModels) 27 | { 28 | var corsRule = new CORSRule(); 29 | if (corsRuleModel.AllowedHeaders != null && corsRuleModel.AllowedHeaders.Length > 0) 30 | corsRule.AllowedHeaders = ToList(corsRuleModel.AllowedHeaders); 31 | if (corsRuleModel.AllowedMethods != null && corsRuleModel.AllowedMethods.Length > 0) 32 | corsRule.AllowedMethods = ToList(corsRuleModel.AllowedMethods); 33 | if (corsRuleModel.AllowedOrigins != null && corsRuleModel.AllowedOrigins.Length > 0) 34 | corsRule.AllowedOrigins = ToList(corsRuleModel.AllowedOrigins); 35 | if (corsRuleModel.ExposeHeaders != null && corsRuleModel.ExposeHeaders.Length > 0) 36 | corsRule.ExposeHeaders = ToList(corsRuleModel.ExposeHeaders); 37 | corsRule.MaxAgeSeconds = corsRuleModel.MaxAgeSeconds; 38 | corsRuleList.Add(corsRule); 39 | } 40 | 41 | return corsRuleList; 42 | } 43 | 44 | private IList ToList(string[] array) 45 | { 46 | IList list = new List(); 47 | foreach(var value in array) 48 | { 49 | list.Add(value); 50 | } 51 | return list; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sdk/Transform/GetObjectResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | 10 | namespace Aliyun.OSS.Transform 11 | { 12 | internal class GetObjectResponseDeserializer : ResponseDeserializer 13 | { 14 | private readonly GetObjectRequest _getObjectRequest; 15 | 16 | public GetObjectResponseDeserializer(GetObjectRequest getObjectRequest) 17 | : base(null) 18 | { 19 | _getObjectRequest = getObjectRequest; 20 | } 21 | 22 | public override OssObject Deserialize(ServiceResponse xmlStream) 23 | { 24 | return new OssObject(_getObjectRequest.Key) 25 | { 26 | BucketName = _getObjectRequest.BucketName, 27 | Content = xmlStream.Content, 28 | Metadata = DeserializerFactory.GetFactory() 29 | .CreateGetObjectMetadataResultDeserializer().Deserialize(xmlStream) 30 | }; 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/Transform/IDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Transform 9 | { 10 | internal interface IDeserializer 11 | { 12 | TOutput Deserialize(TInput xmlStream); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/Transform/ISerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Transform 9 | { 10 | internal interface ISerializer 11 | { 12 | TOutput Serialize(TInput input); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /sdk/Transform/InitiateMultipartUploadResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Model; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class InitiateMultipartUploadResultDeserializer 15 | : ResponseDeserializer 16 | { 17 | public InitiateMultipartUploadResultDeserializer(IDeserializer contentDeserializer) 18 | : base(contentDeserializer) 19 | { } 20 | 21 | public override InitiateMultipartUploadResult Deserialize(ServiceResponse xmlStream) 22 | { 23 | var result = ContentDeserializer.Deserialize(xmlStream.Content); 24 | string encodeType = result.EncodingType == null ? 25 | string.Empty : result.EncodingType.ToLowerInvariant(); 26 | 27 | return new InitiateMultipartUploadResult 28 | { 29 | BucketName = result.Bucket, 30 | Key = Decode(result.Key, encodeType), 31 | UploadId = result.UploadId 32 | }; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sdk/Transform/ListBucketsResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using System.Collections.Generic; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Model; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal class ListBucketsResultDeserializer : ResponseDeserializer 16 | { 17 | public ListBucketsResultDeserializer(IDeserializer contentDeserializer) 18 | : base(contentDeserializer) 19 | { } 20 | 21 | public override ListBucketsResult Deserialize(ServiceResponse xmlStream) 22 | { 23 | var model = ContentDeserializer.Deserialize(xmlStream.Content); 24 | 25 | var result = new ListBucketsResult {Prefix = model.Prefix, Marker = model.Marker}; 26 | if (model.MaxKeys.HasValue) 27 | result.MaxKeys = model.MaxKeys.Value; 28 | if (model.IsTruncated.HasValue) 29 | result.IsTruncated = model.IsTruncated.Value; 30 | result.NextMaker = model.NextMarker; 31 | 32 | var selectedBuckets = new List(); 33 | foreach (var e in model.Buckets) 34 | { 35 | var newBucket = new Bucket(e.Name) 36 | { 37 | Location = e.Location, 38 | Owner = new Owner(model.Owner.Id, model.Owner.DisplayName), 39 | CreationDate = e.CreationDate 40 | }; 41 | selectedBuckets.Add(newBucket); 42 | } 43 | result.Buckets = selectedBuckets; 44 | return result; 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /sdk/Transform/ListPartsResultDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Model; 12 | using Aliyun.OSS.Util; 13 | 14 | namespace Aliyun.OSS.Transform 15 | { 16 | internal class ListPartsResponseDeserializer : ResponseDeserializer 17 | { 18 | public ListPartsResponseDeserializer(IDeserializer contentDeserializer) 19 | : base(contentDeserializer) 20 | { } 21 | 22 | public override PartListing Deserialize(ServiceResponse xmlStream) 23 | { 24 | var listPartResult = ContentDeserializer.Deserialize(xmlStream.Content); 25 | 26 | var partListing = new PartListing 27 | { 28 | BucketName = listPartResult.Bucket, 29 | Key = listPartResult.EncodingType.ToLowerInvariant().Equals(HttpUtils.UrlEncodingType) ? HttpUtils.DecodeUri(listPartResult.Key) : listPartResult.Key, 30 | MaxParts = listPartResult.MaxParts, 31 | NextPartNumberMarker = listPartResult.NextPartNumberMarker.Length == 0 ? 32 | 0 : Convert.ToInt32(listPartResult.NextPartNumberMarker), 33 | PartNumberMarker = listPartResult.PartNumberMarker, 34 | UploadId = listPartResult.UploadId, 35 | IsTruncated = listPartResult.IsTruncated 36 | }; 37 | 38 | if (listPartResult.PartResults != null) 39 | { 40 | foreach (var partResult in listPartResult.PartResults) 41 | { 42 | var part = new Part 43 | { 44 | ETag = partResult.ETag != null ? OssUtils.TrimQuotes(partResult.ETag) : string.Empty, 45 | LastModified = partResult.LastModified, 46 | PartNumber = partResult.PartNumber, 47 | Size = partResult.Size 48 | }; 49 | partListing.AddPart(part); 50 | } 51 | } 52 | 53 | return partListing; 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sdk/Transform/PutObjectResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class PutObjectResponseDeserializer : ResponseDeserializer 14 | { 15 | public PutObjectResponseDeserializer() 16 | : base(null) 17 | { } 18 | 19 | public override PutObjectResult Deserialize(ServiceResponse xmlStream) 20 | { 21 | var result = new PutObjectResult(); 22 | if (xmlStream.Headers.ContainsKey(HttpHeaders.ETag)) 23 | result.ETag = OssUtils.TrimQuotes(xmlStream.Headers[HttpHeaders.ETag]); 24 | return result; 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /sdk/Transform/RequestSerializationException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Runtime.Serialization; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | [Serializable] 14 | internal class RequestSerializationException : InvalidOperationException, ISerializable 15 | { 16 | public RequestSerializationException() 17 | { } 18 | 19 | public RequestSerializationException(string message) : base(message) 20 | { } 21 | 22 | public RequestSerializationException(string message, Exception innerException) 23 | : base(message, innerException) 24 | { } 25 | 26 | protected RequestSerializationException(SerializationInfo info, StreamingContext context) 27 | : base(info, context) 28 | { } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /sdk/Transform/RequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | 10 | namespace Aliyun.OSS.Transform 11 | { 12 | internal abstract class RequestSerializer : ISerializer 13 | { 14 | protected ISerializer ContentSerializer { get; private set; } 15 | 16 | public RequestSerializer(ISerializer contentSerializer) 17 | { 18 | ContentSerializer = contentSerializer; 19 | } 20 | 21 | public abstract Stream Serialize(TRequest request); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /sdk/Transform/ResponseDeserializationException.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Runtime.Serialization; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | [Serializable] 14 | internal class ResponseDeserializationException : InvalidOperationException, ISerializable 15 | { 16 | public ResponseDeserializationException() 17 | { } 18 | 19 | public ResponseDeserializationException(string message) : base(message) 20 | { } 21 | 22 | public ResponseDeserializationException(string message, Exception innerException) 23 | : base(message, innerException) 24 | { } 25 | 26 | protected ResponseDeserializationException(SerializationInfo info, StreamingContext context) 27 | : base(info, context) 28 | { } 29 | } 30 | } -------------------------------------------------------------------------------- /sdk/Transform/ResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Util; 10 | 11 | using Aliyun.OSS.Common.Communication; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal abstract class ResponseDeserializer : IDeserializer 16 | { 17 | protected IDeserializer ContentDeserializer { get; private set; } 18 | 19 | public ResponseDeserializer(IDeserializer contentDeserializer) 20 | { 21 | ContentDeserializer = contentDeserializer; 22 | } 23 | 24 | public abstract TResult Deserialize(ServiceResponse xmlStream); 25 | 26 | protected string Decode(string value, string decodeType) 27 | { 28 | if (decodeType.Equals(HttpUtils.UrlEncodingType)) 29 | { 30 | return HttpUtils.DecodeUri(value); 31 | } 32 | return value; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sdk/Transform/SetBucketLifecycleRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Util; 10 | using Aliyun.OSS.Model; 11 | 12 | namespace Aliyun.OSS.Transform 13 | { 14 | internal class SetBucketLifecycleRequestSerializer : RequestSerializer 15 | { 16 | public SetBucketLifecycleRequestSerializer(ISerializer contentSerializer) 17 | : base(contentSerializer) 18 | { } 19 | 20 | public override Stream Serialize(SetBucketLifecycleRequest request) 21 | { 22 | var rules = request.LifecycleRules; 23 | var lcc = new LifecycleConfiguration 24 | { 25 | LifecycleRules = new Model.LifecycleRule[rules.Count] 26 | }; 27 | 28 | for (var i = 0; i < rules.Count; i++) 29 | { 30 | lcc.LifecycleRules[i] = new Model.LifecycleRule 31 | { 32 | ID = rules[i].ID, 33 | Prefix = rules[i].Prefix 34 | }; 35 | 36 | switch (rules[i].Status) 37 | { 38 | case RuleStatus.Enabled: 39 | lcc.LifecycleRules[i].Status = RuleStatus.Enabled.ToString(); 40 | break; 41 | case RuleStatus.Disabled: 42 | lcc.LifecycleRules[i].Status = RuleStatus.Disabled.ToString(); 43 | break; 44 | } 45 | 46 | lcc.LifecycleRules[i].Expiration = new Expiration(); 47 | if (rules[i].ExpirationTime.HasValue) 48 | lcc.LifecycleRules[i].Expiration.Date = DateUtils.FormatIso8601Date(rules[i].ExpirationTime.Value); 49 | else if (rules[i].ExpriationDays.HasValue) 50 | lcc.LifecycleRules[i].Expiration.Days = rules[i].ExpriationDays.Value; 51 | } 52 | 53 | return ContentSerializer.Serialize(lcc); 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /sdk/Transform/SetBucketLoggingRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Model; 9 | using System.IO; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class SetBucketLoggingRequestSerializer : RequestSerializer 14 | { 15 | public SetBucketLoggingRequestSerializer(ISerializer contentSerializer) 16 | : base(contentSerializer) 17 | { } 18 | 19 | public override Stream Serialize(SetBucketLoggingRequest request) 20 | { 21 | var model = new SetBucketLoggingRequestModel(); 22 | 23 | var setBucketLoggingEnabled = new SetBucketLoggingRequestModel.SetBucketLoggingEnabled 24 | { 25 | TargetBucket = request.TargetBucket, 26 | TargetPrefix = request.TargetPrefix 27 | }; 28 | model.LoggingEnabled = setBucketLoggingEnabled; 29 | 30 | return ContentSerializer.Serialize(model); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /sdk/Transform/SetBucketRefererRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | 10 | namespace Aliyun.OSS.Transform 11 | { 12 | internal class SetBucketRefererRequestSerializer : RequestSerializer 13 | { 14 | public SetBucketRefererRequestSerializer(ISerializer contentSerializer) 15 | : base(contentSerializer) 16 | { } 17 | 18 | public override Stream Serialize(SetBucketRefererRequest request) 19 | { 20 | var model = new RefererConfiguration 21 | { 22 | AllowEmptyReferer = request.AllowEmptyReferer, 23 | RefererList = new RefererConfiguration.RefererListModel {Referers = new string[request.RefererList.Count]} 24 | }; 25 | for (var i = 0; i < request.RefererList.Count ; i++) 26 | model.RefererList.Referers[i] = request.RefererList[i]; 27 | 28 | return ContentSerializer.Serialize(model); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/Transform/SetBucketWebsiteRequestSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Model; 9 | using System.IO; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class SetBucketWebsiteRequestSerializer : RequestSerializer 14 | { 15 | public SetBucketWebsiteRequestSerializer(ISerializer contentSerializer) 16 | : base(contentSerializer) 17 | { } 18 | 19 | public override Stream Serialize(SetBucketWebsiteRequest request) 20 | { 21 | var model = new SetBucketWebsiteRequestModel 22 | { 23 | ErrorDocument = new SetBucketWebsiteRequestModel.ErrorDocumentModel(), 24 | IndexDocument = new SetBucketWebsiteRequestModel.IndexDocumentModel {Suffix = request.IndexDocument} 25 | }; 26 | 27 | model.ErrorDocument.Key = request.ErrorDocument; 28 | 29 | return ContentSerializer.Serialize(model); 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /sdk/Transform/SimpleResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class SimpleResponseDeserializer : ResponseDeserializer 14 | { 15 | public SimpleResponseDeserializer(IDeserializer contentDeserializer) 16 | : base(contentDeserializer) 17 | { } 18 | 19 | public override T Deserialize(ServiceResponse xmlStream) 20 | { 21 | using (xmlStream.Content) 22 | { 23 | return ContentDeserializer.Deserialize(xmlStream.Content); 24 | } 25 | } 26 | } 27 | } -------------------------------------------------------------------------------- /sdk/Transform/UploadPartCopyResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | using Aliyun.OSS.Common.Communication; 10 | using Aliyun.OSS.Util; 11 | using Aliyun.OSS.Model; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | internal class UploadPartCopyResultDeserializer : ResponseDeserializer 16 | { 17 | private readonly int _partNumber; 18 | 19 | public UploadPartCopyResultDeserializer(IDeserializer contentDeserializer, int partNumber) 20 | : base(contentDeserializer) 21 | { 22 | _partNumber = partNumber; 23 | } 24 | 25 | public override UploadPartCopyResult Deserialize(ServiceResponse xmlStream) 26 | { 27 | var partCopyRequestModel = ContentDeserializer.Deserialize(xmlStream.Content); 28 | var result = new UploadPartCopyResult 29 | { 30 | ETag = OssUtils.TrimQuotes(partCopyRequestModel.ETag), 31 | PartNumber = _partNumber 32 | }; 33 | 34 | return result; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /sdk/Transform/UploadPartResponseDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using Aliyun.OSS.Common.Communication; 9 | using Aliyun.OSS.Util; 10 | 11 | namespace Aliyun.OSS.Transform 12 | { 13 | internal class UploadPartResultDeserializer : ResponseDeserializer 14 | { 15 | private readonly int _partNumber; 16 | 17 | public UploadPartResultDeserializer(int partNumber) 18 | : base(null) 19 | { 20 | _partNumber = partNumber; 21 | } 22 | 23 | public override UploadPartResult Deserialize(ServiceResponse xmlStream) 24 | { 25 | var result = new UploadPartResult(); 26 | if (xmlStream.Headers.ContainsKey(HttpHeaders.ETag)) 27 | { 28 | result.ETag = OssUtils.TrimQuotes(xmlStream.Headers[HttpHeaders.ETag]); 29 | } 30 | result.PartNumber = _partNumber; 31 | 32 | return result; 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /sdk/Transform/XmlStreamDeserializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using System.Xml; 11 | using System.Xml.Serialization; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | /// 16 | /// Deserialize an object of type T from XML stream. 17 | /// 18 | internal class XmlStreamDeserializer : IDeserializer 19 | { 20 | private static readonly XmlSerializer Serializer = new XmlSerializer(typeof(T)); 21 | 22 | /// 23 | /// Deserialize an object of type T, then close the underlying stream. 24 | /// 25 | public T Deserialize(Stream xmlStream) 26 | { 27 | using (xmlStream) 28 | { 29 | try 30 | { 31 | return (T)Serializer.Deserialize(xmlStream); 32 | } 33 | catch (XmlException ex) 34 | { 35 | throw new ResponseDeserializationException(ex.Message, ex); 36 | } 37 | catch (InvalidOperationException ex) 38 | { 39 | throw new ResponseDeserializationException(ex.Message, ex); 40 | } 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sdk/Transform/XmlStreamSerializer.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.IO; 10 | using System.Text; 11 | using System.Xml.Serialization; 12 | 13 | namespace Aliyun.OSS.Transform 14 | { 15 | /// 16 | /// Serialize an object of type TRequest to XML stream. 17 | /// 18 | internal class XmlStreamSerializer : ISerializer 19 | { 20 | private static readonly XmlSerializer Serializer = new XmlSerializer(typeof(TRequest)); 21 | 22 | public Stream Serialize(TRequest requestObject) 23 | { 24 | MemoryStream stream = null; 25 | try 26 | { 27 | stream = new MemoryStream(); 28 | var namespaces = new XmlSerializerNamespaces(); 29 | namespaces.Add(string.Empty, string.Empty); 30 | StreamWriter textWriter = new StreamWriter(stream, Encoding.GetEncoding("utf-8")); 31 | Serializer.Serialize(textWriter, requestObject, namespaces); 32 | stream.Seek(0, SeekOrigin.Begin); 33 | return stream; 34 | } 35 | catch (InvalidOperationException ex) 36 | { 37 | if (stream != null) 38 | stream.Close(); 39 | 40 | throw new RequestSerializationException(ex.Message, ex); 41 | } 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /sdk/Util/DateUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Globalization; 10 | 11 | namespace Aliyun.OSS.Util 12 | { 13 | internal static class DateUtils 14 | { 15 | private const string Rfc822DateFormat = "ddd, dd MMM yyyy HH:mm:ss \\G\\M\\T"; 16 | private const string Iso8601DateFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z'"; 17 | 18 | /// 19 | /// Format an instance of to a GMT format string. 20 | /// 21 | public static string FormatRfc822Date(DateTime dtime) 22 | { 23 | return dtime.ToUniversalTime().ToString(Rfc822DateFormat, 24 | CultureInfo.InvariantCulture); 25 | } 26 | 27 | /// 28 | /// Format a GMT format string to an instance of . 29 | /// 30 | /// 31 | public static DateTime ParseRfc822Date(String s) 32 | { 33 | return DateTime.SpecifyKind( 34 | DateTime.ParseExact(s, Rfc822DateFormat, CultureInfo.InvariantCulture), 35 | DateTimeKind.Utc); 36 | } 37 | 38 | /// 39 | /// Format an instance of to string in iso-8601 format. 40 | /// 41 | public static string FormatIso8601Date(DateTime dtime) 42 | { 43 | 44 | return dtime.ToUniversalTime().ToString(Iso8601DateFormat, 45 | CultureInfo.CurrentCulture); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sdk/Util/EnumUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using System.Collections.Generic; 10 | 11 | namespace Aliyun.OSS.Util 12 | { 13 | internal static class EnumUtils 14 | { 15 | private static readonly IDictionary StringValues = 16 | new Dictionary(); 17 | 18 | public static string GetStringValue(Enum value) 19 | { 20 | string output; 21 | var type = value.GetType(); 22 | 23 | if (StringValues.ContainsKey(value)) 24 | { 25 | output = StringValues[value].Value; 26 | } 27 | else 28 | { 29 | var fi = type.GetField(value.ToString()); 30 | var attrs = fi.GetCustomAttributes(typeof (StringValueAttribute), false) 31 | as StringValueAttribute[]; 32 | if (attrs != null && attrs.Length > 0) 33 | { 34 | output = attrs[0].Value; 35 | // Put it in the cache. 36 | lock(StringValues) 37 | { 38 | // Double check 39 | if (!StringValues.ContainsKey(value)) 40 | { 41 | StringValues.Add(value, attrs[0]); 42 | } 43 | } 44 | } 45 | else 46 | { 47 | return value.ToString(); 48 | } 49 | } 50 | 51 | return output; 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sdk/Util/ExceptionFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Properties; 10 | using Aliyun.OSS.Common; 11 | 12 | namespace Aliyun.OSS.Util 13 | { 14 | internal static class ExceptionFactory 15 | { 16 | public static OssException CreateException(string errorCode, 17 | string message, 18 | string requestId, 19 | string hostId) 20 | { 21 | return CreateException(errorCode, message, requestId, hostId, null); 22 | } 23 | 24 | public static OssException CreateException(string errorCode, 25 | string message, 26 | string requestId, 27 | string hostId, 28 | Exception innerException) 29 | { 30 | var exception = innerException != null ? 31 | new OssException(message, innerException) : 32 | new OssException(message); 33 | 34 | exception.RequestId = requestId; 35 | exception.HostId = hostId; 36 | exception.ErrorCode = errorCode; 37 | 38 | return exception; 39 | } 40 | 41 | public static Exception CreateInvalidResponseException(Exception innerException) 42 | { 43 | throw new InvalidOperationException(Resources.ExceptionInvalidResponse, innerException); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /sdk/Util/ExecutionContextBuilder.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Collections.Generic; 9 | using Aliyun.OSS.Common.Authentication; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Common.Handlers; 12 | 13 | namespace Aliyun.OSS.Util 14 | { 15 | internal class ExecutionContextBuilder 16 | { 17 | public ICredentials Credentials { get; set; } 18 | 19 | public IList ResponseHandlers { get; private set; } 20 | 21 | public HttpMethod Method { get; set; } 22 | 23 | public string Bucket { get; set; } 24 | 25 | public string Key { get; set; } 26 | 27 | public ExecutionContextBuilder() 28 | { 29 | ResponseHandlers = new List(); 30 | } 31 | 32 | public ExecutionContext Build() 33 | { 34 | var context = new ExecutionContext 35 | { 36 | Signer = CreateSigner(Bucket, Key), 37 | Credentials = Credentials 38 | }; 39 | foreach(var h in ResponseHandlers) 40 | { 41 | context.ResponseHandlers.Add(h); 42 | } 43 | return context; 44 | } 45 | 46 | private static IRequestSigner CreateSigner(string bucket, string key) 47 | { 48 | var resourcePath = "/" + (bucket ?? string.Empty) + 49 | ((key != null ? "/" + key : "")); 50 | 51 | // Hacked. the sign path is /bucket/key for two-level-domain mode 52 | // but /bucket/key/ for the three-level-domain mode. 53 | if (bucket != null && key == null) 54 | { 55 | resourcePath = resourcePath + "/"; 56 | } 57 | 58 | return new OssRequestSigner(resourcePath); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /sdk/Util/HttpHeaders.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Util 9 | { 10 | internal static class HttpHeaders 11 | { 12 | public const string Authorization = "Authorization"; 13 | 14 | public const string CacheControl = "Cache-Control"; 15 | 16 | public const string ContentDisposition = "Content-Disposition"; 17 | 18 | public const string ContentEncoding = "Content-Encoding"; 19 | 20 | public const string ContentLength = "Content-Length"; 21 | 22 | public const string ContentMd5 = "Content-MD5"; 23 | 24 | public const string ContentType = "Content-Type"; 25 | 26 | public const string Date = "Date"; 27 | 28 | public const string Expires = "Expires"; 29 | 30 | public const string ETag = "ETag"; 31 | 32 | public const string LastModified = "Last-Modified"; 33 | 34 | public const string Range = "Range"; 35 | 36 | public const string CopySource = "x-oss-copy-source"; 37 | 38 | public const string CopySourceRange = "x-oss-copy-source-range"; 39 | 40 | public const string Location = "Location"; 41 | 42 | public const string ServerSideEncryption = "x-oss-server-side-encryption"; 43 | 44 | public const string SecurityToken = "x-oss-security-token"; 45 | 46 | public const string NextAppendPosition = "x-oss-next-append-position"; 47 | 48 | public const string HashCrc64Ecma = "x-oss-hash-crc64ecma"; 49 | 50 | public const string ObjectType = "x-oss-object-type"; 51 | 52 | public const string RequestId = "x-oss-request-id"; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /sdk/Util/IOUtils.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.IO; 9 | 10 | namespace Aliyun.OSS.Util 11 | { 12 | public static class IoUtils 13 | { 14 | private const int BufferSize = 4 * 1024; 15 | 16 | public static void WriteTo(Stream src, Stream dest) 17 | { 18 | var buffer = new byte[BufferSize]; 19 | int bytesRead; 20 | while((bytesRead = src.Read(buffer, 0, buffer.Length)) > 0) 21 | { 22 | dest.Write(buffer, 0, bytesRead); 23 | } 24 | dest.Flush(); 25 | } 26 | 27 | public static long WriteTo(Stream orignStream, Stream destStream, long totalSize) 28 | { 29 | var buffer = new byte[BufferSize]; 30 | 31 | long alreadyRead = 0; 32 | while (alreadyRead < totalSize) 33 | { 34 | var readSize = orignStream.Read(buffer, 0, BufferSize); 35 | if (readSize <= 0) 36 | break; 37 | 38 | if (alreadyRead + readSize > totalSize) 39 | readSize = (int) (totalSize - alreadyRead); 40 | alreadyRead += readSize; 41 | destStream.Write(buffer, 0, readSize); 42 | } 43 | destStream.Flush(); 44 | 45 | return alreadyRead; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /sdk/Util/OssHeaders.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Util 9 | { 10 | internal static class OssHeaders 11 | { 12 | public const string OssPrefix = "x-oss-"; 13 | public const string OssUserMetaPrefix = "x-oss-meta-"; 14 | 15 | public const string OssCannedAcl = "x-oss-acl"; 16 | public const string OssObjectCannedAcl = "x-oss-object-acl"; 17 | 18 | public const string GetObjectIfModifiedSince = "If-Modified-Since"; 19 | public const string GetObjectIfUnmodifiedSince = "If-Unmodified-Since"; 20 | public const string GetObjectIfMatch = "If-Match"; 21 | public const string GetObjectIfNoneMatch = "If-None-Match"; 22 | 23 | public const string CopyObjectSource = "x-oss-copy-source"; 24 | public const string CopySourceIfMatch = "x-oss-copy-source-if-match"; 25 | public const string CopySourceIfNoneMatch = "x-oss-copy-source-if-none-match"; 26 | public const string CopySourceIfUnmodifiedSince = "x-oss-copy-source-if-unmodified-since"; 27 | public const string CopySourceIfModifedSince = "x-oss-copy-source-if-modified-since"; 28 | public const string CopyObjectMetaDataDirective = "x-oss-metadata-directive"; 29 | 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /sdk/Util/OssRequestSigner.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | using Aliyun.OSS.Common.Authentication; 10 | using Aliyun.OSS.Common.Communication; 11 | using Aliyun.OSS.Util; 12 | 13 | namespace Aliyun.OSS.Util 14 | { 15 | internal class OssRequestSigner : IRequestSigner 16 | { 17 | private readonly string _resourcePath; 18 | 19 | public OssRequestSigner(String resourcePath) 20 | { 21 | _resourcePath = resourcePath; 22 | } 23 | 24 | public void Sign(ServiceRequest request, ICredentials credentials) 25 | { 26 | var accessKeyId = credentials.AccessKeyId; 27 | var accessKeySecret = credentials.AccessKeySecret; 28 | var httpMethod = request.Method.ToString().ToUpperInvariant(); 29 | // Because the resource path to is different from the one in the request uri, 30 | // can't use ServiceRequest.ResourcePath here. 31 | var resourcePath = _resourcePath; 32 | if (!string.IsNullOrEmpty(accessKeySecret)) 33 | { 34 | var canonicalString = SignUtils.BuildCanonicalString(httpMethod, resourcePath, request); 35 | var signature = ServiceSignature.Create().ComputeSignature(accessKeySecret, canonicalString); 36 | 37 | request.Headers.Add(HttpHeaders.Authorization, "OSS " + accessKeyId + ":" + signature); 38 | } 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /sdk/Util/RequestParameters.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | namespace Aliyun.OSS.Util 9 | { 10 | internal static class RequestParameters 11 | { 12 | public const string SUBRESOURCE_ACL = "acl"; 13 | public const string SUBRESOURCE_REFERER = "referer"; 14 | public const string SUBRESOURCE_LOGGING = "logging"; 15 | public const string SUBRESOURCE_WEBSITE = "website"; 16 | public const string SUBRESOURCE_LIFECYCLE = "lifecycle"; 17 | public const string SUBRESOURCE_UPLOADS = "uploads"; 18 | public const string SUBRESOURCE_DELETE = "delete"; 19 | public const string SUBRESOURCE_CORS = "cors"; 20 | 21 | public const string PREFIX = "prefix"; 22 | public const string DELIMITER = "delimiter"; 23 | public const string MARKER = "marker"; 24 | public const string MAX_KEYS = "max-keys"; 25 | public const string ENCODING_TYPE = "encoding-type"; 26 | 27 | public const string UPLOAD_ID = "uploadId"; 28 | public const string PART_NUMBER = "partNumber"; 29 | public const string MAX_UPLOADS = "max-uploads"; 30 | public const string UPLOAD_ID_MARKER = "upload-id-marker"; 31 | public const string KEY_MARKER = "key-marker"; 32 | public const string MAX_PARTS = "max-parts"; 33 | public const string PART_NUMBER_MARKER = "part-number-marker"; 34 | 35 | public const string EXPIRES = "Expires"; 36 | public const string SIGNATURE = "Signature"; 37 | public const string OSS_ACCESS_KEY_ID = "OSSAccessKeyId"; 38 | 39 | public const string SECURITY_TOKEN = "security-token"; 40 | 41 | public const string OSS_PROCESS = "x-oss-process"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /sdk/Util/ServiceClientFactory.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved. 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System.Diagnostics; 9 | using System.Net; 10 | using Aliyun.OSS.Common; 11 | using Aliyun.OSS.Common.Communication; 12 | 13 | namespace Aliyun.OSS.Util 14 | { 15 | internal static class ServiceClientFactory 16 | { 17 | static ServiceClientFactory() 18 | { 19 | ServicePointManager.Expect100Continue = true; 20 | ServicePointManager.DefaultConnectionLimit = ClientConfiguration.ConnectionLimit; 21 | } 22 | 23 | public static IServiceClient CreateServiceClient(ClientConfiguration configuration) 24 | { 25 | Debug.Assert(configuration != null); 26 | 27 | var retryableServiceClient = 28 | new RetryableServiceClient(ServiceClient.Create(configuration)) 29 | { 30 | MaxRetryTimes = configuration.MaxErrorRetry 31 | }; 32 | 33 | return retryableServiceClient; 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /sdk/Util/StringValueAttribute.cs: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) Alibaba Cloud Computing 3 | * All rights reserved.OSS.Utilities 4 | * 5 | * 版权所有 (C)阿里云计算有限公司 6 | */ 7 | 8 | using System; 9 | 10 | namespace Aliyun.OSS.Util 11 | { 12 | internal sealed class StringValueAttribute : Attribute 13 | { 14 | public string Value { get; private set; } 15 | 16 | public StringValueAttribute(string value) 17 | { 18 | Value = value; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /sdk/aliyun_sdk_net.snk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shirlman/aliyun-oss-unity-sdk/3ebf22bb46d1f0e149a0a380d0c50224d1e65ab7/sdk/aliyun_sdk_net.snk -------------------------------------------------------------------------------- /test/ConcurrencyTestConfig.xml: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | UniqueTest10Concurrency 5 | 10 6 | 7 | 40960 8 | 9 | 15 | 16 | DifferentTest10Concurrency 17 | 10 18 | 19 | 40960 20 | 21 | 22 | -------------------------------------------------------------------------------- /test/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Resources; 2 | using System.Reflection; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("Aliyun.OSS.Test")] 9 | [assembly: AssemblyDescription("Aliyun OSS SDK Test for C#")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("Alibaba Cloud Computing")] 12 | [assembly: AssemblyProduct("Aliyun.OSS.Test")] 13 | [assembly: AssemblyCopyright("Copyright © 2012")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("bb52666e-92e8-4f0f-906c-9dead305f82a")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("2.4.0")] 36 | [assembly: AssemblyFileVersion("2.4.0")] 37 | [assembly: NeutralResourcesLanguage("zh-CN")] 38 | 39 | -------------------------------------------------------------------------------- /test/TestCase/AccessKeyTestCase/AccessKeyTest.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.OSS; 2 | using Aliyun.OSS.Common; 3 | using Aliyun.OSS.Test.Util; 4 | 5 | using NUnit.Framework; 6 | 7 | namespace Aliyun.OSS.Test.TestClass.AccessKeyTestClass 8 | { 9 | [TestFixture] 10 | public class AccessKeyTest 11 | { 12 | [Test] 13 | public void InvalidAccessKeyIdTest() 14 | { 15 | try 16 | { 17 | //Key Id is invalid 18 | var ossClient = new OssClient(Config.Endpoint, "invalidKeyId", Config.AccessKeySecret); 19 | ossClient.ListBuckets(); 20 | Assert.Fail("Invalid key Id should not initialize OssClient successfully"); 21 | } 22 | catch (OssException e) 23 | { 24 | Assert.AreEqual(OssErrorCode.InvalidAccessKeyId, e.ErrorCode); 25 | } 26 | } 27 | 28 | [Test] 29 | public void InvalidAccessKeySecretTest() 30 | { 31 | try 32 | { 33 | //Key secret is invalid 34 | var ossClient = new OssClient(Config.Endpoint, Config.AccessKeyId, "invalidKeySecret"); 35 | ossClient.ListBuckets(); 36 | Assert.Fail("Invalid key secret should not initialize OssClient successfully"); 37 | } 38 | catch (OssException e) 39 | { 40 | Assert.AreEqual(OssErrorCode.SignatureDoesNotMatch, e.ErrorCode); 41 | } 42 | } 43 | 44 | [Test] 45 | public void DisabledAccessKeyTest() 46 | { 47 | try 48 | { 49 | //Key id/secret is valid but disabled 50 | var ossClient = new OssClient(Config.Endpoint, Config.DisabledAccessKeyId, Config.DisabledAccessKeySecret); 51 | ossClient.ListBuckets(); 52 | Assert.Fail("Disabled access key should not initialize OssClient successfully"); 53 | } 54 | catch(OssException e) 55 | { 56 | Assert.AreEqual(OssErrorCode.InvalidAccessKeyId, e.ErrorCode); 57 | } 58 | } 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /test/TestCase/BucketTestCase/BucketSettingsTest.cs: -------------------------------------------------------------------------------- 1 | using Aliyun.OSS; 2 | using Aliyun.OSS.Test.Util; 3 | 4 | using NUnit.Framework; 5 | 6 | namespace Aliyun.OSS.Test.TestClass.BucketTestClass 7 | { 8 | [TestFixture] 9 | public partial class BucketSettingsTest 10 | { 11 | private static IOss _ossClient; 12 | private static string _className; 13 | private static string _bucketName; 14 | 15 | [TestFixtureSetUp] 16 | public static void ClassInitialize() 17 | { 18 | //get a OSS client object 19 | _ossClient = OssClientFactory.CreateOssClient(); 20 | //prefix of bucket name used in current test class 21 | _className = TestContext.CurrentContext.Test.FullName; 22 | _className = _className.Substring(_className.LastIndexOf('.') + 1).ToLowerInvariant(); 23 | //create the bucket 24 | _bucketName = OssTestUtils.GetBucketName(_className); 25 | _ossClient.CreateBucket(_bucketName); 26 | } 27 | 28 | [TestFixtureTearDown] 29 | public static void ClassCleanup() 30 | { 31 | OssTestUtils.CleanBucket(_ossClient, _bucketName); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /test/Util/AccountSettings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | 3 | namespace Aliyun.OSS.Test.Util 4 | { 5 | internal class AccountSettings 6 | { 7 | public string OssEndpoint { get; set; } 8 | public string OssAccessKeyId { get; set; } 9 | public string OssAccessKeySecret { get; set; } 10 | 11 | public string ProxyHost { get; set; } 12 | public int ProxyPort { get; set; } 13 | public string ProxyUser { get; set; } 14 | public string ProxyPassword { get; set; } 15 | 16 | private AccountSettings() 17 | { 18 | } 19 | 20 | public static AccountSettings Load() 21 | { 22 | //setup an AccountSettings object with endpoint, accessKeyId, and accessKeySecret 23 | var accountSettings = new AccountSettings 24 | { 25 | OssEndpoint = Config.Endpoint, 26 | OssAccessKeyId = Config.AccessKeyId, 27 | OssAccessKeySecret = Config.AccessKeySecret 28 | }; 29 | //check if proxyHost and proxyPort has been configured, if yes, set proxyHost and proxyPort values 30 | if (string.IsNullOrEmpty(Config.ProxyHost) || string.IsNullOrEmpty(Config.ProxyPort)) 31 | return accountSettings; 32 | 33 | accountSettings.ProxyHost = Config.ProxyHost; 34 | int proxyPort; 35 | if (!Int32.TryParse(Config.ProxyPort, out proxyPort)) 36 | { 37 | throw new Exception("ProxyPort in configuration is not configured as a valid integer"); 38 | } 39 | accountSettings.ProxyPort = proxyPort; 40 | accountSettings.ProxyUser = Config.ProxyUser; 41 | accountSettings.ProxyPassword = Config.ProxyPassword; 42 | 43 | return accountSettings; 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /test/Util/Config.cs: -------------------------------------------------------------------------------- 1 | using System.Configuration; 2 | 3 | namespace Aliyun.OSS.Test.Util 4 | { 5 | public static class Config 6 | { 7 | public static readonly string Endpoint = ConfigurationManager.AppSettings["Endpoint"]; 8 | public static readonly string AccessKeyId = ConfigurationManager.AppSettings["AccessKeyId"]; 9 | public static readonly string AccessKeySecret = ConfigurationManager.AppSettings["AccessKeySecret"]; 10 | public static readonly string ProxyHost = ConfigurationManager.AppSettings["ProxyHost"]; 11 | public static readonly string ProxyPort = ConfigurationManager.AppSettings["ProxyPort"]; 12 | public static readonly string ProxyUser = ConfigurationManager.AppSettings["ProxyUser"]; 13 | public static readonly string ProxyPassword = ConfigurationManager.AppSettings["ProxyPassword"]; 14 | public static readonly string DisabledAccessKeyId = ConfigurationManager.AppSettings["DisabledAccessKeyId"]; 15 | public static readonly string DisabledAccessKeySecret = ConfigurationManager.AppSettings["DisabledAccessKeySecret"]; 16 | public static readonly string SecondEndpoint = ConfigurationManager.AppSettings["SecondEndpoint"]; 17 | public static readonly string UploadTestFile = ConfigurationManager.AppSettings["UploadTestFile"]; 18 | public static readonly string MultiUploadTestFile = ConfigurationManager.AppSettings["MultiUploadTestFile"]; 19 | public static readonly string DownloadFolder = ConfigurationManager.AppSettings["DownloadFolder"]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /test/Util/LogUtility.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | 4 | namespace Aliyun.OSS.Test.Util 5 | { 6 | public static class LogUtility 7 | { 8 | public static void LogMessage(string message) 9 | { 10 | Trace.TraceInformation(DateTime.Now + ": " + message); 11 | } 12 | 13 | public static void LogMessage(string message, params object[] args) 14 | { 15 | LogMessage(string.Format(message, args)); 16 | } 17 | 18 | public static void LogWarning(string message) 19 | { 20 | Trace.TraceWarning(DateTime.UtcNow + ": " + message); 21 | } 22 | 23 | public static void LogWarning(string message, params object[] args) 24 | { 25 | LogWarning(string.Format(message, args)); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /test/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/example.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Shirlman/aliyun-oss-unity-sdk/3ebf22bb46d1f0e149a0a380d0c50224d1e65ab7/test/example.jpg --------------------------------------------------------------------------------