Skip to content

Commit eaa8196

Browse files
authored
Merge pull request #3 from cnblogs/improve
Merge improve into master
2 parents 742f5a2 + fcbced4 commit eaa8196

23 files changed

+437
-275
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,4 +301,5 @@ $RECYCLE.BIN/
301301

302302
# Windows shortcuts
303303
*.lnk
304-
.vscode
304+
.vscode
305+
tests/Sample/appsettings.Development.json

.vscode/launch.json

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,28 @@
11
{
2-
"version": "0.2.0",
3-
"configurations": [
2+
// Use IntelliSense to find out which attributes exist for C# debugging
3+
// Use hover for the description of the existing attributes
4+
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
5+
"version": "0.2.0",
6+
"configurations": [
47
{
58
"name": ".NET Core Launch (console)",
69
"type": "coreclr",
710
"request": "launch",
811
"preLaunchTask": "build",
9-
"program": "${workspaceRoot}\\tests\\Sample\\bin\\Debug\\netcoreapp1.0\\Sample.dll",
12+
// If you have changed target frameworks, make sure to update the program path.
13+
"program": "${workspaceFolder}/tests/Sample/bin/Debug/netcoreapp2.0/Sample.dll",
1014
"args": [],
11-
"cwd": "${workspaceRoot}",
12-
"externalConsole": false,
15+
"cwd": "${workspaceFolder}/tests/Sample",
16+
// For more information about the 'console' field, see https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md#console-terminal-window
17+
"console": "internalConsole",
1318
"stopAtEntry": false,
1419
"internalConsoleOptions": "openOnSessionStart"
1520
},
1621
{
1722
"name": ".NET Core Attach",
1823
"type": "coreclr",
1924
"request": "attach",
20-
"processId": "${command.pickProcess}"
25+
"processId": "${command:pickProcess}"
2126
}
22-
]
27+
,]
2328
}

.vscode/tasks.json

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
{
2-
"version": "0.1.0",
3-
"command": "dotnet",
4-
"isShellCommand": true,
5-
"args": [],
2+
"version": "2.0.0",
63
"tasks": [
74
{
8-
"taskName": "build",
5+
"label": "build",
6+
"command": "dotnet",
7+
"type": "process",
98
"args": [
10-
"${workspaceRoot}\\tests\\Sample\\Sample.csproj"
9+
"build",
10+
"${workspaceFolder}/tests/Sample/Sample.csproj"
1111
],
12-
"isBuildCommand": true,
1312
"problemMatcher": "$msCompile"
1413
}
1514
]

Cuiliang.AliyunOssSdk.sln

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 15
4-
VisualStudioVersion = 15.0.26020.0
4+
VisualStudioVersion = 15.0.27130.2026
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cuiliang.AliyunOssSdk", "src\Cuiliang.AliyunOssSdk.csproj", "{07E0FD05-ED53-49DC-AD10-D24685A388D3}"
77
EndProject
8-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "tests\Sample\Sample.csproj", "{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}"
8+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Sample", "tests\Sample\Sample.csproj", "{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}"
99
EndProject
1010
Global
1111
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,30 +19,33 @@ Global
1919
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2020
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2121
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
22-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.ActiveCfg = Debug|x64
23-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.Build.0 = Debug|x64
24-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.ActiveCfg = Debug|x86
25-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.Build.0 = Debug|x86
22+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.ActiveCfg = Debug|Any CPU
23+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.Build.0 = Debug|Any CPU
24+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.ActiveCfg = Debug|Any CPU
25+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.Build.0 = Debug|Any CPU
2626
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
2727
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|Any CPU.Build.0 = Release|Any CPU
28-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.ActiveCfg = Release|x64
29-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.Build.0 = Release|x64
30-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.ActiveCfg = Release|x86
31-
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.Build.0 = Release|x86
28+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.ActiveCfg = Release|Any CPU
29+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.Build.0 = Release|Any CPU
30+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.ActiveCfg = Release|Any CPU
31+
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.Build.0 = Release|Any CPU
3232
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3333
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|Any CPU.Build.0 = Debug|Any CPU
34-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.ActiveCfg = Debug|x64
35-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.Build.0 = Debug|x64
36-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.ActiveCfg = Debug|x86
37-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.Build.0 = Debug|x86
34+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.ActiveCfg = Debug|Any CPU
35+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.Build.0 = Debug|Any CPU
36+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.ActiveCfg = Debug|Any CPU
37+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.Build.0 = Debug|Any CPU
3838
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|Any CPU.ActiveCfg = Release|Any CPU
3939
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|Any CPU.Build.0 = Release|Any CPU
40-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.ActiveCfg = Release|x64
41-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.Build.0 = Release|x64
42-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.ActiveCfg = Release|x86
43-
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.Build.0 = Release|x86
40+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.ActiveCfg = Release|Any CPU
41+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.Build.0 = Release|Any CPU
42+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.ActiveCfg = Release|Any CPU
43+
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.Build.0 = Release|Any CPU
4444
EndGlobalSection
4545
GlobalSection(SolutionProperties) = preSolution
4646
HideSolutionNode = FALSE
4747
EndGlobalSection
48+
GlobalSection(ExtensibilityGlobals) = postSolution
49+
SolutionGuid = {961F679A-9DCD-42D9-8CE7-5B3F6B9019AD}
50+
EndGlobalSection
4851
EndGlobal

src/Api/Base/BaseOssCommand.cs

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
2+
using System.IO;
23
using System.Net;
34
using System.Net.Http;
5+
using System.Text;
46
using System.Threading.Tasks;
57
using Cuiliang.AliyunOssSdk.Api.Common.Consts;
68
using Cuiliang.AliyunOssSdk.Entites;
@@ -42,7 +44,7 @@ public virtual async Task<OssResult<TResult>> ParseResultAsync(HttpResponseMessa
4244
var result = SerializeHelper.Deserialize<TResult>(await response.Content.ReadAsStreamAsync());
4345
var ossResult = new OssResult<TResult>()
4446
{
45-
IsSuccess = true,
47+
IsSuccess = true,
4648
SuccessResult = result
4749
};
4850

@@ -51,7 +53,7 @@ public virtual async Task<OssResult<TResult>> ParseResultAsync(HttpResponseMessa
5153

5254
return new OssResult<TResult>()
5355
{
54-
IsSuccess = false,
56+
IsSuccess = false,
5557
ErrorMessage = "ContentLength = 0"
5658
};
5759
}
@@ -60,24 +62,24 @@ public virtual async Task<OssResult<TResult>> ParseResultAsync(HttpResponseMessa
6062
/// 执行请求并返回结果
6163
/// </summary>
6264
/// <returns></returns>
63-
public async Task<OssResult<TResult>> ExecuteAsync()
65+
public async Task<OssResult<TResult>> ExecuteAsync(HttpClient client)
6466
{
6567
try
6668
{
6769
ServiceRequest request = BuildRequest();
6870

6971
//加入dateheader
72+
7073
request.Headers[HttpHeaders.Date] = DateUtils.FormatRfc822Date(DateTime.UtcNow);
71-
74+
7275

7376
if (RequestContext.OssCredential.UseToken)
7477
{
7578
request.Headers[HttpHeaders.SecurityToken] = RequestContext.OssCredential.SecurityToken;
7679
}
7780

78-
7981
// 发送请求
80-
var caller = new ServiceCaller(RequestContext);
82+
var caller = new ServiceCaller(RequestContext, client);
8183
HttpResponseMessage response = await caller.CallServiceAsync(request);
8284

8385
// 解析结果
@@ -92,7 +94,7 @@ public async Task<OssResult<TResult>> ExecuteAsync()
9294
ErrorMessage = ex.Message
9395
};
9496
}
95-
97+
9698
}
9799

98100
/// <summary>
@@ -110,17 +112,25 @@ private async Task<OssResult<TResult>> ProcessResponseInternal(HttpResponseMessa
110112
{
111113
return new OssResult<TResult>()
112114
{
113-
IsSuccess = false,
115+
IsSuccess = false,
114116
ErrorMessage = "NOT_MODIFIED"
115117
};
116-
}else
118+
}
119+
else
117120
{
118121
//错误的http代码
119122
if (response.Content?.Headers.ContentLength > 0)
120123
{
124+
//var responseContent = await response.Content.ReadAsStreamAsync();
125+
//var errorResult =
126+
// SerializeHelper.Deserialize<ErrorResult>(responseContent);
127+
128+
var responseContent = await response.Content.ReadAsStringAsync();
121129
var errorResult =
122-
SerializeHelper.Deserialize<ErrorResult>(await response.Content.ReadAsStreamAsync());
123-
130+
131+
SerializeHelper.Deserialize<ErrorResult>(responseContent);
132+
133+
124134
return new OssResult<TResult>()
125135
{
126136
IsSuccess = false,

src/Api/Object/Get/GetObjectCommand.cs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
using System.Net.Http;
1+
using System;
2+
using System.Diagnostics;
3+
using System.Globalization;
4+
using System.Linq;
5+
using System.Net.Http;
26
using System.Threading.Tasks;
37
using Cuiliang.AliyunOssSdk.Api.Base;
8+
using Cuiliang.AliyunOssSdk.Api.Common.Consts;
49
using Cuiliang.AliyunOssSdk.Entites;
510
using Cuiliang.AliyunOssSdk.Request;
11+
using Cuiliang.AliyunOssSdk.Utility;
612

713
namespace Cuiliang.AliyunOssSdk.Api.Object.Get
814
{
@@ -43,12 +49,47 @@ public override async Task<OssResult<GetObjectResult>> ParseResultAsync(HttpResp
4349
var result = new GetObjectResult();
4450
result.Headers = response.Headers;
4551
result.Content = response.Content;
52+
result.Metadata = Deserialize(response);
4653

4754
return new OssResult<GetObjectResult>()
4855
{
4956
IsSuccess = true,
5057
SuccessResult = result
5158
};
5259
}
60+
61+
private ObjectMetadata Deserialize(HttpResponseMessage response)
62+
{
63+
64+
var metadata = new ObjectMetadata();
65+
foreach (var header in response.Headers)
66+
{
67+
if (header.Key.StartsWith(OssHeaders.OssUserMetaPrefix, false, CultureInfo.InvariantCulture))
68+
{
69+
// The key of user in the metadata should not contain the prefix.
70+
metadata.UserMetadata.Add(header.Key.Substring(OssHeaders.OssUserMetaPrefix.Length),
71+
header.Value.FirstOrDefault());
72+
}
73+
else if (string.Equals(header.Key, HttpHeaders.ContentLength, StringComparison.InvariantCultureIgnoreCase))
74+
{
75+
// Content-Length. Parse should not fail.
76+
metadata.ContentLength = long.Parse(header.Value.FirstOrDefault(), CultureInfo.InvariantCulture);
77+
}
78+
else if (string.Equals(header.Key, HttpHeaders.ETag, StringComparison.InvariantCultureIgnoreCase))
79+
{
80+
metadata.ETag = OssUtils.TrimETag(header.Value.FirstOrDefault());
81+
}
82+
else if (string.Equals(header.Key, HttpHeaders.LastModified, StringComparison.InvariantCultureIgnoreCase))
83+
{
84+
metadata.LastModified = DateUtils.ParseRfc822Date(header.Value.FirstOrDefault());
85+
}
86+
else
87+
{
88+
// Treat the other headers just as strings.
89+
metadata.AddHeader(header.Key, header.Value);
90+
}
91+
}
92+
return metadata;
93+
}
5394
}
5495
}

src/Api/Object/Get/GetObjectResult.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Net.Http;
22
using System.Net.Http.Headers;
3+
using Cuiliang.AliyunOssSdk.Entites;
34

45
namespace Cuiliang.AliyunOssSdk.Api.Object.Get
56
{
@@ -9,6 +10,6 @@ public class GetObjectResult
910

1011
public HttpContent Content { get; set; }
1112

12-
13+
public ObjectMetadata Metadata { get; set; }
1314
}
1415
}

src/Cuiliang.AliyunOssSdk.csproj

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,18 @@
11
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
22
<PropertyGroup>
3-
<TargetFramework>netstandard1.6</TargetFramework>
4-
<NoWarn>$(NoWarn);CS1998</NoWarn>
5-
<AssemblyName>Cuiliang.AliyunOssSdk</AssemblyName>
6-
<PackageTargetFallback Condition=" '$(TargetFramework)' == 'netstandard1.6' ">$(PackageTargetFallback);dnxcore50</PackageTargetFallback>
7-
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
8-
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
9-
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
10-
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
3+
<Version>0.2.0</Version>
4+
<TargetFramework>netstandard2.0</TargetFramework>
115
<Authors>cuiliang.bj@gmail.com</Authors>
126
<Description>Aliyun oss sdk for dotnet core.</Description>
137
<PackageTags>Aliyun</PackageTags>
148
<RepositoryUrl>https://github.com/cuiliang/Cuiliang.AliyunOssSdk</RepositoryUrl>
9+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
1510
</PropertyGroup>
1611
<ItemGroup>
17-
<PackageReference Include="System.Collections.NonGeneric">
18-
<Version>4.3.0</Version>
19-
</PackageReference>
20-
<PackageReference Include="System.Runtime.Serialization.Xml">
21-
<Version>4.3.0</Version>
22-
</PackageReference>
23-
<PackageReference Include="System.Security.Cryptography.Primitives">
24-
<Version>4.3.0</Version>
25-
</PackageReference>
26-
<PackageReference Include="System.Threading.Thread">
27-
<Version>4.3.0</Version>
28-
</PackageReference>
29-
<PackageReference Include="System.Xml.XmlDocument">
30-
<Version>4.3.0</Version>
31-
</PackageReference>
32-
<PackageReference Include="System.Xml.XmlSerializer">
33-
<Version>4.3.0</Version>
34-
</PackageReference>
12+
<Folder Include="Properties\" />
3513
</ItemGroup>
36-
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
37-
<DefineConstants>$(DefineConstants);RELEASE</DefineConstants>
38-
</PropertyGroup>
14+
<ItemGroup>
15+
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.1.0" />
16+
<PackageReference Include="Microsoft.Extensions.Http" Version="2.1.0" />
17+
</ItemGroup>
3918
</Project>

src/Cuiliang.AliyunOssSdk.xproj

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/Entites/OssRegions.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ public class OssRegions
1717
// 华北 2
1818
public const string BeiJing = "oss-cn-beijing";
1919

20+
// 华北3 张家口
21+
public const string ZhangJiaKou = "oss-cn-zhangjiakou";
22+
23+
// 华北5 呼和浩特
24+
public const string HuHeHaoTe = "oss-cn-huhehaote";
25+
26+
27+
2028
// 华南 1
2129
public const string ShenZhen = "oss-cn-shenzhen";
2230

0 commit comments

Comments
 (0)