Skip to content

Commit

Permalink
更改目录,增加sample项目。
Browse files Browse the repository at this point in the history
  • Loading branch information
cuiliang committed Jan 20, 2017
1 parent 03540c8 commit 07c84a4
Show file tree
Hide file tree
Showing 65 changed files with 261 additions and 0 deletions.
48 changes: 48 additions & 0 deletions Cuiliang.AliyunOssSdk.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26020.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Cuiliang.AliyunOssSdk", "src\Cuiliang.AliyunOssSdk.csproj", "{07E0FD05-ED53-49DC-AD10-D24685A388D3}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sample", "tests\Sample\Sample.csproj", "{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|Any CPU = Release|Any CPU
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.ActiveCfg = Debug|x64
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x64.Build.0 = Debug|x64
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.ActiveCfg = Debug|x86
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Debug|x86.Build.0 = Debug|x86
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|Any CPU.Build.0 = Release|Any CPU
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.ActiveCfg = Release|x64
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x64.Build.0 = Release|x64
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.ActiveCfg = Release|x86
{07E0FD05-ED53-49DC-AD10-D24685A388D3}.Release|x86.Build.0 = Release|x86
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.ActiveCfg = Debug|x64
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x64.Build.0 = Debug|x64
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.ActiveCfg = Debug|x86
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Debug|x86.Build.0 = Debug|x86
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|Any CPU.Build.0 = Release|Any CPU
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.ActiveCfg = Release|x64
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x64.Build.0 = Release|x64
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.ActiveCfg = Release|x86
{A83B76BE-EAEA-4367-BC0C-28C20A9E6510}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
169 changes: 169 additions & 0 deletions tests/Sample/NewSdkTester.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
using Cuiliang.AliyunOssSdk;
using Cuiliang.AliyunOssSdk.Entites;
using System;
using System.Collections.Generic;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace Sample
{
class NewSdkTester
{
public static string AccessKeyId = ""; // 设置您的AccessKeyId

internal static string AssessSecret = ""; //设置您的AssessSecret

internal static string EndPoint = "oss-cn-shanghai.aliyuncs.com"; //设置要操作的区域


internal static string BucketName = ""; //设置要操作的BucketName


public static async Task RunAsync()
{



var crediential = new OssCredential()
{
AccessKeyId = AccessKeyId,
AccessKeySecret = AssessSecret
};

var client = new OssClient(crediential);

////list buckets
//var listBucketResult = await client.ListBucketsAsync(OssRegions.ShangHai);
//Console.WriteLine(listBucketResult.IsSuccess + ":" + listBucketResult.ErrorMessage);

var bucket = BucketInfo.CreateByRegion(EndPoint, BucketName, false, false);

// put string
{
string content = "这是一个文本文件\naaaaaaaa\nbbbbbb\nccccccccc";
var putResult = await client.PutObjectAsync(bucket, "test_put_object_string.txt", content);
Console.WriteLine($"Put string object {putResult.IsSuccess} {putResult.ErrorMessage} Etag:{putResult.SuccessResult?.ETag}");
}



//// put file
//var file = @"D:\Work\Weixin\resource\IMG_1399.png";
//putResult = await client.PutObjectByFileNameAsync(bucket, "test_put_file.png", file);
//Console.WriteLine($"Put file object {putResult.IsSuccess} {putResult.ErrorMessage} Etag:{putResult.SuccessResult?.ETag}");


//// copy file
//Console.WriteLine("\n\n===Copy Object=============");
//var copyResult =
// await
// client.CopyObjectAsync(bucket, "test_put_object_string.txt", bucket,
// "test_03_copy_object_string.txt", null);
//Console.WriteLine($"Copy object {copyResult.IsSuccess} {copyResult.ErrorMessage} Etag:{copyResult.SuccessResult?.LastModified}");

//// get file
//Console.WriteLine("\n\n===Get Object=============");
//var getResult = await client.GetObjectAsync(bucket, "test_put_object_string.txt");
//Console.WriteLine($"Get Object = {getResult.IsSuccess}");
//if (getResult.IsSuccess)
//{
// var content = await getResult.SuccessResult.Content.ReadAsStringAsync();
// Console.WriteLine("FileContent" + content);
//}

//// append file
//Console.WriteLine("\n\n===append Object=============");
//{
// var content = "This is a line 这是一行字符串.";
// var file = new OssObjectInfo()
// {
// ContentType = RequestContentType.String,
// MimeType = "text/text",
// StringContent = content
// };
// var appendResult = await client.AppendObject(bucket, "test_append_object.txt", 0, file);
// Console.WriteLine($"1st append:{appendResult.IsSuccess} nextPos={appendResult.SuccessResult?.NextAppendPosition}");
// if (appendResult.IsSuccess)
// {
// appendResult = await client.AppendObject(bucket, "test_append_object.txt", appendResult.SuccessResult.NextAppendPosition, file);
// Console.WriteLine($"2st append:{appendResult.IsSuccess} nextPos={appendResult.SuccessResult?.NextAppendPosition}");

// }
//}

//// delete object
//Console.WriteLine("\n\n===append Object=============");
//{
// var content = "This is a line 这是一行字符串.";
// var key = "test_delete_object.txt";
// var putResult = await client.PutObjectAsync(bucket, key, content);
// if (putResult.IsSuccess)
// {
// var deleteResult = await client.DeleteObjectAsync(bucket, key);
// Console.WriteLine($"Delete reuslt:{deleteResult.IsSuccess} {deleteResult.ErrorMessage}");
// }
// else
// {
// Console.WriteLine($" Put object failed.{putResult.ErrorMessage}");
// }
//}

//// delete multiple
//Console.WriteLine("\n\n===delete multiple=============");
//{
// var content = "This is a line 这是一行字符串.";

// IList<string> fielKeys = new List<string>();

// for (int i = 1; i < 10; i++)
// {
// var key = $"test_delete_multi_object_{i}.txt";
// var putResult = await client.PutObjectAsync(bucket, key, content);
// if (putResult.IsSuccess == false)
// {
// Console.WriteLine($" Put object {i} failed.{putResult.ErrorMessage}");
// return;
// }
// fielKeys.Add(key);
// }

// var deleteResult = await client.DeleteMultipleObjectsAsync(bucket, fielKeys, false);

// Console.WriteLine($"Delete multi:{deleteResult.IsSuccess} {deleteResult.ErrorMessage}");

//}


// head object
// delete multiple
Console.WriteLine("\n\n===head object=============");
{
var content = "This is a line 这是一行字符串.";
var key = "test_head_object.txt";
//var putResult = await client.PutObjectAsync(bucket, key, content);
//if (putResult.IsSuccess)
{
var headResult = await client.HeadObjectAsync(bucket, key, null);
Console.WriteLine($"Head object: {headResult.IsSuccess} {headResult.ErrorMessage}");
}

}


Console.WriteLine("\n\n===Get object meta=============");
{
//var content = "This is a line 这是一行字符串.";
var key = "test_get_meta_object.txt";
//var putResult = await client.PutObjectAsync(bucket, key, content);
//if (putResult.IsSuccess)
{
var headResult = await client.GetObjectMetaAsync(bucket, key);
Console.WriteLine($"Head object: {headResult.IsSuccess} {headResult.ErrorMessage}");
}

}

}
}
}
28 changes: 28 additions & 0 deletions tests/Sample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Threading.Tasks;
using Sample;

class Program
{
public static void Main(string[] args)
{
MainAsync(args).GetAwaiter().GetResult();

Console.ReadKey();
}

public static async Task MainAsync(string[] args)
{
try
{
await NewSdkTester.RunAsync();
}
catch (Exception ex)
{
Console.WriteLine("Ex:" + ex.Message);
throw;
}


}
}
16 changes: 16 additions & 0 deletions tests/Sample/Sample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp1.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<Compile Include="**\*.cs" />
<EmbeddedResource Include="**\*.resx" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NETCore.App" Version="1.0.1" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Cuiliang.AliyunOssSdk.csproj" />
</ItemGroup>
</Project>

0 comments on commit 07c84a4

Please sign in to comment.