-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSocketRequest.cs
More file actions
84 lines (74 loc) · 2.35 KB
/
Copy pathSocketRequest.cs
File metadata and controls
84 lines (74 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Linq;
namespace SocketTest.Common
{
/// <summary>
/// Copyright (C) 2017 yjq 版权所有。
/// 类名:SocketRequest.cs
/// 类属性:公共类(非静态)
/// 类功能描述:
/// 创建标识:yjq 2017/11/24 10:33:42
/// </summary>
public class SocketRequest
{
/// <summary>
/// 请求ID,唯一不重复
/// </summary>
public string Id { get; set; }
/// <summary>
/// 请求类型
/// </summary>
public short Type { get; set; }
/// <summary>
/// 请求状态码
/// </summary>
public short Code { get; set; }
/// <summary>
///
/// </summary>
public byte[] Body { get; set; }
/// <summary>
///
/// </summary>
public DateTime CreatedTime { get; set; }
/// <summary>
///
/// </summary>
public IDictionary<string, string> Header { get; set; }
public SocketRequest()
{
}
public SocketRequest(short code, byte[] body, IDictionary<string, string> header = null) : this(ObjectId.GenerateNewStringId(), code, body, DateTime.Now, header) { }
public SocketRequest(string id, short code, byte[] body, DateTime createdTime, IDictionary<string, string> header)
{
Id = id;
Code = code;
Body = body;
Header = header;
CreatedTime = createdTime;
}
public override string ToString()
{
var createdTime = CreatedTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
var bodyLength = 0;
if (Body != null)
{
bodyLength = Body.Length;
}
var header = string.Empty;
if (Header != null && Header.Count > 0)
{
header = string.Join(",", Header.Select(x => string.Format("{0}:{1}", x.Key, x.Value)));
}
return string.Format("[Id:{0}, Type:{1}, Code:{2}, CreatedTime:{3}, BodyLength:{4}, Header: [{5}]]",
Id, Type, Code, createdTime, bodyLength, header);
}
}
public class SocketRequestType
{
public const short Async = 1;
public const short Oneway = 2;
public const short Callback = 3;
}
}