首次推送
This commit is contained in:
44
.gitignore
vendored
Normal file
44
.gitignore
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
# IDE配置文件
|
||||
.idea/
|
||||
.vs/
|
||||
*.suo
|
||||
*.user
|
||||
|
||||
# 编译生成文件
|
||||
bin/
|
||||
obj/
|
||||
|
||||
# 临时文件
|
||||
*.cache
|
||||
|
||||
# 大文件
|
||||
*.zip
|
||||
*.apk
|
||||
|
||||
# 数据库文件
|
||||
App_Data/*.mdb
|
||||
App_Data/*.xls
|
||||
|
||||
# 其他临时文件
|
||||
*.log
|
||||
*.swp
|
||||
*.swo
|
||||
*~
|
||||
|
||||
# 操作系统文件
|
||||
Thumbs.db
|
||||
.DS_Store
|
||||
|
||||
# 环境变量文件
|
||||
.env
|
||||
|
||||
# 构建工具文件
|
||||
.nuget/
|
||||
.paket/
|
||||
|
||||
# 测试文件
|
||||
TestResults/
|
||||
coverage/
|
||||
|
||||
# 发布文件
|
||||
publish/
|
||||
5
COSXML/.nuspec
Normal file
5
COSXML/.nuspec
Normal file
@@ -0,0 +1,5 @@
|
||||
?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<dependencies>
|
||||
</dependencies>
|
||||
</package>
|
||||
132
COSXML/Auth/QCloudCredentialProvider.cs
Normal file
132
COSXML/Auth/QCloudCredentialProvider.cs
Normal file
@@ -0,0 +1,132 @@
|
||||
using System;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Utils;
|
||||
using COSXML.CosException;
|
||||
using COSXML.Common;
|
||||
using COSXML.Log;
|
||||
using System.IO;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/9/2018 12:16:20 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Auth
|
||||
{
|
||||
|
||||
public abstract class QCloudCredentialProvider
|
||||
{
|
||||
public abstract QCloudCredentials GetQCloudCredentials();
|
||||
|
||||
public abstract void Refresh();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 云 api
|
||||
/// </summary>
|
||||
public class DefaultQCloudCredentialProvider : QCloudCredentialProvider
|
||||
{
|
||||
private string secretId;
|
||||
|
||||
private string secretKey;
|
||||
|
||||
private long keyTimDuration;
|
||||
|
||||
public DefaultQCloudCredentialProvider(string secretId, string secretKey, long keyDurationSecond)
|
||||
{
|
||||
this.secretId = secretId;
|
||||
this.secretKey = secretKey;
|
||||
this.keyTimDuration = keyDurationSecond;
|
||||
}
|
||||
|
||||
public override QCloudCredentials GetQCloudCredentials()
|
||||
{
|
||||
long keyStartTime = TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
|
||||
long keyEndTime = keyStartTime + keyTimDuration;
|
||||
string keyTime = String.Format("{0};{1}", keyStartTime, keyEndTime);
|
||||
if (secretId == null) throw new CosClientException((int)CosClientError.INVALID_CREDENTIALS, "secretId == null");
|
||||
if (secretKey == null) throw new CosClientException((int)CosClientError.INVALID_CREDENTIALS, "secretKey == null");
|
||||
string signKey = DigestUtils.GetHamcSha1ToHexString(keyTime, Encoding.UTF8, secretKey, Encoding.UTF8);
|
||||
return new QCloudCredentials(secretId, signKey, keyTime);
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
{
|
||||
//TODO update value
|
||||
QLog.D("DefaultQCloudCredentialProvider", "need to update QCloudCredentials");
|
||||
//invoke SetSetQCloudCredential(string secretId, string secretKey, string keyTime)
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过 临时密钥
|
||||
/// </summary>
|
||||
public class DefaultSessionQCloudCredentialProvider : QCloudCredentialProvider
|
||||
{
|
||||
private string tmpSecretId;
|
||||
private string tmpSecretKey;
|
||||
private string keyTime;
|
||||
private string token;
|
||||
|
||||
public DefaultSessionQCloudCredentialProvider(string tmpSecretId, string tmpSecretKey, long tmpExpiredTime, string sessionToken)
|
||||
:this(tmpSecretId, tmpSecretKey, TimeUtils.GetCurrentTime(TimeUnit.SECONDS),tmpExpiredTime, sessionToken)
|
||||
{
|
||||
}
|
||||
|
||||
public DefaultSessionQCloudCredentialProvider(string tmpSecretId, string tmpSecretKey, long keyStartTimeSecond, long tmpExpiredTime, string sessionToken)
|
||||
{
|
||||
this.tmpSecretId = tmpSecretId;
|
||||
this.tmpSecretKey = tmpSecretKey;
|
||||
this.keyTime = String.Format("{0};{1}", keyStartTimeSecond, tmpExpiredTime);
|
||||
this.token = sessionToken;
|
||||
}
|
||||
|
||||
public override QCloudCredentials GetQCloudCredentials()
|
||||
{
|
||||
if (IsNeedUpdateNow()) Refresh();
|
||||
if (tmpSecretId == null) throw new CosClientException((int)CosClientError.INVALID_CREDENTIALS, "secretId == null");
|
||||
if (tmpSecretKey == null) throw new CosClientException((int)CosClientError.INVALID_CREDENTIALS, "secretKey == null");
|
||||
if (keyTime == null) throw new CosClientException((int)CosClientError.INVALID_CREDENTIALS, "keyTime == null");
|
||||
string signKey = DigestUtils.GetHamcSha1ToHexString(keyTime, Encoding.UTF8, tmpSecretKey, Encoding.UTF8);
|
||||
return new SessionQCloudCredentials(tmpSecretId, signKey, token, keyTime);
|
||||
}
|
||||
|
||||
public override void Refresh()
|
||||
{
|
||||
//TODO update value
|
||||
QLog.D("DefaultSessionQCloudCredentialProvider", "need to update QCloudCredentials");
|
||||
//invoke SetQCloudCredential(string tmpSecretId, string tmpSecretKey, string tmpkeyTime, string sessionToken)
|
||||
}
|
||||
|
||||
public bool IsNeedUpdateNow()
|
||||
{
|
||||
if (String.IsNullOrEmpty(keyTime) || String.IsNullOrEmpty(tmpSecretId) || String.IsNullOrEmpty(tmpSecretKey) || String.IsNullOrEmpty(token))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int index = keyTime.IndexOf(';');
|
||||
long endTime = -1L;
|
||||
long.TryParse(keyTime.Substring(index + 1), out endTime);
|
||||
long nowTime = TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
|
||||
if (endTime <= nowTime) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接复制临时密钥信息
|
||||
/// </summary>
|
||||
/// <param name="tmpSecretId">临时安全证书 Id</param>
|
||||
/// <param name="tmpSecretKey">临时安全证书 Key</param>
|
||||
/// <param name="tmpkeyTime">证书有效的期间</param>
|
||||
/// <param name="sessionToken">token 值</param>
|
||||
public void SetQCloudCredential(string tmpSecretId, string tmpSecretKey, string tmpkeyTime, string sessionToken)
|
||||
{
|
||||
this.tmpSecretId = tmpSecretId;
|
||||
this.tmpSecretKey = tmpSecretKey;
|
||||
this.token = sessionToken;
|
||||
this.keyTime = tmpkeyTime;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
47
COSXML/Auth/QCloudCredentials.cs
Normal file
47
COSXML/Auth/QCloudCredentials.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/9/2018 12:09:40 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Auth
|
||||
{
|
||||
/// <summary>
|
||||
/// cos 业务认证: secretId, signKey, keyTime
|
||||
/// signKey be calculated by secretKey and keyTime
|
||||
/// </summary>
|
||||
public class QCloudCredentials
|
||||
{
|
||||
public QCloudCredentials(string secretId, string signKey, string keyTime)
|
||||
{
|
||||
this.SecretId = secretId;
|
||||
this.SignKey = signKey;
|
||||
this.KeyTime = keyTime;
|
||||
}
|
||||
|
||||
public string SecretId
|
||||
{ get; private set; }
|
||||
|
||||
public string SignKey
|
||||
{ get; private set; }
|
||||
|
||||
public string KeyTime
|
||||
{ get; private set; }
|
||||
|
||||
}
|
||||
|
||||
public class SessionQCloudCredentials : QCloudCredentials
|
||||
{
|
||||
public SessionQCloudCredentials(string secretId, string signKey, string token, string keyTime) :
|
||||
base(secretId, signKey, keyTime)
|
||||
{
|
||||
this.Token = token;
|
||||
|
||||
}
|
||||
|
||||
public string Token
|
||||
{ get; private set; }
|
||||
}
|
||||
}
|
||||
382
COSXML/Auth/QCloudSigner.cs
Normal file
382
COSXML/Auth/QCloudSigner.cs
Normal file
@@ -0,0 +1,382 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using COSXML.Network;
|
||||
using COSXML.Common;
|
||||
using COSXML.Log;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/9/2018 4:30:34 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Auth
|
||||
{
|
||||
|
||||
public delegate void OnGetSign(Request request, string sign);
|
||||
|
||||
/// <summary>
|
||||
/// sign caculation
|
||||
/// </summary>
|
||||
public interface QCloudSigner
|
||||
{
|
||||
void Sign(Request request, QCloudSignSource qcloudSignSource, QCloudCredentials qcloudCredentials);
|
||||
}
|
||||
|
||||
public interface QCloudSignSource
|
||||
{
|
||||
string Source(Request request);
|
||||
}
|
||||
|
||||
public sealed class CosXmlSignSourceProvider : QCloudSignSource
|
||||
{
|
||||
private HashSet<string> parameterKeys;
|
||||
private HashSet<string> headerKeys;
|
||||
private string signTime;
|
||||
private string headerList;
|
||||
private string parameterList;
|
||||
|
||||
private Boolean signAll;
|
||||
|
||||
private String cosHost;
|
||||
|
||||
public OnGetSign onGetSign;
|
||||
|
||||
public CosXmlSignSourceProvider()
|
||||
{
|
||||
parameterKeys = new HashSet<string>();
|
||||
headerKeys = new HashSet<string>();
|
||||
this.signAll = true;
|
||||
}
|
||||
|
||||
public void setSignAll(Boolean signAll) {
|
||||
this.signAll = signAll;
|
||||
}
|
||||
|
||||
public void AddParameterKey(string key)
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
parameterKeys.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddParameterKeys(List<string> keys)
|
||||
{
|
||||
if (keys != null)
|
||||
{
|
||||
foreach (string key in keys) {
|
||||
this.parameterKeys.Add(key.ToLower());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeaderKey(string key)
|
||||
{
|
||||
if(key != null)
|
||||
{
|
||||
headerKeys.Add(key);
|
||||
}
|
||||
}
|
||||
|
||||
public void AddHeaderKeys(List<string> keys)
|
||||
{
|
||||
if (keys != null)
|
||||
{
|
||||
foreach (string key in keys) {
|
||||
this.headerKeys.Add(key.ToLower());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSignTime(string signTime)
|
||||
{
|
||||
if(signTime != null)
|
||||
{
|
||||
this.signTime = signTime;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSignTime(long signStartTime, long duration)
|
||||
{
|
||||
this.signTime = String.Format("{0};{1}",signStartTime, signStartTime + duration);
|
||||
}
|
||||
|
||||
public string GetSignTime()
|
||||
{
|
||||
return signTime;
|
||||
}
|
||||
|
||||
public string GetHeaderList()
|
||||
{
|
||||
return headerList;
|
||||
}
|
||||
|
||||
public string GetParameterList()
|
||||
{
|
||||
return parameterList;
|
||||
}
|
||||
|
||||
public void setCosHost(string host) {
|
||||
cosHost = host;
|
||||
}
|
||||
|
||||
public string Source(Request request)
|
||||
{
|
||||
|
||||
Dictionary<string, string> sourceHeaders = request.Headers;
|
||||
Dictionary<string, string> lowerKeySourceHeaders = new Dictionary<string, string>(sourceHeaders.Count);
|
||||
foreach (KeyValuePair<string, string> pair in sourceHeaders)
|
||||
{
|
||||
lowerKeySourceHeaders.Add(pair.Key.ToLower(), pair.Value);
|
||||
if (signAll) {
|
||||
headerKeys.Add(pair.Key.ToLower());
|
||||
}
|
||||
}
|
||||
try
|
||||
{
|
||||
lowerKeySourceHeaders.Add("host", cosHost);
|
||||
headerKeys.Add("host");
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
if (signAll) {
|
||||
try
|
||||
{
|
||||
long contentLength = 0;
|
||||
if (request.Body != null) {
|
||||
contentLength = request.Body.ContentLength;
|
||||
}
|
||||
if (contentLength > 0) {
|
||||
lowerKeySourceHeaders.Add("content-length", contentLength.ToString());
|
||||
headerKeys.Add("content-length");
|
||||
}
|
||||
}
|
||||
catch (Exception) {}
|
||||
}
|
||||
Dictionary<string, string> sourceParameters = request.Url.GetQueryParameters();
|
||||
Dictionary<string, string> lowerKeySourceParameters = new Dictionary<string, string>(sourceParameters.Count);
|
||||
foreach (KeyValuePair<string, string> pair in sourceParameters)
|
||||
{
|
||||
lowerKeySourceParameters.Add(pair.Key.ToLower(), pair.Value);
|
||||
if (signAll) {
|
||||
parameterKeys.Add(pair.Key.ToLower());
|
||||
}
|
||||
}
|
||||
string path = URLEncodeUtils.Decode(request.Url.Path);
|
||||
return GenerateSource(request.Method, path, lowerKeySourceParameters, lowerKeySourceHeaders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// $HttpString = [HttpMethod]\n[HttpURI]\n[HttpParameters]\n[HttpHeaders]\n
|
||||
/// </summary>
|
||||
/// <param name="method"></param>
|
||||
/// <param name="path"></param>
|
||||
/// <param name="queryParameters"></param>
|
||||
/// <param name="headers"></param>
|
||||
/// <returns></returns>
|
||||
public string GenerateSource(string method, string path, Dictionary<string, string> queryParameters, Dictionary<string, string> headers)
|
||||
{
|
||||
StringBuilder formatString = new StringBuilder();
|
||||
formatString.Append(method.ToLower()).Append('\n'); // method
|
||||
formatString.Append(path).Append('\n'); // path
|
||||
|
||||
//check header and parameter in request
|
||||
string headerResult = CheckHeaders(headers);
|
||||
string parameterResult = CheckParameters(queryParameters);
|
||||
|
||||
if (parameterResult != null) formatString.Append(parameterResult); // parameters
|
||||
formatString.Append('\n');
|
||||
if (headerResult != null) formatString.Append(headerResult); // headers
|
||||
formatString.Append('\n');
|
||||
StringBuilder stringToSign = new StringBuilder();
|
||||
stringToSign.Append(CosAuthConstants.SHA1).Append('\n');
|
||||
stringToSign.Append(signTime).Append('\n');
|
||||
stringToSign.Append(DigestUtils.GetSha1ToHexString(formatString.ToString(), Encoding.UTF8)).Append('\n');
|
||||
return stringToSign.ToString();
|
||||
}
|
||||
|
||||
public string CheckHeaders(Dictionary<string, string> sourceHeaders)
|
||||
{
|
||||
if (sourceHeaders == null) return null;
|
||||
|
||||
//将指定的headers 小写且排序
|
||||
List<String> keys = new List<String>(headerKeys);
|
||||
LowerAndSort(keys);
|
||||
|
||||
//计算结果
|
||||
string[] result = Calculate(keys, sourceHeaders, true);
|
||||
if (result != null)
|
||||
{
|
||||
headerList = result[1];
|
||||
return result[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string CheckParameters(Dictionary<string, string> sourceQueryParameters)
|
||||
{
|
||||
if (sourceQueryParameters == null) return null;
|
||||
|
||||
//将指定的parameter key 小写 且 排序
|
||||
List<String> keys = new List<String>(parameterKeys);
|
||||
LowerAndSort(keys);
|
||||
|
||||
//计算结果
|
||||
string[] result = Calculate(keys, sourceQueryParameters, false);
|
||||
if (result != null)
|
||||
{
|
||||
parameterList = result[1];
|
||||
return result[0];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public string[] Calculate(List<string> keys, Dictionary<string, string> dict, bool isNeedEncode)
|
||||
{
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
StringBuilder keyResultBuilder = new StringBuilder();
|
||||
foreach (string key in keys)
|
||||
{
|
||||
if (!dict.ContainsKey(key)) continue; // 排除一些不可能存在的key
|
||||
string value = dict[key];
|
||||
if (value != null)
|
||||
{
|
||||
if(isNeedEncode)resultBuilder.Append(key).Append('=').Append(URLEncodeUtils.Encode(value)).Append('&');
|
||||
else resultBuilder.Append(key).Append('=').Append(value).Append('&');
|
||||
keyResultBuilder.Append(key).Append(';');
|
||||
}
|
||||
}
|
||||
string result = resultBuilder.ToString();
|
||||
string keyResult = keyResultBuilder.ToString();
|
||||
if (result.EndsWith("&", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
result = result.Substring(0, result.Length - 1);
|
||||
keyResult = keyResult.Substring(0, keyResult.Length - 1);
|
||||
return new string[]{result, keyResult};
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 小写 排序
|
||||
/// </summary>
|
||||
/// <param name="list"></param>
|
||||
public void LowerAndSort(List<string> list)
|
||||
{
|
||||
if (list != null)
|
||||
{
|
||||
for (int i = 0, size = list.Count; i < size; i++)
|
||||
{
|
||||
list[i] = list[i].ToLower();
|
||||
}
|
||||
list.Sort(delegate(string strA, string strB)
|
||||
{
|
||||
return StringUtils.Compare(strA, strB, false);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public sealed class CosXmlSigner : QCloudSigner
|
||||
{
|
||||
public CosXmlSigner() { }
|
||||
|
||||
public void Sign(Request request, QCloudSignSource qcloudSignSource, QCloudCredentials qcloudCredentials)
|
||||
{
|
||||
if (request == null) throw new ArgumentNullException("Request == null");
|
||||
if (qcloudCredentials == null) throw new ArgumentNullException("QCloudCredentials == null");
|
||||
if(qcloudSignSource == null || !(qcloudSignSource is CosXmlSignSourceProvider)) throw new ArgumentNullException("CosXmlSourceProvider == null");
|
||||
CosXmlSignSourceProvider cosXmlSourceProvider = (CosXmlSignSourceProvider)qcloudSignSource;
|
||||
|
||||
string signTime = cosXmlSourceProvider.GetSignTime();
|
||||
if (signTime == null)
|
||||
{
|
||||
signTime = qcloudCredentials.KeyTime;
|
||||
cosXmlSourceProvider.SetSignTime(signTime);
|
||||
}
|
||||
string signature = DigestUtils.GetHamcSha1ToHexString(cosXmlSourceProvider.Source(request), Encoding.UTF8, qcloudCredentials.SignKey, Encoding.UTF8);
|
||||
StringBuilder signBuilder = new StringBuilder();
|
||||
|
||||
signBuilder.Append(CosAuthConstants.Q_SIGN_ALGORITHM).Append('=').Append(CosAuthConstants.SHA1).Append('&')
|
||||
.Append(CosAuthConstants.Q_AK).Append('=').Append(qcloudCredentials.SecretId).Append('&')
|
||||
.Append(CosAuthConstants.Q_SIGN_TIME).Append('=').Append(signTime).Append('&')
|
||||
.Append(CosAuthConstants.Q_KEY_TIME).Append('=').Append(qcloudCredentials.KeyTime).Append('&')
|
||||
.Append(CosAuthConstants.Q_HEADER_LIST).Append('=').Append(cosXmlSourceProvider.GetHeaderList()).Append('&')
|
||||
.Append(CosAuthConstants.Q_URL_PARAM_LIST).Append('=').Append(cosXmlSourceProvider.GetParameterList()).Append('&')
|
||||
.Append(CosAuthConstants.Q_SIGNATURE).Append('=').Append(signature);
|
||||
string sign = signBuilder.ToString();
|
||||
request.AddHeader(CosRequestHeaderKey.AUTHORIZAIION, sign);
|
||||
if(qcloudCredentials is SessionQCloudCredentials)
|
||||
{
|
||||
request.AddHeader(CosRequestHeaderKey.COS_SESSION_TOKEN,((SessionQCloudCredentials)qcloudCredentials).Token);
|
||||
}
|
||||
if (cosXmlSourceProvider.onGetSign != null)
|
||||
{
|
||||
cosXmlSourceProvider.onGetSign(request, sign);
|
||||
}
|
||||
}
|
||||
|
||||
public static string GenerateSign(string method, string path, Dictionary<string, string> queryParameters, Dictionary<string, string> headers,
|
||||
string signTime, QCloudCredentials qcloudCredentials)
|
||||
{
|
||||
if (qcloudCredentials == null) throw new ArgumentNullException("QCloudCredentials == null");
|
||||
CosXmlSignSourceProvider cosXmlSourceProvider = new CosXmlSignSourceProvider();
|
||||
if (signTime == null) signTime = qcloudCredentials.KeyTime;
|
||||
cosXmlSourceProvider.SetSignTime(signTime);
|
||||
if (headers != null)
|
||||
{
|
||||
foreach (string key in headers.Keys)
|
||||
{
|
||||
cosXmlSourceProvider.AddHeaderKey(key);
|
||||
}
|
||||
}
|
||||
if (queryParameters != null)
|
||||
{
|
||||
foreach (string key in queryParameters.Keys)
|
||||
{
|
||||
cosXmlSourceProvider.AddParameterKey(key);
|
||||
}
|
||||
}
|
||||
string signature = DigestUtils.GetHamcSha1ToHexString(cosXmlSourceProvider.GenerateSource(method, path, queryParameters, headers), Encoding.UTF8,
|
||||
qcloudCredentials.SignKey, Encoding.UTF8);
|
||||
|
||||
StringBuilder signBuilder = new StringBuilder();
|
||||
signBuilder.Append(CosAuthConstants.Q_SIGN_ALGORITHM).Append('=').Append(CosAuthConstants.SHA1).Append('&')
|
||||
.Append(CosAuthConstants.Q_AK).Append('=').Append(qcloudCredentials.SecretId).Append('&')
|
||||
.Append(CosAuthConstants.Q_SIGN_TIME).Append('=').Append(cosXmlSourceProvider.GetSignTime()).Append('&')
|
||||
.Append(CosAuthConstants.Q_KEY_TIME).Append('=').Append(qcloudCredentials.KeyTime).Append('&')
|
||||
.Append(CosAuthConstants.Q_HEADER_LIST).Append('=').Append(cosXmlSourceProvider.GetHeaderList()).Append('&')
|
||||
.Append(CosAuthConstants.Q_URL_PARAM_LIST).Append('=').Append(cosXmlSourceProvider.GetParameterList()).Append('&')
|
||||
.Append(CosAuthConstants.Q_SIGNATURE).Append('=').Append(signature);
|
||||
|
||||
if (qcloudCredentials is SessionQCloudCredentials)
|
||||
{
|
||||
signBuilder.Append("&").Append(CosRequestHeaderKey.COS_SESSION_TOKEN).Append("=").Append(((SessionQCloudCredentials)qcloudCredentials).Token);
|
||||
}
|
||||
return signBuilder.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class CosAuthConstants
|
||||
{
|
||||
public const string Q_SIGN_ALGORITHM = "q-sign-algorithm";
|
||||
|
||||
public const string Q_AK = "q-ak";
|
||||
|
||||
public const string Q_SIGN_TIME = "q-sign-time";
|
||||
|
||||
public const string Q_KEY_TIME = "q-key-time";
|
||||
|
||||
public const string Q_HEADER_LIST = "q-header-list";
|
||||
|
||||
public const string Q_URL_PARAM_LIST = "q-url-param-list";
|
||||
|
||||
public const string Q_SIGNATURE = "q-signature";
|
||||
|
||||
public const string SHA1 = "sha1";
|
||||
}
|
||||
}
|
||||
48
COSXML/COSXML.csproj
Normal file
48
COSXML/COSXML.csproj
Normal file
@@ -0,0 +1,48 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project Sdk="Microsoft.NET.Sdk" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<ProjectGuid>{FC694C68-F0E3-411F-8E6C-2E9F94826016}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>COSXML</RootNamespace>
|
||||
<AssemblyName>COSXML</AssemblyName>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
|
||||
<PackageId>Tencent.QCloud.Cos.Sdk</PackageId>
|
||||
<Version>5.4.11.0</Version>
|
||||
<Authors>Tencent</Authors>
|
||||
<Company>Tencent</Company>
|
||||
<description>Tencent Cloud COS(Cloud Object Service) .Net SDK</description>
|
||||
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>bin\Release\COSXML.xml</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Reference Include="COSXML">
|
||||
<HintPath>..\Mtxfw.VipSite\App_Data\COSXML.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
33
COSXML/Common/CosACL.cs
Normal file
33
COSXML/Common/CosACL.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 1:53:35 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosACL
|
||||
{
|
||||
/// <summary>
|
||||
/// 私有读写
|
||||
/// </summary>
|
||||
[CosValue("private")]
|
||||
PRIVATE = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 私有写公有读
|
||||
/// </summary>
|
||||
[CosValue("public-read")]
|
||||
PUBLIC_READ,
|
||||
|
||||
/// <summary>
|
||||
/// 公有读写
|
||||
/// </summary>
|
||||
[CosValue("public-read-write")]
|
||||
PUBLIC_READ_WRITE,
|
||||
}
|
||||
}
|
||||
46
COSXML/Common/CosClientError.cs
Normal file
46
COSXML/Common/CosClientError.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:19:06 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosClientError
|
||||
{
|
||||
[CosValue("InvalidArgument")]
|
||||
INVALID_ARGUMENT = 10000,
|
||||
|
||||
[CosValue("InvalidCredentials")]
|
||||
INVALID_CREDENTIALS = 10001,
|
||||
|
||||
[CosValue("BadRequest")]
|
||||
BAD_REQUEST = 10002,
|
||||
|
||||
[CosValue("SinkSourceNotFound")]
|
||||
SINK_SOURCE_NOT_FOUND = 10003,
|
||||
|
||||
[CosValue("InternalError")]
|
||||
INTERNA_LERROR = 20000,
|
||||
|
||||
[CosValue("ServerError")]
|
||||
SERVER_ERROR = 20001,
|
||||
|
||||
[CosValue("IOError")]
|
||||
IO_ERROR = 20002,
|
||||
|
||||
[CosValue("PoorNetwork")]
|
||||
POOR_NETWORK = 20003,
|
||||
|
||||
[CosValue("UserCancelled")]
|
||||
USER_CANCELLED = 30000,
|
||||
|
||||
[CosValue("AlreadyFinished")]
|
||||
ALREADY_FINISHED = 30001,
|
||||
}
|
||||
}
|
||||
34
COSXML/Common/CosGrantPermission.cs
Normal file
34
COSXML/Common/CosGrantPermission.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 2:30:52 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosGrantPermission
|
||||
{
|
||||
/// <summary>
|
||||
/// 只读权限
|
||||
/// </summary>
|
||||
[CosValue("READ")]
|
||||
READ = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 只写权限
|
||||
/// </summary>
|
||||
[CosValue("WRITE")]
|
||||
WRITE,
|
||||
|
||||
/// <summary>
|
||||
/// 读写权限
|
||||
/// </summary>
|
||||
[CosValue("FULL_CONTROL")]
|
||||
FULL_CONTROL
|
||||
}
|
||||
}
|
||||
22
COSXML/Common/CosMetaDataDirective.cs
Normal file
22
COSXML/Common/CosMetaDataDirective.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 2:49:33 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosMetaDataDirective
|
||||
{
|
||||
[CosValue("Copy")]
|
||||
COPY = 0,
|
||||
|
||||
[CosValue("Replaced")]
|
||||
REPLACED
|
||||
}
|
||||
}
|
||||
120
COSXML/Common/CosRegion.cs
Normal file
120
COSXML/Common/CosRegion.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/1/2018 9:48:15 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosRegion
|
||||
{
|
||||
/// <summary>
|
||||
/// 北京一区(华北)
|
||||
/// </summary>
|
||||
[CosValue("ap-beijing-1")]
|
||||
AP_Beijing_1 = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 北京
|
||||
/// </summary>
|
||||
[CosValue("ap-beijing")]
|
||||
AP_Beijing,
|
||||
|
||||
/// <summary>
|
||||
/// 上海(华东)
|
||||
/// </summary>
|
||||
[CosValue("ap-shanghai")]
|
||||
AP_Shanghai,
|
||||
|
||||
/// <summary>
|
||||
/// 广州(华南)
|
||||
/// </summary>
|
||||
[CosValue("ap-guangzhou")]
|
||||
AP_Guangzhou,
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
[CosValue("ap-guangzhou-2")]
|
||||
AP_Guangzhou_2,
|
||||
|
||||
/// <summary>
|
||||
/// 成都(西南)
|
||||
/// </summary>
|
||||
[CosValue("ap-chengdu")]
|
||||
AP_Chengdu,
|
||||
|
||||
/// <summary>
|
||||
/// 新加坡
|
||||
/// </summary>
|
||||
[CosValue("ap-singapore")]
|
||||
AP_Singapore,
|
||||
|
||||
/// <summary>
|
||||
/// 香港
|
||||
/// </summary>
|
||||
[CosValue("ap-hongkong")]
|
||||
AP_Hongkong,
|
||||
|
||||
/// <summary>
|
||||
/// 多伦多
|
||||
/// </summary>
|
||||
[CosValue("na-toronto")]
|
||||
NA_Toronto,
|
||||
|
||||
/// <summary>
|
||||
/// 法兰克福
|
||||
/// </summary>
|
||||
[CosValue("eu-frankfurt")]
|
||||
EU_Frankfurt,
|
||||
|
||||
[CosValue("ap-chongqing")]
|
||||
AP_Chongqing,
|
||||
|
||||
/// <summary>
|
||||
/// 孟买
|
||||
/// </summary>
|
||||
[CosValue("ap-mumbai")]
|
||||
AP_Mumbai,
|
||||
|
||||
/// <summary>
|
||||
/// 首尔
|
||||
/// </summary>
|
||||
[CosValue("ap-seoul")]
|
||||
AP_Seoul,
|
||||
|
||||
/// <summary>
|
||||
/// 硅谷
|
||||
/// </summary>
|
||||
[CosValue("na-siliconvalley")]
|
||||
NA_Siliconvalley,
|
||||
|
||||
/// <summary>
|
||||
/// 弗吉尼亚
|
||||
/// </summary>
|
||||
[CosValue("na-ashburn")]
|
||||
NA_Ashburn,
|
||||
|
||||
/// <summary>
|
||||
/// 曼谷
|
||||
/// </summary>
|
||||
[CosValue("ap-bangkok")]
|
||||
AP_Bangkok,
|
||||
|
||||
/// <summary>
|
||||
/// 莫斯科
|
||||
/// </summary>
|
||||
[CosValue("eu-moscow")]
|
||||
EU_Moscow,
|
||||
|
||||
/// <summary>
|
||||
/// 东京
|
||||
/// </summary>
|
||||
[CosValue("ap-tokyo")]
|
||||
AO_Tokyo,
|
||||
}
|
||||
}
|
||||
53
COSXML/Common/CosRequestHeaderKey.cs
Normal file
53
COSXML/Common/CosRequestHeaderKey.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public sealed class CosRequestHeaderKey
|
||||
{
|
||||
public const string COS_SESSION_TOKEN = "x-cos-security-token";
|
||||
public const string AUTHORIZAIION = "Authorization";
|
||||
public const string CONTENT_TYPE = "Content-Type";
|
||||
public const string X_COS_ACL = "x-cos-acl";
|
||||
public const string X_COS_GRANT_READ = "x-cos-grant-read";
|
||||
public const string X_COS_GRANT_WRITE = "x-cos-grant-write";
|
||||
public const string X_COS_GRANT_FULL_CONTROL = "x-cos-grant-full-control";
|
||||
public const string CACHE_CONTROL = "Cache-Control";
|
||||
public const string CONTENT_DISPOSITION = "Content-Disposition";
|
||||
public const string CONTENT_ENCODING = "Content-Encoding";
|
||||
public const string EXPIRES = "Expires";
|
||||
public const string X_COS_COPY_SOURCE = "x-cos-copy-source";
|
||||
public const string X_COS_METADATA_DIRECTIVE = "x-cos-metadata-directive";
|
||||
public const string X_COS_COPY_SOURCE_IF_MODIFIED_SINCE= "x-cos-copy-source-If-Modified-Since";
|
||||
public const string X_COS_COPY_SOURCE_IF_UNMODIFIED_SINCE = "x-cos-copy-source-If-Unmodified-Since";
|
||||
public const string X_COS_COPY_SOURCE_IF_MATCH = "x-cos-copy-source-If-Match";
|
||||
public const string X_COS_COPY_SOURCE_IF_NONE_MATCH = "x-cos-copy-source-If-None-Match";
|
||||
public const string X_COS_STORAGE_CLASS_ = "x-cos-storage-class";
|
||||
public const string X_COS_COPY_SOURCE_RANGE = "x-cos-copy-source-range";
|
||||
public const string X_COS_TRAFFIC_LIMIT = "x-cos-traffic-limit"; // 限速
|
||||
public const string ORIGIN = "Origin";
|
||||
public const string ACCESS_CONTROL_REQUEST_METHOD = "Access-Control-Request-Method";
|
||||
public const string ACCESS_CONTROL_REQUEST_HEADERS = "Access-Control-Request-Headers";
|
||||
public const string IF_MODIFIED_SINCE = "If-Modified-Since";
|
||||
public const string IF_UNMODIFIED_SINCE = "If-Unmodified-Since";
|
||||
public const string IF_MATCH = "If-Match";
|
||||
public const string IF_NONE_MATCH = "If-None-Match";
|
||||
public const string APPLICATION_XML = "application/xml";
|
||||
public const string TEXT_PLAIN = "text/plain";
|
||||
public const string APPLICATION_OCTET_STREAM = "application/octet-stream";
|
||||
public const string RANGE = "Range";
|
||||
public const string VERSION_ID = "versionId";
|
||||
public const string ENCODING_TYPE = "Encoding-type";
|
||||
public const string PART_NUMBER_MARKER = "part-number-marker";
|
||||
public const string MAX_PARTS = "max-parts";
|
||||
public const string CONTENT_MD5 = "Content-MD5";
|
||||
public const string RESPONSE_CONTENT_TYPE = "response-content-type";
|
||||
public const string RESPONSE_CONTENT_LANGUAGE = "response-content-language";
|
||||
public const string RESPONSE_CACHE_CONTROL = "response-cache-control";
|
||||
public const string RESPONSE_CONTENT_DISPOSITION = "response-content-disposition";
|
||||
public const string RESPONSE_CONTENT_ENCODING = "response-content-encoding";
|
||||
public const string RESPONSE_EXPIRES = "response-expires";
|
||||
}
|
||||
}
|
||||
21
COSXML/Common/CosRequestMethod.cs
Normal file
21
COSXML/Common/CosRequestMethod.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 2:42:24 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public sealed class CosRequestMethod
|
||||
{
|
||||
public const string GET = "GET";
|
||||
public const string POST = "POST";
|
||||
public const string PUT = "PUT";
|
||||
public const string DELETE = "DELETE";
|
||||
public const string HEAD = "HEAD";
|
||||
public const string OPTIONS = "OPTIONS";
|
||||
}
|
||||
}
|
||||
34
COSXML/Common/CosStorageClass.cs
Normal file
34
COSXML/Common/CosStorageClass.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 1:58:05 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public enum CosStorageClass
|
||||
{
|
||||
/// <summary>
|
||||
/// 标准储存
|
||||
/// </summary>
|
||||
[CosValue("Standard")]
|
||||
STANDARD = 0,
|
||||
|
||||
/// <summary>
|
||||
/// 低频存储
|
||||
/// </summary>
|
||||
[CosValue("Standard_IA")]
|
||||
STANDARD_IA = 1,
|
||||
|
||||
/// <summary>
|
||||
/// 归档储存
|
||||
/// </summary>
|
||||
[CosValue("ARCHIVE")]
|
||||
ARCHIVE
|
||||
}
|
||||
}
|
||||
44
COSXML/Common/CosVersion.cs
Normal file
44
COSXML/Common/CosVersion.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Diagnostics;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 2:34:04 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Common
|
||||
{
|
||||
public sealed class CosVersion
|
||||
{
|
||||
private static string SDKVersion = "5.4.11.0";
|
||||
|
||||
public static string GetUserAgent()
|
||||
{
|
||||
StringBuilder userAgent = new StringBuilder();
|
||||
userAgent.Append("cos-net-sdk").Append('.')
|
||||
.Append(SDKVersion);
|
||||
return userAgent.ToString();
|
||||
}
|
||||
|
||||
//public static string GetOsVersion()
|
||||
//{
|
||||
// try
|
||||
// {
|
||||
// var os = Environment.OSVersion;
|
||||
// return "windows " + os.Version.Major + "." + os.Version.Minor;
|
||||
// }
|
||||
// catch (InvalidOperationException)
|
||||
// {
|
||||
// return "Unknown OSVersion";
|
||||
// }
|
||||
//}
|
||||
|
||||
//public static string GetOsArchitecture()
|
||||
//{
|
||||
// return (IntPtr.Size == 8) ? "x86_64" : "x86";
|
||||
//}
|
||||
}
|
||||
}
|
||||
36
COSXML/CosException/CosClientException.cs
Normal file
36
COSXML/CosException/CosClientException.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 11:26:53 AM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.CosException
|
||||
{
|
||||
/// <summary>
|
||||
/// cosClientException for parametes in cos request.
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CosClientException : System.ApplicationException
|
||||
{
|
||||
/// <summary>
|
||||
/// errorCode is for client exception code.
|
||||
/// <see cref="Common.CosClientError"/>
|
||||
/// </summary>
|
||||
public int errorCode;
|
||||
|
||||
public CosClientException(int errorCode, string message)
|
||||
: base(message)
|
||||
{
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
|
||||
public CosClientException(int errorCode, string message, Exception cause)
|
||||
:base(message, cause)
|
||||
{
|
||||
this.errorCode = errorCode;
|
||||
}
|
||||
}
|
||||
}
|
||||
94
COSXML/CosException/CosServerException.cs
Normal file
94
COSXML/CosException/CosServerException.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.Serialization;
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 11:27:27 AM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.CosException
|
||||
{
|
||||
/// <summary>
|
||||
/// CosServerException for cos server error.
|
||||
/// <see cref="Model.Tag.CosServerError"/>
|
||||
/// </summary>
|
||||
[Serializable]
|
||||
public class CosServerException : System.ApplicationException
|
||||
{
|
||||
/// <summary>
|
||||
/// http status code
|
||||
/// </summary>
|
||||
public int statusCode;
|
||||
/// <summary>
|
||||
/// http status message
|
||||
/// </summary>
|
||||
public string statusMessage;
|
||||
/// <summary>
|
||||
/// cos server error code
|
||||
/// </summary>
|
||||
public string errorCode;
|
||||
/// <summary>
|
||||
/// cos server error message
|
||||
/// </summary>
|
||||
public string errorMessage;
|
||||
/// <summary>
|
||||
/// cos server requestId for tracking error
|
||||
/// </summary>
|
||||
public string requestId;
|
||||
/// <summary>
|
||||
/// cos server trace id
|
||||
/// </summary>
|
||||
public string traceId;
|
||||
/// <summary>
|
||||
/// cos server resuorce
|
||||
/// </summary>
|
||||
public string resource;
|
||||
|
||||
public CosServerException(int statusCode, string statusMessage, CosServerError serverError)
|
||||
:this(statusCode, statusMessage)
|
||||
{
|
||||
if (serverError != null)
|
||||
{
|
||||
this.resource = serverError.resource;
|
||||
this.errorCode = serverError.code;
|
||||
this.errorMessage = serverError.message;
|
||||
this.requestId = serverError.requestId;
|
||||
this.traceId = serverError.traceId;
|
||||
}
|
||||
}
|
||||
|
||||
public CosServerException(int statusCode, string statusMessage)
|
||||
: base("server exception: " + statusCode)
|
||||
{
|
||||
this.statusCode = statusCode;
|
||||
this.statusMessage = statusMessage;
|
||||
}
|
||||
|
||||
public void SetCosServerError(CosServerError serverError)
|
||||
{
|
||||
if (serverError != null)
|
||||
{
|
||||
this.resource = serverError.resource;
|
||||
this.errorCode = serverError.code;
|
||||
this.errorMessage = serverError.message;
|
||||
this.requestId = serverError.requestId;
|
||||
this.traceId = serverError.traceId;
|
||||
}
|
||||
}
|
||||
|
||||
public string GetInfo()
|
||||
{
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.Append("(")
|
||||
.Append("statusCode = ").Append(statusCode).Append(", statusMessage = ").Append(statusMessage)
|
||||
.Append(", errorCode = ").Append(errorCode).Append(", errorMessage = ").Append(errorMessage)
|
||||
.Append(", requestId = ").Append(requestId).Append(", traceId = ").Append(traceId)
|
||||
.Append(", resouce = ").Append(resource)
|
||||
.Append(")");
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
2802
COSXML/CosXml.cs
Normal file
2802
COSXML/CosXml.cs
Normal file
File diff suppressed because it is too large
Load Diff
187
COSXML/CosXmlConfig.cs
Normal file
187
COSXML/CosXmlConfig.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Network;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/6/2018 9:29:29 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML
|
||||
{
|
||||
public sealed class CosXmlConfig
|
||||
{
|
||||
private HttpClientConfig httpConfig;
|
||||
private string appid;
|
||||
private string region;
|
||||
private bool isHttps;
|
||||
private bool isDebug;
|
||||
public string endpointSuffix {get;}
|
||||
|
||||
public string host {get;}
|
||||
|
||||
private CosXmlConfig(Builder builder)
|
||||
{
|
||||
this.appid = builder.appid;
|
||||
this.region = builder.region;
|
||||
this.isHttps = builder.isHttps;
|
||||
this.httpConfig = builder.httpClientConfigBuilder.Build();
|
||||
this.isDebug = builder.isDebug;
|
||||
this.endpointSuffix = builder.endpointSuffix;
|
||||
this.host = builder.host;
|
||||
}
|
||||
|
||||
public string Appid
|
||||
{
|
||||
get { return appid; }
|
||||
}
|
||||
|
||||
public string Region
|
||||
{
|
||||
get { return region; }
|
||||
}
|
||||
|
||||
public bool IsHttps
|
||||
{
|
||||
get { return isHttps; }
|
||||
}
|
||||
|
||||
public HttpClientConfig HttpConfig
|
||||
{
|
||||
get { return httpConfig; }
|
||||
}
|
||||
|
||||
public bool IsDebugLog
|
||||
{
|
||||
get { return isDebug; }
|
||||
}
|
||||
|
||||
public sealed class Builder
|
||||
{
|
||||
internal string appid;
|
||||
internal string region;
|
||||
internal bool isHttps = false;
|
||||
internal HttpClientConfig.Builder httpClientConfigBuilder;
|
||||
internal bool isDebug = false;
|
||||
internal string endpointSuffix;
|
||||
internal string host;
|
||||
public Builder()
|
||||
{
|
||||
httpClientConfigBuilder = new HttpClientConfig.Builder();
|
||||
}
|
||||
/// <summary>
|
||||
/// cos 服务的Appid
|
||||
/// </summary>
|
||||
/// <param name="appid"></param>
|
||||
/// <returns></returns>
|
||||
public Builder SetAppid(string appid)
|
||||
{
|
||||
this.appid = appid;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// 存储桶所属地域
|
||||
/// <see cref="COSXML.Common.CosRegion"/>
|
||||
/// </summary>
|
||||
/// <param name="region"></param>
|
||||
/// <returns></returns>
|
||||
public Builder SetRegion(string region)
|
||||
{
|
||||
this.region = region;
|
||||
return this;
|
||||
}
|
||||
/// <summary>
|
||||
/// true:https请求
|
||||
/// </summary>
|
||||
/// <param name="isHttps"></param>
|
||||
/// <returns></returns>
|
||||
public Builder IsHttps(bool isHttps)
|
||||
{
|
||||
this.isHttps = isHttps;
|
||||
return this;
|
||||
}
|
||||
public Builder SetConnectionLimit(int connectionLimit)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetConnectionLimit(connectionLimit);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetMaxRetry(int maxRetry)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetMaxRetry(maxRetry);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetConnectionTimeoutMs(int connectionTimeoutMs)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetConnectionTimeoutMs(connectionTimeoutMs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetReadWriteTimeoutMs(int readWriteTimeoutMs)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetReadWriteTimeoutMs(readWriteTimeoutMs);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetProxyHost(string host)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetProxyHost(host);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetProxyPort(int port)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetProxyPort(port);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetProxyUserName(string userName)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetProxyUserName(userName);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetProxyUserPassword(string password)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetProxyUserPassword(password);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetProxyDomain(string domain)
|
||||
{
|
||||
this.httpClientConfigBuilder.SetProxyDomain(domain);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetAllowAutoRedirect(bool isAllow)
|
||||
{
|
||||
this.httpClientConfigBuilder.AllowAutoRedirect(isAllow);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder SetDebugLog(bool isDebug)
|
||||
{
|
||||
this.isDebug = isDebug;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setEndpointSuffix(string suffix) {
|
||||
this.endpointSuffix = suffix;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder setHost(string host) {
|
||||
this.host = host;
|
||||
return this;
|
||||
}
|
||||
|
||||
public CosXmlConfig Build()
|
||||
{
|
||||
return new CosXmlConfig(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
778
COSXML/CosXmlServer.cs
Normal file
778
COSXML/CosXmlServer.cs
Normal file
@@ -0,0 +1,778 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Network;
|
||||
using COSXML.Model;
|
||||
using COSXML.Model.Service;
|
||||
using COSXML.Model.Object;
|
||||
using COSXML.Model.Bucket;
|
||||
using COSXML.Auth;
|
||||
using COSXML.Log;
|
||||
using COSXML.Utils;
|
||||
using COSXML.CosException;
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Callback;
|
||||
|
||||
namespace COSXML
|
||||
{
|
||||
public class CosXmlServer : CosXml
|
||||
{
|
||||
private CosXmlConfig config;
|
||||
|
||||
private QCloudCredentialProvider qcloudCredentailProvider;
|
||||
|
||||
private HttpClient httpClient;
|
||||
|
||||
public CosXmlServer(CosXmlConfig config, QCloudCredentialProvider qcloudCredentailProvider)
|
||||
{
|
||||
if (config != null)
|
||||
{
|
||||
this.config = config;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.config = new CosXmlConfig.Builder().Build();
|
||||
}
|
||||
if(this.config.IsDebugLog)
|
||||
{
|
||||
QLog.AddLogAdapter(new LogImpl());
|
||||
}
|
||||
this.qcloudCredentailProvider = qcloudCredentailProvider;
|
||||
HttpClient.Init(this.config.HttpConfig, this.qcloudCredentailProvider);
|
||||
httpClient = HttpClient.GetInstance();
|
||||
}
|
||||
|
||||
private void CheckAppidAndRegion(CosRequest request)
|
||||
{
|
||||
request.serviceConfig = config;
|
||||
if (request.IsHttps == null)
|
||||
{
|
||||
request.IsHttps = config.IsHttps;
|
||||
}
|
||||
if (request is GetServiceRequest) return;
|
||||
if (request.APPID == null) request.APPID = config.Appid;
|
||||
if (request is ObjectRequest)
|
||||
{
|
||||
if (((ObjectRequest)request).Region == null)
|
||||
{
|
||||
((ObjectRequest)request).Region = config.Region;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (request is BucketRequest)
|
||||
{
|
||||
if (((BucketRequest)request).Region == null)
|
||||
{
|
||||
((BucketRequest)request).Region = config.Region;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private CosResult excute(CosRequest request, CosResult result)
|
||||
{
|
||||
CheckAppidAndRegion(request);
|
||||
httpClient.Excute(request, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void schedue(CosRequest request, CosResult result, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
CheckAppidAndRegion(request);
|
||||
httpClient.Schedue(request, result, successCallback, failCallback);
|
||||
}
|
||||
|
||||
public Model.Service.GetServiceResult GetService(Model.Service.GetServiceRequest request)
|
||||
{
|
||||
return (Model.Service.GetServiceResult)excute(request, new Model.Service.GetServiceResult());
|
||||
}
|
||||
|
||||
public void GetService(Model.Service.GetServiceRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetServiceResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketResult PutBucket(PutBucketRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketResult)excute(request, new Model.Bucket.PutBucketResult());
|
||||
}
|
||||
|
||||
public void PutBucket(PutBucketRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketResult DeleteBucket(DeleteBucketRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketResult)excute(request, new Model.Bucket.DeleteBucketResult());
|
||||
}
|
||||
|
||||
public void DeleteBucket(DeleteBucketRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteBucketResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public HeadBucketResult HeadBucket(HeadBucketRequest request)
|
||||
{
|
||||
return (Model.Bucket.HeadBucketResult)excute(request, new Model.Bucket.HeadBucketResult());
|
||||
}
|
||||
|
||||
public void HeadBucket(HeadBucketRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new HeadBucketResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketResult GetBucket(GetBucketRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketResult)excute(request, new Model.Bucket.GetBucketResult());
|
||||
}
|
||||
|
||||
public void GetBucket(GetBucketRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketLocationResult GetBucketLocation(GetBucketLocationRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketLocationResult)excute(request, new Model.Bucket.GetBucketLocationResult());
|
||||
}
|
||||
|
||||
public void GetBucketLocation(GetBucketLocationRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketLocationResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketACLResult PutBucketACL(PutBucketACLRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketACLResult)excute(request, new Model.Bucket.PutBucketACLResult());
|
||||
}
|
||||
|
||||
public void PutBucketACL(PutBucketACLRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketACLResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketACLResult GetBucketACL(GetBucketACLRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketACLResult)excute(request, new Model.Bucket.GetBucketACLResult());
|
||||
}
|
||||
|
||||
public void GetBucketACL(GetBucketACLRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketACLResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketCORSResult PutBucketCORS(PutBucketCORSRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketCORSResult)excute(request, new Model.Bucket.PutBucketCORSResult());
|
||||
}
|
||||
|
||||
public void PutBucketCORS(PutBucketCORSRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketCORSResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketCORSResult GetBucketCORS(GetBucketCORSRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketCORSResult)excute(request, new Model.Bucket.GetBucketCORSResult());
|
||||
}
|
||||
|
||||
public void GetBucketCORS(GetBucketCORSRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketCORSResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketCORSResult DeleteBucketCORS(DeleteBucketCORSRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketCORSResult)excute(request, new Model.Bucket.DeleteBucketCORSResult());
|
||||
}
|
||||
|
||||
public void DeleteBucketCORS(DeleteBucketCORSRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteBucketCORSResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketLifecycleResult PutBucketLifecycle(PutBucketLifecycleRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketLifecycleResult)excute(request, new Model.Bucket.PutBucketLifecycleResult());
|
||||
}
|
||||
|
||||
public void PutBucketLifecycle(PutBucketLifecycleRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketLifecycleResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketLifecycleResult GetBucketLifecycle(GetBucketLifecycleRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketLifecycleResult)excute(request, new Model.Bucket.GetBucketLifecycleResult());
|
||||
}
|
||||
|
||||
public void GetBucketLifecycle(GetBucketLifecycleRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketLifecycleResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketLifecycleResult DeleteBucketLifecycle(DeleteBucketLifecycleRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketLifecycleResult)excute(request, new Model.Bucket.DeleteBucketLifecycleResult());
|
||||
}
|
||||
|
||||
public void DeleteBucketLifecycle(DeleteBucketLifecycleRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteBucketLifecycleResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketReplicationResult PutBucketReplication(PutBucketReplicationRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketReplicationResult)excute(request, new Model.Bucket.PutBucketReplicationResult());
|
||||
}
|
||||
|
||||
public void PutBucketReplication(PutBucketReplicationRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketReplicationResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketReplicationResult GetBucketReplication(GetBucketReplicationRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketReplicationResult)excute(request, new Model.Bucket.GetBucketReplicationResult());
|
||||
}
|
||||
|
||||
|
||||
public void GetBucketReplication(GetBucketReplicationRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketReplicationResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketReplicationResult DeleteBucketReplication(DeleteBucketReplicationRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketReplicationResult)excute(request, new Model.Bucket.DeleteBucketReplicationResult());
|
||||
}
|
||||
|
||||
public void DeleteBucketReplication(DeleteBucketReplicationRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteBucketReplicationResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketVersioningResult PutBucketVersioning(PutBucketVersioningRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketVersioningResult)excute(request, new Model.Bucket.PutBucketVersioningResult());
|
||||
}
|
||||
|
||||
public void PutBucketVersioning(PutBucketVersioningRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutBucketVersioningResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketVersioningResult GetBucketVersioning(GetBucketVersioningRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketVersioningResult)excute(request, new Model.Bucket.GetBucketVersioningResult());
|
||||
}
|
||||
|
||||
public void GetBucketVersioning(GetBucketVersioningRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetBucketVersioningResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public ListBucketVersionsResult ListBucketVersions(ListBucketVersionsRequest request)
|
||||
{
|
||||
return (Model.Bucket.ListBucketVersionsResult)excute(request, new Model.Bucket.ListBucketVersionsResult());
|
||||
}
|
||||
|
||||
public void ListBucketVersions(ListBucketVersionsRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new ListBucketVersionsResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public ListMultiUploadsResult ListMultiUploads(ListMultiUploadsRequest request)
|
||||
{
|
||||
return (Model.Bucket.ListMultiUploadsResult)excute(request, new Model.Bucket.ListMultiUploadsResult());
|
||||
}
|
||||
|
||||
public void ListMultiUploads(ListMultiUploadsRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new ListMultiUploadsResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketPolicyResult DeleteBucketPolicy(DeleteBucketPolicyRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketPolicyResult)excute(request, new Model.Bucket.DeleteBucketPolicyResult());
|
||||
}
|
||||
|
||||
public void DeleteBucketPolicy(DeleteBucketPolicyRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteBucketPolicyResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutObjectResult PutObject(PutObjectRequest request)
|
||||
{
|
||||
return (Model.Object.PutObjectResult)excute(request, new Model.Object.PutObjectResult());
|
||||
}
|
||||
|
||||
public void PutObject(PutObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public HeadObjectResult HeadObject(HeadObjectRequest request)
|
||||
{
|
||||
return (Model.Object.HeadObjectResult)excute(request, new Model.Object.HeadObjectResult());
|
||||
}
|
||||
|
||||
public void HeadObject(HeadObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new HeadObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetObjectResult GetObject(GetObjectRequest request)
|
||||
{
|
||||
return (Model.Object.GetObjectResult)excute(request, new Model.Object.GetObjectResult());
|
||||
}
|
||||
|
||||
public void GetObject(GetObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutObjectACLResult PutObjectACL(PutObjectACLRequest request)
|
||||
{
|
||||
return (Model.Object.PutObjectACLResult)excute(request, new Model.Object.PutObjectACLResult());
|
||||
}
|
||||
|
||||
public void PutObjectACL(PutObjectACLRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PutObjectACLResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetObjectACLResult GetObjectACL(GetObjectACLRequest request)
|
||||
{
|
||||
return (Model.Object.GetObjectACLResult)excute(request, new Model.Object.GetObjectACLResult());
|
||||
}
|
||||
|
||||
public void GetObjectACL(GetObjectACLRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetObjectACLResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteObjectResult DeleteObject(DeleteObjectRequest request)
|
||||
{
|
||||
return (Model.Object.DeleteObjectResult)excute(request, new Model.Object.DeleteObjectResult());
|
||||
}
|
||||
|
||||
public void DeleteObject(DeleteObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteMultiObjectResult DeleteMultiObjects(DeleteMultiObjectRequest request)
|
||||
{
|
||||
return (Model.Object.DeleteMultiObjectResult)excute(request, new Model.Object.DeleteMultiObjectResult());
|
||||
}
|
||||
|
||||
public void DeleteMultiObjects(DeleteMultiObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new DeleteMultiObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public InitMultipartUploadResult InitMultipartUpload(InitMultipartUploadRequest request)
|
||||
{
|
||||
return (Model.Object.InitMultipartUploadResult)excute(request, new Model.Object.InitMultipartUploadResult());
|
||||
}
|
||||
|
||||
public void InitMultipartUpload(InitMultipartUploadRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new InitMultipartUploadResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public ListPartsResult ListParts(ListPartsRequest request)
|
||||
{
|
||||
return (Model.Object.ListPartsResult)excute(request, new Model.Object.ListPartsResult());
|
||||
}
|
||||
|
||||
public void ListParts(ListPartsRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new ListPartsResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public UploadPartResult UploadPart(UploadPartRequest request)
|
||||
{
|
||||
return (Model.Object.UploadPartResult)excute(request, new Model.Object.UploadPartResult());
|
||||
}
|
||||
|
||||
public void UploadPart(UploadPartRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new UploadPartResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public CompleteMultipartUploadResult CompleteMultiUpload(CompleteMultipartUploadRequest request)
|
||||
{
|
||||
return (Model.Object.CompleteMultipartUploadResult)excute(request, new Model.Object.CompleteMultipartUploadResult());
|
||||
}
|
||||
|
||||
public void CompleteMultiUpload(CompleteMultipartUploadRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new CompleteMultipartUploadResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public AbortMultipartUploadResult AbortMultiUpload(AbortMultipartUploadRequest request)
|
||||
{
|
||||
return (Model.Object.AbortMultipartUploadResult)excute(request, new Model.Object.AbortMultipartUploadResult());
|
||||
}
|
||||
|
||||
public void AbortMultiUpload(AbortMultipartUploadRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new AbortMultipartUploadResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public CopyObjectResult CopyObject(CopyObjectRequest request)
|
||||
{
|
||||
return (Model.Object.CopyObjectResult)excute(request, new Model.Object.CopyObjectResult());
|
||||
}
|
||||
|
||||
public void CopyObject(CopyObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new CopyObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public UploadPartCopyResult PartCopy(UploadPartCopyRequest request)
|
||||
{
|
||||
return (Model.Object.UploadPartCopyResult)excute(request, new Model.Object.UploadPartCopyResult());
|
||||
}
|
||||
|
||||
public void PartCopy(UploadPartCopyRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new UploadPartCopyResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public OptionObjectResult OptionObject(OptionObjectRequest request)
|
||||
{
|
||||
return (Model.Object.OptionObjectResult)excute(request, new Model.Object.OptionObjectResult());
|
||||
}
|
||||
|
||||
public void OptionObject(OptionObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new OptionObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PostObjectResult PostObject(PostObjectRequest request)
|
||||
{
|
||||
return (Model.Object.PostObjectResult)excute(request, new Model.Object.PostObjectResult());
|
||||
}
|
||||
|
||||
public void PostObject(PostObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new PostObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public RestoreObjectResult RestoreObject(RestoreObjectRequest request)
|
||||
{
|
||||
return (Model.Object.RestoreObjectResult)excute(request, new Model.Object.RestoreObjectResult());
|
||||
}
|
||||
|
||||
public void RestoreObject(RestoreObjectRequest request, Callback.OnSuccessCallback<CosResult> successCallback, Callback.OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new RestoreObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public string GenerateSign(string method, string key, Dictionary<string, string> queryParameters, Dictionary<string, string> headers, long signDurationSecond)
|
||||
{
|
||||
try
|
||||
{
|
||||
string signTime = null;
|
||||
if (signDurationSecond > 0)
|
||||
{
|
||||
long currentTimeSecond = TimeUtils.GetCurrentTime(TimeUnit.SECONDS);
|
||||
signTime = String.Format("{0};{1}", currentTimeSecond, currentTimeSecond + signDurationSecond);
|
||||
}
|
||||
Dictionary<string, string> encodeQuery = null;
|
||||
if (queryParameters != null)
|
||||
{
|
||||
encodeQuery = new Dictionary<string, string>(queryParameters.Count);
|
||||
foreach (KeyValuePair<string, string> keyValuePair in queryParameters)
|
||||
{
|
||||
encodeQuery[keyValuePair.Key] = URLEncodeUtils.Encode(keyValuePair.Value);
|
||||
}
|
||||
}
|
||||
return CosXmlSigner.GenerateSign(method, key, encodeQuery, headers, signTime, qcloudCredentailProvider.GetQCloudCredentials());
|
||||
}
|
||||
catch (CosClientException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public string GenerateSignURL(PreSignatureStruct preSignatureStruct)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (preSignatureStruct.httpMethod == null)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "httpMethod = null");
|
||||
}
|
||||
if (preSignatureStruct.key == null)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "key = null");
|
||||
}
|
||||
StringBuilder urlBuilder = new StringBuilder();
|
||||
if (preSignatureStruct.isHttps)
|
||||
{
|
||||
urlBuilder.Append("https://");
|
||||
}
|
||||
else
|
||||
{
|
||||
urlBuilder.Append("http://");
|
||||
}
|
||||
if (preSignatureStruct.host == null)
|
||||
{
|
||||
if (preSignatureStruct.bucket == null)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "bucket = null");
|
||||
}
|
||||
if (preSignatureStruct.bucket.EndsWith("-" + preSignatureStruct.appid))
|
||||
{
|
||||
urlBuilder.Append(preSignatureStruct.bucket);
|
||||
}
|
||||
else
|
||||
{
|
||||
urlBuilder.Append(preSignatureStruct.bucket).Append("-")
|
||||
.Append(preSignatureStruct.appid);
|
||||
}
|
||||
urlBuilder.Append(".cos.")
|
||||
.Append(preSignatureStruct.region)
|
||||
.Append(".myqcloud.com");
|
||||
}
|
||||
else
|
||||
{
|
||||
urlBuilder.Append(preSignatureStruct.host);
|
||||
}
|
||||
|
||||
if (!preSignatureStruct.key.StartsWith("/"))
|
||||
{
|
||||
preSignatureStruct.key = "/" + preSignatureStruct.key;
|
||||
}
|
||||
urlBuilder.Append(preSignatureStruct.key);
|
||||
|
||||
string sign = GenerateSign(preSignatureStruct.httpMethod, preSignatureStruct.key,
|
||||
preSignatureStruct.queryParameters, preSignatureStruct.headers, preSignatureStruct.signDurationSecond);
|
||||
|
||||
StringBuilder queryBuilder = new StringBuilder();
|
||||
if (preSignatureStruct.queryParameters != null && preSignatureStruct.queryParameters.Count > 0)
|
||||
{
|
||||
foreach (KeyValuePair<string, string> keyValuePair in preSignatureStruct.queryParameters)
|
||||
{
|
||||
queryBuilder.Append(keyValuePair.Key).Append('=').Append(URLEncodeUtils.Encode(keyValuePair.Value));
|
||||
queryBuilder.Append('&');
|
||||
}
|
||||
}
|
||||
queryBuilder.Append(sign);
|
||||
urlBuilder.Append("?").Append(queryBuilder.ToString());
|
||||
return urlBuilder.ToString();
|
||||
}
|
||||
catch (CosClientException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public string GetAccessURL(CosRequest request)
|
||||
{
|
||||
try
|
||||
{
|
||||
CheckAppidAndRegion(request);
|
||||
request.CheckParameters();
|
||||
StringBuilder urlBuilder = new StringBuilder();
|
||||
if (request.IsHttps != null && (bool)request.IsHttps)
|
||||
{
|
||||
urlBuilder.Append("https://");
|
||||
}
|
||||
else
|
||||
{
|
||||
urlBuilder.Append("http://");
|
||||
}
|
||||
urlBuilder.Append(request.GetHost());
|
||||
urlBuilder.Append(request.RequestPath);
|
||||
return urlBuilder.ToString();
|
||||
}
|
||||
catch (CosClientException)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, ex.Message, ex);
|
||||
}
|
||||
}
|
||||
|
||||
public void Cancel(CosRequest cosRequest)
|
||||
{
|
||||
if (cosRequest != null)
|
||||
{
|
||||
cosRequest.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public GetObjectBytesResult GetObject(GetObjectBytesRequest request)
|
||||
{
|
||||
return (Model.Object.GetObjectBytesResult)excute(request, new Model.Object.GetObjectBytesResult());
|
||||
}
|
||||
|
||||
public void GetObject(GetObjectBytesRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new GetObjectBytesResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketWebsiteResult putBucketWebsite(PutBucketWebsiteRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketWebsiteResult)excute(request, new Model.Bucket.PutBucketWebsiteResult());
|
||||
}
|
||||
|
||||
public void putBucketWebsiteAsync(PutBucketWebsiteRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.PutBucketWebsiteResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketWebsiteResult getBucketWebsite(GetBucketWebsiteRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketWebsiteResult)excute(request, new Model.Bucket.GetBucketWebsiteResult());
|
||||
}
|
||||
|
||||
public void getBucketWebsiteAsync(GetBucketWebsiteRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.GetBucketWebsiteResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketWebsiteResult deleteBucketWebsite(DeleteBucketWebsiteRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketWebsiteResult)excute(request, new Model.Bucket.DeleteBucketWebsiteResult());
|
||||
}
|
||||
|
||||
public void deleteBucketWebsiteAsync(DeleteBucketWebsiteRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.DeleteBucketWebsiteResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketLoggingResult putBucketLogging(PutBucketLoggingRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketLoggingResult)excute(request, new Model.Bucket.PutBucketLoggingResult());
|
||||
}
|
||||
|
||||
public void putBucketLoggingAsync(PutBucketLoggingRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.PutBucketLoggingResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketLoggingResult getBucketLogging(GetBucketLoggingRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketLoggingResult)excute(request, new Model.Bucket.GetBucketLoggingResult());
|
||||
}
|
||||
|
||||
public void getBucketLoggingAsync(GetBucketLoggingRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.GetBucketLoggingResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketInventoryResult putBucketInventory(PutBucketInventoryRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketInventoryResult)excute(request, new Model.Bucket.PutBucketInventoryResult());
|
||||
}
|
||||
|
||||
public void putBucketInventoryAsync(PutBucketInventoryRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.PutBucketInventoryResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketInventoryResult getBucketInventory(GetBucketInventoryRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketInventoryResult)excute(request, new Model.Bucket.GetBucketInventoryResult());
|
||||
}
|
||||
|
||||
public void getBucketInventoryAsync(GetBucketInventoryRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.GetBucketInventoryResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketInventoryResult deleteBucketInventory(DeleteBucketInventoryRequest request)
|
||||
{
|
||||
return (Model.Bucket.DeleteBucketInventoryResult)excute(request, new Model.Bucket.DeleteBucketInventoryResult());
|
||||
}
|
||||
|
||||
public void deleteInventoryAsync(DeleteBucketInventoryRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.DeleteBucketInventoryResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public ListBucketInventoryResult listBucketInventory(ListBucketInventoryRequest request)
|
||||
{
|
||||
return (Model.Bucket.ListBucketInventoryResult)excute(request, new Model.Bucket.ListBucketInventoryResult());
|
||||
}
|
||||
|
||||
public void listBucketInventoryAsync(ListBucketInventoryRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.ListBucketInventoryResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketTaggingResult putBucketTagging(PutBucketTaggingRequest request) {
|
||||
return (Model.Bucket.PutBucketTaggingResult)excute(request, new Model.Bucket.PutBucketTaggingResult());
|
||||
}
|
||||
|
||||
public void putBucketTaggingAsync(PutBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback) {
|
||||
schedue(request, new Model.Bucket.PutBucketTaggingResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketTaggingResult getBucketTagging(GetBucketTaggingRequest request) {
|
||||
return (Model.Bucket.GetBucketTaggingResult)excute(request, new Model.Bucket.GetBucketTaggingResult());
|
||||
}
|
||||
|
||||
public void getBucketTaggingAsync(GetBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback) {
|
||||
schedue(request, new Model.Bucket.GetBucketTaggingResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public DeleteBucketTaggingResult deleteBucketTagging(DeleteBucketTaggingRequest request) {
|
||||
return (Model.Bucket.DeleteBucketTaggingResult)excute(request, new Model.Bucket.DeleteBucketTaggingResult());
|
||||
}
|
||||
|
||||
public void deleteBucketTaggingAsync(DeleteBucketTaggingRequest request, COSXML.Callback.OnSuccessCallback<CosResult> successCallback, COSXML.Callback.OnFailedCallback failCallback) {
|
||||
schedue(request, new Model.Bucket.DeleteBucketTaggingResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public PutBucketDomainResult putBucketDomain(PutBucketDomainRequest request)
|
||||
{
|
||||
return (Model.Bucket.PutBucketDomainResult)excute(request, new Model.Bucket.PutBucketDomainResult());
|
||||
}
|
||||
|
||||
public void putBucketDomainAsync(PutBucketDomainRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.PutBucketDomainResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
public GetBucketDomainResult getBucketDomain(GetBucketDomainRequest request)
|
||||
{
|
||||
return (Model.Bucket.GetBucketDomainResult)excute(request, new Model.Bucket.GetBucketDomainResult());
|
||||
}
|
||||
|
||||
public void getBucketDomainAsync(GetBucketDomainRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Bucket.GetBucketDomainResult(), successCallback, failCallback);
|
||||
}
|
||||
|
||||
SelectObjectResult CosXml.selectObject(SelectObjectRequest request)
|
||||
{
|
||||
return (Model.Object.SelectObjectResult)excute(request, new Model.Object.SelectObjectResult());
|
||||
}
|
||||
|
||||
void CosXml.selectObjectAsync(SelectObjectRequest request, OnSuccessCallback<CosResult> successCallback, OnFailedCallback failCallback)
|
||||
{
|
||||
schedue(request, new Model.Object.SelectObjectResult(), successCallback, failCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
55
COSXML/Listener/CosCallback.cs
Normal file
55
COSXML/Listener/CosCallback.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using COSXML.Model;
|
||||
using COSXML.CosException;
|
||||
using System.IO;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/21/2018 10:12:14 AM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Callback
|
||||
{
|
||||
/// <summary>
|
||||
/// progress
|
||||
/// </summary>
|
||||
/// <param name="completed"></param>
|
||||
/// <param name="total"></param>
|
||||
public delegate void OnProgressCallback(long completed, long total);
|
||||
|
||||
/// <summary>
|
||||
/// notify has been got response
|
||||
/// </summary>
|
||||
public delegate void OnNotifyGetResponse();
|
||||
|
||||
/// <summary>
|
||||
/// success
|
||||
/// </summary>
|
||||
/// <typeparam name="T1"></typeparam>
|
||||
/// <typeparam name="T2"></typeparam>
|
||||
/// <param name="cosRequest"></param>
|
||||
/// <param name="cosResult"></param>
|
||||
public delegate void OnSuccessCallback<T>(T cosResult)
|
||||
where T : CosResult;
|
||||
|
||||
/// <summary>
|
||||
/// failed
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
/// <param name="cosRequest"></param>
|
||||
/// <param name="clientException"></param>
|
||||
/// <param name="serverException"></param>
|
||||
public delegate void OnFailedCallback (CosClientException clientException, CosServerException serverException);
|
||||
|
||||
/// <summary>
|
||||
/// parse stream
|
||||
/// </summary>
|
||||
/// <param name="inputStream"></param>
|
||||
/// <param name="contentType"></param>
|
||||
/// <param name="contentLength"></param>
|
||||
/// <exception cref="CosServerException">throw CosServerException</exception>
|
||||
/// <exception cref="CosClientException">throw CosClientException</exception>
|
||||
/// <exception cref="Exception"> throw Excetpion</exception>
|
||||
public delegate void OnParseStream(Stream inputStream, string contentType, long contentLength);
|
||||
}
|
||||
117
COSXML/Model/Bucket/BucketRequest.cs
Normal file
117
COSXML/Model/Bucket/BucketRequest.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.CosException;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:03:59 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/**
|
||||
* Buceket request for cos
|
||||
* base class
|
||||
* provider bucket,region property
|
||||
*/
|
||||
public abstract class BucketRequest : CosRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// cos 存储桶,即 Bucket
|
||||
/// </summary>
|
||||
protected string bucket;
|
||||
|
||||
/// <summary>
|
||||
/// Bucket 所在的地域
|
||||
/// </summary>
|
||||
protected string region;
|
||||
|
||||
public BucketRequest(string bucket)
|
||||
{
|
||||
this.bucket = bucket;
|
||||
this.path = "/";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bucket 名称, "BucketName-APPID"
|
||||
/// </summary>
|
||||
public string Bucket
|
||||
{
|
||||
get { return this.bucket; }
|
||||
set { this.bucket = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bucket 所在地域
|
||||
/// <see cref="COSXML.Common.CosRegion"/>
|
||||
/// </summary>
|
||||
public string Region
|
||||
{
|
||||
get { return this.region; }
|
||||
set { this.region = value; }
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
public override string GetCOSHost() {
|
||||
StringBuilder hostBuilder = new StringBuilder();
|
||||
hostBuilder.Append(bucket);
|
||||
if (!String.IsNullOrEmpty(appid) && !bucket.EndsWith("-" + appid))
|
||||
{
|
||||
hostBuilder.Append("-")
|
||||
.Append(appid);
|
||||
}
|
||||
hostBuilder.Append(".cos.")
|
||||
.Append(region)
|
||||
.Append(".myqcloud.com");
|
||||
return hostBuilder.ToString();
|
||||
}
|
||||
|
||||
public override string GetHost()
|
||||
{
|
||||
StringBuilder hostBuilder = new StringBuilder();
|
||||
if (!String.IsNullOrEmpty(serviceConfig.host)) {
|
||||
hostBuilder.Append(serviceConfig.host);
|
||||
} else {
|
||||
hostBuilder.Append(bucket);
|
||||
if (!String.IsNullOrEmpty(appid) && !bucket.EndsWith("-" + appid))
|
||||
{
|
||||
hostBuilder.Append("-")
|
||||
.Append(appid);
|
||||
}
|
||||
if (serviceConfig.endpointSuffix != null) {
|
||||
hostBuilder.Append(".")
|
||||
.Append(serviceConfig.endpointSuffix);
|
||||
} else {
|
||||
hostBuilder.Append(".cos.")
|
||||
.Append(region)
|
||||
.Append(".myqcloud.com");
|
||||
}
|
||||
}
|
||||
return hostBuilder.ToString();
|
||||
}
|
||||
|
||||
public override void CheckParameters()
|
||||
{
|
||||
if (requestUrlWithSign != null) return;
|
||||
//if (appid == null)
|
||||
//{
|
||||
// throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "appid is null");
|
||||
//}
|
||||
if (bucket == null)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "bucket is null");
|
||||
}
|
||||
// if (region == null)
|
||||
// {
|
||||
// throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "region is null");
|
||||
// }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/DeleteBucketCORSRequest.cs
Normal file
25
COSXML/Model/Bucket/DeleteBucketCORSRequest.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:33:02 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket CORS
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8283"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketCORSRequest : BucketRequest
|
||||
{
|
||||
public DeleteBucketCORSRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("cors", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
COSXML/Model/Bucket/DeleteBucketCORSResult.cs
Normal file
19
COSXML/Model/Bucket/DeleteBucketCORSResult.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:37:56 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket CORS 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8283"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketCORSResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
26
COSXML/Model/Bucket/DeleteBucketInventoryRequest.cs
Normal file
26
COSXML/Model/Bucket/DeleteBucketInventoryRequest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketInventoryRequest : BucketRequest
|
||||
{
|
||||
public DeleteBucketInventoryRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("inventory", null);
|
||||
}
|
||||
|
||||
public void SetInventoryId(string inventoryId)
|
||||
{
|
||||
if (inventoryId != null)
|
||||
{
|
||||
SetQueryParameter("id", inventoryId);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
11
COSXML/Model/Bucket/DeleteBucketInventoryResult.cs
Normal file
11
COSXML/Model/Bucket/DeleteBucketInventoryResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketInventoryResult : CosResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
26
COSXML/Model/Bucket/DeleteBucketLifecycleRequest.cs
Normal file
26
COSXML/Model/Bucket/DeleteBucketLifecycleRequest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:39:37 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket Lifecycle
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8284"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketLifecycleRequest : BucketRequest
|
||||
{
|
||||
public DeleteBucketLifecycleRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("lifecycle", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
COSXML/Model/Bucket/DeleteBucketLifecycleResult.cs
Normal file
19
COSXML/Model/Bucket/DeleteBucketLifecycleResult.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:40:44 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket Lifecycle 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8284"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketLifecycleResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/DeleteBucketPolicyRequest.cs
Normal file
25
COSXML/Model/Bucket/DeleteBucketPolicyRequest.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/12/2018 9:22:06 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket 权限策略
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8285"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketPolicyRequest : BucketRequest
|
||||
{
|
||||
public DeleteBucketPolicyRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("policy", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
18
COSXML/Model/Bucket/DeleteBucketPolicyResult.cs
Normal file
18
COSXML/Model/Bucket/DeleteBucketPolicyResult.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/12/2018 9:23:46 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 Bucket 权限策略返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8285"/>
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketPolicyResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
22
COSXML/Model/Bucket/DeleteBucketReplicationRequest.cs
Normal file
22
COSXML/Model/Bucket/DeleteBucketReplicationRequest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:44:41 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketReplicationRequest : BucketRequest
|
||||
{
|
||||
public DeleteBucketReplicationRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("replication", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
15
COSXML/Model/Bucket/DeleteBucketReplicationResult.cs
Normal file
15
COSXML/Model/Bucket/DeleteBucketReplicationResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 8:48:08 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketReplicationResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/DeleteBucketRequest.cs
Normal file
25
COSXML/Model/Bucket/DeleteBucketRequest.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 9:03:15 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketRequest : BucketRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 空 Bucket
|
||||
/// </summary>
|
||||
/// <param name="bucket"></param>
|
||||
public DeleteBucketRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
}
|
||||
}
|
||||
}
|
||||
18
COSXML/Model/Bucket/DeleteBucketResult.cs
Normal file
18
COSXML/Model/Bucket/DeleteBucketResult.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 9:04:44 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 删除 空 Bucket返回的结果
|
||||
/// </summary>
|
||||
public sealed class DeleteBucketResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
19
COSXML/Model/Bucket/DeleteBucketTaggingRequest.cs
Normal file
19
COSXML/Model/Bucket/DeleteBucketTaggingRequest.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketTaggingRequest:BucketRequest
|
||||
{
|
||||
public DeleteBucketTaggingRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("tagging", null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
8
COSXML/Model/Bucket/DeleteBucketTaggingResult.cs
Normal file
8
COSXML/Model/Bucket/DeleteBucketTaggingResult.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketTaggingResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
17
COSXML/Model/Bucket/DeleteBucketWebsiteRequest.cs
Normal file
17
COSXML/Model/Bucket/DeleteBucketWebsiteRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketWebsiteRequest:BucketRequest
|
||||
{
|
||||
public DeleteBucketWebsiteRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
this.queryParameters.Add("website", null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
8
COSXML/Model/Bucket/DeleteBucketWebsiteResult.cs
Normal file
8
COSXML/Model/Bucket/DeleteBucketWebsiteResult.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class DeleteBucketWebsiteResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
26
COSXML/Model/Bucket/GetBucketACLRequest.cs
Normal file
26
COSXML/Model/Bucket/GetBucketACLRequest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 9:07:34 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 的访问权限控制列表
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7733"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketACLRequest : BucketRequest
|
||||
{
|
||||
public GetBucketACLRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("acl", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
COSXML/Model/Bucket/GetBucketACLResult.cs
Normal file
38
COSXML/Model/Bucket/GetBucketACLResult.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using System.IO;
|
||||
using COSXML.Transfer;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 9:08:55 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 访问权限列表返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7733"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketACLResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 访问权限列表信息
|
||||
/// <see cref="COSXML.Model.Tag.AccessControlPolicy"/>
|
||||
/// </summary>
|
||||
public AccessControlPolicy accessControlPolicy;
|
||||
|
||||
internal override void ParseResponseBody(Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
accessControlPolicy = new AccessControlPolicy();
|
||||
XmlParse.ParseAccessControlPolicy(inputStream, accessControlPolicy);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (accessControlPolicy == null ? "" : "\n" + accessControlPolicy.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
26
COSXML/Model/Bucket/GetBucketCORSRequest.cs
Normal file
26
COSXML/Model/Bucket/GetBucketCORSRequest.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 9:59:44 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket CORS 配置信息
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8274"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketCORSRequest : BucketRequest
|
||||
{
|
||||
public GetBucketCORSRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("cors", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
38
COSXML/Model/Bucket/GetBucketCORSResult.cs
Normal file
38
COSXML/Model/Bucket/GetBucketCORSResult.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 10:01:37 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket CORS 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8274"/>
|
||||
/// </summary>
|
||||
public class GetBucketCORSResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 跨域资源共享配置的所有信息,最多可以包含100条 CORSRule
|
||||
/// <see cref="COSXML.Model.Tag.CORSConfiguration"/>
|
||||
/// </summary>
|
||||
public CORSConfiguration corsConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
corsConfiguration = new CORSConfiguration();
|
||||
XmlParse.ParseCORSConfiguration(inputStream, corsConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (corsConfiguration == null ? "" : "\n " + corsConfiguration.GetInfo());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
18
COSXML/Model/Bucket/GetBucketDomainRequest.cs
Normal file
18
COSXML/Model/Bucket/GetBucketDomainRequest.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketDomainRequest :BucketRequest
|
||||
{
|
||||
public GetBucketDomainRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("domain", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/GetBucketDomainResult.cs
Normal file
21
COSXML/Model/Bucket/GetBucketDomainResult.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketDomainResult : CosResult
|
||||
{
|
||||
public DomainConfiguration domainConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
domainConfiguration = new DomainConfiguration();
|
||||
XmlParse.ParseBucketDomain(inputStream, domainConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (domainConfiguration == null ? "" : "\n" + domainConfiguration.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
24
COSXML/Model/Bucket/GetBucketInventoryRequest.cs
Normal file
24
COSXML/Model/Bucket/GetBucketInventoryRequest.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketInventoryRequest : BucketRequest
|
||||
{
|
||||
public GetBucketInventoryRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("inventory", null);
|
||||
}
|
||||
|
||||
public void SetInventoryId(string inventoryId)
|
||||
{
|
||||
if (inventoryId != null)
|
||||
{
|
||||
SetQueryParameter("id", inventoryId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/GetBucketInventoryResult.cs
Normal file
21
COSXML/Model/Bucket/GetBucketInventoryResult.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketInventoryResult : CosResult
|
||||
{
|
||||
|
||||
public InventoryConfiguration inventoryConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
inventoryConfiguration = new InventoryConfiguration();
|
||||
XmlParse.ParseInventoryConfiguration(inputStream, inventoryConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (inventoryConfiguration == null ? "" : "\n" + inventoryConfiguration.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
22
COSXML/Model/Bucket/GetBucketLifecycleRequest.cs
Normal file
22
COSXML/Model/Bucket/GetBucketLifecycleRequest.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 Bucket 的生命周期配置
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8278"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketLifecycleRequest : BucketRequest
|
||||
{
|
||||
public GetBucketLifecycleRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("lifecycle", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
COSXML/Model/Bucket/GetBucketLifecycleResult.cs
Normal file
33
COSXML/Model/Bucket/GetBucketLifecycleResult.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 Bucket 的生命周期配置 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8278"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketLifecycleResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 生命周期配置信息
|
||||
/// <see cref="COSXML.Model.Tag.LifecycleConfiguration"/>
|
||||
/// </summary>
|
||||
public LifecycleConfiguration lifecycleConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
lifecycleConfiguration = new LifecycleConfiguration();
|
||||
XmlParse.ParseLifecycleConfiguration(inputStream, lifecycleConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (lifecycleConfiguration == null ? "" : "\n " + lifecycleConfiguration.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/GetBucketLocationRequest.cs
Normal file
21
COSXML/Model/Bucket/GetBucketLocationRequest.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 地域信息
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8275"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketLocationRequest : BucketRequest
|
||||
{
|
||||
public GetBucketLocationRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("location", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
33
COSXML/Model/Bucket/GetBucketLocationResult.cs
Normal file
33
COSXML/Model/Bucket/GetBucketLocationResult.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 Bucket 地域信息返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8275"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketLocationResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 地域信息
|
||||
/// <see cref="COSXML.Model.Tag.LocationConstraint"/>
|
||||
/// </summary>
|
||||
public LocationConstraint locationConstraint;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
locationConstraint = new LocationConstraint();
|
||||
XmlParse.ParseLocationConstraint(inputStream, locationConstraint);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (locationConstraint == null ? "" : "\n" + locationConstraint.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
16
COSXML/Model/Bucket/GetBucketLoggingRequest.cs
Normal file
16
COSXML/Model/Bucket/GetBucketLoggingRequest.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketLoggingRequest : BucketRequest
|
||||
{
|
||||
public GetBucketLoggingRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("logging", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
23
COSXML/Model/Bucket/GetBucketLoggingResult.cs
Normal file
23
COSXML/Model/Bucket/GetBucketLoggingResult.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketLoggingResult : CosResult
|
||||
{
|
||||
public BucketLoggingStatus bucketLoggingStatus;
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
bucketLoggingStatus = new BucketLoggingStatus();
|
||||
XmlParse.ParseBucketLoggingStatus(inputStream, bucketLoggingStatus);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (bucketLoggingStatus == null ? "" : "\n" + bucketLoggingStatus.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/GetBucketPolicyRequest.cs
Normal file
21
COSXML/Model/Bucket/GetBucketPolicyRequest.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 权限策略
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8276"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketPolicyRequest : BucketRequest
|
||||
{
|
||||
public GetBucketPolicyRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("policy", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
14
COSXML/Model/Bucket/GetBucketPolicyResult.cs
Normal file
14
COSXML/Model/Bucket/GetBucketPolicyResult.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 权限策略
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8276"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketPolicyResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
18
COSXML/Model/Bucket/GetBucketReplicationRequest.cs
Normal file
18
COSXML/Model/Bucket/GetBucketReplicationRequest.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketReplicationRequest : BucketRequest
|
||||
{
|
||||
public GetBucketReplicationRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("replication", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/GetBucketReplicationResult.cs
Normal file
25
COSXML/Model/Bucket/GetBucketReplicationResult.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketReplicationResult : CosResult
|
||||
{
|
||||
public ReplicationConfiguration replicationConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
replicationConfiguration = new ReplicationConfiguration();
|
||||
XmlParse.ParseReplicationConfiguration(inputStream, replicationConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (replicationConfiguration == null ? "" : "\n" + replicationConfiguration.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
84
COSXML/Model/Bucket/GetBucketRequest.cs
Normal file
84
COSXML/Model/Bucket/GetBucketRequest.cs
Normal file
@@ -0,0 +1,84 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 中对象列表
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7734"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketRequest : BucketRequest
|
||||
{
|
||||
public GetBucketRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("max-keys", 1000.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 前缀匹配,用来规定返回的文件前缀地址
|
||||
/// </summary>
|
||||
/// <param name="prefix"></param>
|
||||
public void SetPrefix(string prefix)
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
SetQueryParameter("prefix", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定界符为一个符号,
|
||||
/// 如果有 Prefix,则将 Prefix 到 delimiter 之间的相同路径归为一类,定义为 Common Prefix,然后列出所有 Common Prefix。
|
||||
/// 如果没有 Prefix,则从路径起点开始
|
||||
/// </summary>
|
||||
/// <param name="delimiter"></param>
|
||||
public void SetDelimiter(string delimiter)
|
||||
{
|
||||
if (delimiter != null)
|
||||
{
|
||||
SetQueryParameter("delimiter", delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 规定返回值的编码方式,可选值:url
|
||||
/// </summary>
|
||||
/// <param name="encodingType"></param>
|
||||
public void SetEncodingType(string encodingType)
|
||||
{
|
||||
if (encodingType != null)
|
||||
{
|
||||
SetQueryParameter("encoding-type", encodingType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 默认以 UTF-8 二进制顺序列出条目,所有列出条目从 marker 开始
|
||||
/// </summary>
|
||||
/// <param name="marker"></param>
|
||||
public void SetMarker(string marker)
|
||||
{
|
||||
if (marker != null)
|
||||
{
|
||||
SetQueryParameter("marker", marker);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 单次返回最大的条目数量,默认 1000
|
||||
/// </summary>
|
||||
/// <param name="maxKeys"></param>
|
||||
public void SetMaxKeys(string maxKeys)
|
||||
{
|
||||
if (maxKeys != null)
|
||||
{
|
||||
SetQueryParameter("max-keys", maxKeys);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
COSXML/Model/Bucket/GetBucketResult.cs
Normal file
34
COSXML/Model/Bucket/GetBucketResult.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
using System.IO;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 获取 Bucket 对象列表返回的jieguo
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7734"/>
|
||||
/// </summary>
|
||||
public sealed class GetBucketResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 保存 Get Bucket 请求结果的所有信息
|
||||
/// <see cref="COSXML.Model.Tag.ListBucket"/>
|
||||
/// </summary>
|
||||
public ListBucket listBucket;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
listBucket = new ListBucket();
|
||||
XmlParse.ParseListBucket(inputStream, listBucket);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (listBucket == null ? "" : "\n" + listBucket.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
17
COSXML/Model/Bucket/GetBucketTaggingRequest.cs
Normal file
17
COSXML/Model/Bucket/GetBucketTaggingRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketTaggingRequest : BucketRequest
|
||||
{
|
||||
public GetBucketTaggingRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("tagging", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
20
COSXML/Model/Bucket/GetBucketTaggingResult.cs
Normal file
20
COSXML/Model/Bucket/GetBucketTaggingResult.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketTaggingResult : CosResult
|
||||
{
|
||||
public Tagging tagging;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
tagging = new Tagging();
|
||||
XmlParse.ParseTagging(inputStream, tagging);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
COSXML/Model/Bucket/GetBucketVersioningRequest.cs
Normal file
17
COSXML/Model/Bucket/GetBucketVersioningRequest.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketVersioningRequest : BucketRequest
|
||||
{
|
||||
public GetBucketVersioningRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("versioning", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/GetBucketVersioningResult.cs
Normal file
25
COSXML/Model/Bucket/GetBucketVersioningResult.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketVersioningResult : CosResult
|
||||
{
|
||||
public VersioningConfiguration versioningConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
versioningConfiguration = new VersioningConfiguration();
|
||||
XmlParse.ParseVersioningConfiguration(inputStream, versioningConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (versioningConfiguration == null ? "" : "\n" + versioningConfiguration.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
16
COSXML/Model/Bucket/GetBucketWebsiteRequest.cs
Normal file
16
COSXML/Model/Bucket/GetBucketWebsiteRequest.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketWebsiteRequest :BucketRequest
|
||||
{
|
||||
public GetBucketWebsiteRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("website", null);
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/GetBucketWebsiteResult.cs
Normal file
21
COSXML/Model/Bucket/GetBucketWebsiteResult.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class GetBucketWebsiteResult : CosResult
|
||||
{
|
||||
public WebsiteConfiguration websiteConfiguration;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
websiteConfiguration = new WebsiteConfiguration();
|
||||
XmlParse.ParseWebsiteConfig(inputStream, websiteConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (websiteConfiguration == null ? "" : "\n" + websiteConfiguration.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/HeadBucketRequest.cs
Normal file
21
COSXML/Model/Bucket/HeadBucketRequest.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 检索 Bucket 是否存在
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7735"/>
|
||||
/// </summary>
|
||||
public sealed class HeadBucketRequest : BucketRequest
|
||||
{
|
||||
public HeadBucketRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.HEAD;
|
||||
}
|
||||
}
|
||||
}
|
||||
16
COSXML/Model/Bucket/HeadBucketResult.cs
Normal file
16
COSXML/Model/Bucket/HeadBucketResult.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 检索 Bucket 是否存在的返回结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7735"/>
|
||||
/// </summary>
|
||||
public sealed class HeadBucketResult : CosResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/ListBucketInventoryRequest.cs
Normal file
25
COSXML/Model/Bucket/ListBucketInventoryRequest.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class ListBucketInventoryRequest: BucketRequest
|
||||
{
|
||||
private String continuationToken;
|
||||
public ListBucketInventoryRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("inventory", null);
|
||||
}
|
||||
|
||||
public void SetContinuationToken(String continuationToken)
|
||||
{
|
||||
if (continuationToken != null)
|
||||
{
|
||||
SetQueryParameter("continuation-token", continuationToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
COSXML/Model/Bucket/ListBucketInventoryResult.cs
Normal file
21
COSXML/Model/Bucket/ListBucketInventoryResult.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class ListBucketInventoryResult : CosResult
|
||||
{
|
||||
public ListInventoryConfiguration listInventoryConfiguration;
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
listInventoryConfiguration = new ListInventoryConfiguration();
|
||||
XmlParse.ParseListInventoryConfiguration(inputStream, listInventoryConfiguration);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (listInventoryConfiguration == null ? "" : "\n" + listInventoryConfiguration.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
70
COSXML/Model/Bucket/ListBucketVersionsRequest.cs
Normal file
70
COSXML/Model/Bucket/ListBucketVersionsRequest.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class ListBucketVersionsRequest : BucketRequest
|
||||
{
|
||||
public ListBucketVersionsRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("versions", null);
|
||||
}
|
||||
|
||||
public void SetPrefix(string prefix)
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
SetQueryParameter("prefix", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetKeyMarker(string keyMarker)
|
||||
{
|
||||
if (keyMarker != null)
|
||||
{
|
||||
SetQueryParameter("key-marker", keyMarker);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetVersionIdMarker(string versionIdMarker)
|
||||
{
|
||||
if (versionIdMarker != null)
|
||||
{
|
||||
SetQueryParameter("version-id-marker", versionIdMarker);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDelimiter(string delimiter)
|
||||
{
|
||||
if (delimiter != null)
|
||||
{
|
||||
SetQueryParameter("delimiter", delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetEncodingType(string encodingType)
|
||||
{
|
||||
if (encodingType != null)
|
||||
{
|
||||
SetQueryParameter("encoding-type", encodingType);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetMaxKeys(string maxKeys)
|
||||
{
|
||||
if (maxKeys != null)
|
||||
{
|
||||
SetQueryParameter("max-keys", maxKeys);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetQueryParameter("max-keys", "1000");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
25
COSXML/Model/Bucket/ListBucketVersionsResult.cs
Normal file
25
COSXML/Model/Bucket/ListBucketVersionsResult.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Transfer;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class ListBucketVersionsResult :CosResult
|
||||
{
|
||||
public ListBucketVersions listBucketVersions;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
listBucketVersions = new ListBucketVersions();
|
||||
XmlParse.ParseListBucketVersions(inputStream, listBucketVersions);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (listBucketVersions == null ? "" : "\n" + listBucketVersions.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
104
COSXML/Model/Bucket/ListMultiUploadsRequest.cs
Normal file
104
COSXML/Model/Bucket/ListMultiUploadsRequest.cs
Normal file
@@ -0,0 +1,104 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 Bucket 正在进行中的分块上传
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7736"/>
|
||||
/// </summary>
|
||||
public sealed class ListMultiUploadsRequest : BucketRequest
|
||||
{
|
||||
public ListMultiUploadsRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.bucket = bucket;
|
||||
this.method = CosRequestMethod.GET;
|
||||
this.queryParameters.Add("uploads", null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定界符为一个符号,
|
||||
/// 对 Object 名字包含指定前缀且第一次出现 delimiter 字符之间的 Object 作为一组元素:common prefix。
|
||||
/// 如果没有 prefix,则从路径起点开始
|
||||
/// </summary>
|
||||
/// <param name="delimiter"></param>
|
||||
public void SetDelimiter(string delimiter)
|
||||
{
|
||||
if (delimiter != null)
|
||||
{
|
||||
SetQueryParameter("delimiter", delimiter);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 规定返回值的编码格式,合法值:url
|
||||
/// </summary>
|
||||
/// <param name="encodingType"></param>
|
||||
public void SetEncodingType(string encodingType)
|
||||
{
|
||||
if (encodingType != null)
|
||||
{
|
||||
SetQueryParameter("Encoding-type", encodingType);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 与 upload-id-marker 一起使用.
|
||||
/// 当 upload-id-marker 未被指定时,ObjectName 字母顺序大于 key-marker 的条目将被列出.
|
||||
/// 当upload-id-marker被指定时,ObjectName 字母顺序大于key-marker的条目被列出,
|
||||
/// ObjectName 字母顺序等于 key-marker 同时 UploadID 大于 upload-id-marker 的条目将被列出。
|
||||
/// </summary>
|
||||
/// <param name="keyMarker"></param>
|
||||
public void SetKeyMarker(string keyMarker)
|
||||
{
|
||||
if (keyMarker != null)
|
||||
{
|
||||
SetQueryParameter("key-marker", keyMarker);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置最大返回的 multipart 数量,合法取值从1到1000,默认1000
|
||||
/// </summary>
|
||||
/// <param name="maxUploads"></param>
|
||||
public void SetMaxUploads(string maxUploads)
|
||||
{
|
||||
if (maxUploads != null)
|
||||
{
|
||||
SetQueryParameter("max-uploads", maxUploads);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 限定返回的 Object key 必须以 Prefix 作为前缀。
|
||||
/// 注意使用 prefix 查询时,返回的 key 中仍会包含 Prefix
|
||||
/// </summary>
|
||||
/// <param name="prefix"></param>
|
||||
public void SetPrefix(string prefix)
|
||||
{
|
||||
if (prefix != null)
|
||||
{
|
||||
SetQueryParameter("Prefix", prefix);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 与 key-marker 一起使用.
|
||||
/// 当 key-marker 未被指定时,upload-id-marker 将被忽略.
|
||||
/// 当 key-marker 被指定时,ObjectName字母顺序大于 key-marker 的条目被列出,
|
||||
/// ObjectName 字母顺序等于 key-marker 同时 UploadID 大于 upload-id-marker 的条目将被列出.
|
||||
/// </summary>
|
||||
/// <param name="uploadIdMarker"></param>
|
||||
public void SetUploadIdMarker(string uploadIdMarker)
|
||||
{
|
||||
if (uploadIdMarker != null)
|
||||
{
|
||||
SetQueryParameter("upload-id-marker", uploadIdMarker);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
33
COSXML/Model/Bucket/ListMultiUploadsResult.cs
Normal file
33
COSXML/Model/Bucket/ListMultiUploadsResult.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Transfer;
|
||||
using COSXML.Model.Tag;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 Bucket 正在进行中的分块上传返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7736"/>
|
||||
/// </summary>
|
||||
public sealed class ListMultiUploadsResult : CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// 所有分块上传的信息
|
||||
/// <see cref="COSXML.Model.Tag.ListMultipartUploads"/>
|
||||
/// </summary>
|
||||
public ListMultipartUploads listMultipartUploads;
|
||||
|
||||
internal override void ParseResponseBody(System.IO.Stream inputStream, string contentType, long contentLength)
|
||||
{
|
||||
listMultipartUploads = new ListMultipartUploads();
|
||||
XmlParse.ParseListMultipartUploads(inputStream, listMultipartUploads);
|
||||
}
|
||||
|
||||
public override string GetResultInfo()
|
||||
{
|
||||
return base.GetResultInfo() + (listMultipartUploads == null ? "" : "\n" + listMultipartUploads.GetInfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
87
COSXML/Model/Bucket/PutBucketACLRequest.cs
Normal file
87
COSXML/Model/Bucket/PutBucketACLRequest.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
using COSXML.Model.Tag;
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket 的ACL
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7737"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketACLRequest : BucketRequest
|
||||
{
|
||||
public PutBucketACLRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("acl", null);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
|
||||
/// <see cref="Common.CosACL"/>
|
||||
/// </summary>
|
||||
/// <param name="cosACL"></param>
|
||||
public void SetCosACL(string cosACL)
|
||||
{
|
||||
if (cosACL != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_ACL, cosACL);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
|
||||
/// <see cref="Common.CosACL"/>
|
||||
/// </summary>
|
||||
/// <param name="cosACL"></param>
|
||||
public void SetCosACL(CosACL cosACL)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_ACL, EnumUtils.GetValue(cosACL));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者读的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosGrantRead(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_READ, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者写的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosGrantWrite(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_WRITE, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者所有的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosReadWrite(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_FULL_CONTROL, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
COSXML/Model/Bucket/PutBucketACLResult.cs
Normal file
15
COSXML/Model/Bucket/PutBucketACLResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket ACL返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7737"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketACLResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
73
COSXML/Model/Bucket/PutBucketCORSRequest.cs
Normal file
73
COSXML/Model/Bucket/PutBucketCORSRequest.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using COSXML.CosException;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket CORS
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8279"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketCORSRequest : BucketRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// CORS 配置信息
|
||||
/// <see cref="Model.Tag.CORSConfiguration"/>
|
||||
/// </summary>
|
||||
private CORSConfiguration corsConfiguration;
|
||||
|
||||
public PutBucketCORSRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("cors", null);
|
||||
corsConfiguration = new CORSConfiguration();
|
||||
corsConfiguration.corsRules = new List<CORSConfiguration.CORSRule>();
|
||||
this.needMD5 = true;
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildCORSConfigXML(corsConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置 CORS 规则
|
||||
/// <see cref="Model.Tag.CORSConfiguration.CORSRule"/>
|
||||
/// </summary>
|
||||
/// <param name="corsRule"></param>
|
||||
public void SetCORSRule(CORSConfiguration.CORSRule corsRule)
|
||||
{
|
||||
if (corsRule != null)
|
||||
{
|
||||
corsConfiguration.corsRules.Add(corsRule);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置 CORS 规则
|
||||
/// <see cref="Model.Tag.CORSConfiguration.CORSRule"/>
|
||||
/// </summary>
|
||||
/// <param name="corsRules"></param>
|
||||
public void SetCORSRules(List<CORSConfiguration.CORSRule> corsRules)
|
||||
{
|
||||
if (corsRules != null)
|
||||
{
|
||||
corsConfiguration.corsRules.AddRange(corsRules);
|
||||
}
|
||||
}
|
||||
|
||||
public override void CheckParameters()
|
||||
{
|
||||
base.CheckParameters();
|
||||
if (corsConfiguration.corsRules.Count == 0) throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "corsConfiguration.corsRules.Count = 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
15
COSXML/Model/Bucket/PutBucketCORSResult.cs
Normal file
15
COSXML/Model/Bucket/PutBucketCORSResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket CORS 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8279"
|
||||
/// </summary>
|
||||
public sealed class PutBucketCORSResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
34
COSXML/Model/Bucket/PutBucketDomainRequest.cs
Normal file
34
COSXML/Model/Bucket/PutBucketDomainRequest.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 检索 Bucket 是否存在
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7735"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketDomainRequest : BucketRequest
|
||||
{
|
||||
private DomainConfiguration domain;
|
||||
|
||||
public PutBucketDomainRequest(string bucket, DomainConfiguration domain)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.domain = domain;
|
||||
this.queryParameters.Add("domain", null);
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildDomain(this.domain);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
COSXML/Model/Bucket/PutBucketDomainResult.cs
Normal file
11
COSXML/Model/Bucket/PutBucketDomainResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketDomainResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
96
COSXML/Model/Bucket/PutBucketInventoryRequest.cs
Normal file
96
COSXML/Model/Bucket/PutBucketInventoryRequest.cs
Normal file
@@ -0,0 +1,96 @@
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketInventoryRequest : BucketRequest
|
||||
{
|
||||
private InventoryConfiguration inventoryConfiguration;
|
||||
public PutBucketInventoryRequest(string bucket, string id) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("inventory", null);
|
||||
this.queryParameters.Add("id", id);
|
||||
this.IsNeedMD5 = true;
|
||||
inventoryConfiguration = new InventoryConfiguration();
|
||||
inventoryConfiguration.isEnabled = true;
|
||||
inventoryConfiguration.id = id;
|
||||
inventoryConfiguration.schedule = new InventoryConfiguration.Schedule();
|
||||
inventoryConfiguration.destination = new InventoryConfiguration.Destination();
|
||||
inventoryConfiguration.destination.cosBucketDestination = new InventoryConfiguration.COSBucketDestination();
|
||||
}
|
||||
|
||||
public void IsEnable(bool isEnabled)
|
||||
{
|
||||
inventoryConfiguration.isEnabled = isEnabled;
|
||||
}
|
||||
|
||||
public void SetFilter(string prefix)
|
||||
{
|
||||
if (!String.IsNullOrEmpty(prefix))
|
||||
{
|
||||
inventoryConfiguration.filter = new InventoryConfiguration.Filter();
|
||||
inventoryConfiguration.filter.prefix = prefix;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetDestination(string format, string accountId, string bucket, string region, string prefix)
|
||||
{
|
||||
if (format != null) inventoryConfiguration.destination.cosBucketDestination.format = format;
|
||||
if (accountId != null) inventoryConfiguration.destination.cosBucketDestination.accountId = accountId;
|
||||
if (bucket != null && region != null)
|
||||
{
|
||||
inventoryConfiguration.destination.cosBucketDestination.bucket = "qcs::cos:" + region
|
||||
+ "::" + bucket;
|
||||
}
|
||||
if (prefix != null) inventoryConfiguration.destination.cosBucketDestination.prefix = prefix;
|
||||
}
|
||||
|
||||
public void enableSSE() {
|
||||
inventoryConfiguration.destination.cosBucketDestination.encryption = new InventoryConfiguration.Encryption();
|
||||
inventoryConfiguration.destination.cosBucketDestination.encryption.sSECOS = ""; //默认不填
|
||||
}
|
||||
|
||||
public void SetScheduleFrequency(String frequency)
|
||||
{
|
||||
if (frequency != null)
|
||||
{
|
||||
inventoryConfiguration.schedule.frequency = frequency;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetOptionalFields(string field)
|
||||
{
|
||||
if (field != null)
|
||||
{
|
||||
if (inventoryConfiguration.optionalFields == null)
|
||||
{
|
||||
inventoryConfiguration.optionalFields = new InventoryConfiguration.OptionalFields();
|
||||
inventoryConfiguration.optionalFields.fields = new List<string>(6);
|
||||
}
|
||||
inventoryConfiguration.optionalFields.fields.Add(field);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetIncludedObjectVersions(string includedObjectVersions)
|
||||
{
|
||||
if (includedObjectVersions != null)
|
||||
{
|
||||
inventoryConfiguration.includedObjectVersions = includedObjectVersions;
|
||||
}
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildInventoryConfiguration(inventoryConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
10
COSXML/Model/Bucket/PutBucketInventoryResult.cs
Normal file
10
COSXML/Model/Bucket/PutBucketInventoryResult.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketInventoryResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
69
COSXML/Model/Bucket/PutBucketLifecycleRequest.cs
Normal file
69
COSXML/Model/Bucket/PutBucketLifecycleRequest.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using COSXML.CosException;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket 生命周期
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8280"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketLifecycleRequest : BucketRequest
|
||||
{
|
||||
private LifecycleConfiguration lifecycleConfiguration;
|
||||
|
||||
public PutBucketLifecycleRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("lifecycle", null);
|
||||
lifecycleConfiguration = new LifecycleConfiguration();
|
||||
lifecycleConfiguration.rules = new List<LifecycleConfiguration.Rule>();
|
||||
this.needMD5 = true;
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildLifecycleConfiguration(lifecycleConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置生命周期规则
|
||||
/// <see cref="Model.Tag.LifecycleConfiguration.Rule"/>
|
||||
/// </summary>
|
||||
/// <param name="rule"></param>
|
||||
public void SetRule(LifecycleConfiguration.Rule rule)
|
||||
{
|
||||
if(rule != null)
|
||||
{
|
||||
lifecycleConfiguration.rules.Add(rule);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 设置生命周期规则
|
||||
/// <see cref="Model.Tag.LifecycleConfiguration.Rule"/>
|
||||
/// </summary>
|
||||
/// <param name="rules"></param>
|
||||
public void SetRules(List<LifecycleConfiguration.Rule> rules)
|
||||
{
|
||||
if (rules != null)
|
||||
{
|
||||
lifecycleConfiguration.rules.AddRange(rules);
|
||||
}
|
||||
}
|
||||
|
||||
public override void CheckParameters()
|
||||
{
|
||||
base.CheckParameters();
|
||||
if (lifecycleConfiguration.rules.Count == 0) throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "lifecycleConfiguration.rules.Count = 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
16
COSXML/Model/Bucket/PutBucketLifecycleResult.cs
Normal file
16
COSXML/Model/Bucket/PutBucketLifecycleResult.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 设置 Bucket 生命周期的返回结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/8280"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketLifecycleResult : CosResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
39
COSXML/Model/Bucket/PutBucketLoggingRequest.cs
Normal file
39
COSXML/Model/Bucket/PutBucketLoggingRequest.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketLoggingRequest : BucketRequest
|
||||
{
|
||||
private BucketLoggingStatus bucketLoggingStatus;
|
||||
public PutBucketLoggingRequest(string bucket):base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("logging", null);
|
||||
this.bucketLoggingStatus = new BucketLoggingStatus();
|
||||
}
|
||||
|
||||
public void SetTarget(string targetBucket, string targetPrefix)
|
||||
{
|
||||
if (targetPrefix == null && targetPrefix == null) return;
|
||||
if (bucketLoggingStatus.loggingEnabled == null)
|
||||
{
|
||||
bucketLoggingStatus.loggingEnabled = new BucketLoggingStatus.LoggingEnabled();
|
||||
}
|
||||
if(targetBucket != null) bucketLoggingStatus.loggingEnabled.targetBucket = targetBucket;
|
||||
if(targetPrefix != null) bucketLoggingStatus.loggingEnabled.targetPrefix = targetPrefix;
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildBucketLogging(bucketLoggingStatus);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
COSXML/Model/Bucket/PutBucketLoggingResult.cs
Normal file
10
COSXML/Model/Bucket/PutBucketLoggingResult.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketLoggingResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
18
COSXML/Model/Bucket/PutBucketPolicyRequest.cs
Normal file
18
COSXML/Model/Bucket/PutBucketPolicyRequest.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using COSXML.Common;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketPolicyRequest : BucketRequest
|
||||
{
|
||||
public PutBucketPolicyRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("policy ", null);
|
||||
this.needMD5 = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
10
COSXML/Model/Bucket/PutBucketPolicyResult.cs
Normal file
10
COSXML/Model/Bucket/PutBucketPolicyResult.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketPolicyResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
100
COSXML/Model/Bucket/PutBucketReplicationRequest.cs
Normal file
100
COSXML/Model/Bucket/PutBucketReplicationRequest.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using COSXML.CosException;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public sealed class PutBucketReplicationRequest : BucketRequest
|
||||
{
|
||||
private ReplicationConfiguration replicationConfiguration;
|
||||
|
||||
public PutBucketReplicationRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.needMD5 = true;
|
||||
this.queryParameters.Add("replication", null);
|
||||
replicationConfiguration = new ReplicationConfiguration();
|
||||
replicationConfiguration.rules = new List<ReplicationConfiguration.Rule>();
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildReplicationConfiguration(replicationConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
|
||||
public void SetReplicationConfiguration(string ownerUin, string subUin, List<RuleStruct> ruleStructs)
|
||||
{
|
||||
SetReplicationConfigurationWithRole(ownerUin, subUin);
|
||||
if (ruleStructs != null)
|
||||
{
|
||||
foreach (RuleStruct ruleStruct in ruleStructs)
|
||||
{
|
||||
SetReplicationConfigurationWithRule(ruleStruct);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void SetReplicationConfigurationWithRole(string ownerUin, string subUin)
|
||||
{
|
||||
if (ownerUin != null && subUin != null)
|
||||
{
|
||||
string role = "qcs::cam::uin/" + ownerUin + ":uin/" + subUin;
|
||||
replicationConfiguration.role = role;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetReplicationConfigurationWithRule(RuleStruct ruleStruct)
|
||||
{
|
||||
if (ruleStruct != null)
|
||||
{
|
||||
ReplicationConfiguration.Rule rule = new ReplicationConfiguration.Rule();
|
||||
rule.id = ruleStruct.id;
|
||||
rule.status = ruleStruct.isEnable ? "Enabled" : "Disabled";
|
||||
rule.prefix = ruleStruct.prefix;
|
||||
ReplicationConfiguration.Destination destination = new ReplicationConfiguration.Destination();
|
||||
destination.storageClass = ruleStruct.storageClass;
|
||||
string bucketName = ruleStruct.bucket;
|
||||
if (ruleStruct.bucket.EndsWith("-" + ruleStruct.appid))
|
||||
{
|
||||
bucketName = ruleStruct.bucket.Replace("-" + ruleStruct.appid, "");
|
||||
}
|
||||
StringBuilder bucket = new StringBuilder();
|
||||
bucket.Append("qcs:id/0:cos:").Append(ruleStruct.region).Append(":appid/")
|
||||
.Append(ruleStruct.appid).Append(":").Append(bucketName);
|
||||
destination.bucket = bucket.ToString();
|
||||
rule.destination = destination;
|
||||
replicationConfiguration.rules.Add(rule);
|
||||
}
|
||||
}
|
||||
|
||||
public override void CheckParameters()
|
||||
{
|
||||
base.CheckParameters();
|
||||
if (replicationConfiguration.rules.Count == 0) throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "replicationConfiguration.rules.Count = 0");
|
||||
}
|
||||
|
||||
public sealed class RuleStruct
|
||||
{
|
||||
public string appid;
|
||||
public string region;
|
||||
public string bucket;
|
||||
public string storageClass;
|
||||
public string id;
|
||||
public string prefix;
|
||||
public bool isEnable;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
12
COSXML/Model/Bucket/PutBucketReplicationResult.cs
Normal file
12
COSXML/Model/Bucket/PutBucketReplicationResult.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketReplicationResult : CosResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
87
COSXML/Model/Bucket/PutBucketRequest.cs
Normal file
87
COSXML/Model/Bucket/PutBucketRequest.cs
Normal file
@@ -0,0 +1,87 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Utils;
|
||||
using COSXML.Model.Tag;
|
||||
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建 Bucket
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7738"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketRequest : BucketRequest
|
||||
{
|
||||
public PutBucketRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
|
||||
/// <see cref="Common.CosACL"/>
|
||||
/// </summary>
|
||||
/// <param name="cosACL"></param>
|
||||
public void SetCosACL(string cosACL)
|
||||
{
|
||||
if (cosACL != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_ACL, cosACL);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 定义 Object 的 acl 属性。有效值:private,public-read-write,public-read;默认值:private
|
||||
/// <see cref="Common.CosACL"/>
|
||||
/// </summary>
|
||||
/// <param name="cosACL"></param>
|
||||
public void SetCosACL(CosACL cosACL)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_ACL, EnumUtils.GetValue(cosACL));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者读的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosGrantRead(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_READ, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者写的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosGrantWrite(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_WRITE, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 赋予被授权者所有的权限
|
||||
/// <see cref="Model.Tag.GrantAccount"/>
|
||||
/// </summary>
|
||||
/// <param name="grantAccount"></param>
|
||||
public void SetXCosReadWrite(GrantAccount grantAccount)
|
||||
{
|
||||
if (grantAccount != null)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.X_COS_GRANT_FULL_CONTROL, grantAccount.GetGrantAccounts());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
COSXML/Model/Bucket/PutBucketResult.cs
Normal file
15
COSXML/Model/Bucket/PutBucketResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 创建 Bucket 返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7738"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
40
COSXML/Model/Bucket/PutBucketTaggingRequest.cs
Normal file
40
COSXML/Model/Bucket/PutBucketTaggingRequest.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
/// <summary>
|
||||
/// 检索 Bucket 是否存在
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7735"/>
|
||||
/// </summary>
|
||||
public sealed class PutBucketTaggingRequest : BucketRequest
|
||||
{
|
||||
private Tagging tagging;
|
||||
|
||||
public PutBucketTaggingRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.tagging = new Tagging();
|
||||
this.IsNeedMD5 = true;
|
||||
this.queryParameters.Add("tagging", null);
|
||||
}
|
||||
|
||||
public void AddTag(string key, string value) {
|
||||
this.tagging.AddTag(key, value);
|
||||
}
|
||||
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildTagging(tagging);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
COSXML/Model/Bucket/PutBucketTaggingResult.cs
Normal file
11
COSXML/Model/Bucket/PutBucketTaggingResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketTaggingResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
44
COSXML/Model/Bucket/PutBucketVersioningRequest.cs
Normal file
44
COSXML/Model/Bucket/PutBucketVersioningRequest.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketVersioningRequest : BucketRequest
|
||||
{
|
||||
private VersioningConfiguration versioningConfiguration;
|
||||
|
||||
public PutBucketVersioningRequest(string bucket)
|
||||
: base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("versioning", null);
|
||||
versioningConfiguration = new VersioningConfiguration();
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildVersioningConfiguration(versioningConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
public void IsEnableVersionConfig(bool isEnable)
|
||||
{
|
||||
if (isEnable)
|
||||
{
|
||||
versioningConfiguration.status = "Enabled";
|
||||
}
|
||||
else
|
||||
{
|
||||
versioningConfiguration.status = "Suspended";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
COSXML/Model/Bucket/PutBucketVersioningResult.cs
Normal file
11
COSXML/Model/Bucket/PutBucketVersioningResult.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketVersioningResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
69
COSXML/Model/Bucket/PutBucketWebsiteRequest.cs
Normal file
69
COSXML/Model/Bucket/PutBucketWebsiteRequest.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
|
||||
|
||||
using COSXML.Common;
|
||||
using COSXML.Model.Tag;
|
||||
using COSXML.Network;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketWebsiteRequest:BucketRequest
|
||||
{
|
||||
private WebsiteConfiguration websiteConfiguration;
|
||||
|
||||
public PutBucketWebsiteRequest(string bucket) : base(bucket)
|
||||
{
|
||||
this.method = CosRequestMethod.PUT;
|
||||
this.queryParameters.Add("website", null);
|
||||
websiteConfiguration = new WebsiteConfiguration();
|
||||
}
|
||||
|
||||
public void SetIndexDocument(string suffix)
|
||||
{
|
||||
if (suffix != null)
|
||||
{
|
||||
if (websiteConfiguration.indexDocument == null) websiteConfiguration.indexDocument = new WebsiteConfiguration.IndexDocument();
|
||||
websiteConfiguration.indexDocument.suffix = suffix;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetErrorDocument(string key)
|
||||
{
|
||||
if (key != null)
|
||||
{
|
||||
if (websiteConfiguration.errorDocument == null) websiteConfiguration.errorDocument = new WebsiteConfiguration.ErrorDocument();
|
||||
websiteConfiguration.errorDocument.key = key;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRedirectAllRequestTo(string protocol)
|
||||
{
|
||||
if (protocol != null)
|
||||
{
|
||||
if (websiteConfiguration.redirectAllRequestTo == null) websiteConfiguration.redirectAllRequestTo = new WebsiteConfiguration.RedirectAllRequestTo();
|
||||
websiteConfiguration.redirectAllRequestTo.protocol = protocol;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetRoutingRules(List<WebsiteConfiguration.RoutingRule> rules)
|
||||
{
|
||||
if (rules != null && rules.Count > 0)
|
||||
{
|
||||
if (websiteConfiguration.routingRules == null) websiteConfiguration.routingRules = new List<WebsiteConfiguration.RoutingRule>();
|
||||
foreach (WebsiteConfiguration.RoutingRule rule in rules)
|
||||
{
|
||||
websiteConfiguration.routingRules.Add(rule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override Network.RequestBody GetRequestBody()
|
||||
{
|
||||
string content = Transfer.XmlBuilder.BuildWebsiteConfiguration(websiteConfiguration);
|
||||
byte[] data = Encoding.UTF8.GetBytes(content);
|
||||
ByteRequestBody body = new ByteRequestBody(data);
|
||||
return body;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
COSXML/Model/Bucket/PutBucketWebsiteResult.cs
Normal file
9
COSXML/Model/Bucket/PutBucketWebsiteResult.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
|
||||
|
||||
namespace COSXML.Model.Bucket
|
||||
{
|
||||
public sealed class PutBucketWebsiteResult : CosResult
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
309
COSXML/Model/CosRequest.cs
Normal file
309
COSXML/Model/CosRequest.cs
Normal file
@@ -0,0 +1,309 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.Network;
|
||||
using COSXML.Log;
|
||||
using COSXML.Auth;
|
||||
using COSXML.Utils;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 1:05:09 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model
|
||||
{
|
||||
/**
|
||||
* cos request base class, all cos operator must be extended this.
|
||||
*
|
||||
* request method | request path | query parameters
|
||||
* request headers
|
||||
* request body
|
||||
*
|
||||
* special:
|
||||
* cos sign;
|
||||
*/
|
||||
public abstract class CosRequest
|
||||
{
|
||||
private static string TAG = typeof(CosRequest).FullName;
|
||||
|
||||
protected Request realRequest;
|
||||
|
||||
/// <summary>
|
||||
/// isHttps = true, https 请求; isHttps = false, http 请求; default isHttps = false.
|
||||
/// </summary>
|
||||
protected bool? isHttps = null;
|
||||
|
||||
/// <summary>
|
||||
/// cos api 请求对应的 http method.
|
||||
/// </summary>
|
||||
protected string method = CosRequestMethod.GET;
|
||||
|
||||
/// <summary>
|
||||
/// http 请求url中 path 部分.
|
||||
/// </summary>
|
||||
protected string path;
|
||||
|
||||
/// <summary>
|
||||
/// http 请求url中 query 部分.
|
||||
/// </summary>
|
||||
protected Dictionary<string, string> queryParameters = new Dictionary<string,string>();
|
||||
|
||||
/// <summary>
|
||||
/// http 请求 header 部分.
|
||||
/// </summary>
|
||||
protected Dictionary<string, string> headers = new Dictionary<string,string>();
|
||||
|
||||
/// <summary>
|
||||
/// cos 服务的 appid.
|
||||
/// </summary>
|
||||
protected string appid;
|
||||
|
||||
/// <summary>
|
||||
/// cos 服务签名的签名源部分.
|
||||
/// </summary>
|
||||
protected CosXmlSignSourceProvider cosXmlSignSourceProvider = new CosXmlSignSourceProvider();
|
||||
|
||||
/// <summary>
|
||||
/// needMD5 = true, 请求中带上 Content-Md5; needMd5 = false, 请求中不带 Content-Md5; defalut needMd5 = false.
|
||||
/// </summary>
|
||||
protected bool needMD5 = true;
|
||||
|
||||
/// <summary>
|
||||
/// 请求预签名URL
|
||||
/// </summary>
|
||||
protected string requestUrlWithSign = null;
|
||||
|
||||
public CosXmlConfig serviceConfig {get; set;}
|
||||
|
||||
/// <summary>
|
||||
/// http or https for cos request.
|
||||
/// </summary>
|
||||
public bool? IsHttps
|
||||
{
|
||||
get { return isHttps; }
|
||||
set { isHttps = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http method
|
||||
/// </summary>
|
||||
public string Method
|
||||
{
|
||||
get { return method; }
|
||||
private set { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// path of http url.
|
||||
/// </summary>
|
||||
public string RequestPath
|
||||
{
|
||||
get { return path; }
|
||||
private set { }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// query of http url.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual Dictionary<string, string> GetRequestParamters()
|
||||
{
|
||||
return queryParameters;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// http request header
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual Dictionary<string, string> GetRequestHeaders()
|
||||
{
|
||||
return headers;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add query parameter for cos request, and cover the current value if it exists with the key.
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
public void SetQueryParameter(string key, string value)
|
||||
{
|
||||
SetQueryParameter(key, value, true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// url 部分都统一 url encode
|
||||
/// </summary>
|
||||
/// <param name="key"></param>
|
||||
/// <param name="value"></param>
|
||||
/// <param name="isNeedUrlEncode"></param>
|
||||
public void SetQueryParameter(string key, string value, bool isNeedUrlEncode)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (value == null) value = "";
|
||||
if (isNeedUrlEncode)
|
||||
{
|
||||
value = URLEncodeUtils.Encode(value);
|
||||
}
|
||||
queryParameters.Add(key, value);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
QLog.D(TAG, "SetQueryParameter: key ==null");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
queryParameters[key] = value; // cover the current value
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// add header for cos request, and cover the current value, if it exists with the key.
|
||||
/// </summary>
|
||||
/// <param name="key"> header: key </param>
|
||||
/// <param name="value"> header: value</param>
|
||||
public void SetRequestHeader(string key, string value)
|
||||
{
|
||||
SetRequestHeader(key, value, false);
|
||||
}
|
||||
/// <summary>
|
||||
/// header 默认不 encode
|
||||
/// </summary>
|
||||
/// <param name="key">不能为null 即不包含空格,即 位于(\u0020, \u007F),超过这个范围,urlencode</param>
|
||||
/// <param name="value">可以为null,为空,且位于(\u001f,\u007F) 和 '\t',超过这个范围,urlencode</param>
|
||||
/// <param name="isNeedUrlEncode"></param>
|
||||
public void SetRequestHeader(string key, string value, bool isNeedUrlEncode)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (value == null) value = "";
|
||||
if (isNeedUrlEncode)
|
||||
{
|
||||
value = URLEncodeUtils.Encode(value);
|
||||
}
|
||||
headers.Add(key, value);
|
||||
}
|
||||
catch (ArgumentNullException)
|
||||
{
|
||||
QLog.D(TAG, "SetRequestHeader: key ==null");
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
headers[key] = value; // cover the current value
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// set appid for cos.
|
||||
/// </summary>
|
||||
/// <param name="appid"> cos appid </param>
|
||||
public string APPID
|
||||
{
|
||||
get { return this.appid; }
|
||||
set { this.appid = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 是否带上content-md5
|
||||
/// </summary>
|
||||
public bool IsNeedMD5
|
||||
{
|
||||
get { return needMD5; }
|
||||
set { needMD5 = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// return the host for cos request
|
||||
/// </summary>
|
||||
/// <returns>host(string)</returns>
|
||||
public abstract string GetCOSHost();
|
||||
|
||||
/// <summary>
|
||||
/// return the host for cos request
|
||||
/// </summary>
|
||||
/// <returns>host(string)</returns>
|
||||
public abstract string GetHost();
|
||||
|
||||
/// <summary>
|
||||
/// return the body for cos request. such as upload file.
|
||||
/// </summary>
|
||||
/// <returns> <see cref="COSXML.Network.RequestBody"/></returns>
|
||||
public abstract RequestBody GetRequestBody();
|
||||
|
||||
/// <summary>
|
||||
/// check parameter for cos.
|
||||
/// </summary>
|
||||
/// <exception cref="COSXML.CosException.CosClientException"></exception>
|
||||
public abstract void CheckParameters();
|
||||
|
||||
/// <summary>
|
||||
/// 设置签名的有效期: [signStartTimeSecond, signStartTimeSecond + durationSecond]
|
||||
/// </summary>
|
||||
/// <param name="signStartTimeSecond"></param>
|
||||
/// <param name="durationSecond"></param>
|
||||
public virtual void SetSign(long signStartTimeSecond, long durationSecond)
|
||||
{
|
||||
if (cosXmlSignSourceProvider == null) cosXmlSignSourceProvider = new CosXmlSignSourceProvider();
|
||||
cosXmlSignSourceProvider.SetSignTime(signStartTimeSecond, durationSecond);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 计算签名时,带上头部header 和查询参数 query验证.
|
||||
/// 设置签名的有效期: [signStartTimeSecond, signStartTimeSecond + durationSecond]
|
||||
/// </summary>
|
||||
/// <param name="signStartTimeSecond"></param>
|
||||
/// <param name="durationSecond"></param>
|
||||
/// <param name="headerKeys"></param>
|
||||
/// <param name="queryParameterKeys"></param>
|
||||
public virtual void SetSign(long signStartTimeSecond, long durationSecond, List<string> headerKeys, List<string> queryParameterKeys)
|
||||
{
|
||||
if (cosXmlSignSourceProvider == null) cosXmlSignSourceProvider = new CosXmlSignSourceProvider();
|
||||
cosXmlSignSourceProvider.SetSignTime(signStartTimeSecond, durationSecond);
|
||||
cosXmlSignSourceProvider.AddHeaderKeys(headerKeys);
|
||||
cosXmlSignSourceProvider.AddParameterKeys(queryParameterKeys);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 直接设置签名串.
|
||||
/// </summary>
|
||||
/// <param name="sign"></param>
|
||||
public virtual void SetSign(string sign)
|
||||
{
|
||||
SetRequestHeader(CosRequestHeaderKey.AUTHORIZAIION, sign);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 返回签名数据源
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual CosXmlSignSourceProvider GetSignSourceProvider()
|
||||
{
|
||||
return cosXmlSignSourceProvider;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 设置预签名URL
|
||||
/// </summary>
|
||||
/// <param name="requestSignURL"></param>
|
||||
public string RequestURLWithSign
|
||||
{
|
||||
get { return requestUrlWithSign; }
|
||||
set { requestUrlWithSign = value; }
|
||||
}
|
||||
|
||||
public void BindRequest(Request request)
|
||||
{
|
||||
this.realRequest = request;
|
||||
}
|
||||
|
||||
public void Cancel()
|
||||
{
|
||||
if (realRequest != null)
|
||||
{
|
||||
realRequest.Cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
74
COSXML/Model/CosResult.cs
Normal file
74
COSXML/Model/CosResult.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Network;
|
||||
using System.IO;
|
||||
/**
|
||||
* Copyright (c) 2018 Tencent Cloud. All rights reserved.
|
||||
* 11/2/2018 1:05:46 PM
|
||||
* bradyxiao
|
||||
*/
|
||||
namespace COSXML.Model
|
||||
{
|
||||
/**
|
||||
* this class for cos result.
|
||||
*
|
||||
*/
|
||||
public abstract class CosResult
|
||||
{
|
||||
/// <summary>
|
||||
/// http code
|
||||
/// </summary>
|
||||
public int httpCode;
|
||||
|
||||
/// <summary>
|
||||
/// http message
|
||||
/// </summary>
|
||||
public string httpMessage;
|
||||
|
||||
/// <summary>
|
||||
/// http response headers
|
||||
/// </summary>
|
||||
public Dictionary<string, List<string>> responseHeaders;
|
||||
|
||||
/// <summary>
|
||||
/// exchange infor between request and result
|
||||
/// </summary>
|
||||
/// <param name="cosRequest"></param>
|
||||
internal virtual void ExternInfo(CosRequest cosRequest) { }
|
||||
|
||||
/// <summary>
|
||||
/// parse status line and headers
|
||||
/// </summary>
|
||||
/// <param name="response"> <see cref="COSXML.Network.Response"/></param>
|
||||
internal virtual void InternalParseResponseHeaders() { }
|
||||
|
||||
/// <summary>
|
||||
/// parse response body, such as download files.
|
||||
/// </summary>
|
||||
/// <param name="inputStream"> input stream </param>
|
||||
/// <param name="contentType"> body mime type</param>
|
||||
/// <param name="contentLength">body length</param>
|
||||
internal virtual void ParseResponseBody(Stream inputStream, string contentType, long contentLength) { }
|
||||
|
||||
/// <summary>
|
||||
/// get result message
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual string GetResultInfo()
|
||||
{
|
||||
StringBuilder resultBuilder = new StringBuilder();
|
||||
resultBuilder.Append(httpCode).Append(" ").Append(httpMessage).Append("\n");
|
||||
if (responseHeaders != null)
|
||||
{
|
||||
foreach(KeyValuePair<string, List<string>> element in responseHeaders)
|
||||
{
|
||||
resultBuilder.Append(element.Key).Append(": ").Append(element.Value[0]).Append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
return resultBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
68
COSXML/Model/Object/AbortMultipartUploadRequest.cs
Normal file
68
COSXML/Model/Object/AbortMultipartUploadRequest.cs
Normal file
@@ -0,0 +1,68 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using COSXML.Common;
|
||||
using COSXML.CosException;
|
||||
|
||||
namespace COSXML.Model.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// 舍弃一个分块上传并删除已上传的块
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7740"/>
|
||||
/// </summary>
|
||||
public sealed class AbortMultipartUploadRequest : ObjectRequest
|
||||
{
|
||||
/// <summary>
|
||||
/// 分片块的UploadId,使用 Initiate Multipart Upload 接口初始化分片上传时会得到一个 uploadId,该 ID 不但唯一标识这一分块数据,也标识了这分块数据在整个文件内的相对位置
|
||||
/// </summary>
|
||||
private string uploadId;
|
||||
|
||||
public AbortMultipartUploadRequest(string bucket, string key, string uploadId)
|
||||
: base(bucket, key)
|
||||
{
|
||||
this.uploadId = uploadId;
|
||||
this.method = CosRequestMethod.DELETE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 分片块上传的UploadId
|
||||
/// </summary>
|
||||
/// <param name="uploadId"></param>
|
||||
public void SetUploadId(string uploadId)
|
||||
{
|
||||
this.uploadId = uploadId;
|
||||
}
|
||||
/// <summary>
|
||||
/// 分片块上传的UploadId
|
||||
/// </summary>
|
||||
/// <returns>uploadId</returns>
|
||||
public string GetUploadId()
|
||||
{
|
||||
return uploadId;
|
||||
}
|
||||
|
||||
public override void CheckParameters()
|
||||
{
|
||||
if (requestUrlWithSign != null) return;
|
||||
base.CheckParameters();
|
||||
if (uploadId == null)
|
||||
{
|
||||
throw new CosClientException((int)CosClientError.INVALID_ARGUMENT, "uploadId is null");
|
||||
}
|
||||
}
|
||||
|
||||
protected override void InternalUpdateQueryParameters()
|
||||
{
|
||||
try
|
||||
{
|
||||
this.queryParameters.Add("uploadId", uploadId);
|
||||
}
|
||||
catch (ArgumentException)
|
||||
{
|
||||
this.queryParameters["uploadId"] = uploadId;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
15
COSXML/Model/Object/AbortMultipartUploadResult.cs
Normal file
15
COSXML/Model/Object/AbortMultipartUploadResult.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
|
||||
namespace COSXML.Model.Object
|
||||
{
|
||||
/// <summary>
|
||||
/// 舍弃一个分块上传并删除已上传的块返回的结果
|
||||
/// <see cref="https://cloud.tencent.com/document/product/436/7740"/>
|
||||
/// </summary>
|
||||
public sealed class AbortMultipartUploadResult : CosResult
|
||||
{
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user