初始化
This commit is contained in:
542
bin/aliyun-log-csharp-sdk-master/SLSSDK/Client.cs
Normal file
542
bin/aliyun-log-csharp-sdk-master/SLSSDK/Client.cs
Normal file
@@ -0,0 +1,542 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
using Aliyun.Api.LOG.Request;
|
||||
using Aliyun.Api.LOG.Response;
|
||||
using Aliyun.Api.LOG.Common.Authentication;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
using Aliyun.Api.LOG.Data;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG
|
||||
{
|
||||
/// <summary>
|
||||
/// This is the main class in the sdk. It can be used to communicate with sls server to put/get/query data.
|
||||
/// </summary>
|
||||
public class LogClient
|
||||
{
|
||||
private ServiceClient serviceClient;
|
||||
private Object _slsClientLockObj = new Object();
|
||||
|
||||
private String _accessKeyId;
|
||||
private String _accessKey;
|
||||
|
||||
private String _endpoint;
|
||||
private String _hostName;
|
||||
private String _uriScheme;
|
||||
private int _port;
|
||||
|
||||
private String _localMachinePrivateIp;
|
||||
private String _securityToken;
|
||||
/// <summary>
|
||||
/// readonly property, AccessKeyId of LogClient
|
||||
/// </summary>
|
||||
public String AccessKeyId { get { return _accessKeyId; } }
|
||||
|
||||
/// <summary>
|
||||
/// readonly property, AccessKey of LogClient
|
||||
/// </summary>
|
||||
public String AccessKey { get { return _accessKey; } }
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// readonly property, Endpoint of LogClient
|
||||
/// </summary>
|
||||
public String Endpoint { get { return _endpoint; } }
|
||||
|
||||
/// <summary>
|
||||
/// Read/Write Timeouf for underlying HTTPWebRequest.ReadWriteTimeout
|
||||
/// </summary>
|
||||
public int ReadWriteTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return serviceClient.Configuration.ReadWriteTimeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
lock (_slsClientLockObj)
|
||||
serviceClient.Configuration.ReadWriteTimeout = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Connection Timeout for underlying HttpWebRequest.Timeout
|
||||
/// </summary>
|
||||
public int ConnectionTimeout
|
||||
{
|
||||
get
|
||||
{
|
||||
return serviceClient.Configuration.ConnectionTimeout;
|
||||
}
|
||||
set
|
||||
{
|
||||
if (value > 0)
|
||||
{
|
||||
lock (_slsClientLockObj)
|
||||
serviceClient.Configuration.ConnectionTimeout = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct the sls client with accessId, accessKey and server address,
|
||||
/// all other parameters will be set to default value
|
||||
/// </summary>
|
||||
/// <param name="endpoint">the sls server address(e.g.,http://cn-hangzhou.sls.aliyuncs.com)</param>
|
||||
/// <param name="accessKeyId">aliyun accessId</param>
|
||||
/// <param name="accessKey">aliyun accessKey</param>
|
||||
public LogClient(String endpoint, String accessKeyId, String accessKey)
|
||||
{
|
||||
if (!endpoint.StartsWith("http://") && !endpoint.StartsWith("https://"))
|
||||
endpoint = "http://" + endpoint;
|
||||
setEndpoint(endpoint);
|
||||
if (IpUtils.IsIpAddress(this._hostName))
|
||||
throw new LogException("LogClientError", "client error happens");
|
||||
|
||||
_localMachinePrivateIp = IpUtils.GetLocalMachinePrivateIp();
|
||||
_accessKeyId = accessKeyId;
|
||||
_accessKey = accessKey;
|
||||
|
||||
serviceClient = ServiceClient.Create(new ClientConfiguration());
|
||||
serviceClient.Configuration.ConnectionTimeout = LogConsts.DEFAULT_SLS_CONNECT_TIMEOUT;
|
||||
serviceClient.Configuration.ReadWriteTimeout = LogConsts.DEFAULT_SLS_READWRT_TIMEOUT;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Construct the sls client with accessId, accessKey and server address,
|
||||
/// all other parameters will be set to default value
|
||||
/// </summary>
|
||||
/// <param name="endpoint">the sls server address(e.g.,http://cn-hangzhou.sls.aliyuncs.com)</param>
|
||||
/// <param name="accessKeyId">aliyun accessId</param>
|
||||
/// <param name="accessKey">aliyun accessKey</param>
|
||||
public LogClient(String endpoint, String accessKeyId, String accessKey, String securityToken)
|
||||
{
|
||||
if (!endpoint.StartsWith("http://") && !endpoint.StartsWith("https://"))
|
||||
endpoint = "http://" + endpoint;
|
||||
setEndpoint(endpoint);
|
||||
if (IpUtils.IsIpAddress(this._hostName))
|
||||
throw new LogException("LogClientError", "client error happens");
|
||||
|
||||
_localMachinePrivateIp = IpUtils.GetLocalMachinePrivateIp();
|
||||
_accessKeyId = accessKeyId;
|
||||
_accessKey = accessKey;
|
||||
_securityToken = securityToken;
|
||||
serviceClient = ServiceClient.Create(new ClientConfiguration());
|
||||
serviceClient.Configuration.ConnectionTimeout = LogConsts.DEFAULT_SLS_CONNECT_TIMEOUT;
|
||||
serviceClient.Configuration.ReadWriteTimeout = LogConsts.DEFAULT_SLS_READWRT_TIMEOUT;
|
||||
}
|
||||
public GetCursorResponse GetCursor(GetCursorRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES
|
||||
+ LogConsts.RESOURCE_SEPARATOR
|
||||
+ request.Logstore
|
||||
+ LogConsts.RESOURCE_SHARDS
|
||||
+ LogConsts.RESOURCE_SEPARATOR
|
||||
+ request.Shard;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
request.AddSpecHeadersTo(sReq.Headers);
|
||||
request.AddSpecParamsTo(sReq.Parameters);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JObject body = LogClientTools.ParserResponseToJObject(response.Content);
|
||||
GetCursorResponse getCursorResp = new GetCursorResponse(response.Headers, body.GetValue("cursor").ToString());
|
||||
return getCursorResp;
|
||||
}
|
||||
}
|
||||
}
|
||||
public ListShardsResponse ListShards(ListShardsRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES
|
||||
+ LogConsts.RESOURCE_SEPARATOR
|
||||
+ request.Logstore
|
||||
+ LogConsts.RESOURCE_SHARDS;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
request.AddSpecHeadersTo(sReq.Headers);
|
||||
request.AddSpecParamsTo(sReq.Parameters);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JArray body = LogClientTools.ParserResponseToJArray(response.Content);
|
||||
ListShardsResponse listShardsResp = new ListShardsResponse(response.Headers, body);
|
||||
return listShardsResp;
|
||||
}
|
||||
}
|
||||
}
|
||||
public BatchGetLogsResponse BatchGetLogs(BatchGetLogsRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES
|
||||
+ LogConsts.RESOURCE_SEPARATOR
|
||||
+ request.Logstore
|
||||
+ LogConsts.RESOURCE_SHARDS
|
||||
+ LogConsts.RESOURCE_SEPARATOR
|
||||
+ request.Shard;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
request.AddSpecHeadersTo(sReq.Headers);
|
||||
request.AddSpecParamsTo(sReq.Parameters);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
BatchGetLogsResponse batchGetLogsResp = new BatchGetLogsResponse(response.Headers, response.Content);
|
||||
return batchGetLogsResp;
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// List all of the logstores under specified project
|
||||
/// </summary>
|
||||
/// <param name="request">The request to list logstores</param>
|
||||
/// <exception>LogException</exception>
|
||||
/// <returns>The response of list log logstores</returns>
|
||||
public ListLogstoresResponse ListLogstores(ListLogstoresRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JObject body = LogClientTools.ParserResponseToJObject(response.Content);
|
||||
ListLogstoresResponse res = new ListLogstoresResponse(response.Headers, body);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// put logs into sls server
|
||||
/// </summary>
|
||||
/// <param name="request">The request to put logs </param>
|
||||
/// <exception>LogException</exception>
|
||||
/// <returns>The response to put logs</returns>
|
||||
public PutLogsResponse PutLogs(PutLogsRequest request)
|
||||
{
|
||||
LogGroup.Builder lgBuilder = LogGroup.CreateBuilder();
|
||||
|
||||
if (request.IsSetTopic())
|
||||
lgBuilder.Topic = request.Topic;
|
||||
|
||||
if (request.IsSetSource())
|
||||
lgBuilder.Source = request.Source;
|
||||
else
|
||||
lgBuilder.Source = _localMachinePrivateIp; //use default machine private ip as source (should we
|
||||
|
||||
if (request.IsSetLogItems())
|
||||
{
|
||||
foreach (var item in request.LogItems)
|
||||
{
|
||||
Log.Builder logBuilder = Log.CreateBuilder();
|
||||
logBuilder.Time = item.Time;
|
||||
foreach (var kv in item.Contents)
|
||||
{
|
||||
Log.Types.Content.Builder contentBuilder = Log.Types.Content.CreateBuilder();
|
||||
contentBuilder.Key = kv.Key;
|
||||
contentBuilder.Value = kv.Value;
|
||||
logBuilder.AddContents(contentBuilder);
|
||||
}
|
||||
lgBuilder.AddLogs(logBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
return PutLogs(request, lgBuilder.Build());
|
||||
}
|
||||
|
||||
internal PutLogsResponse PutLogs(PutLogsRequest request, LogGroup logGroup)
|
||||
{
|
||||
if (logGroup.LogsCount > LogConsts.LIMIT_LOG_COUNT)
|
||||
throw new LogException("InvalidLogSize", "logItems' length exceeds maximum limitation: " + LogConsts.LIMIT_LOG_COUNT + " lines.");
|
||||
else if(logGroup.SerializedSize > LogConsts.LIMIT_LOG_SIZE)
|
||||
throw new LogException("InvalidLogSize", "logItems' size exceeds maximum limitation: " + LogConsts.LIMIT_LOG_SIZE + " byte.");
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Post;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
//use empty string to replace Logstore if not set by user explicitly
|
||||
string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty;
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_CONTENTTYPE, LogConsts.PBVALUE_HEADER_CONTENTTYPE);
|
||||
byte[] logBytes = logGroup.ToByteArray();
|
||||
sReq.Headers[LogConsts.NAME_HEADER_BODYRAWSIZE] = logBytes.Length.ToString();
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_COMPRESSTYPE, LogConsts.VALUE_HEADER_COMPRESSTYPE_LZ4);
|
||||
logBytes = LogClientTools.CompressToLz4(logBytes);
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_MD5, LogClientTools.GetMd5Value(logBytes));
|
||||
sReq.Content = new MemoryStream(logBytes);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Post);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
PutLogsResponse putLogResp = new PutLogsResponse(response.Headers);
|
||||
return putLogResp;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the topics in the logtstore
|
||||
/// </summary>
|
||||
/// <param name="request">The list topics request</param>
|
||||
/// <exception>LogException</exception>
|
||||
/// <returns>The List topics response</returns>
|
||||
public ListTopicsResponse ListTopics(ListTopicsRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
//use empty string to replace Logstore if not set by user explicitly
|
||||
string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty;
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TYPE, LogConsts.RESOURCE_TOPIC);
|
||||
|
||||
if (request.IsSetToken())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TOKEN, request.Token);
|
||||
|
||||
if (request.IsSetLines())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_LINES, request.Lines.ToString());
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JArray body = LogClientTools.ParserResponseToJArray(response.Content);
|
||||
ListTopicsResponse res = new ListTopicsResponse(response.Headers, body);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get The sub set of logs data from sls server which match input
|
||||
/// parameters.
|
||||
/// </summary>
|
||||
/// <param name="request">The get logs request</param>
|
||||
/// <exception>LogException</exception>
|
||||
/// <returns>The get Logs response</returns>
|
||||
public GetLogsResponse GetLogs(GetLogsRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
//use empty string to replace Logstore if not set by user explicitly
|
||||
string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty;
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TYPE, LogConsts.VALUE_TYPE_CONTENT);
|
||||
|
||||
if (request.IsSetTopic())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TOPIC, request.Topic);
|
||||
|
||||
if (request.IsSetFrom())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_FROM, request.From.ToString());
|
||||
|
||||
if (request.IsSetTo())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TO, request.To.ToString());
|
||||
|
||||
if (request.IsSetQuery())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_QUERY, request.Query);
|
||||
|
||||
if (request.IsSetLines())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_LINES, request.Lines.ToString());
|
||||
|
||||
if (request.IsSetOffset())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_OFFSET, request.Offset.ToString());
|
||||
|
||||
if (request.IsSetReverse())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_REVERSE, request.Reverse.ToString());
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JArray body = LogClientTools.ParserResponseToJArray(response.Content);
|
||||
GetLogsResponse res = new GetLogsResponse(response.Headers, body);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get The log status(histogram info) from sls server which match input
|
||||
/// parameters. All the logs with logstore and topic in [from, to) which
|
||||
/// contain the keys in query are the matched data.
|
||||
/// </summary>
|
||||
/// <param name="request">The get histograms request</param>
|
||||
/// <exception>LogException</exception>
|
||||
/// <returns>The get histograms response</returns>
|
||||
public GetHistogramsResponse GetHistograms(GetHistogramsRequest request)
|
||||
{
|
||||
using (ServiceRequest sReq = new ServiceRequest())
|
||||
{
|
||||
sReq.Method = HttpMethod.Get;
|
||||
sReq.Endpoint = BuildReqEndpoint(request);
|
||||
|
||||
//use empty string to replace Logstore if not set by user explicitly
|
||||
string logstore = request.IsSetLogstore() ? request.Logstore : String.Empty;
|
||||
sReq.ResourcePath = LogConsts.RESOURCE_LOGSTORES + LogConsts.RESOURCE_SEPARATOR + logstore;
|
||||
|
||||
FillCommonHeaders(sReq);
|
||||
FillCommonParameters(sReq);
|
||||
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TYPE, LogConsts.VALUE_TYPE_STATUS);
|
||||
|
||||
if (request.IsSetTopic())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TOPIC, request.Topic);
|
||||
|
||||
if (request.IsSetFrom())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_FROM, request.From.ToString());
|
||||
|
||||
if (request.IsSetTo())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_TO, request.To.ToString());
|
||||
|
||||
if (request.IsSetQuery())
|
||||
sReq.Parameters.Add(LogConsts.PARAMETER_QUERY, request.Query);
|
||||
|
||||
ExecutionContext context = new ExecutionContext();
|
||||
context.Signer = new LogRequestSigner(sReq.ResourcePath, HttpMethod.Get);
|
||||
context.Credentials = new ServiceCredentials(this.AccessKeyId, this.AccessKey);
|
||||
|
||||
using (ServiceResponse response = serviceClient.Send(sReq, context))
|
||||
{
|
||||
LogClientTools.ResponseErrorCheck(response, context.Credentials);
|
||||
JArray body = LogClientTools.ParserResponseToJArray(response.Content);
|
||||
GetHistogramsResponse res = new GetHistogramsResponse(response.Headers, body);
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//used for unit testing
|
||||
internal void SetWebSend(ServiceClientImpl.WebSend send)
|
||||
{
|
||||
((ServiceClientImpl)serviceClient).SendMethod = send;
|
||||
}
|
||||
|
||||
//set endpoint of service. It may throw exceptions if endpoint is not in valid format.
|
||||
private void setEndpoint(String endpoint)
|
||||
{
|
||||
try
|
||||
{
|
||||
Uri endpointUri = new Uri(endpoint);
|
||||
_endpoint = endpointUri.ToString();
|
||||
_hostName = endpointUri.Host;
|
||||
_uriScheme = endpointUri.Scheme;
|
||||
_port = endpointUri.Port;
|
||||
}
|
||||
catch (Exception) {
|
||||
throw new LogException("LogClientError", "client error happens");
|
||||
}
|
||||
}
|
||||
|
||||
private void FillCommonHeaders(ServiceRequest sReq)
|
||||
{
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_DATE, DateUtils.FormatRfc822Date(DateTime.Now));
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_APIVERSION, LogConsts.VALUE_HEADER_APIVERSION);
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_BODYRAWSIZE, "0");
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_SIGMETHOD, LogConsts.VALUE_HEADER_SIGMETHOD);
|
||||
if (_securityToken != null && _securityToken.Length != 0)
|
||||
{
|
||||
sReq.Headers.Add(LogConsts.NAME_HEADER_ACS_SECURITY_TOKEN, _securityToken);
|
||||
}
|
||||
}
|
||||
|
||||
private void FillCommonParameters(ServiceRequest sReq)
|
||||
{
|
||||
//TODO: add any additional parameters
|
||||
}
|
||||
|
||||
private Uri BuildReqEndpoint(LogRequest request)
|
||||
{
|
||||
//use empty string as project name if not set (expection will be thrown when do request)
|
||||
string project = request.IsSetProject() ? request.Project : String.Empty;
|
||||
return new Uri(this._uriScheme + "://" + project + "." + this._hostName + ":" + this._port);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
internal class HmacSHA1Signature : ServiceSignature
|
||||
{
|
||||
private Encoding _encoding = Encoding.UTF8;
|
||||
|
||||
public override string SignatureMethod
|
||||
{
|
||||
get { return "HmacSHA1"; }
|
||||
}
|
||||
|
||||
public override string SignatureVersion
|
||||
{
|
||||
get { return "1"; }
|
||||
}
|
||||
|
||||
public HmacSHA1Signature()
|
||||
{
|
||||
}
|
||||
|
||||
protected override string ComputeSignatureCore(string key, string data)
|
||||
{
|
||||
Debug.Assert(!string.IsNullOrEmpty(data));
|
||||
|
||||
using (KeyedHashAlgorithm algorithm = KeyedHashAlgorithm.Create(
|
||||
this.SignatureMethod.ToString().ToUpperInvariant()))
|
||||
{
|
||||
algorithm.Key = _encoding.GetBytes(key.ToCharArray());
|
||||
return Convert.ToBase64String(
|
||||
algorithm.ComputeHash(_encoding.GetBytes(data.ToCharArray())));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* Created by SharpDevelop.
|
||||
* User: xiaoming.yin
|
||||
* Date: 2012/5/30
|
||||
* Time: 14:18
|
||||
*
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
using System;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of IRequestSigner.
|
||||
/// </summary>
|
||||
internal interface IRequestSigner
|
||||
{
|
||||
/// <summary>
|
||||
/// Signs a request.
|
||||
/// </summary>
|
||||
/// <param name="request">The request to sign.</param>
|
||||
/// <param name="credentials">The credentials used to sign.</param>
|
||||
void Sign(ServiceRequest request, ServiceCredentials credentials);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the credentials used to access Aliyun Open Services.
|
||||
/// </summary>
|
||||
internal class ServiceCredentials
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the access ID.
|
||||
/// </summary>
|
||||
public string AccessId { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the access key.
|
||||
/// </summary>
|
||||
public string AccessKey { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Initialize an new instance of <see cref="ServiceCredentials"/>.
|
||||
/// </summary>
|
||||
/// <param name="accessId">The access ID.</param>
|
||||
/// <param name="accessKey">The access key.</param>
|
||||
public ServiceCredentials(string accessId, string accessKey)
|
||||
{
|
||||
if (string.IsNullOrEmpty(accessId))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "accessId");
|
||||
|
||||
AccessId = accessId;
|
||||
AccessKey = accessKey;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Authentication
|
||||
{
|
||||
internal abstract class ServiceSignature
|
||||
{
|
||||
public abstract string SignatureMethod { get; }
|
||||
|
||||
public abstract string SignatureVersion { get; }
|
||||
|
||||
protected ServiceSignature()
|
||||
{
|
||||
}
|
||||
|
||||
public string ComputeSignature(String key, String data)
|
||||
{
|
||||
if (string.IsNullOrEmpty(key))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "key");
|
||||
if (string.IsNullOrEmpty(data))
|
||||
throw new ArgumentException(Aliyun.Api.LOG.Properties.Resources.ExceptionIfArgumentStringIsNullOrEmpty, "data");
|
||||
|
||||
return ComputeSignatureCore(key, data);
|
||||
}
|
||||
|
||||
protected abstract string ComputeSignatureCore(string key, string data);
|
||||
|
||||
public static ServiceSignature Create()
|
||||
{
|
||||
return new HmacSHA1Signature();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Created by SharpDevelop.
|
||||
* User: xiaoming.yin
|
||||
* Date: 2012/5/30
|
||||
* Time: 14:21
|
||||
*
|
||||
* To change this template use Tools | Options | Coding | Edit Standard Headers.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Aliyun.Api.LOG.Common.Authentication;
|
||||
using Aliyun.Api.LOG.Common.Handlers;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of ExecutionContext.
|
||||
/// </summary>
|
||||
internal class ExecutionContext
|
||||
{
|
||||
/// <summary>
|
||||
/// The default encoding (charset name).
|
||||
/// </summary>
|
||||
private const string DefaultEncoding = "utf-8";
|
||||
|
||||
private IList<IResponseHandler> _responseHandlers = new List<IResponseHandler>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the charset.
|
||||
/// </summary>
|
||||
public string Charset { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the request signer.
|
||||
/// </summary>
|
||||
public IRequestSigner Signer { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the credentials.
|
||||
/// </summary>
|
||||
public ServiceCredentials Credentials { get; set ;}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the list of <see cref="IResponseHandler" />.
|
||||
/// </summary>
|
||||
public IList<IResponseHandler> ResponseHandlers
|
||||
{
|
||||
get { return _responseHandlers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public ExecutionContext()
|
||||
{
|
||||
this.Charset = DefaultEncoding;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a HTTP method.
|
||||
/// </summary>
|
||||
internal enum HttpMethod
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents HTTP GET. Default value.
|
||||
/// </summary>
|
||||
Get = 0,
|
||||
|
||||
/// <summary>
|
||||
/// Represents HTTP DELETE.
|
||||
/// </summary>
|
||||
Delete,
|
||||
|
||||
/// <summary>
|
||||
/// Represents HTTP HEAD.
|
||||
/// </summary>
|
||||
Head,
|
||||
|
||||
/// <summary>
|
||||
/// Represents HTTP POST.
|
||||
/// </summary>
|
||||
Post,
|
||||
|
||||
/// <summary>
|
||||
/// Represents HTTP PUT.
|
||||
/// </summary>
|
||||
Put,
|
||||
|
||||
/// <summary>
|
||||
/// Represents HTTP OPTIONS.
|
||||
/// </summary>
|
||||
Options,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represent the channel that communicates with an Aliyun Open Service.
|
||||
/// </summary>
|
||||
internal interface IServiceClient
|
||||
{
|
||||
/// <summary>
|
||||
/// Sends a request to the service.
|
||||
/// </summary>
|
||||
/// <param name="request">The request data.</param>
|
||||
/// <param name="context">The execution context.</param>
|
||||
/// <returns>The response data.</returns>
|
||||
ServiceResponse Send(ServiceRequest request, ExecutionContext context);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Net;
|
||||
using Aliyun.Api.LOG;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using Aliyun.Api.LOG.Common;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
using Aliyun.Api.LOG.Common.Handlers;
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// The default implementation of <see cref="IServiceClient" />.
|
||||
/// </summary>
|
||||
internal abstract class ServiceClient : IServiceClient
|
||||
{
|
||||
|
||||
#region Fields and Properties
|
||||
|
||||
private ClientConfiguration _configuration;
|
||||
|
||||
public ClientConfiguration Configuration
|
||||
{
|
||||
get { return _configuration; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
protected ServiceClient(ClientConfiguration configuration)
|
||||
{
|
||||
Debug.Assert(configuration != null);
|
||||
// Make a definsive copy to ensure the class is immutable.
|
||||
_configuration = (ClientConfiguration)configuration.Clone();
|
||||
}
|
||||
|
||||
public static ServiceClient Create(ClientConfiguration configuration)
|
||||
{
|
||||
return new ServiceClientImpl(configuration);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region IServiceClient Members
|
||||
|
||||
public ServiceResponse Send(ServiceRequest request, ExecutionContext context)
|
||||
{
|
||||
Debug.Assert(request != null);
|
||||
SignRequest(request, context);
|
||||
ServiceResponse response = SendCore(request, context);
|
||||
HandleResponse(response, context.ResponseHandlers);
|
||||
return response;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
protected abstract ServiceResponse SendCore(ServiceRequest request, ExecutionContext context);
|
||||
|
||||
|
||||
internal static void SignRequest(ServiceRequest request, ExecutionContext context)
|
||||
{
|
||||
if (context.Signer != null)
|
||||
{
|
||||
context.Signer.Sign(request, context.Credentials);
|
||||
}
|
||||
}
|
||||
|
||||
protected static void HandleResponse(ServiceResponse response, IList<IResponseHandler> handlers)
|
||||
{
|
||||
foreach(IResponseHandler handler in handlers)
|
||||
{
|
||||
handler.Handle(response);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,429 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
//#define __UT_TEST_0EC173788C65DD08DA60575219707632__
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Reflection;
|
||||
using Aliyun.Api.LOG;
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// An default <see cref="ServiceClient"/> implementation that
|
||||
/// communicates with Aliyun Services over the HTTP protocol.
|
||||
/// </summary>
|
||||
internal class ServiceClientImpl : ServiceClient
|
||||
{
|
||||
|
||||
#region Embeded Classes
|
||||
|
||||
/// <summary>
|
||||
/// Represents the async operation of requests in <see cref="ServiceClientImpl"/>.
|
||||
/// </summary>
|
||||
private class HttpAsyncResult : AsyncResult<ServiceResponse>
|
||||
{
|
||||
public HttpWebRequest WebRequest { get; set; }
|
||||
|
||||
public ExecutionContext Context { get; set; }
|
||||
|
||||
public HttpAsyncResult(AsyncCallback callback, object state)
|
||||
: base(callback, state)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the response data of <see cref="ServiceClientImpl"/> requests.
|
||||
/// </summary>
|
||||
internal class ResponseImpl : ServiceResponse
|
||||
{
|
||||
private bool _disposed;
|
||||
private HttpWebResponse _response;
|
||||
private Exception _failure;
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
private HttpStatusCode _httpStatusCode = HttpStatusCode.OK;
|
||||
#endif
|
||||
public override HttpStatusCode StatusCode
|
||||
{
|
||||
get
|
||||
{
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
return _httpStatusCode;
|
||||
#else
|
||||
return _response.StatusCode;
|
||||
#endif
|
||||
}
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
set {
|
||||
_httpStatusCode = value;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override Exception Failure {
|
||||
get
|
||||
{
|
||||
return this._failure;
|
||||
}
|
||||
}
|
||||
|
||||
public override IDictionary<string, string> Headers
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfObjectDisposed();
|
||||
if (_headers == null)
|
||||
{
|
||||
_headers = GetResponseHeaders(_response);
|
||||
}
|
||||
|
||||
return _headers;
|
||||
}
|
||||
|
||||
}
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
private Stream _stream;
|
||||
#endif
|
||||
public override Stream Content
|
||||
{
|
||||
get
|
||||
{
|
||||
ThrowIfObjectDisposed();
|
||||
|
||||
try
|
||||
{
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
return _response != null ?
|
||||
_response.GetResponseStream() : _stream;
|
||||
#else
|
||||
return _response != null ?
|
||||
_response.GetResponseStream() : null;
|
||||
#endif
|
||||
}
|
||||
catch (ProtocolViolationException ex)
|
||||
{
|
||||
throw new InvalidOperationException(ex.Message, ex);
|
||||
}
|
||||
}
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
set
|
||||
{
|
||||
_stream = value;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
public ResponseImpl(HttpWebResponse httpWebResponse)
|
||||
{
|
||||
Debug.Assert(httpWebResponse != null);
|
||||
_response = httpWebResponse;
|
||||
|
||||
Debug.Assert(this.IsSuccessful(), "This constructor only allows a successfull response.");
|
||||
}
|
||||
|
||||
public ResponseImpl(WebException failure)
|
||||
{
|
||||
Debug.Assert(failure != null);
|
||||
HttpWebResponse httpWebResponse = failure.Response as HttpWebResponse;
|
||||
Debug.Assert(httpWebResponse != null);
|
||||
|
||||
_failure = failure;
|
||||
_response = httpWebResponse;
|
||||
Debug.Assert(!this.IsSuccessful(), "This constructor only allows a failed response.");
|
||||
}
|
||||
//#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
internal ResponseImpl()
|
||||
{
|
||||
}
|
||||
//#endif
|
||||
|
||||
|
||||
private static IDictionary<string, string> GetResponseHeaders(HttpWebResponse response)
|
||||
{
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
if (response == null)
|
||||
{
|
||||
IDictionary<string, string> testHeaders = new Dictionary<String, String>();
|
||||
testHeaders.Add(LogConsts.NAME_HEADER_AUTH, "LOG mockkeyid:EX2VSCpdyFrcysmBaQ+aokupwcg=");
|
||||
return testHeaders;
|
||||
}
|
||||
#endif
|
||||
var headers = response.Headers;
|
||||
var result = new Dictionary<string, string>(headers.Count,StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
for (int i = 0; i < headers.Count; i++)
|
||||
{
|
||||
var key = headers.Keys[i];
|
||||
var value = headers.Get(key);
|
||||
result.Add(key,
|
||||
HttpUtils.ReEncode(
|
||||
value,
|
||||
HttpUtils.Iso88591Charset,
|
||||
HttpUtils.UTF8Charset));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
base.Dispose(disposing);
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (_response != null)
|
||||
{
|
||||
_response.Close();
|
||||
_response = null;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void ThrowIfObjectDisposed()
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
throw new ObjectDisposedException(this.GetType().Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ServiceClientImpl(ClientConfiguration configuration)
|
||||
: base(configuration)
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Implementations
|
||||
internal delegate ServiceResponse WebSend(HttpWebRequest request);
|
||||
internal WebSend SendMethod = DefaultSend;
|
||||
internal static ResponseImpl DefaultSend(HttpWebRequest request)
|
||||
{
|
||||
var response = request.GetResponse() as HttpWebResponse;
|
||||
return new ResponseImpl(response);
|
||||
}
|
||||
private static ServiceResponse HandleException(WebException ex)
|
||||
{
|
||||
var response = ex.Response as HttpWebResponse;
|
||||
if (response == null)
|
||||
{
|
||||
throw new LogException("LogRequestError", "request is failed.", ex);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new ResponseImpl(ex);
|
||||
}
|
||||
}
|
||||
protected override ServiceResponse SendCore(ServiceRequest serviceRequest,
|
||||
ExecutionContext context)
|
||||
{
|
||||
try
|
||||
{
|
||||
serviceRequest.HttpRequest = HttpFactory.CreateWebRequest(serviceRequest, Configuration);
|
||||
#if(!__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
SetRequestContent(serviceRequest.HttpRequest, serviceRequest);
|
||||
#endif
|
||||
|
||||
return SendMethod(serviceRequest.HttpRequest);
|
||||
}
|
||||
catch (WebException ex)
|
||||
{
|
||||
return HandleException(ex);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static void SetRequestContent(HttpWebRequest webRequest,
|
||||
ServiceRequest serviceRequest)
|
||||
{
|
||||
|
||||
var data = serviceRequest.BuildRequestContent();
|
||||
|
||||
if (data == null ||
|
||||
(serviceRequest.Method != HttpMethod.Put &&
|
||||
serviceRequest.Method != HttpMethod.Post))
|
||||
{
|
||||
// Skip setting content body in this case.
|
||||
webRequest.ContentLength = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Write data to the request stream.
|
||||
long userSetContentLength = -1;
|
||||
if (serviceRequest.Headers.ContainsKey(Aliyun.Api.LOG.Common.Utilities.HttpHeaders.ContentLength))
|
||||
{
|
||||
userSetContentLength = long.Parse(serviceRequest.Headers[Aliyun.Api.LOG.Common.Utilities.HttpHeaders.ContentLength]);
|
||||
}
|
||||
|
||||
long streamLength = data.Length - data.Position;
|
||||
webRequest.ContentLength = (userSetContentLength >= 0 && userSetContentLength <= streamLength) ?
|
||||
userSetContentLength : streamLength;
|
||||
|
||||
webRequest.KeepAlive = false;
|
||||
try
|
||||
{
|
||||
webRequest.ServicePoint.ConnectionLeaseTimeout = 5000;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
// https://github.com/dotnet/standard/issues/642
|
||||
}
|
||||
|
||||
webRequest.ServicePoint.MaxIdleTime = 5000;
|
||||
webRequest.ServicePoint.ConnectionLimit = 1000;
|
||||
webRequest.ServicePoint.Expect100Continue = false;
|
||||
// Generate GUID for connection group name, force close it when request is done.
|
||||
webRequest.ConnectionGroupName = Guid.NewGuid().ToString();
|
||||
|
||||
using (var requestStream = webRequest.GetRequestStream())
|
||||
{
|
||||
data.WriteTo(requestStream, webRequest.ContentLength);
|
||||
data.Seek(0, SeekOrigin.Begin);
|
||||
requestStream.Flush();
|
||||
requestStream.Close();
|
||||
|
||||
}
|
||||
data.Close();
|
||||
data.Dispose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
}
|
||||
|
||||
internal static class HttpFactory
|
||||
{
|
||||
internal static HttpWebRequest CreateWebRequest(ServiceRequest serviceRequest, ClientConfiguration configuration)
|
||||
{
|
||||
Debug.Assert(serviceRequest != null && configuration != null);
|
||||
|
||||
HttpWebRequest webRequest = WebRequest.Create(serviceRequest.BuildRequestUri()) as HttpWebRequest;
|
||||
|
||||
SetRequestHeaders(webRequest, serviceRequest, configuration);
|
||||
SetRequestProxy(webRequest, configuration);
|
||||
|
||||
return webRequest;
|
||||
}
|
||||
|
||||
// Set request headers
|
||||
private static void SetRequestHeaders(HttpWebRequest webRequest, ServiceRequest serviceRequest,
|
||||
ClientConfiguration configuration)
|
||||
{
|
||||
webRequest.Timeout = configuration.ConnectionTimeout;
|
||||
webRequest.ReadWriteTimeout = configuration.ReadWriteTimeout;
|
||||
webRequest.Method = serviceRequest.Method.ToString().ToUpperInvariant();
|
||||
|
||||
// Because it is not allowed to set common headers
|
||||
// with the WebHeaderCollection.Add method,
|
||||
// we have to call an internal method to skip validation.
|
||||
foreach (var h in serviceRequest.Headers)
|
||||
{
|
||||
//if (h.Key.CompareTo(LogConsts.NAME_HEADER_HOST) == 0)
|
||||
// webRequest.Host = h.Value;
|
||||
//else if (h.Key.CompareTo(LogConsts.NAME_HEADER_DATE) == 0)
|
||||
// webRequest.Date = DateUtils.ParseRfc822Date(h.Value);
|
||||
//if (h.Key.CompareTo(LogConsts.NAME_HEADER_CONTENTTYPE) == 0)
|
||||
// webRequest.ContentType = h.Value;
|
||||
//else
|
||||
webRequest.Headers.AddInternal(h.Key, h.Value);
|
||||
}
|
||||
|
||||
// Set user-agent
|
||||
if (!string.IsNullOrEmpty(configuration.UserAgent))
|
||||
{
|
||||
webRequest.UserAgent = configuration.UserAgent;
|
||||
}
|
||||
}
|
||||
|
||||
// Set proxy
|
||||
private static void SetRequestProxy(HttpWebRequest webRequest, ClientConfiguration configuration)
|
||||
{
|
||||
// Perf Improvement:
|
||||
// If HttpWebRequest.Proxy is not set to null explicitly,
|
||||
// it will try to load the IE proxy settings including auto proxy detection,
|
||||
// which is quite time consuming.
|
||||
webRequest.Proxy = null;
|
||||
|
||||
// Set proxy if proxy settings are specified.
|
||||
if (!string.IsNullOrEmpty(configuration.ProxyHost))
|
||||
{
|
||||
if (configuration.ProxyPort < 0)
|
||||
{
|
||||
webRequest.Proxy = new WebProxy(configuration.ProxyHost);
|
||||
} else
|
||||
{
|
||||
webRequest.Proxy = new WebProxy(configuration.ProxyHost, configuration.ProxyPort);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(configuration.ProxyUserName)) {
|
||||
webRequest.Proxy.Credentials = String.IsNullOrEmpty(configuration.ProxyDomain) ?
|
||||
new NetworkCredential(configuration.ProxyUserName, configuration.ProxyPassword ?? string.Empty) :
|
||||
new NetworkCredential(configuration.ProxyUserName, configuration.ProxyPassword ?? string.Empty,
|
||||
configuration.ProxyDomain);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal static class HttpExtensions
|
||||
{
|
||||
private static MethodInfo _addInternalMethod;
|
||||
private static ICollection<PlatformID> monoPlatforms = new List<PlatformID>
|
||||
{ PlatformID.MacOSX, PlatformID.Unix };
|
||||
private static bool? isMonoPlatform;
|
||||
|
||||
internal static void AddInternal(this WebHeaderCollection headers, string key, string value)
|
||||
{
|
||||
if (isMonoPlatform == null)
|
||||
{
|
||||
isMonoPlatform = monoPlatforms.Contains(System.Environment.OSVersion.Platform);
|
||||
}
|
||||
|
||||
// HTTP headers should be encoded to iso-8859-1,
|
||||
// however it will be encoded automatically by HttpWebRequest in mono.
|
||||
if (isMonoPlatform == false)
|
||||
// Encode headers for win platforms.
|
||||
value = HttpUtils.ReEncode(
|
||||
value,
|
||||
HttpUtils.UTF8Charset,
|
||||
HttpUtils.Iso88591Charset);
|
||||
|
||||
if (_addInternalMethod == null)
|
||||
{
|
||||
// Specify the internal method name for adding headers
|
||||
// mono: AddWithoutValidate
|
||||
// win: AddInternal
|
||||
string internalMethodName = (isMonoPlatform == true) ? "AddWithoutValidate" : "AddInternal";
|
||||
|
||||
MethodInfo mi = typeof(WebHeaderCollection).GetMethod(
|
||||
internalMethodName,
|
||||
BindingFlags.NonPublic | BindingFlags.Instance,
|
||||
null,
|
||||
new Type[] { typeof(string), typeof(string) },
|
||||
null);
|
||||
_addInternalMethod = mi;
|
||||
}
|
||||
|
||||
_addInternalMethod.Invoke(headers, new object[] { key, value });
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of ServiceMessage.
|
||||
/// </summary>
|
||||
internal class ServiceMessage
|
||||
{
|
||||
// HTTP header keys are case-insensitive.
|
||||
protected IDictionary<String, String> _headers;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dictionary of HTTP headers.
|
||||
/// </summary>
|
||||
public virtual IDictionary<String, String> Headers
|
||||
{
|
||||
get { return _headers; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the content stream.
|
||||
/// </summary>
|
||||
public virtual Stream Content { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public ServiceMessage()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
using System.Net;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the information for sending requests.
|
||||
/// </summary>
|
||||
internal class ServiceRequest : ServiceMessage, IDisposable
|
||||
{
|
||||
private bool _disposed;
|
||||
|
||||
private IDictionary<String, String> parameters =
|
||||
new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the endpoint.
|
||||
/// </summary>
|
||||
public Uri Endpoint { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the resource path of the request URI.
|
||||
/// </summary>
|
||||
public String ResourcePath { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the HTTP method.
|
||||
/// </summary>
|
||||
public HttpMethod Method { get; set; }
|
||||
|
||||
public HttpWebRequest HttpRequest { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the dictionary of the request parameters.
|
||||
/// </summary>
|
||||
public IDictionary<String, String> Parameters{
|
||||
get { return parameters; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets whether the request can be repeated.
|
||||
/// </summary>
|
||||
public bool IsRepeatable
|
||||
{
|
||||
get { return this.Content == null || this.Content.CanSeek; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constuctor.
|
||||
/// </summary>
|
||||
public ServiceRequest()
|
||||
{
|
||||
_headers = new Dictionary<String, String>(StringComparer.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build the request URI from the request message.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public string BuildRequestUri()
|
||||
{
|
||||
const string delimiter = "/";
|
||||
String uri = Endpoint.ToString();
|
||||
if (!uri.EndsWith(delimiter)
|
||||
&& (ResourcePath == null ||
|
||||
!ResourcePath.StartsWith(delimiter)))
|
||||
{
|
||||
uri += delimiter;
|
||||
}
|
||||
else if (uri.EndsWith(delimiter) && (ResourcePath != null && ResourcePath.StartsWith(delimiter)))
|
||||
{
|
||||
uri = uri.Substring(0, uri.Length - 1);
|
||||
}
|
||||
|
||||
if (ResourcePath != null){
|
||||
uri += ResourcePath;
|
||||
}
|
||||
|
||||
if (IsParameterInUri())
|
||||
{
|
||||
String paramString = HttpUtils.GetRequestParameterString(parameters);
|
||||
if (!string.IsNullOrEmpty(paramString))
|
||||
{
|
||||
uri += "?" + paramString;
|
||||
}
|
||||
}
|
||||
return uri;
|
||||
}
|
||||
|
||||
public Stream BuildRequestContent()
|
||||
{
|
||||
if (!IsParameterInUri())
|
||||
{
|
||||
String paramString = HttpUtils.GetRequestParameterString(parameters);
|
||||
if (!string.IsNullOrEmpty(paramString))
|
||||
{
|
||||
byte[] buffer = Encoding.GetEncoding("utf-8").GetBytes(paramString);
|
||||
Stream content = new MemoryStream();
|
||||
content.Write(buffer, 0, buffer.Length);
|
||||
content.Flush();
|
||||
// Move the marker to the beginning for further read.
|
||||
content.Seek(0, SeekOrigin.Begin);
|
||||
return content;
|
||||
}
|
||||
}
|
||||
|
||||
return this.Content;
|
||||
}
|
||||
|
||||
private bool IsParameterInUri()
|
||||
{
|
||||
bool requestHasPayload = this.Content != null;
|
||||
bool requestIsPost = this.Method == HttpMethod.Post;
|
||||
bool putParamsInUri = !requestIsPost || requestHasPayload;
|
||||
return putParamsInUri;
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (_disposed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (disposing)
|
||||
{
|
||||
if (Content != null)
|
||||
{
|
||||
Content.Close();
|
||||
Content = null;
|
||||
}
|
||||
if (HttpRequest != null)
|
||||
{
|
||||
// force close connection group
|
||||
//Console.WriteLine(HttpRequest.ConnectionGroupName + "[]" + HttpRequest.ConnectionGroupName.Length.ToString() + "[]" + HttpRequest.ServicePoint.CurrentConnections.ToString());
|
||||
HttpRequest.ServicePoint.CloseConnectionGroup(HttpRequest.ConnectionGroupName);
|
||||
HttpRequest.Abort();
|
||||
HttpRequest = null;
|
||||
}
|
||||
_disposed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
//#define __UT_TEST_0EC173788C65DD08DA60575219707632__
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Communication
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the data of the responses of requests.
|
||||
/// </summary>
|
||||
internal abstract class ServiceResponse : ServiceMessage, IDisposable
|
||||
{
|
||||
public abstract HttpStatusCode StatusCode {
|
||||
get;
|
||||
#if(__UT_TEST_0EC173788C65DD08DA60575219707632__)
|
||||
set;
|
||||
#endif
|
||||
}
|
||||
|
||||
public abstract Exception Failure { get; }
|
||||
|
||||
public virtual bool IsSuccessful()
|
||||
{
|
||||
return (int)this.StatusCode / 100 == (int)HttpStatusCode.OK / 100;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Throws the exception from communication if the status code is not 2xx.
|
||||
/// </summary>
|
||||
public virtual void EnsureSuccessful()
|
||||
{
|
||||
if (!IsSuccessful())
|
||||
{
|
||||
// Disposing the content should help users: If users call EnsureSuccessStatusCode(), an exception is
|
||||
// thrown if the response status code is != 2xx. I.e. the behavior is similar to a failed request (e.g.
|
||||
// connection failure). Users don't expect to dispose the content in this case: If an exception is
|
||||
// thrown, the object is responsible fore cleaning up its state.
|
||||
if (Content != null)
|
||||
{
|
||||
Content.Dispose();
|
||||
}
|
||||
|
||||
Debug.Assert(this.Failure != null);
|
||||
throw this.Failure;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Constructor.
|
||||
/// </summary>
|
||||
public ServiceResponse()
|
||||
{
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Handles the response message from the services.
|
||||
/// </summary>
|
||||
internal interface IResponseHandler
|
||||
{
|
||||
void Handle(ServiceResponse response);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Handlers
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of ResponseHandler.
|
||||
/// </summary>
|
||||
internal class ResponseHandler : IResponseHandler
|
||||
{
|
||||
public ResponseHandler()
|
||||
{
|
||||
}
|
||||
|
||||
public virtual void Handle(ServiceResponse response)
|
||||
{
|
||||
Debug.Assert(response != null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,224 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// The implementation of <see cref="IAsyncResult"/>
|
||||
/// that represents the status of an async operation.
|
||||
/// </summary>
|
||||
internal abstract class AsyncResult : IAsyncResult, IDisposable
|
||||
{
|
||||
#region Fields
|
||||
|
||||
private object _asyncState;
|
||||
private bool _completedSynchronously;
|
||||
private bool _isCompleted;
|
||||
private AsyncCallback _userCallback;
|
||||
private ManualResetEvent _asyncWaitEvent;
|
||||
private Exception _exception;
|
||||
|
||||
#endregion
|
||||
|
||||
#region IAsyncResult Members
|
||||
|
||||
/// <summary>
|
||||
/// Gets a user-defined object that qualifies or contains information about an asynchronous operation.
|
||||
/// </summary>
|
||||
[DebuggerNonUserCode]
|
||||
public object AsyncState
|
||||
{
|
||||
get
|
||||
{
|
||||
return _asyncState;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a <see cref="WaitHandle"/> that is used to wait for an asynchronous operation to complete.
|
||||
/// </summary>
|
||||
[DebuggerNonUserCode]
|
||||
public WaitHandle AsyncWaitHandle
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_asyncWaitEvent != null)
|
||||
{
|
||||
return _asyncWaitEvent;
|
||||
}
|
||||
|
||||
ManualResetEvent manualResetEvent = new ManualResetEvent(false);
|
||||
if (Interlocked.CompareExchange<ManualResetEvent>(ref _asyncWaitEvent, manualResetEvent, null) != null)
|
||||
{
|
||||
manualResetEvent.Close();
|
||||
}
|
||||
if (this.IsCompleted)
|
||||
{
|
||||
_asyncWaitEvent.Set();
|
||||
}
|
||||
|
||||
return _asyncWaitEvent;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that indicates whether the asynchronous operation completed synchronously.
|
||||
/// </summary>
|
||||
[DebuggerNonUserCode]
|
||||
public bool CompletedSynchronously
|
||||
{
|
||||
get
|
||||
{
|
||||
return _completedSynchronously;
|
||||
}
|
||||
protected set
|
||||
{
|
||||
_completedSynchronously = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a value that indicates whether the asynchronous operation has completed.
|
||||
/// </summary>
|
||||
[DebuggerNonUserCode]
|
||||
public bool IsCompleted
|
||||
{
|
||||
get
|
||||
{
|
||||
return _isCompleted;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="AsyncResult"/>.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback method when the async operation completes.</param>
|
||||
/// <param name="state">A user-defined object that qualifies or contains information about an asynchronous operation.</param>
|
||||
protected AsyncResult(AsyncCallback callback, object state)
|
||||
{
|
||||
_userCallback = callback;
|
||||
_asyncState = state;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Completes the async operation with an exception.
|
||||
/// </summary>
|
||||
/// <param name="ex">Exception from the async operation.</param>
|
||||
public void Complete(Exception ex)
|
||||
{
|
||||
// Complete should not throw if disposed.
|
||||
Debug.Assert(ex != null);
|
||||
_exception = ex;
|
||||
this.NotifyCompletion();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When called in the dervied classes, wait for completion.
|
||||
/// It throws exception if the async operation ends with an exception.
|
||||
/// </summary>
|
||||
protected void WaitForCompletion()
|
||||
{
|
||||
if (!this.IsCompleted)
|
||||
{
|
||||
_asyncWaitEvent.WaitOne();
|
||||
}
|
||||
|
||||
if (this._exception != null)
|
||||
{
|
||||
throw this._exception;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When called in the derived classes, notify operation completion
|
||||
/// by setting <see cref="P:AsyncWaitHandle"/> and calling the user callback.
|
||||
/// </summary>
|
||||
[DebuggerNonUserCode]
|
||||
protected void NotifyCompletion()
|
||||
{
|
||||
_isCompleted = true;
|
||||
if (_asyncWaitEvent != null)
|
||||
{
|
||||
_asyncWaitEvent.Set();
|
||||
}
|
||||
|
||||
if (_userCallback != null)
|
||||
{
|
||||
_userCallback(this);
|
||||
}
|
||||
}
|
||||
|
||||
#region IDisposable Members
|
||||
|
||||
/// <summary>
|
||||
/// Disposes the object and release resource.
|
||||
/// </summary>
|
||||
public void Dispose()
|
||||
{
|
||||
this.Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// When overrided in the derived classes, release resources.
|
||||
/// </summary>
|
||||
/// <param name="disposing">Whether the method is called <see cref="M:Dispose"/></param>
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && _asyncWaitEvent != null)
|
||||
{
|
||||
_asyncWaitEvent.Close();
|
||||
_asyncWaitEvent = null;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the status of an async operation.
|
||||
/// It also holds the result of the operation.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Type of the operation result.</typeparam>
|
||||
internal class AsyncResult<T> : AsyncResult
|
||||
{
|
||||
/// <summary>
|
||||
/// The result of the async operation.
|
||||
/// </summary>
|
||||
private T _result;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes an instance of <see cref="AsyncResult<T>"/>.
|
||||
/// </summary>
|
||||
/// <param name="callback">The callback method when the async operation completes.</param>
|
||||
/// <param name="state">A user-defined object that qualifies or contains information about an asynchronous operation.</param>
|
||||
public AsyncResult(AsyncCallback callback, object state)
|
||||
: base(callback, state)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets result and release resources.
|
||||
/// </summary>
|
||||
/// <returns>The instance of result.</returns>
|
||||
public T GetResult()
|
||||
{
|
||||
base.WaitForCompletion();
|
||||
return _result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets result and notify completion.
|
||||
/// </summary>
|
||||
/// <param name="result">The instance of result.</param>
|
||||
public void Complete(T result)
|
||||
{
|
||||
// Complete should not throw if disposed.
|
||||
this._result = result;
|
||||
base.NotifyCompletion();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of DateUtils.
|
||||
/// </summary>
|
||||
public static class DateUtils
|
||||
{
|
||||
private static DateTime _1970StartDateTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
|
||||
private const string _rfc822DateFormat = "ddd, dd MMM yyyy HH:mm:ss \\G\\M\\T";
|
||||
private const string _iso8601DateFormat = "yyyy-MM-dd'T'HH:mm:ss.fff'Z'";
|
||||
|
||||
/// <summary>
|
||||
/// Formats an instance of <see cref="DateTime" /> to a GMT string.
|
||||
/// </summary>
|
||||
/// <param name="dt">The date time to format.</param>
|
||||
/// <returns></returns>
|
||||
public static string FormatRfc822Date(DateTime dt)
|
||||
{
|
||||
return dt.ToUniversalTime().ToString(_rfc822DateFormat,
|
||||
CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a GMT date string to an object of <see cref="DateTime" />.
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static DateTime ParseRfc822Date(String dt)
|
||||
{
|
||||
Debug.Assert(!string.IsNullOrEmpty(dt));
|
||||
return DateTime.SpecifyKind(
|
||||
DateTime.ParseExact(dt,
|
||||
_rfc822DateFormat,
|
||||
CultureInfo.InvariantCulture),
|
||||
DateTimeKind.Utc);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats a date to a string in the format of ISO 8601 spec.
|
||||
/// </summary>
|
||||
/// <param name="dt"></param>
|
||||
/// <returns></returns>
|
||||
public static string FormatIso8601Date(DateTime dt)
|
||||
{
|
||||
return dt.ToUniversalTime().ToString(_iso8601DateFormat,
|
||||
CultureInfo.CreateSpecificCulture("en-US"));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// convert time stamp to DateTime.
|
||||
/// </summary>
|
||||
/// <param name="timeStamp">seconds</param>
|
||||
/// <returns></returns>
|
||||
public static DateTime GetDateTime(uint timeStamp)
|
||||
{
|
||||
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
|
||||
long lTime = ((long)timeStamp * System.TimeSpan.TicksPerSecond);
|
||||
System.TimeSpan toNow = new System.TimeSpan(lTime);
|
||||
DateTime targetDt = dtStart.Add(toNow);
|
||||
return targetDt;
|
||||
}
|
||||
|
||||
public static uint TimeSpan() {
|
||||
return (uint)Math.Round((DateTime.Now - _1970StartDateTime).TotalSeconds, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of EnumUtils.
|
||||
/// </summary>
|
||||
internal static class EnumUtils
|
||||
{
|
||||
private static IDictionary<Enum, StringValueAttribute> _stringValues =
|
||||
new Dictionary<Enum, StringValueAttribute>();
|
||||
|
||||
public static string GetStringValue(this Enum value)
|
||||
{
|
||||
string output = null;
|
||||
Type type = value.GetType();
|
||||
|
||||
if (_stringValues.ContainsKey(value))
|
||||
{
|
||||
output = (_stringValues[value] as StringValueAttribute).Value;
|
||||
}
|
||||
else
|
||||
{
|
||||
FieldInfo fi = type.GetField(value.ToString());
|
||||
StringValueAttribute[] attrs =
|
||||
fi.GetCustomAttributes(typeof (StringValueAttribute),
|
||||
false) as StringValueAttribute[];
|
||||
if (attrs.Length > 0)
|
||||
{
|
||||
output = attrs[0].Value;
|
||||
// Put it in the cache.
|
||||
lock(_stringValues)
|
||||
{
|
||||
// Double check
|
||||
if (!_stringValues.ContainsKey(value))
|
||||
{
|
||||
_stringValues.Add(value, attrs[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return value.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of HttpHeaders.
|
||||
/// </summary>
|
||||
internal static class HttpHeaders
|
||||
{
|
||||
public const string Authorization = "Authorization";
|
||||
|
||||
public const string CacheControl = "Cache-Control";
|
||||
|
||||
public const string ContentDisposition = "Content-Disposition";
|
||||
|
||||
public const string ContentEncoding = "Content-Encoding";
|
||||
|
||||
public const string ContentLength = "Content-Length";
|
||||
|
||||
public const string ContentMd5 = "Content-MD5";
|
||||
|
||||
public const string ContentType = "Content-Type";
|
||||
|
||||
public const string Date = "Date";
|
||||
|
||||
public const string Expires = "Expires";
|
||||
|
||||
public const string ETag = "ETag";
|
||||
|
||||
public const string LastModified = "Last-Modified";
|
||||
|
||||
public const string Range = "Range";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of HttpUtils.
|
||||
/// </summary>
|
||||
internal static class HttpUtils
|
||||
{
|
||||
public const string UTF8Charset = "utf-8";
|
||||
public const string Iso88591Charset = "iso-8859-1";
|
||||
|
||||
/// <summary>
|
||||
/// Builds the URI parameter string from the request parameters.
|
||||
/// </summary>
|
||||
/// <param name="parameters"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetRequestParameterString(IEnumerable<KeyValuePair<string, string>> parameters)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
bool isFirst = true;
|
||||
foreach (var p in parameters)
|
||||
{
|
||||
Debug.Assert(!string.IsNullOrEmpty(p.Key), "Null Or empty key is not allowed.");
|
||||
if (!isFirst)
|
||||
{
|
||||
stringBuilder.Append("&");
|
||||
}
|
||||
isFirst = false;
|
||||
stringBuilder.Append(p.Key);
|
||||
if (p.Value != null)
|
||||
{
|
||||
stringBuilder.Append("=").Append(UrlEncode(p.Value, UTF8Charset));
|
||||
}
|
||||
}
|
||||
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Encodes the URL.
|
||||
/// </summary>
|
||||
/// <param name="data"></param>
|
||||
/// <param name="charset"></param>
|
||||
/// <returns></returns>
|
||||
public static string UrlEncode(string data, string charset = UTF8Charset)
|
||||
{
|
||||
Debug.Assert(data != null && !string.IsNullOrEmpty(charset));
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder(data.Length * 2);
|
||||
string text = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_.~";
|
||||
byte[] bytes = Encoding.GetEncoding(charset).GetBytes(data);
|
||||
foreach (char c in bytes)
|
||||
{
|
||||
if (text.IndexOf(c) != -1)
|
||||
{
|
||||
stringBuilder.Append(c);
|
||||
}
|
||||
else
|
||||
{
|
||||
stringBuilder.Append("%").Append(
|
||||
string.Format(CultureInfo.InvariantCulture, "{0:X2}", (int)c));
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
|
||||
// Convert a text from one charset to another.
|
||||
public static string ReEncode(string text, string fromCharset, string toCharset)
|
||||
{
|
||||
Debug.Assert(text != null);
|
||||
var buffer = Encoding.GetEncoding(fromCharset).GetBytes(text);
|
||||
return Encoding.GetEncoding(toCharset).GetString(buffer);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// Description of IOUtils.
|
||||
/// </summary>
|
||||
internal static class IOUtils
|
||||
{
|
||||
private const int _bufferSize = 1024 * 4;
|
||||
|
||||
public static void WriteTo(this Stream src, Stream dest){
|
||||
if (dest == null)
|
||||
throw new ArgumentNullException("dest");
|
||||
|
||||
byte[] buffer = new byte[_bufferSize];
|
||||
int bytesRead = 0;
|
||||
while((bytesRead = src.Read(buffer, 0, buffer.Length)) > 0)
|
||||
{
|
||||
dest.Write(buffer, 0, bytesRead);
|
||||
}
|
||||
dest.Flush();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write a stream to another
|
||||
/// </summary>
|
||||
/// <param name="orignStream">The stream you want to write from</param>
|
||||
/// <param name="destStream">The stream written to</param>
|
||||
/// <param name="maxLength">The max length of the stream to write</param>
|
||||
/// <returns>The actual length written to destStream</returns>
|
||||
public static long WriteTo(this Stream orignStream, Stream destStream, long maxLength)
|
||||
{
|
||||
const int buffSize = 1024;
|
||||
byte[] buff = new byte[buffSize];
|
||||
long alreadyRead = 0;
|
||||
|
||||
int readCount = 0;
|
||||
while (alreadyRead < maxLength)
|
||||
{
|
||||
readCount = orignStream.Read(buff, 0, buffSize);
|
||||
if (readCount <= 0) { break; }
|
||||
|
||||
if (alreadyRead + readCount > maxLength)
|
||||
{
|
||||
readCount = (int) (maxLength - alreadyRead);
|
||||
}
|
||||
alreadyRead += readCount;
|
||||
destStream.Write(buff, 0, readCount);
|
||||
}
|
||||
destStream.Flush();
|
||||
return alreadyRead;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
|
||||
namespace Aliyun.Api.LOG.Common.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// The Attribute to mark a field that corresponds a string.
|
||||
/// </summary>
|
||||
internal sealed class StringValueAttribute : System.Attribute
|
||||
{
|
||||
public string Value { get; private set; }
|
||||
|
||||
public StringValueAttribute(string value)
|
||||
{
|
||||
this.Value = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
90
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/Histogram.cs
Normal file
90
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/Histogram.cs
Normal file
@@ -0,0 +1,90 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// The log status(histogram info)
|
||||
/// </summary>
|
||||
public class Histogram
|
||||
{
|
||||
private UInt32 _from;
|
||||
private UInt32 _to;
|
||||
private Int64 _count;
|
||||
private String _progress;
|
||||
|
||||
/// <summary>
|
||||
/// The begin timestamp of time range
|
||||
/// </summary>
|
||||
public UInt32 From
|
||||
{
|
||||
get { return _from; }
|
||||
set { _from = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The end timestamp of time range
|
||||
/// </summary>
|
||||
public UInt32 To
|
||||
{
|
||||
get { return _to; }
|
||||
set { _to = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log count
|
||||
/// </summary>
|
||||
public Int64 Count
|
||||
{
|
||||
get { return _count; }
|
||||
set { _count = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// detect whether histogram is complete or not.
|
||||
/// </summary>
|
||||
/// <returns>true if return histogram is complete. otherwise return false</returns>
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return _progress == LogConsts.STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public Histogram()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static List<Histogram> DeserializeFromJson(JArray json)
|
||||
{
|
||||
List<Histogram> hlst = new List<Histogram>();
|
||||
if (json != null)
|
||||
{
|
||||
for (int i = 0; i < json.Count; ++i)
|
||||
{
|
||||
Histogram htg = new Histogram();
|
||||
htg._from = (UInt32)json[i][LogConsts.NAME_GETSTATUS_FROM];
|
||||
htg._to = (UInt32)json[i][LogConsts.NAME_GETSTATUS_TO];
|
||||
htg._count = (UInt32)json[i][LogConsts.NAME_GETSTATUS_COUNT];
|
||||
htg._progress = (String)json[i][LogConsts.NAME_GETSTATUS_PROGRESS];
|
||||
hlst.Add(htg);
|
||||
}
|
||||
}
|
||||
return hlst;
|
||||
}
|
||||
}
|
||||
}
|
||||
60
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/LogContent.cs
Normal file
60
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/LogContent.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// This class presents one log content in logItem
|
||||
/// </summary>
|
||||
public class LogContent
|
||||
{
|
||||
private String _key = String.Empty;
|
||||
private String _value = String.Empty;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public LogContent()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructure with specified parameters
|
||||
/// </summary>
|
||||
/// <param name="key">log content's key </param>
|
||||
/// <param name="value">log content's value </param>
|
||||
public LogContent(String key, String value)
|
||||
{
|
||||
_key = key;
|
||||
_value = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the logcontent's key
|
||||
/// </summary>
|
||||
public String Key
|
||||
{
|
||||
get { return _key; }
|
||||
set { _key = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// the logcontent's value
|
||||
/// </summary>
|
||||
public String Value
|
||||
{
|
||||
get { return _value; }
|
||||
set { _value = value; }
|
||||
}
|
||||
}
|
||||
}
|
||||
67
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/LogItem.cs
Normal file
67
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/LogItem.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// This class presents one log event item that will put into SLS
|
||||
/// </summary>
|
||||
public class LogItem
|
||||
{
|
||||
private UInt32 _time;
|
||||
private List<LogContent> _contents;
|
||||
|
||||
/// <summary>
|
||||
/// the log's timestamp
|
||||
/// </summary>
|
||||
public UInt32 Time
|
||||
{
|
||||
get { return _time; }
|
||||
set { _time = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// logcontents in logs
|
||||
/// </summary>
|
||||
public List<LogContent> Contents
|
||||
{
|
||||
get { return _contents; }
|
||||
set { _contents = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public LogItem()
|
||||
{
|
||||
_contents = new List<LogContent>();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method to append log content by key/value pair
|
||||
/// </summary>
|
||||
/// <param name="key">user define field to name the value</param>
|
||||
/// <param name="value">the value of field key</param>
|
||||
public void PushBack(String key, String value)
|
||||
{
|
||||
_contents.Add(new LogContent(key, value));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// method to append log content by key/value pair
|
||||
/// </summary>
|
||||
/// <param name="content">log content</param>
|
||||
public void PushBack(LogContent content)
|
||||
{
|
||||
_contents.Add(content);
|
||||
}
|
||||
}
|
||||
}
|
||||
99
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/QueriedLog.cs
Normal file
99
bin/aliyun-log-csharp-sdk-master/SLSSDK/Data/QueriedLog.cs
Normal file
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// QuriedLog used to present a log in query result. It contains log time, log source(ip/hostname,e.g),
|
||||
/// and multiple of key/value pairs to present the log content
|
||||
/// </summary>
|
||||
public class QueriedLog
|
||||
{
|
||||
private UInt32 _time;
|
||||
private String _source = String.Empty;
|
||||
private List<LogContent> _contents = new List<LogContent>();
|
||||
|
||||
/// <summary>
|
||||
/// The log timestamp
|
||||
/// </summary>
|
||||
public UInt32 Time
|
||||
{
|
||||
get { return _time; }
|
||||
set { _time = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log source
|
||||
/// </summary>
|
||||
public String Source
|
||||
{
|
||||
get { return _source; }
|
||||
set { _source = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of key/value pair to present the log content
|
||||
/// </summary>
|
||||
public List<LogContent> Contents
|
||||
{
|
||||
get { return _contents; }
|
||||
set { _contents = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public QueriedLog()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
internal static List<QueriedLog> DeserializeFromJson(JArray json)
|
||||
{
|
||||
List<QueriedLog> logs = new List<QueriedLog>();
|
||||
for (int i = 0; i < json.Count; ++i)
|
||||
{
|
||||
QueriedLog log = new QueriedLog();
|
||||
log._time = (UInt32)json[i][LogConsts.NAME_GETDATA_TIME];
|
||||
log._source = (String)json[i][LogConsts.NAME_GETDATA_SOURCE];
|
||||
log._contents = new List<LogContent>();
|
||||
foreach (var item in json[i].Children<JProperty>())
|
||||
{
|
||||
if (item.Name.CompareTo(LogConsts.NAME_GETDATA_TIME) != 0 && item.Name.CompareTo(LogConsts.NAME_GETDATA_SOURCE) != 0)
|
||||
{
|
||||
log._contents.Add(new LogContent(item.Name, (String)json[i][item.Name]));
|
||||
}
|
||||
}
|
||||
logs.Add(log);
|
||||
}
|
||||
return logs;
|
||||
}
|
||||
|
||||
//used only in testing project
|
||||
internal String Print()
|
||||
{
|
||||
StringBuilder strBuilder = new StringBuilder();
|
||||
if (_contents != null)
|
||||
{
|
||||
for (int i = 0; i < _contents.Count; ++i)
|
||||
{
|
||||
strBuilder.Append("(" + _contents[i].Key + "," + _contents[i].Value + ")");
|
||||
}
|
||||
}
|
||||
|
||||
return strBuilder.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
74
bin/aliyun-log-csharp-sdk-master/SLSSDK/Exception.cs
Normal file
74
bin/aliyun-log-csharp-sdk-master/SLSSDK/Exception.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
|
||||
namespace Aliyun.Api.LOG
|
||||
{
|
||||
/// <summary>
|
||||
/// The Exception of the sls request and response.
|
||||
/// </summary>
|
||||
public class LogException : ApplicationException
|
||||
{
|
||||
private String _errorCode;
|
||||
private String _requestId;
|
||||
/// <summary>
|
||||
/// Get Sls sever requestid.
|
||||
/// </summary>
|
||||
public String RequestId {
|
||||
get {
|
||||
return _requestId;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Get LogException error code.
|
||||
/// </summary>
|
||||
public String ErrorCode {
|
||||
get {
|
||||
return _errorCode;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// LogException constructor
|
||||
/// </summary>
|
||||
/// <param name="code">error code</param>
|
||||
/// <param name="message">error message</param>
|
||||
/// <param name="requestId">request identifier</param>
|
||||
public LogException(String code, String message,String requestId = "")
|
||||
: base(message) {
|
||||
_errorCode = code;
|
||||
_requestId = requestId;
|
||||
}
|
||||
/// <summary>
|
||||
/// LogException constructor
|
||||
/// </summary>
|
||||
/// <param name="code">error code</param>
|
||||
/// <param name="message">error message</param>
|
||||
/// <param name="innerException">the inner exception wrapped by LogException</param>
|
||||
/// <param name="requestId"></param>
|
||||
public LogException(String code, String message, Exception innerException, String requestId = "")
|
||||
: base(message, innerException)
|
||||
{
|
||||
_errorCode = code;
|
||||
_requestId = requestId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// get string presentation of LogException
|
||||
/// </summary>
|
||||
/// <returns>object in string</returns>
|
||||
public override String ToString()
|
||||
{
|
||||
String msgFormat = @"ErrorCode : {0}, Message: {1}, RequestId: {2}";
|
||||
return String.Format(msgFormat, _errorCode, Message, _requestId);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
#if SLS_SDK_40
|
||||
[assembly: AssemblyTitle("SLS SDK .NET 4.0")]
|
||||
#elif SLS_SDK_35
|
||||
[assembly: AssemblyTitle("SLS SDK .NET 3.5")]
|
||||
#else
|
||||
[assembly: AssemblyTitle("SLS SDK .NET")]
|
||||
#endif
|
||||
|
||||
[assembly: AssemblyDescription(".NET SDK for Aliyun Simple Log Service (SLS)")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("Aliyun")]
|
||||
[assembly: AssemblyProduct("SLSSDK")]
|
||||
[assembly: AssemblyCopyright("Copyright © Aliyun 2014")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("4328d16b-4359-4acd-a34e-d5c0224572c0")]
|
||||
[assembly: InternalsVisibleTo("SLSSDKTest")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("0.6.0")]
|
||||
[assembly: AssemblyFileVersion("0.6.0")]
|
||||
99
bin/aliyun-log-csharp-sdk-master/SLSSDK/Properties/Resources.Designer.cs
generated
Normal file
99
bin/aliyun-log-csharp-sdk-master/SLSSDK/Properties/Resources.Designer.cs
generated
Normal file
@@ -0,0 +1,99 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <auto-generated>
|
||||
// This code was generated by a tool.
|
||||
// Runtime Version:4.0.30319.18408
|
||||
//
|
||||
// Changes to this file may cause incorrect behavior and will be lost if
|
||||
// the code is regenerated.
|
||||
// </auto-generated>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace Aliyun.Api.LOG.Properties {
|
||||
using System;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A strongly-typed resource class, for looking up localized strings, etc.
|
||||
/// </summary>
|
||||
// This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
// class via a tool like ResGen or Visual Studio.
|
||||
// To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
// with the /str option, or rebuild your VS project.
|
||||
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
|
||||
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
|
||||
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
|
||||
internal class Resources {
|
||||
|
||||
private static global::System.Resources.ResourceManager resourceMan;
|
||||
|
||||
private static global::System.Globalization.CultureInfo resourceCulture;
|
||||
|
||||
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
|
||||
internal Resources() {
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the cached ResourceManager instance used by this class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Resources.ResourceManager ResourceManager {
|
||||
get {
|
||||
if (object.ReferenceEquals(resourceMan, null)) {
|
||||
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Aliyun.Api.LOG.Properties.Resources", typeof(Resources).Assembly);
|
||||
resourceMan = temp;
|
||||
}
|
||||
return resourceMan;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the current thread's CurrentUICulture property for all
|
||||
/// resource lookups using this strongly typed resource class.
|
||||
/// </summary>
|
||||
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
|
||||
internal static global::System.Globalization.CultureInfo Culture {
|
||||
get {
|
||||
return resourceCulture;
|
||||
}
|
||||
set {
|
||||
resourceCulture = value;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 以前使用 asyncResult调用过此方法。.
|
||||
/// </summary>
|
||||
internal static string ExceptionEndOperationHasBeenCalled {
|
||||
get {
|
||||
return ResourceManager.GetString("ExceptionEndOperationHasBeenCalled", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 参数为空引用或值为长度是零的字符串。.
|
||||
/// </summary>
|
||||
internal static string ExceptionIfArgumentStringIsNullOrEmpty {
|
||||
get {
|
||||
return ResourceManager.GetString("ExceptionIfArgumentStringIsNullOrEmpty", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 返回结果无法解析。.
|
||||
/// </summary>
|
||||
internal static string ExceptionInvalidResponse {
|
||||
get {
|
||||
return ResourceManager.GetString("ExceptionInvalidResponse", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to 服务器返回未知错误。.
|
||||
/// </summary>
|
||||
internal static string ExceptionUnknowError {
|
||||
get {
|
||||
return ResourceManager.GetString("ExceptionUnknowError", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ExceptionEndOperationHasBeenCalled" xml:space="preserve">
|
||||
<value>以前使用 asyncResult调用过此方法。</value>
|
||||
</data>
|
||||
<data name="ExceptionIfArgumentStringIsNullOrEmpty" xml:space="preserve">
|
||||
<value>参数为空引用或值为长度是零的字符串。</value>
|
||||
</data>
|
||||
<data name="ExceptionInvalidResponse" xml:space="preserve">
|
||||
<value>返回结果无法解析。</value>
|
||||
</data>
|
||||
<data name="ExceptionUnknowError" xml:space="preserve">
|
||||
<value>服务器返回未知错误。</value>
|
||||
</data>
|
||||
</root>
|
||||
1839
bin/aliyun-log-csharp-sdk-master/SLSSDK/Proto/LogGroup.cs
Normal file
1839
bin/aliyun-log-csharp-sdk-master/SLSSDK/Proto/LogGroup.cs
Normal file
File diff suppressed because it is too large
Load Diff
26
bin/aliyun-log-csharp-sdk-master/SLSSDK/Proto/LogGroup.proto
Normal file
26
bin/aliyun-log-csharp-sdk-master/SLSSDK/Proto/LogGroup.proto
Normal file
@@ -0,0 +1,26 @@
|
||||
import "google/protobuf/csharp_options.proto";
|
||||
option (google.protobuf.csharp_file_options).namespace = "Aliyun.Api.LOG";
|
||||
|
||||
message Log
|
||||
{
|
||||
required uint32 Time = 1;// UNIX Time Format
|
||||
message Content
|
||||
{
|
||||
required string Key = 1;
|
||||
required string Value = 2;
|
||||
}
|
||||
repeated Content Contents= 2;
|
||||
|
||||
}
|
||||
message LogGroup
|
||||
{
|
||||
repeated Log Logs= 1;
|
||||
optional string Reserved =2; // <20>ڲ<EFBFBD><DAB2>ֶΣ<D6B6><CEA3><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><D2AA>д
|
||||
optional string Topic = 3;
|
||||
optional string Source = 4;
|
||||
}
|
||||
|
||||
message LogGroupList
|
||||
{
|
||||
repeated LogGroup logGroupList = 1;
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
public class BatchGetLogsRequest: LogStoreRequest
|
||||
{
|
||||
private int _shard;
|
||||
private int _count;
|
||||
private String _cursor;
|
||||
public int Shard
|
||||
{
|
||||
get { return _shard; }
|
||||
set { _shard = value; }
|
||||
}
|
||||
public int Count
|
||||
{
|
||||
get { return _count; }
|
||||
set { _count = value; }
|
||||
}
|
||||
public String Cursor
|
||||
{
|
||||
get { return _cursor; }
|
||||
set { _cursor = value; }
|
||||
}
|
||||
public BatchGetLogsRequest(String project, String logstore, int shard, String cursor, int count)
|
||||
: base(project, logstore)
|
||||
{
|
||||
Shard = shard;
|
||||
Cursor = cursor;
|
||||
Count = count;
|
||||
}
|
||||
override public void AddSpecParamsTo(IDictionary<String, String> dic)
|
||||
{
|
||||
dic.Add("type", "log");
|
||||
dic.Add("cursor", Cursor);
|
||||
dic.Add("count", _count.ToString());
|
||||
}
|
||||
override public void AddSpecHeadersTo(IDictionary<String, String> dic)
|
||||
{
|
||||
dic.Add(LogConsts.NAME_HEADER_ACCEPT_ENCODING, LogConsts.VALUE_HEADER_COMPRESSTYPE_LZ4);
|
||||
dic.Add(LogConsts.NAME_HEADER_ACCEPT, LogConsts.PBVALUE_HEADER_CONTENTTYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
using Aliyun.Api.LOG.Request;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
public enum ShardCursorMode
|
||||
{
|
||||
BEGIN, END
|
||||
};
|
||||
public class GetCursorRequest : LogStoreRequest
|
||||
{
|
||||
private int _shard;
|
||||
private ShardCursorMode? _cursorMode;
|
||||
private uint? _cursorTime;
|
||||
public int Shard
|
||||
{
|
||||
get { return _shard; }
|
||||
set { _shard = value; }
|
||||
}
|
||||
public ShardCursorMode CursorMode
|
||||
{
|
||||
get { return _cursorMode ?? default(ShardCursorMode); }
|
||||
set { _cursorMode = value; }
|
||||
}
|
||||
public bool IsSetCursorMode()
|
||||
{
|
||||
return _cursorMode.HasValue;
|
||||
}
|
||||
public uint CursorTime
|
||||
{
|
||||
get { return _cursorTime ?? default(uint); }
|
||||
set { _cursorTime = value; }
|
||||
}
|
||||
public GetCursorRequest(String project, String logstore, int shard, ShardCursorMode mode)
|
||||
: base(project, logstore)
|
||||
{
|
||||
Shard = shard;
|
||||
CursorMode = mode;
|
||||
}
|
||||
public GetCursorRequest(String project, String logstore, int shard, uint time)
|
||||
: base(project, logstore)
|
||||
{
|
||||
Shard = shard;
|
||||
CursorTime = time;
|
||||
}
|
||||
override public void AddSpecParamsTo(IDictionary<String, String> dic)
|
||||
{
|
||||
dic.Add("type", "cursor");
|
||||
if (IsSetCursorMode())
|
||||
{
|
||||
dic.Add("from", CursorMode == ShardCursorMode.BEGIN ? "begin" : "end");
|
||||
}
|
||||
else
|
||||
{
|
||||
dic.Add("from", _cursorTime.ToString());
|
||||
}
|
||||
}
|
||||
override public void AddSpecHeadersTo(IDictionary<String, String> dic)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,140 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The Request used to get histograms of a query from sls server
|
||||
/// </summary>
|
||||
public class GetHistogramsRequest : LogRequest
|
||||
{
|
||||
private String _logstore;
|
||||
private String _topic;
|
||||
private uint? _from;
|
||||
private uint? _to;
|
||||
private String _query;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor.
|
||||
/// please set required fileds(project, logstore, from, to) initialized by this default constructor before
|
||||
/// using it to send request. Otherwise, request will be failed with exception.
|
||||
/// </summary>
|
||||
public GetHistogramsRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all required fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="from">begin timestamp of time range to query</param>
|
||||
/// <param name="to">end timestamp of time range to query</param>
|
||||
public GetHistogramsRequest(String project, String logstore, uint from, uint to)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_from = from;
|
||||
_to = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all possible fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="from">begin timestamp of time range to query</param>
|
||||
/// <param name="to">end timestamp of time range to query</param>
|
||||
/// <param name="topic">log topic to query</param>
|
||||
/// <param name="query">query string to run</param>
|
||||
public GetHistogramsRequest(String project, String logstore, uint from, uint to, String topic, String query)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_from = from;
|
||||
_to = to;
|
||||
_topic = topic;
|
||||
_query = query;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logstore name
|
||||
/// </summary>
|
||||
public String Logstore
|
||||
{
|
||||
get { return _logstore; }
|
||||
set { _logstore = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLogstore()
|
||||
{
|
||||
return _logstore != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log topic to query
|
||||
/// </summary>
|
||||
public String Topic
|
||||
{
|
||||
get { return _topic; }
|
||||
set { _topic = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetTopic()
|
||||
{
|
||||
return _topic != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The begin timestamp of time range to query
|
||||
/// </summary>
|
||||
public uint From
|
||||
{
|
||||
get { return _from ?? default(uint); }
|
||||
set { _from = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetFrom()
|
||||
{
|
||||
return _from.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The end timestamp of time range to query
|
||||
/// </summary>
|
||||
public uint To
|
||||
{
|
||||
get { return _to ?? default(uint); }
|
||||
set { _to = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetTo()
|
||||
{
|
||||
return _to.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The query string to run
|
||||
/// </summary>
|
||||
public String Query
|
||||
{
|
||||
get { return _query; }
|
||||
set { _query = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetQuery()
|
||||
{
|
||||
return _query != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,193 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The Request used to get data of a query from sls server
|
||||
/// </summary>
|
||||
public class GetLogsRequest : LogRequest
|
||||
{
|
||||
private String _logstore;
|
||||
private String _topic;
|
||||
private uint? _from;
|
||||
private uint? _to;
|
||||
private String _query;
|
||||
private int? _lines;
|
||||
private long? _offset;
|
||||
private bool? _reverse;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor.
|
||||
/// please set required fileds(project, logstore, from, to) initialized by this default constructor before
|
||||
/// using it to send request. Otherwise, request will be failed with exception.
|
||||
/// </summary>
|
||||
public GetLogsRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all required fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="from">begin timestamp of time range to query</param>
|
||||
/// <param name="to">end timestamp of time range to query</param>
|
||||
public GetLogsRequest(String project, String logstore, uint from, uint to)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_from = from;
|
||||
_to = to;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all possible fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="from">begin timestamp of time range to query</param>
|
||||
/// <param name="to">end timestamp of time range to query</param>
|
||||
/// <param name="topic">log topic to query</param>
|
||||
/// <param name="query">query string to run</param>
|
||||
/// <param name="lines">count of logs to request</param>
|
||||
/// <param name="offset">offset of logs to request</param>
|
||||
/// <param name="reverse">flag indicates whether logs in response are in reversed order</param>
|
||||
public GetLogsRequest(String project, String logstore, uint from, uint to, String topic, String query,
|
||||
int lines, int offset, bool reverse)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_from = from;
|
||||
_to = to;
|
||||
_topic = topic;
|
||||
_query = query;
|
||||
_lines = lines;
|
||||
_offset = offset;
|
||||
_reverse = reverse;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logstore name
|
||||
/// </summary>
|
||||
public String Logstore
|
||||
{
|
||||
get { return _logstore; }
|
||||
set { _logstore = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLogstore()
|
||||
{
|
||||
return _logstore != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log topic to query
|
||||
/// </summary>
|
||||
public String Topic
|
||||
{
|
||||
get { return _topic; }
|
||||
set { _topic = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetTopic()
|
||||
{
|
||||
return _topic != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The begin timestamp of time range to query
|
||||
/// </summary>
|
||||
public uint From
|
||||
{
|
||||
get { return _from ?? default(uint); }
|
||||
set { _from = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetFrom()
|
||||
{
|
||||
return _from.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The end timestamp of time range to query
|
||||
/// </summary>
|
||||
public uint To
|
||||
{
|
||||
get { return _to ?? default(uint); }
|
||||
set { _to = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetTo()
|
||||
{
|
||||
return _to.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The query string to run
|
||||
/// </summary>
|
||||
public String Query
|
||||
{
|
||||
get { return _query; }
|
||||
set { _query = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetQuery()
|
||||
{
|
||||
return _query != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The count of logs to request
|
||||
/// </summary>
|
||||
public int Lines
|
||||
{
|
||||
get { return _lines ?? default(int); }
|
||||
set { _lines = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLines()
|
||||
{
|
||||
return _lines.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The offset of logs to request
|
||||
/// </summary>
|
||||
public long Offset
|
||||
{
|
||||
get { return _offset ?? default(long); }
|
||||
set { _offset = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetOffset()
|
||||
{
|
||||
return _offset.HasValue;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// flag of logs' order int response.
|
||||
/// If reverse is true, the query will return the latest logs.
|
||||
/// </summary>
|
||||
public bool Reverse
|
||||
{
|
||||
get { return _reverse ?? false; }
|
||||
set { _reverse = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetReverse()
|
||||
{
|
||||
return _reverse.HasValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The request used to list log store from sls server
|
||||
/// </summary>
|
||||
public class ListLogstoresRequest : LogRequest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// default constructor
|
||||
/// </summary>
|
||||
public ListLogstoresRequest()
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// constructor with project name
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
public ListLogstoresRequest(String project): base(project){
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
public class ListShardsRequest: LogStoreRequest
|
||||
{
|
||||
public ListShardsRequest(String projrct, String logstore)
|
||||
: base(projrct, logstore)
|
||||
{
|
||||
}
|
||||
override public void AddSpecParamsTo(IDictionary<String, String> dic)
|
||||
{
|
||||
|
||||
}
|
||||
override public void AddSpecHeadersTo(IDictionary<String, String> dic)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The request used to list topic from sls server
|
||||
/// </summary>
|
||||
public class ListTopicsRequest : LogRequest
|
||||
{
|
||||
private String _logstore;
|
||||
private String _token;
|
||||
private int? _lines;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor.
|
||||
/// please set required fileds(project, logstore) initialized by this default constructor before using it to
|
||||
/// send request. Otherwise, request will be failed with exception.
|
||||
/// </summary>
|
||||
public ListTopicsRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all required fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
public ListTopicsRequest(String project, String logstore)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all possible fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="token">token to list more topics</param>
|
||||
/// <param name="lines">count of topics to request</param>
|
||||
public ListTopicsRequest(String project, String logstore, String token, Int32 lines)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_token = token;
|
||||
_lines = lines;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logstore name
|
||||
/// </summary>
|
||||
public String Logstore
|
||||
{
|
||||
get { return _logstore; }
|
||||
set { _logstore = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLogstore()
|
||||
{
|
||||
return _logstore != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The token to list more topics
|
||||
/// </summary>
|
||||
public String Token
|
||||
{
|
||||
get { return _token; }
|
||||
set { _token = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetToken()
|
||||
{
|
||||
return _token != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The count of topics to request
|
||||
/// </summary>
|
||||
public int Lines
|
||||
{
|
||||
get { return _lines ?? default(int); }
|
||||
set { _lines = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLines()
|
||||
{
|
||||
return _lines.HasValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
using Aliyun.Api.LOG.Request;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
public abstract class LogStoreRequest : LogRequest
|
||||
{
|
||||
private String _logstore;
|
||||
|
||||
/// <summary>
|
||||
/// The logstore name
|
||||
/// </summary>
|
||||
public String Logstore
|
||||
{
|
||||
get { return _logstore; }
|
||||
set { _logstore = value; }
|
||||
}
|
||||
public LogStoreRequest(String project, String logstore)
|
||||
: base(project)
|
||||
{
|
||||
Logstore = logstore;
|
||||
}
|
||||
abstract public void AddSpecParamsTo(IDictionary<String, String> dic);
|
||||
abstract public void AddSpecHeadersTo(IDictionary<String, String> dic);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aliyun.Api.LOG.Data;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// The request used to send data to sls server
|
||||
/// Note: if source is not set explicitly, machine's local private ip is used
|
||||
/// </summary>
|
||||
public class PutLogsRequest : LogRequest
|
||||
{
|
||||
private String _logstore;
|
||||
private String _topic;
|
||||
private String _source;
|
||||
private List<LogItem> _logItems;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor.
|
||||
/// please set required fileds(project, logstore) initialized by this default constructor before
|
||||
/// using it to send request. Otherwise, request will be failed with exception.
|
||||
/// </summary>
|
||||
public PutLogsRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all required fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
public PutLogsRequest(String project, String logstore)
|
||||
: base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructor with all possilbe fileds
|
||||
/// </summary>
|
||||
/// <param name="project">project name</param>
|
||||
/// <param name="logstore">logstore name</param>
|
||||
/// <param name="topic">log topic</param>
|
||||
/// <param name="source">log source</param>
|
||||
/// <param name="items">log data</param>
|
||||
public PutLogsRequest(String project, String logstore, String topic, String source, List<LogItem> items)
|
||||
:base(project)
|
||||
{
|
||||
_logstore = logstore;
|
||||
_topic = topic;
|
||||
_source = source;
|
||||
_logItems = items;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The logstore name
|
||||
/// </summary>
|
||||
public String Logstore
|
||||
{
|
||||
get { return _logstore; }
|
||||
set { _logstore = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLogstore()
|
||||
{
|
||||
return _logstore != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log topic
|
||||
/// </summary>
|
||||
public String Topic
|
||||
{
|
||||
get { return _topic; }
|
||||
set { _topic = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetTopic()
|
||||
{
|
||||
return _topic != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The log source
|
||||
/// </summary>
|
||||
public String Source
|
||||
{
|
||||
get { return _source; }
|
||||
set { _source = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetSource()
|
||||
{
|
||||
return _source != null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of logs
|
||||
/// </summary>
|
||||
public List<LogItem> LogItems
|
||||
{
|
||||
get { return _logItems; }
|
||||
set { _logItems = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetLogItems()
|
||||
{
|
||||
return _logItems != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
bin/aliyun-log-csharp-sdk-master/SLSSDK/Request/Request.cs
Normal file
53
bin/aliyun-log-csharp-sdk-master/SLSSDK/Request/Request.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Request
|
||||
{
|
||||
/// <summary>
|
||||
/// Super class of all request
|
||||
/// </summary>
|
||||
public class LogRequest
|
||||
{
|
||||
private String _project;
|
||||
|
||||
/// <summary>
|
||||
/// default constructor of SLS Request.
|
||||
/// </summary>
|
||||
public LogRequest()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// LogRequest constructor with project name.
|
||||
/// </summary>
|
||||
/// <param name="project">project name to do SLS Request</param>
|
||||
public LogRequest(String project)
|
||||
{
|
||||
_project = project;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// project name of the request
|
||||
/// </summary>
|
||||
public String Project
|
||||
{
|
||||
get { return _project; }
|
||||
set { _project = value; }
|
||||
}
|
||||
|
||||
internal bool IsSetProject()
|
||||
{
|
||||
return _project != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
using Aliyun.Api.LOG;
|
||||
using Aliyun.Api.LOG.Response;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
public class BatchGetLogsResponse : LogResponse
|
||||
{
|
||||
private String _nextCursor;
|
||||
private int _logCount;
|
||||
private int _rawSize;
|
||||
private LogGroupList _logGroupList;
|
||||
|
||||
public BatchGetLogsResponse(IDictionary<String, String> headers, Stream body)
|
||||
: base(headers)
|
||||
{
|
||||
headers.TryGetValue(LogConsts.NAME_HEADER_NEXT_CURSOR, out _nextCursor);
|
||||
String tmpLogCount, tmpRawSize, tmpContentLength ;
|
||||
if (headers.TryGetValue(LogConsts.NAME_HEADER_LOG_COUNT, out tmpLogCount))
|
||||
{
|
||||
int.TryParse(tmpLogCount, out _logCount);
|
||||
}
|
||||
if (headers.TryGetValue(LogConsts.NAME_HEADER_LOG_BODY_RAW_SIZE, out tmpRawSize))
|
||||
{
|
||||
int.TryParse(tmpRawSize, out _rawSize);
|
||||
}
|
||||
int contentLength = 0;
|
||||
if (headers.TryGetValue("Content-Length", out tmpContentLength))
|
||||
{
|
||||
int.TryParse(tmpContentLength, out contentLength);
|
||||
}
|
||||
_logGroupList = LogGroupList.ParseFrom(LogClientTools.DecompressFromLZ4(body, _rawSize));
|
||||
}
|
||||
|
||||
public String NextCursor
|
||||
{
|
||||
get { return _nextCursor; }
|
||||
}
|
||||
public int LogCount
|
||||
{
|
||||
get { return _logCount; }
|
||||
}
|
||||
public int RawSize
|
||||
{
|
||||
get { return _rawSize; }
|
||||
}
|
||||
public LogGroupList LogGroupList
|
||||
{
|
||||
get { return _logGroupList; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using Aliyun.Api.LOG.Response;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
public class GetCursorResponse : LogResponse
|
||||
{
|
||||
private String _cursor;
|
||||
public String Cursor
|
||||
{
|
||||
get { return _cursor; }
|
||||
set { _cursor = value; }
|
||||
}
|
||||
public GetCursorResponse(IDictionary<String, String> headers, String cursor)
|
||||
: base(headers)
|
||||
{
|
||||
Cursor = cursor;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aliyun.Api.LOG.Data;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// The response of the GetHistogram API from sls server
|
||||
/// </summary>
|
||||
public class GetHistogramsResponse : LogResponse
|
||||
{
|
||||
private String _progress;
|
||||
private Int64 _count;
|
||||
private List<Histogram> _histograms;
|
||||
|
||||
/// <summary>
|
||||
/// constructor with http header and body from response
|
||||
/// </summary>
|
||||
/// <param name="headers">http header from respsone</param>
|
||||
/// <param name="jsonBody">http body (in json) from response</param>
|
||||
public GetHistogramsResponse(IDictionary<String, String> headers, JArray jsonBody)
|
||||
:base(headers)
|
||||
{
|
||||
String count;
|
||||
if (headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_COUNT, out count))
|
||||
{
|
||||
_count = Int64.Parse(count);
|
||||
}
|
||||
headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_PROGRESS, out _progress);
|
||||
ParseResponseBody(jsonBody);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// detect whether response are complete or not.
|
||||
/// </summary>
|
||||
/// <returns>true if response is complete. otherwise return false</returns>
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return _progress == LogConsts.STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The count of histograms
|
||||
/// </summary>
|
||||
public Int64 TotalCount
|
||||
{
|
||||
get { return _count; }
|
||||
}
|
||||
/// <summary>
|
||||
/// All of histograms
|
||||
/// </summary>
|
||||
public List<Histogram> Histograms
|
||||
{
|
||||
get { return _histograms; }
|
||||
}
|
||||
|
||||
internal override void DeserializeFromJsonInternal(JArray json)
|
||||
{
|
||||
_histograms = Histogram.DeserializeFromJson(json);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aliyun.Api.LOG.Data;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// The response of the GetLog API from sls server
|
||||
/// </summary>
|
||||
public class GetLogsResponse : LogResponse
|
||||
{
|
||||
private Int64 _count;
|
||||
private String _progress;
|
||||
private List<QueriedLog> _logs;
|
||||
|
||||
/// <summary>
|
||||
/// constructor with http header and body from response
|
||||
/// </summary>
|
||||
/// <param name="headers">http header from response</param>
|
||||
/// <param name="jsonBody">http body (in json) from response</param>
|
||||
public GetLogsResponse(IDictionary<String, String> headers, JArray jsonBody)
|
||||
:base(headers)
|
||||
{
|
||||
String count;
|
||||
if(headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_COUNT, out count))
|
||||
{
|
||||
_count = Int64.Parse(count);
|
||||
}
|
||||
headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_PROGRESS, out _progress);
|
||||
ParseResponseBody(jsonBody);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The count of logs
|
||||
/// </summary>
|
||||
public Int64 Count
|
||||
{
|
||||
get { return _count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// detect whether response are complete or not.
|
||||
/// </summary>
|
||||
/// <returns>true if response is complete. otherwise return false</returns>
|
||||
public bool IsCompleted()
|
||||
{
|
||||
return _progress == LogConsts.STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// List of logs
|
||||
/// </summary>
|
||||
public List<QueriedLog> Logs
|
||||
{
|
||||
get { return _logs; }
|
||||
}
|
||||
|
||||
internal override void DeserializeFromJsonInternal(JArray json)
|
||||
{
|
||||
_logs = QueriedLog.DeserializeFromJson(json);
|
||||
}
|
||||
|
||||
//used only in testing project
|
||||
internal String Print()
|
||||
{
|
||||
StringBuilder strBuilder = new StringBuilder();
|
||||
strBuilder.Append("{count:" + _count + "," + "progress:" + _progress + ",");
|
||||
if (_logs != null)
|
||||
{
|
||||
strBuilder.Append("{");
|
||||
foreach (QueriedLog log in _logs)
|
||||
strBuilder.Append("[" + log.Print() + "]");
|
||||
strBuilder.Append("}");
|
||||
}
|
||||
strBuilder.Append("}");
|
||||
return strBuilder.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// The response of the ListLogStore API from sls server
|
||||
/// </summary>
|
||||
public class ListLogstoresResponse : LogResponse
|
||||
{
|
||||
private int _count;
|
||||
private List<String> _logstores;
|
||||
|
||||
/// <summary>
|
||||
/// constructor with http header and body from response
|
||||
/// </summary>
|
||||
/// <param name="headers">http header from respsone</param>
|
||||
/// <param name="jsonBody">http body (in json) from response</param>
|
||||
public ListLogstoresResponse(IDictionary<String, String> headers, JObject jsonBody)
|
||||
:base(headers)
|
||||
{
|
||||
ParseResponseBody(jsonBody);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Count of the logstores
|
||||
/// </summary>
|
||||
public int Count
|
||||
{
|
||||
get { return _count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All of the logstores
|
||||
/// </summary>
|
||||
public List<String> Logstores
|
||||
{
|
||||
get { return _logstores; }
|
||||
}
|
||||
|
||||
internal override void DeserializeFromJsonInternal(JObject json)
|
||||
{
|
||||
_count = (int)json[LogConsts.NAME_LISTLOGSTORE_TOTAL];
|
||||
_logstores = JsonConvert.DeserializeObject<List<string>>(json[LogConsts.NAME_LISTLOGSTORE_ITEM].ToString());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
using Aliyun.Api.LOG.Response;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
public class ListShardsResponse: LogResponse
|
||||
{
|
||||
private List<int> _shards;
|
||||
|
||||
public ListShardsResponse(IDictionary<String, String> httpHeaders, JArray body)
|
||||
: base(httpHeaders)
|
||||
{
|
||||
ParseResponseBody(body);
|
||||
}
|
||||
|
||||
public List<int> Shards
|
||||
{
|
||||
get { return _shards; }
|
||||
}
|
||||
internal override void DeserializeFromJsonInternal(JArray json)
|
||||
{
|
||||
_shards = new List<int>();
|
||||
foreach(JObject obj in json.Children<JObject>())
|
||||
{
|
||||
_shards.Add(int.Parse(obj.GetValue("shardID").ToString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// The response of the ListTopic API from sls server
|
||||
/// </summary>
|
||||
public class ListTopicsResponse : LogResponse
|
||||
{
|
||||
private Int64 _count;
|
||||
private String _nextToken;
|
||||
private List<String> _topics;
|
||||
|
||||
/// <summary>
|
||||
/// constructor with http header and body from response
|
||||
/// </summary>
|
||||
/// <param name="headers">http header from respsone</param>
|
||||
/// <param name="jsonBody">http body (in json) from response</param>
|
||||
public ListTopicsResponse(IDictionary<String, String> headers, JArray jsonBody)
|
||||
:base(headers)
|
||||
{
|
||||
headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_NEXT_TOKEN, out _nextToken);
|
||||
String tmpCount;
|
||||
if (headers.TryGetValue(LogConsts.NAME_HEADER_X_LOG_COUNT, out tmpCount))
|
||||
{
|
||||
_count = int.Parse(tmpCount);
|
||||
}
|
||||
ParseResponseBody(jsonBody);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The count of log topics in the response
|
||||
/// </summary>
|
||||
public Int64 Count
|
||||
{
|
||||
get { return _count; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The next token property in the response. It is used to list more topics in next ListTopics request.
|
||||
/// If there is no more topics to list, it will return an empty string.
|
||||
/// </summary>
|
||||
public String NextToken
|
||||
{
|
||||
get { return _nextToken; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// All log topics in the response
|
||||
/// </summary>
|
||||
public List<String> Topics
|
||||
{
|
||||
get { return _topics; }
|
||||
}
|
||||
internal override void DeserializeFromJsonInternal(JArray json)
|
||||
{
|
||||
_topics = JsonConvert.DeserializeObject<List<string>>(json.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// The response of the PutLogs API from sls server
|
||||
/// </summary>
|
||||
public class PutLogsResponse : LogResponse
|
||||
{
|
||||
/// <summary>
|
||||
/// default constructor for PutLogsResponse
|
||||
/// </summary>
|
||||
/// <param name="header">header information in http response</param>
|
||||
public PutLogsResponse(IDictionary<String, String>header)
|
||||
:base(header)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
95
bin/aliyun-log-csharp-sdk-master/SLSSDK/Response/Response.cs
Normal file
95
bin/aliyun-log-csharp-sdk-master/SLSSDK/Response/Response.cs
Normal file
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Response
|
||||
{
|
||||
/// <summary>
|
||||
/// Super class of SLS response
|
||||
/// </summary>
|
||||
public class LogResponse
|
||||
{
|
||||
// Http header of the response
|
||||
private Dictionary<String, String> _headers = new Dictionary<String, String>();
|
||||
|
||||
/// <summary>
|
||||
/// LogResponse constructor with HTTP response headers
|
||||
/// </summary>
|
||||
/// <param name="httpHeaders">HTTP response header from SLS server</param>
|
||||
public LogResponse(IDictionary<String, String> httpHeaders)
|
||||
{
|
||||
_headers = new Dictionary<String, String>(httpHeaders);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the value from the head of response using key
|
||||
/// </summary>
|
||||
/// <returns>Value of specified http header</returns>
|
||||
public String GetHeader(String key)
|
||||
{
|
||||
String res = null;
|
||||
_headers.TryGetValue(key, out res);
|
||||
return res;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get request Id for current response generated on server-side. it is useful to track any potential issues
|
||||
/// for this request.
|
||||
/// </summary>
|
||||
/// <returns>request Id generated on server-side</returns>
|
||||
public String GetRequestId()
|
||||
{
|
||||
String requestId = String.Empty;
|
||||
_headers.TryGetValue(LogConsts.NAME_HEADER_REQUESTID, out requestId);
|
||||
return requestId;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get all the http response headers
|
||||
/// </summary>
|
||||
/// <returns>Key-pair map for http headers</returns>
|
||||
public Dictionary<String, String> GetAllHeaders()
|
||||
{
|
||||
return new Dictionary<String, String>(_headers);
|
||||
}
|
||||
|
||||
//internal helper function to consolidate logic to throw exception when parsing json string in http response.
|
||||
internal void ParseResponseBody(JObject jsonBody)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeserializeFromJsonInternal(jsonBody);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "The response is not valid json string : " + jsonBody, ex, GetRequestId());
|
||||
}
|
||||
}
|
||||
internal void ParseResponseBody(JArray jsonBody)
|
||||
{
|
||||
try
|
||||
{
|
||||
DeserializeFromJsonInternal(jsonBody);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "The response is not valid json string : " + jsonBody, ex, GetRequestId());
|
||||
}
|
||||
}
|
||||
|
||||
internal virtual void DeserializeFromJsonInternal(JObject json) { }
|
||||
internal virtual void DeserializeFromJsonInternal(JArray json) { }
|
||||
}
|
||||
}
|
||||
167
bin/aliyun-log-csharp-sdk-master/SLSSDK/SLSSDK35.csproj
Normal file
167
bin/aliyun-log-csharp-sdk-master/SLSSDK/SLSSDK35.csproj
Normal file
@@ -0,0 +1,167 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{D730B9A1-387F-429A-BCF0-7BAA9E501BE1}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Aliyun.Api.LOG</RootNamespace>
|
||||
<AssemblyName>LOGSDK</AssemblyName>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\net35\Debug\</OutputPath>
|
||||
<BaseIntermediateOutputPath>obj\net35\</BaseIntermediateOutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;SLS_SDK_35</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<DocumentationFile>..\bin\net35\Debug\LOGSDK.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\net35\Release\</OutputPath>
|
||||
<BaseIntermediateOutputPath>obj\net35\</BaseIntermediateOutputPath>
|
||||
<DefineConstants>TRACE;SLS_SDK_35</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>..\bin\net35\Release\LOGSDK.xml</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Google.ProtocolBuffers, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\protobuf\net35\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.ProtocolBuffers.Serialization, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\protobuf\net35\Google.ProtocolBuffers.Serialization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LZ4Sharp">
|
||||
<HintPath>..\3rdParties\lz4\net35\LZ4Sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\Json60r3\Bin\Net35\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="zlibnet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\zlib\net35\zlibnet.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\Authentication\HmacSHA1Signature.cs" />
|
||||
<Compile Include="Common\Authentication\IRequestSigner.cs" />
|
||||
<Compile Include="Common\Authentication\ServiceCredentials.cs" />
|
||||
<Compile Include="Common\Authentication\ServiceSignature.cs" />
|
||||
<Compile Include="Common\Communication\ExecutionContext.cs" />
|
||||
<Compile Include="Common\Communication\HttpMethod.cs" />
|
||||
<Compile Include="Common\Communication\IServiceClient.cs" />
|
||||
<Compile Include="Common\Communication\ServiceClient.cs" />
|
||||
<Compile Include="Common\Communication\ServiceClientImpl.cs" />
|
||||
<Compile Include="Common\Communication\ServiceMessage.cs" />
|
||||
<Compile Include="Common\Communication\ServiceRequest.cs" />
|
||||
<Compile Include="Common\Communication\ServiceResponse.cs" />
|
||||
<Compile Include="Common\Handlers\IResponseHandler.cs" />
|
||||
<Compile Include="Common\Handlers\ResponseHandler.cs" />
|
||||
<Compile Include="Common\Utilities\AsyncResult.cs" />
|
||||
<Compile Include="Common\Utilities\DateUtils.cs" />
|
||||
<Compile Include="Common\Utilities\EnumUtils.cs" />
|
||||
<Compile Include="Common\Utilities\HttpHeaders.cs" />
|
||||
<Compile Include="Common\Utilities\HttpUtils.cs" />
|
||||
<Compile Include="Common\Utilities\IOUtils.cs" />
|
||||
<Compile Include="Common\Utilities\StringValueAttribute.cs" />
|
||||
<Compile Include="Data\Histogram.cs" />
|
||||
<Compile Include="Data\LogContent.cs" />
|
||||
<Compile Include="Data\QueriedLog.cs" />
|
||||
<Compile Include="Proto\LogGroup.cs" />
|
||||
<Compile Include="Data\LogItem.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Request\BatchGetLogsRequest.cs" />
|
||||
<Compile Include="Request\GetCursorRequest.cs" />
|
||||
<Compile Include="Request\GetHistogramsRequest.cs" />
|
||||
<Compile Include="Request\GetLogsRequest.cs" />
|
||||
<Compile Include="Request\ListLogstoresRequest.cs" />
|
||||
<Compile Include="Request\ListShardsRequest.cs" />
|
||||
<Compile Include="Request\ListTopicsRequest.cs" />
|
||||
<Compile Include="Request\LogStoreRequest.cs" />
|
||||
<Compile Include="Request\PutLogsRequest.cs" />
|
||||
<Compile Include="Request\Request.cs" />
|
||||
<Compile Include="Response\BatchGetLogsResponse.cs" />
|
||||
<Compile Include="Response\GetCursorResponse.cs" />
|
||||
<Compile Include="Response\GetHistogramsResponse.cs" />
|
||||
<Compile Include="Response\GetLogsResponse.cs" />
|
||||
<Compile Include="Response\ListLogstoresResponse.cs" />
|
||||
<Compile Include="Response\ListShardsResponse.cs" />
|
||||
<Compile Include="Response\ListTopicsResponse.cs" />
|
||||
<Compile Include="Response\PutLogsResponse.cs" />
|
||||
<Compile Include="Response\Response.cs" />
|
||||
<Compile Include="sample\LoghubSample.cs" />
|
||||
<Compile Include="Utilities\ClientTools.cs" />
|
||||
<Compile Include="Utilities\ClientConfiguration.cs" />
|
||||
<Compile Include="Utilities\IpUtils.cs" />
|
||||
<Compile Include="Utilities\Consts.cs" />
|
||||
<Compile Include="Utilities\Lz4DecoderStream.cs" />
|
||||
<Compile Include="Utilities\RequestSigner.cs" />
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="Exception.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Proto\LogGroup.proto" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy "$(ProjectDir)..\3rdParties\zlib\net35\zlib32.dll" "$(TargetDir)"
|
||||
copy "$(ProjectDir)..\3rdParties\zlib\net35\zlib64.dll" "$(TargetDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
168
bin/aliyun-log-csharp-sdk-master/SLSSDK/SLSSDK40.csproj
Normal file
168
bin/aliyun-log-csharp-sdk-master/SLSSDK/SLSSDK40.csproj
Normal file
@@ -0,0 +1,168 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4DBAE4C0-1B9A-4BD0-A9D3-8029AE319287}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>Aliyun.Api.LOG</RootNamespace>
|
||||
<AssemblyName>LOGSDK</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<TargetFrameworkProfile />
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\net40\Debug\</OutputPath>
|
||||
<BaseIntermediateOutputPath>obj\net40\</BaseIntermediateOutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;SLS_SDK_40</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
<DocumentationFile>..\bin\net40\Debug\LOGSDK.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\net40\Release\</OutputPath>
|
||||
<BaseIntermediateOutputPath>obj\net40\</BaseIntermediateOutputPath>
|
||||
<DefineConstants>TRACE;SLS_SDK_40</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<DocumentationFile>..\bin\net40\Release\LOGSDK.xml</DocumentationFile>
|
||||
<Prefer32Bit>false</Prefer32Bit>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<StartupObject />
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Google.ProtocolBuffers, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\protobuf\net40\Google.ProtocolBuffers.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Google.ProtocolBuffers.Serialization, Version=2.4.1.521, Culture=neutral, PublicKeyToken=55f7125234beb589, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\protobuf\net40\Google.ProtocolBuffers.Serialization.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="LZ4Sharp, Version=1.0.0.0, Culture=neutral, processorArchitecture=x86">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\lz4\net35\LZ4Sharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\Json60r3\Bin\Net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="zlibnet, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\3rdParties\zlib\net40\zlibnet.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Common\Authentication\HmacSHA1Signature.cs" />
|
||||
<Compile Include="Common\Authentication\IRequestSigner.cs" />
|
||||
<Compile Include="Common\Authentication\ServiceCredentials.cs" />
|
||||
<Compile Include="Common\Authentication\ServiceSignature.cs" />
|
||||
<Compile Include="Common\Communication\ExecutionContext.cs" />
|
||||
<Compile Include="Common\Communication\HttpMethod.cs" />
|
||||
<Compile Include="Common\Communication\IServiceClient.cs" />
|
||||
<Compile Include="Common\Communication\ServiceClient.cs" />
|
||||
<Compile Include="Common\Communication\ServiceClientImpl.cs" />
|
||||
<Compile Include="Common\Communication\ServiceMessage.cs" />
|
||||
<Compile Include="Common\Communication\ServiceRequest.cs" />
|
||||
<Compile Include="Common\Communication\ServiceResponse.cs" />
|
||||
<Compile Include="Common\Handlers\IResponseHandler.cs" />
|
||||
<Compile Include="Common\Handlers\ResponseHandler.cs" />
|
||||
<Compile Include="Common\Utilities\AsyncResult.cs" />
|
||||
<Compile Include="Common\Utilities\DateUtils.cs" />
|
||||
<Compile Include="Common\Utilities\EnumUtils.cs" />
|
||||
<Compile Include="Common\Utilities\HttpHeaders.cs" />
|
||||
<Compile Include="Common\Utilities\HttpUtils.cs" />
|
||||
<Compile Include="Common\Utilities\IOUtils.cs" />
|
||||
<Compile Include="Common\Utilities\StringValueAttribute.cs" />
|
||||
<Compile Include="Data\Histogram.cs" />
|
||||
<Compile Include="Data\LogContent.cs" />
|
||||
<Compile Include="Data\QueriedLog.cs" />
|
||||
<Compile Include="Proto\LogGroup.cs" />
|
||||
<Compile Include="Data\LogItem.cs" />
|
||||
<Compile Include="Properties\Resources.Designer.cs">
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
</Compile>
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="Request\BatchGetLogsRequest.cs" />
|
||||
<Compile Include="Request\GetCursorRequest.cs" />
|
||||
<Compile Include="Request\GetHistogramsRequest.cs" />
|
||||
<Compile Include="Request\GetLogsRequest.cs" />
|
||||
<Compile Include="Request\ListLogstoresRequest.cs" />
|
||||
<Compile Include="Request\ListShardsRequest.cs" />
|
||||
<Compile Include="Request\ListTopicsRequest.cs" />
|
||||
<Compile Include="Request\LogStoreRequest.cs" />
|
||||
<Compile Include="Request\PutLogsRequest.cs" />
|
||||
<Compile Include="Request\Request.cs" />
|
||||
<Compile Include="Response\BatchGetLogsResponse.cs" />
|
||||
<Compile Include="Response\GetCursorResponse.cs" />
|
||||
<Compile Include="Response\GetHistogramsResponse.cs" />
|
||||
<Compile Include="Response\GetLogsResponse.cs" />
|
||||
<Compile Include="Response\ListLogstoresResponse.cs" />
|
||||
<Compile Include="Response\ListShardsResponse.cs" />
|
||||
<Compile Include="Response\ListTopicsResponse.cs" />
|
||||
<Compile Include="Response\PutLogsResponse.cs" />
|
||||
<Compile Include="Response\Response.cs" />
|
||||
<Compile Include="sample\LoghubSample.cs" />
|
||||
<Compile Include="Utilities\ClientTools.cs" />
|
||||
<Compile Include="Utilities\ClientConfiguration.cs" />
|
||||
<Compile Include="Utilities\IpUtils.cs" />
|
||||
<Compile Include="Utilities\Consts.cs" />
|
||||
<Compile Include="Utilities\Lz4DecoderStream.cs" />
|
||||
<Compile Include="Utilities\RequestSigner.cs" />
|
||||
<Compile Include="Client.cs" />
|
||||
<Compile Include="Exception.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="Properties\Resources.resx">
|
||||
<Generator>ResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.cs</LastGenOutput>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="Proto\LogGroup.proto" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy "$(ProjectDir)..\3rdParties\zlib\net40\zlib32.dll" "$(TargetDir)"
|
||||
copy "$(ProjectDir)..\3rdParties\zlib\net40\zlib64.dll" "$(TargetDir)"</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using System.Text;
|
||||
using System.Reflection;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
|
||||
namespace Aliyun.Api.LOG.Utilities
|
||||
{
|
||||
/// <summary>
|
||||
/// 表示访问阿里云服务的配置信息。
|
||||
/// </summary>
|
||||
internal class ClientConfiguration : ICloneable
|
||||
{
|
||||
private string _userAgent = LogConsts.CONST_USER_AGENT_PREFIX + typeof(ClientConfiguration).Assembly.GetName().Version.ToString();
|
||||
|
||||
private int _connectionTimeout = LogConsts.DEFAULT_SLS_CONNECT_TIMEOUT;
|
||||
private int _maxErrorRetry = LogConsts.DEFAULT_SLS_RETRY_TIME;
|
||||
private int _readWrtTimeout = LogConsts.DEFAULT_SLS_READWRT_TIMEOUT;
|
||||
private int _retryInterval = LogConsts.DEFAULT_SLS_RETRY_INTERVALBASE;
|
||||
|
||||
public int RetryIntervalBase
|
||||
{
|
||||
get { return _retryInterval; }
|
||||
set { _retryInterval = value; }
|
||||
}
|
||||
|
||||
public int ReadWriteTimeout
|
||||
{
|
||||
get { return _readWrtTimeout; }
|
||||
set { _readWrtTimeout = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取设置访问请求的User-Agent。
|
||||
/// </summary>
|
||||
public string UserAgent
|
||||
{
|
||||
get { return _userAgent; }
|
||||
set { _userAgent = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置代理服务器的地址。
|
||||
/// </summary>
|
||||
public string ProxyHost { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置代理服务器的端口。
|
||||
/// </summary>
|
||||
public int ProxyPort {get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置用户名。
|
||||
/// </summary>
|
||||
public string ProxyUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置密码。
|
||||
/// </summary>
|
||||
public string ProxyPassword { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置代理服务器授权用户所在的域。
|
||||
/// </summary>
|
||||
public string ProxyDomain { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置连接的超时时间,单位为毫秒。
|
||||
/// </summary>
|
||||
public int ConnectionTimeout
|
||||
{
|
||||
get { return _connectionTimeout; }
|
||||
set { _connectionTimeout = value; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取或设置请求发生错误时最大的重试次数。
|
||||
/// </summary>
|
||||
public int MaxErrorRetry
|
||||
{
|
||||
get { return _maxErrorRetry; }
|
||||
set { _maxErrorRetry = value; }
|
||||
}
|
||||
/// <summary>
|
||||
/// 初始化新的<see cref="ClientConfiguration"/>的实例。
|
||||
/// </summary>
|
||||
public ClientConfiguration()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取该实例的拷贝。
|
||||
/// </summary>
|
||||
/// <returns>该实例的拷贝。</returns>
|
||||
public object Clone()
|
||||
{
|
||||
ClientConfiguration config = new ClientConfiguration();
|
||||
config.ConnectionTimeout = this.ConnectionTimeout;
|
||||
config.MaxErrorRetry = this.MaxErrorRetry;
|
||||
config.ProxyDomain = this.ProxyDomain;
|
||||
config.ProxyHost = this.ProxyHost;
|
||||
config.ProxyPassword = this.ProxyPassword;
|
||||
config.ProxyPort = this.ProxyPort;
|
||||
config.ProxyUserName = this.ProxyUserName;
|
||||
config.UserAgent = this.UserAgent;
|
||||
return config;
|
||||
}
|
||||
}
|
||||
}
|
||||
285
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/ClientTools.cs
Normal file
285
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/ClientTools.cs
Normal file
@@ -0,0 +1,285 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
using Aliyun.Api.LOG.Common.Authentication;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
using Aliyun.Api.LOG;
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Net;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.IO.Compression;
|
||||
using LZ4Sharp;
|
||||
using Lz4;
|
||||
|
||||
namespace Aliyun.Api.LOG.Utilities
|
||||
{
|
||||
internal class LogClientTools
|
||||
{
|
||||
public static byte[] CompressToZlib(byte[] buffer)
|
||||
{
|
||||
using (MemoryStream compressStream = new MemoryStream())
|
||||
{
|
||||
using (ZLibNet.ZLibStream gz = new ZLibNet.ZLibStream(compressStream, ZLibNet.CompressionMode.Compress, ZLibNet.CompressionLevel.Level6, true))
|
||||
{
|
||||
gz.Write(buffer, 0, buffer.Length);
|
||||
compressStream.Seek(0, SeekOrigin.Begin);
|
||||
byte[] compressBuffer = new byte[compressStream.Length];
|
||||
compressStream.Read(compressBuffer, 0, compressBuffer.Length);
|
||||
return compressBuffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte[] DecompressFromZlib(Stream stream, int rawSize)
|
||||
{
|
||||
using (stream)
|
||||
{
|
||||
using (ZLibNet.ZLibStream dz = new ZLibNet.ZLibStream(stream, ZLibNet.CompressionMode.Decompress))
|
||||
{
|
||||
byte[] buffer = new byte[rawSize];
|
||||
dz.Read(buffer, 0, buffer.Length);
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static byte[] CompressToLz4(byte[] buffer)
|
||||
{
|
||||
var compressor = LZ4CompressorFactory.CreateNew();
|
||||
return compressor.Compress(buffer);
|
||||
}
|
||||
public static byte[] DecompressFromLZ4(Stream stream, int rawLength)
|
||||
{
|
||||
using (stream)
|
||||
{
|
||||
using (Lz4DecoderStream streamInner = new Lz4DecoderStream(stream))
|
||||
{
|
||||
byte[] output = new byte[rawLength];
|
||||
streamInner.Read(output, 0, rawLength);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static string GetMd5Value(byte[] buffer)
|
||||
{
|
||||
return GetMd5Value(buffer,0,buffer.Length);
|
||||
}
|
||||
public static string GetMd5Value(byte[] buffer,int offset, int count)
|
||||
{
|
||||
MD5 hash = MD5.Create(LogConsts.NAME_MD5);
|
||||
StringBuilder returnStr = new StringBuilder();
|
||||
byte[] md5hash = hash.ComputeHash(buffer, offset, count);
|
||||
if (md5hash != null)
|
||||
{
|
||||
for (int i = 0; i < md5hash.Length; i++)
|
||||
{
|
||||
returnStr.Append(md5hash[i].ToString("X2").ToUpper());
|
||||
}
|
||||
}
|
||||
return returnStr.ToString();
|
||||
}
|
||||
|
||||
public static void ResponseErrorCheck(ServiceResponse response, ServiceCredentials credentials)
|
||||
{
|
||||
if (response.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
String requestId = "";
|
||||
response.Headers.TryGetValue(LogConsts.NAME_HEADER_REQUESTID, out requestId);
|
||||
JObject body = ParserResponseToJObject(response.Content);
|
||||
throw new LogException(body[LogConsts.NAME_ERROR_CODE].ToString(), body[LogConsts.NAME_ERROR_MESSAGE].ToString(), requestId);
|
||||
}
|
||||
}
|
||||
internal class KeyValueComparer : IComparer<KeyValuePair<string, string>>
|
||||
{
|
||||
public int Compare(KeyValuePair<string, string> x, KeyValuePair<string, string> y)
|
||||
{
|
||||
int rtu = String.Compare(x.Key, y.Key, StringComparison.Ordinal);
|
||||
return rtu == 0 ? String.Compare(x.Value, y.Value, StringComparison.Ordinal) : rtu;
|
||||
}
|
||||
}
|
||||
private static String MapEnumMethodToString(HttpMethod httpMethod)
|
||||
{
|
||||
switch (httpMethod)
|
||||
{
|
||||
case HttpMethod.Get:
|
||||
return LogConsts.NAME_HTTP_GET;
|
||||
case HttpMethod.Post:
|
||||
return LogConsts.NAME_HTTP_POST;
|
||||
case HttpMethod.Put:
|
||||
return LogConsts.NAME_HTTP_PUT;
|
||||
case HttpMethod.Head:
|
||||
return LogConsts.NAME_HTTP_HEAD;
|
||||
case HttpMethod.Delete:
|
||||
return LogConsts.NAME_HTTP_DELETE;
|
||||
case HttpMethod.Options:
|
||||
return LogConsts.NAME_HTTP_OPTIONS;
|
||||
default:
|
||||
Debug.Assert(false, "invalid http method");
|
||||
return "";
|
||||
}
|
||||
}
|
||||
private static string GetRequestString(IEnumerable<KeyValuePair<string, string>> parameters, String kvDelimiter, String separator)
|
||||
{
|
||||
StringBuilder stringBuilder = new StringBuilder("");
|
||||
if (parameters != null)
|
||||
{
|
||||
bool isFirst = true;
|
||||
foreach (var p in parameters)
|
||||
{
|
||||
if (!isFirst)
|
||||
{
|
||||
stringBuilder.Append(separator);
|
||||
}
|
||||
isFirst = false;
|
||||
stringBuilder.Append(p.Key);
|
||||
if (p.Value != null)
|
||||
{
|
||||
stringBuilder.Append(kvDelimiter).Append(p.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
return stringBuilder.ToString();
|
||||
}
|
||||
internal static String BuildHeaderSigStr(IDictionary<String, String> headers)
|
||||
{
|
||||
List<KeyValuePair<string, string>> headerLst = new List<KeyValuePair<string, string>>();
|
||||
foreach (KeyValuePair<string, string> pair in headers)
|
||||
{
|
||||
if ((pair.Key.StartsWith("x-log-") && pair.Key.CompareTo(LogConsts.NAME_HEADER_DATE) != 0)
|
||||
|| pair.Key.StartsWith("x-acs-"))
|
||||
{
|
||||
headerLst.Add(new KeyValuePair<String, String>(pair.Key.Trim().ToLower(), pair.Value.Trim()));
|
||||
}
|
||||
}
|
||||
headerLst.Sort(new KeyValueComparer());
|
||||
StringBuilder reqUri = new StringBuilder();
|
||||
reqUri.Append(LogClientTools.GetValeFromDic(headers, LogConsts.NAME_HEADER_MD5)).Append("\n")
|
||||
.Append(LogClientTools.GetValeFromDic(headers, LogConsts.NAME_HEADER_CONTENTTYPE)).Append("\n")
|
||||
.Append(LogClientTools.GetValeFromDic(headers, LogConsts.NAME_HEADER_DATE)).Append("\n")
|
||||
.Append(GetRequestString(headerLst, ":", "\n"));
|
||||
return reqUri.ToString();
|
||||
}
|
||||
internal static String SigInternal(String source,String accessKeyId, String accessKey)
|
||||
{
|
||||
ServiceSignature signAlthm = ServiceSignature.Create();
|
||||
return LogConsts.PREFIX_VALUE_HEADER_AUTH + accessKeyId + ":" + signAlthm.ComputeSignature(accessKey, source);
|
||||
}
|
||||
public static String Signature(IDictionary<String, String> headers, String accessKeyId, String accessKey)
|
||||
{
|
||||
return SigInternal(BuildHeaderSigStr(headers), accessKeyId, accessKey);
|
||||
}
|
||||
public static String Signature(IDictionary<String,String> headers,IDictionary<String,String> paramDic,HttpMethod method, String resource,String accessKeyId,String accessKey)
|
||||
{
|
||||
List<KeyValuePair<string, string>> paramLst = new List<KeyValuePair<string, string>>(paramDic);
|
||||
|
||||
paramLst.Sort(new KeyValueComparer());
|
||||
|
||||
StringBuilder reqUri = new StringBuilder();
|
||||
reqUri.Append(MapEnumMethodToString(method)).Append("\n")
|
||||
.Append(BuildHeaderSigStr(headers)).Append("\n")
|
||||
.Append(resource)
|
||||
.Append((paramLst != null && paramLst.Count > 0) ? ("?" + GetRequestString(paramLst, "=", "&")) : (""));
|
||||
return SigInternal(reqUri.ToString(), accessKeyId, accessKey);
|
||||
}
|
||||
internal static String GetValeFromDic(IDictionary<String, String> dic, String keyName)
|
||||
{
|
||||
String value = null;
|
||||
if (dic.TryGetValue(keyName, out value))
|
||||
return value;
|
||||
return "";
|
||||
}
|
||||
public static JArray ParserResponseToJArray(Stream response)
|
||||
{
|
||||
using (response)
|
||||
{
|
||||
StreamReader sr = null;
|
||||
String json = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(response, Encoding.UTF8);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Close();
|
||||
throw new LogException("LOGBadResponse", "The response from the server is empty", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
json = sr.ReadToEnd();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "Io exception happened when parse the response data : ", e);
|
||||
}
|
||||
catch (OutOfMemoryException e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "There is not enough memory to continue the execution of parsing the response data : ", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sr.Close();
|
||||
}
|
||||
try
|
||||
{
|
||||
JArray obj = JArray.Parse(json);
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "The response is not valid json string : " + json, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
public static JObject ParserResponseToJObject(Stream response)
|
||||
{
|
||||
using (response)
|
||||
{
|
||||
StreamReader sr = null;
|
||||
String json = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(response, Encoding.UTF8);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
if (sr != null)
|
||||
sr.Close();
|
||||
throw new LogException("LOGBadResponse", "The response from the server is empty", e);
|
||||
}
|
||||
try
|
||||
{
|
||||
json = sr.ReadToEnd();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "Io exception happened when parse the response data : ", e);
|
||||
}
|
||||
catch (OutOfMemoryException e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "There is not enough memory to continue the execution of parsing the response data : ", e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
sr.Close();
|
||||
}
|
||||
try
|
||||
{
|
||||
JObject obj = JObject.Parse(json);
|
||||
return obj;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
throw new LogException("LOGBadResponse", "The response is not valid json string : " + json, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
100
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/Consts.cs
Normal file
100
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/Consts.cs
Normal file
@@ -0,0 +1,100 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Utilities
|
||||
{
|
||||
internal class LogConsts
|
||||
{
|
||||
public const string CONST_USER_AGENT_PREFIX = "log-dotnet-sdk-v-";
|
||||
|
||||
public const int LIMIT_LOG_SIZE = 3 * 1024 * 1024;
|
||||
public const int LIMIT_LOG_COUNT = 4096;
|
||||
public const int DEFAULT_SLS_RETRY_TIME = 3;
|
||||
public const int DEFAULT_SLS_CONNECT_TIMEOUT = 5 * 1000;
|
||||
public const int DEFAULT_SLS_READWRT_TIMEOUT = 20 * 1000;
|
||||
public const int DEFAULT_SLS_RETRY_INTERVALBASE = 100;
|
||||
|
||||
public const String NAME_ERROR_CODE = "errorCode";
|
||||
public const String NAME_ERROR_MESSAGE = "errorMessage";
|
||||
public const String NAME_LISTLOGSTORE_ITEM = "logstores";
|
||||
public const String NAME_LISTLOGSTORE_TOTAL = "count";
|
||||
public const String NAME_LISTTOPIC_COUNT = "count";
|
||||
public const String NAME_LISTTOPIC_TOPICS = "topics";
|
||||
public const String NAME_LISTTOPIC_NEXTTOKEN = "next_token";
|
||||
public const String NAME_GETSTATUS_PROGRESS = "progress";
|
||||
public const String NAME_GETSTATUS_COUNT = "count";
|
||||
public const String NAME_GETSTATUS_FROM = "from";
|
||||
public const String NAME_GETSTATUS_TO = "to";
|
||||
public const String NAME_GETSTATUS_HISTOGRAM = "histograms";
|
||||
public const String NAME_GETDATA_COUNT = "count";
|
||||
public const String NAME_GETDATA_PROGRESS = "progress";
|
||||
public const String NAME_GETDATA_LOGS = "logs";
|
||||
public const String NAME_GETDATA_TIME = "__time__";
|
||||
public const String NAME_GETDATA_SOURCE = "__source__";
|
||||
|
||||
public const string NAME_MD5 = "MD5";
|
||||
|
||||
public const String NAME_HTTP_GET = "GET";
|
||||
public const String NAME_HTTP_POST = "POST";
|
||||
public const String NAME_HTTP_PUT = "PUT";
|
||||
public const String NAME_HTTP_DELETE = "DELETE";
|
||||
public const String NAME_HTTP_PATCH = "PATCH";
|
||||
public const String NAME_HTTP_HEAD = "HEAD";
|
||||
public const String NAME_HTTP_OPTIONS = "OPTIONS";
|
||||
|
||||
public const String NAME_HEADER_AUTH = HttpHeaders.Authorization;
|
||||
public const String PREFIX_VALUE_HEADER_AUTH = "LOG" + " ";
|
||||
public const String NAME_HEADER_CONTENTTYPE = HttpHeaders.ContentType;
|
||||
public const String JSONVALUE_HEADER_CONTENTTYPE = "application/json";
|
||||
public const String PBVALUE_HEADER_CONTENTTYPE = "application/x-protobuf";
|
||||
public const String NAME_HEADER_MD5 = HttpHeaders.ContentMd5;
|
||||
public const String NAME_HEADER_HOST = "Host";
|
||||
public const String NAME_HEADER_APIVERSION = "x-log-apiversion";
|
||||
public const String VALUE_HEADER_APIVERSION = "0.6.0";
|
||||
public const String NAME_HEADER_ACCESSKEYID = "x-log-accesskeyid";
|
||||
public const String NAME_HEADER_COMPRESSTYPE = "x-log-compresstype";
|
||||
public const String NAME_HEADER_REQUESTID = "x-log-requestid";
|
||||
public const String NAME_HEADER_DATE = "x-log-date";
|
||||
public const String NAME_HEADER_X_LOG_COUNT = "x-log-count";
|
||||
public const String NAME_HEADER_X_LOG_NEXT_TOKEN = "x-log-nexttoken";
|
||||
public const String NAME_HEADER_X_LOG_PROGRESS = "x-log-progress";
|
||||
public const String NAME_HEADER_ACCEPT_ENCODING = "Accept-Encoding";
|
||||
public const String NAME_HEADER_ACCEPT = "Accept";
|
||||
public const String VALUE_HEADER_COMPRESSTYPE_DEFLATE = "deflate";
|
||||
public const String VALUE_HEADER_COMPRESSTYPE_LZ4 = "lz4";
|
||||
public const String NAME_HEADER_BODYRAWSIZE = "x-log-bodyrawsize";
|
||||
public const String NAME_HEADER_NEXT_CURSOR = "x-log-cursor";
|
||||
public const String NAME_HEADER_LOG_COUNT = "x-log-count";
|
||||
public const String NAME_HEADER_LOG_BODY_RAW_SIZE = "x-log-bodyrawsize";
|
||||
public const String NAME_HEADER_SIGMETHOD = "x-log-signaturemethod";
|
||||
public const String VALUE_HEADER_SIGMETHOD = "hmac-sha1";
|
||||
public const String NAME_HEADER_ACS_SECURITY_TOKEN = "x-acs-security-token";
|
||||
public const String RESOURCE_SEPARATOR = "/";
|
||||
public const String RESOURCE_LOGSTORES = RESOURCE_SEPARATOR + "logstores";
|
||||
public const String RESOURCE_SHARDS = RESOURCE_SEPARATOR + "shards";
|
||||
public const String PARAMETER_OFFSET = "offset";
|
||||
public const String PARAMETER_LINES = "line";
|
||||
public const String RESOURCE_TOPIC = "topic";
|
||||
public const String PARAMETER_TOKEN = "token";
|
||||
public const String PARAMETER_TYPE = "type";
|
||||
public const String VALUE_TYPE_CONTENT = "log";
|
||||
public const String VALUE_TYPE_STATUS = "histogram";
|
||||
public const String PARAMETER_TOPIC = "topic";
|
||||
public const String PARAMETER_FROM = "from";
|
||||
public const String PARAMETER_TO = "to";
|
||||
public const String PARAMETER_QUERY = "query";
|
||||
public const String PARAMETER_REVERSE = "reverse";
|
||||
|
||||
public const String STATUS_COMPLETE = "Complete";
|
||||
public const String STATUS_INCOMPLETE = "InComplete";
|
||||
}
|
||||
}
|
||||
71
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/IpUtils.cs
Normal file
71
bin/aliyun-log-csharp-sdk-master/SLSSDK/Utilities/IpUtils.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
using System.Net.NetworkInformation;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace Aliyun.Api.LOG.Utilities
|
||||
{
|
||||
internal class IpUtils
|
||||
{
|
||||
public static bool IsInternalIP(IPAddress ip)
|
||||
{
|
||||
//According to RFC 1918 (http://www.faqs.org/rfcs/rfc1918.html). private IP ranges are as bellow
|
||||
// 10.0.0.0 - 10.255.255.255 (10/8 prefix)
|
||||
// 172.16.0.0 - 172.31.255.255 (172.16/12 prefix)
|
||||
// 192.168.0.0 - 192.168.255.255 (192.168/16 prefix)
|
||||
|
||||
byte[] addrs = ip.GetAddressBytes();
|
||||
if ((addrs[0] == 10) ||
|
||||
(addrs[0] == 192 && addrs[1] == 168) ||
|
||||
(addrs[0] == 172 && (addrs[1] >= 16) && (addrs[1] < 32)))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
public static bool IsIpAddress(String str)
|
||||
{
|
||||
Regex regex = new Regex("^(\\d{1,3}\\.){3}\\d{1,3}");
|
||||
return regex.Match(str).Success;
|
||||
}
|
||||
public static string GetLocalMachinePrivateIp()
|
||||
{
|
||||
NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
|
||||
string ip = "";
|
||||
foreach (NetworkInterface adapter in adapters)
|
||||
{
|
||||
if (adapter.OperationalStatus == OperationalStatus.Up)
|
||||
{
|
||||
IPInterfaceProperties IPInterfaceProperties = adapter.GetIPProperties();
|
||||
UnicastIPAddressInformationCollection UnicastIPAddressInformationCollection = IPInterfaceProperties.UnicastAddresses;
|
||||
foreach (UnicastIPAddressInformation UnicastIPAddressInformation in UnicastIPAddressInformationCollection)
|
||||
{
|
||||
IPAddress addr = UnicastIPAddressInformation.Address;
|
||||
|
||||
if (!IPAddress.IsLoopback(addr) &&
|
||||
UnicastIPAddressInformation.Address.AddressFamily == AddressFamily.InterNetwork)
|
||||
{
|
||||
if (IsInternalIP(addr))
|
||||
{
|
||||
ip = addr.ToString();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!String.IsNullOrEmpty(ip))
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ip;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,544 @@
|
||||
#define CHECK_ARGS
|
||||
#define CHECK_EOF
|
||||
//#define LOCAL_SHADOW
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace Lz4
|
||||
{
|
||||
public class Lz4DecoderStream : Stream
|
||||
{
|
||||
public Lz4DecoderStream()
|
||||
{
|
||||
}
|
||||
|
||||
public Lz4DecoderStream(Stream input, long inputLength = long.MaxValue)
|
||||
{
|
||||
Reset(input, inputLength);
|
||||
}
|
||||
|
||||
public void Reset(Stream input, long inputLength = long.MaxValue)
|
||||
{
|
||||
this.inputLength = inputLength;
|
||||
this.input = input;
|
||||
|
||||
phase = DecodePhase.ReadToken;
|
||||
|
||||
decodeBufferPos = 0;
|
||||
|
||||
litLen = 0;
|
||||
matLen = 0;
|
||||
matDst = 0;
|
||||
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen;
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
this.input = null;
|
||||
}
|
||||
|
||||
private long inputLength;
|
||||
private Stream input;
|
||||
|
||||
//because we might not be able to match back across invocations,
|
||||
//we have to keep the last window's worth of bytes around for reuse
|
||||
//we use a circular buffer for this - every time we write into this
|
||||
//buffer, we also write the same into our output buffer
|
||||
|
||||
private const int DecBufLen = 0x10000;
|
||||
private const int DecBufMask = 0xFFFF;
|
||||
|
||||
private const int InBufLen = 128;
|
||||
|
||||
private byte[] decodeBuffer = new byte[DecBufLen + InBufLen];
|
||||
private int decodeBufferPos, inBufPos, inBufEnd;
|
||||
|
||||
//we keep track of which phase we're in so that we can jump right back
|
||||
//into the correct part of decoding
|
||||
|
||||
private DecodePhase phase;
|
||||
|
||||
private enum DecodePhase
|
||||
{
|
||||
ReadToken,
|
||||
ReadExLiteralLength,
|
||||
CopyLiteral,
|
||||
ReadOffset,
|
||||
ReadExMatchLength,
|
||||
CopyMatch,
|
||||
}
|
||||
|
||||
//state within interruptable phases and across phase boundaries is
|
||||
//kept here - again, so that we can punt out and restart freely
|
||||
|
||||
private int litLen, matLen, matDst;
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
#if CHECK_ARGS
|
||||
if (buffer == null)
|
||||
throw new ArgumentNullException("buffer");
|
||||
if (offset < 0 || count < 0 || buffer.Length - count < offset)
|
||||
throw new ArgumentOutOfRangeException();
|
||||
|
||||
if (input == null)
|
||||
throw new InvalidOperationException();
|
||||
#endif
|
||||
int nRead, nToRead = count;
|
||||
|
||||
var decBuf = decodeBuffer;
|
||||
|
||||
//the stringy gotos are obnoxious, but their purpose is to
|
||||
//make it *blindingly* obvious how the state machine transitions
|
||||
//back and forth as it reads - remember, we can yield out of
|
||||
//this routine in several places, and we must be able to re-enter
|
||||
//and pick up where we left off!
|
||||
|
||||
#if LOCAL_SHADOW
|
||||
var phase = this.phase;
|
||||
var inBufPos = this.inBufPos;
|
||||
var inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
switch (phase)
|
||||
{
|
||||
case DecodePhase.ReadToken:
|
||||
goto readToken;
|
||||
|
||||
case DecodePhase.ReadExLiteralLength:
|
||||
goto readExLiteralLength;
|
||||
|
||||
case DecodePhase.CopyLiteral:
|
||||
goto copyLiteral;
|
||||
|
||||
case DecodePhase.ReadOffset:
|
||||
goto readOffset;
|
||||
|
||||
case DecodePhase.ReadExMatchLength:
|
||||
goto readExMatchLength;
|
||||
|
||||
case DecodePhase.CopyMatch:
|
||||
goto copyMatch;
|
||||
}
|
||||
|
||||
readToken:
|
||||
int tok;
|
||||
if (inBufPos < inBufEnd)
|
||||
{
|
||||
tok = decBuf[inBufPos++];
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LOCAL_SHADOW
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
|
||||
tok = ReadByteCore();
|
||||
#if LOCAL_SHADOW
|
||||
inBufPos = this.inBufPos;
|
||||
inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
#if CHECK_EOF
|
||||
if (tok == -1)
|
||||
goto finish;
|
||||
#endif
|
||||
}
|
||||
|
||||
litLen = tok >> 4;
|
||||
matLen = (tok & 0xF) + 4;
|
||||
|
||||
switch (litLen)
|
||||
{
|
||||
case 0:
|
||||
phase = DecodePhase.ReadOffset;
|
||||
goto readOffset;
|
||||
|
||||
case 0xF:
|
||||
phase = DecodePhase.ReadExLiteralLength;
|
||||
goto readExLiteralLength;
|
||||
|
||||
default:
|
||||
phase = DecodePhase.CopyLiteral;
|
||||
goto copyLiteral;
|
||||
}
|
||||
|
||||
readExLiteralLength:
|
||||
int exLitLen;
|
||||
if (inBufPos < inBufEnd)
|
||||
{
|
||||
exLitLen = decBuf[inBufPos++];
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LOCAL_SHADOW
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
exLitLen = ReadByteCore();
|
||||
#if LOCAL_SHADOW
|
||||
inBufPos = this.inBufPos;
|
||||
inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
|
||||
#if CHECK_EOF
|
||||
if (exLitLen == -1)
|
||||
goto finish;
|
||||
#endif
|
||||
}
|
||||
|
||||
litLen += exLitLen;
|
||||
if (exLitLen == 255)
|
||||
goto readExLiteralLength;
|
||||
|
||||
phase = DecodePhase.CopyLiteral;
|
||||
goto copyLiteral;
|
||||
|
||||
copyLiteral:
|
||||
int nReadLit = litLen < nToRead ? litLen : nToRead;
|
||||
if (nReadLit != 0)
|
||||
{
|
||||
if (inBufPos + nReadLit <= inBufEnd)
|
||||
{
|
||||
int ofs = offset;
|
||||
|
||||
for (int c = nReadLit; c-- != 0; )
|
||||
buffer[ofs++] = decBuf[inBufPos++];
|
||||
|
||||
nRead = nReadLit;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LOCAL_SHADOW
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
nRead = ReadCore(buffer, offset, nReadLit);
|
||||
#if LOCAL_SHADOW
|
||||
inBufPos = this.inBufPos;
|
||||
inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
#if CHECK_EOF
|
||||
if (nRead == 0)
|
||||
goto finish;
|
||||
#endif
|
||||
}
|
||||
|
||||
offset += nRead;
|
||||
nToRead -= nRead;
|
||||
|
||||
litLen -= nRead;
|
||||
|
||||
if (litLen != 0)
|
||||
goto copyLiteral;
|
||||
}
|
||||
|
||||
if (nToRead == 0)
|
||||
goto finish;
|
||||
|
||||
phase = DecodePhase.ReadOffset;
|
||||
goto readOffset;
|
||||
|
||||
readOffset:
|
||||
if (inBufPos + 1 < inBufEnd)
|
||||
{
|
||||
matDst = (decBuf[inBufPos + 1] << 8) | decBuf[inBufPos];
|
||||
inBufPos += 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LOCAL_SHADOW
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
matDst = ReadOffsetCore();
|
||||
#if LOCAL_SHADOW
|
||||
inBufPos = this.inBufPos;
|
||||
inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
#if CHECK_EOF
|
||||
if (matDst == -1)
|
||||
goto finish;
|
||||
#endif
|
||||
}
|
||||
|
||||
if (matLen == 15 + 4)
|
||||
{
|
||||
phase = DecodePhase.ReadExMatchLength;
|
||||
goto readExMatchLength;
|
||||
}
|
||||
else
|
||||
{
|
||||
phase = DecodePhase.CopyMatch;
|
||||
goto copyMatch;
|
||||
}
|
||||
|
||||
readExMatchLength:
|
||||
int exMatLen;
|
||||
if (inBufPos < inBufEnd)
|
||||
{
|
||||
exMatLen = decBuf[inBufPos++];
|
||||
}
|
||||
else
|
||||
{
|
||||
#if LOCAL_SHADOW
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
exMatLen = ReadByteCore();
|
||||
#if LOCAL_SHADOW
|
||||
inBufPos = this.inBufPos;
|
||||
inBufEnd = this.inBufEnd;
|
||||
#endif
|
||||
#if CHECK_EOF
|
||||
if (exMatLen == -1)
|
||||
goto finish;
|
||||
#endif
|
||||
}
|
||||
|
||||
matLen += exMatLen;
|
||||
if (exMatLen == 255)
|
||||
goto readExMatchLength;
|
||||
|
||||
phase = DecodePhase.CopyMatch;
|
||||
goto copyMatch;
|
||||
|
||||
copyMatch:
|
||||
int nCpyMat = matLen < nToRead ? matLen : nToRead;
|
||||
if (nCpyMat != 0)
|
||||
{
|
||||
nRead = count - nToRead;
|
||||
|
||||
int bufDst = matDst - nRead;
|
||||
if (bufDst > 0)
|
||||
{
|
||||
//offset is fairly far back, we need to pull from the buffer
|
||||
|
||||
int bufSrc = decodeBufferPos - bufDst;
|
||||
if (bufSrc < 0)
|
||||
bufSrc += DecBufLen;
|
||||
int bufCnt = bufDst < nCpyMat ? bufDst : nCpyMat;
|
||||
|
||||
for (int c = bufCnt; c-- != 0; )
|
||||
buffer[offset++] = decBuf[bufSrc++ & DecBufMask];
|
||||
}
|
||||
else
|
||||
{
|
||||
bufDst = 0;
|
||||
}
|
||||
|
||||
int sOfs = offset - matDst;
|
||||
for (int i = bufDst; i < nCpyMat; i++)
|
||||
buffer[offset++] = buffer[sOfs++];
|
||||
|
||||
nToRead -= nCpyMat;
|
||||
matLen -= nCpyMat;
|
||||
}
|
||||
|
||||
if (nToRead == 0)
|
||||
goto finish;
|
||||
|
||||
phase = DecodePhase.ReadToken;
|
||||
goto readToken;
|
||||
|
||||
finish:
|
||||
nRead = count - nToRead;
|
||||
|
||||
int nToBuf = nRead < DecBufLen ? nRead : DecBufLen;
|
||||
int repPos = offset - nToBuf;
|
||||
|
||||
if (nToBuf == DecBufLen)
|
||||
{
|
||||
Buffer.BlockCopy(buffer, repPos, decBuf, 0, DecBufLen);
|
||||
decodeBufferPos = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
int decPos = decodeBufferPos;
|
||||
|
||||
while (nToBuf-- != 0)
|
||||
decBuf[decPos++ & DecBufMask] = buffer[repPos++];
|
||||
|
||||
decodeBufferPos = decPos & DecBufMask;
|
||||
}
|
||||
|
||||
#if LOCAL_SHADOW
|
||||
this.phase = phase;
|
||||
this.inBufPos = inBufPos;
|
||||
#endif
|
||||
return nRead;
|
||||
}
|
||||
|
||||
private int ReadByteCore()
|
||||
{
|
||||
var buf = decodeBuffer;
|
||||
|
||||
if (inBufPos == inBufEnd)
|
||||
{
|
||||
int nRead = input.Read(buf, DecBufLen,
|
||||
InBufLen < inputLength ? InBufLen : (int)inputLength);
|
||||
|
||||
#if CHECK_EOF
|
||||
if (nRead == 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
inputLength -= nRead;
|
||||
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen + nRead;
|
||||
}
|
||||
|
||||
return buf[inBufPos++];
|
||||
}
|
||||
|
||||
private int ReadOffsetCore()
|
||||
{
|
||||
var buf = decodeBuffer;
|
||||
|
||||
if (inBufPos == inBufEnd)
|
||||
{
|
||||
int nRead = input.Read(buf, DecBufLen,
|
||||
InBufLen < inputLength ? InBufLen : (int)inputLength);
|
||||
|
||||
#if CHECK_EOF
|
||||
if (nRead == 0)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
inputLength -= nRead;
|
||||
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen + nRead;
|
||||
}
|
||||
|
||||
if (inBufEnd - inBufPos == 1)
|
||||
{
|
||||
buf[DecBufLen] = buf[inBufPos];
|
||||
|
||||
int nRead = input.Read(buf, DecBufLen + 1,
|
||||
InBufLen - 1 < inputLength ? InBufLen - 1 : (int)inputLength);
|
||||
|
||||
#if CHECK_EOF
|
||||
if (nRead == 0)
|
||||
{
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen + 1;
|
||||
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
inputLength -= nRead;
|
||||
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen + nRead + 1;
|
||||
}
|
||||
|
||||
int ret = (buf[inBufPos + 1] << 8) | buf[inBufPos];
|
||||
inBufPos += 2;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
private int ReadCore(byte[] buffer, int offset, int count)
|
||||
{
|
||||
int nToRead = count;
|
||||
|
||||
var buf = decodeBuffer;
|
||||
int inBufLen = inBufEnd - inBufPos;
|
||||
|
||||
int fromBuf = nToRead < inBufLen ? nToRead : inBufLen;
|
||||
if (fromBuf != 0)
|
||||
{
|
||||
var bufPos = inBufPos;
|
||||
|
||||
for (int c = fromBuf; c-- != 0; )
|
||||
buffer[offset++] = buf[bufPos++];
|
||||
|
||||
inBufPos = bufPos;
|
||||
nToRead -= fromBuf;
|
||||
}
|
||||
|
||||
if (nToRead != 0)
|
||||
{
|
||||
int nRead;
|
||||
|
||||
if (nToRead >= InBufLen)
|
||||
{
|
||||
nRead = input.Read(buffer, offset,
|
||||
nToRead < inputLength ? nToRead : (int)inputLength);
|
||||
nToRead -= nRead;
|
||||
}
|
||||
else
|
||||
{
|
||||
nRead = input.Read(buf, DecBufLen,
|
||||
InBufLen < inputLength ? InBufLen : (int)inputLength);
|
||||
|
||||
inBufPos = DecBufLen;
|
||||
inBufEnd = DecBufLen + nRead;
|
||||
|
||||
fromBuf = nToRead < nRead ? nToRead : nRead;
|
||||
|
||||
var bufPos = inBufPos;
|
||||
|
||||
for (int c = fromBuf; c-- != 0; )
|
||||
buffer[offset++] = buf[bufPos++];
|
||||
|
||||
inBufPos = bufPos;
|
||||
nToRead -= fromBuf;
|
||||
}
|
||||
|
||||
inputLength -= nRead;
|
||||
}
|
||||
|
||||
return count - nToRead;
|
||||
}
|
||||
|
||||
#region Stream internals
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
{
|
||||
}
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get { throw new NotSupportedException(); }
|
||||
set { throw new NotSupportedException(); }
|
||||
}
|
||||
|
||||
public override long Seek(long offset, SeekOrigin origin)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void SetLength(long value)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) Alibaba Cloud Computing
|
||||
* All rights reserved.
|
||||
*
|
||||
* 版权所有 (C)阿里云计算有限公司
|
||||
*/
|
||||
using Aliyun.Api.LOG.Common.Authentication;
|
||||
using Aliyun.Api.LOG.Common.Communication;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.Utilities
|
||||
{
|
||||
internal class LogRequestSigner : IRequestSigner
|
||||
{
|
||||
private readonly String httpResource;
|
||||
private readonly HttpMethod httpMethod;
|
||||
|
||||
public LogRequestSigner(String httpResource, HttpMethod httpMethod)
|
||||
{
|
||||
this.httpResource = httpResource;
|
||||
this.httpMethod = httpMethod;
|
||||
}
|
||||
|
||||
public void Sign(ServiceRequest request, ServiceCredentials credentials)
|
||||
{
|
||||
request.Headers.Add(LogConsts.NAME_HEADER_AUTH, LogClientTools.Signature(request.Headers, request.Parameters, this.httpMethod, this.httpResource, credentials.AccessId, credentials.AccessKey));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
a8bb8370e02c144f42c903a390abab8bdb6f2982
|
||||
@@ -0,0 +1,78 @@
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.AssemblyReference.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csprojAssemblyReference.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\RCULogAgent\RCU_LogAgent_MySql-v0.01\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csprojAssemblyReference.cache
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
F:\Temp\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.AssemblyReference.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\Project\BLV_RcuLogAgent\SourceCode\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csprojAssemblyReference.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
E:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.AssemblyReference.cache
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
I:\BLV_Sync\RD_PC\Project\BLV_RcuLogAgent\src\RCULogAgent\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.xml
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\bin\net40\Debug\LOGSDK.pdb
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\Aliyun.Api.LOG.Properties.Resources.resources
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.GenerateResource.cache
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CoreCompileInputs.cache
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\SLSSDK40.csproj.CopyComplete
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.dll
|
||||
D:\Sync\RD_PC\陈志豪\czh\RCU_LogAgent\bin\aliyun-log-csharp-sdk-master\SLSSDK\obj\net40\Debug\LOGSDK.pdb
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,64 @@
|
||||
using Aliyun.Api.LOG.Common.Utilities;
|
||||
using Aliyun.Api.LOG.Data;
|
||||
using Aliyun.Api.LOG.Request;
|
||||
using Aliyun.Api.LOG.Response;
|
||||
using Aliyun.Api.LOG.Utilities;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace Aliyun.Api.LOG.sample
|
||||
{
|
||||
class LoghubSample
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
String endpoint = "http://cn-hangzhou-failover-intranet.sls.aliyuncs.com",
|
||||
accesskeyId = "",
|
||||
accessKey = "",
|
||||
project = "",
|
||||
logstore = "";
|
||||
int shardId = 0;
|
||||
LogClient client = new LogClient(endpoint, accesskeyId, accessKey);
|
||||
//init http connection timeout
|
||||
client.ConnectionTimeout = client.ReadWriteTimeout = 10000;
|
||||
//*
|
||||
//list logstores
|
||||
foreach (String l in client.ListLogstores(new ListLogstoresRequest(project)).Logstores)
|
||||
{
|
||||
Console.WriteLine(l);
|
||||
}
|
||||
//put logs
|
||||
PutLogsRequest putLogsReqError = new PutLogsRequest();
|
||||
putLogsReqError.Project = project;
|
||||
putLogsReqError.Topic = "dotnet_topic";
|
||||
putLogsReqError.Logstore = logstore;
|
||||
putLogsReqError.LogItems = new List<LogItem>();
|
||||
for (int i = 1; i <= 10; ++i)
|
||||
{
|
||||
LogItem logItem = new LogItem();
|
||||
logItem.Time = DateUtils.TimeSpan();
|
||||
for (int k = 0; k < 10; ++k)
|
||||
logItem.PushBack("error_", "invalid operation");
|
||||
putLogsReqError.LogItems.Add(logItem);
|
||||
}
|
||||
PutLogsResponse putLogRespError = client.PutLogs(putLogsReqError);
|
||||
//query logs
|
||||
client.GetLogs(new GetLogsRequest(project, logstore, DateUtils.TimeSpan() - 10, DateUtils.TimeSpan()));
|
||||
//query histogram
|
||||
client.GetHistograms(new GetHistogramsRequest(project, logstore, DateUtils.TimeSpan() - 10, DateUtils.TimeSpan()));
|
||||
//list shards
|
||||
client.ListShards(new ListShardsRequest(project, logstore));
|
||||
//get cursor
|
||||
String cursor = client.GetCursor(new GetCursorRequest(project, logstore, shardId, ShardCursorMode.BEGIN)).Cursor;
|
||||
Console.WriteLine(cursor);
|
||||
//batch get logs, loghub interface
|
||||
BatchGetLogsResponse response = client.BatchGetLogs(new BatchGetLogsRequest(project, logstore, shardId, cursor, 10));
|
||||
//list topic
|
||||
client.ListTopics(new ListTopicsRequest(project, logstore));
|
||||
//*/
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user