初始化
This commit is contained in:
@@ -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) { }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user