schangxiang@126.com
2025-11-04 f5ed29dc26c7cd952d56ec5721a2efc43cd25992
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
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace DataEntity.Sockets.Base
{
    /// <summary>
    /// 基础请求消息实体类
    /// </summary>
    public class HxRequestBase
    {
        /// <summary>
        /// 指令编号
        /// </summary>
        public string message_id { get; set; }
        /// <summary>
        /// 消息类型,详见0.8节
        /// </summary>
        public int message_type { get; set; }
        /// <summary>
        /// 指令名称
        /// </summary>
        public string method { get; set; }
        /// <summary>
        /// 设备唯一编号
        /// </summary>
        public string equipment_id { get; set; }
        /// <summary>
        /// 执行方法的工作流编号
        /// </summary>
        public string workflow_id { get; set; }
        /// <summary>
        /// 实验ID
        /// </summary>
        public string experiment_id { get; set; }
        /// <summary>
        /// 预估时间
        /// </summary>
        public int estimate_time { get; set; }
        /// <summary>
        /// 超时时间
        /// </summary>
        public int timeout { get; set; }
        /// <summary>
        /// 描述信息
        /// </summary>
        public string description { get; set; }
 
        /// <summary>
        /// 记录时间
        /// </summary>
        public string timestamp { get; set; }
 
        #region 给基础变量赋值
        /// <summary>
        /// 给基础变量赋值
        /// </summary>
        /// <param name="equipmentId"></param>
        /// <param name="method"></param>
        public void SetBaseVal(string equipmentId, string method)
        {
            this.equipment_id = equipmentId;
            this.method = method;
            string instrunctionId = InstrunctionId();
            this.description = $"description_{this.method}";
            this.message_id = instrunctionId;
            this.message_type = 2;
            this.estimate_time = 3;
            this.timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            string strworkflow_id = "workflow_id_" + instrunctionId;
            this.workflow_id = strworkflow_id;
            this.experiment_id = "experiment_id_" + instrunctionId;
            this.timeout = 3;
        }
        #endregion
 
        #region 随机生成字符串
        /// <summary>
        /// 随机生成字符串
        /// </summary>
        /// <returns></returns>
        public static string InstrunctionId()
        {
            Random random = new Random();
            int randKey = random.Next(1000, 9999);
            string guidStr = Guid.NewGuid().ToString();
            return DateTime.Now.ToString("yyyyMMddHHmmss") + "_" + guidStr;
        }
        #endregion
    }
}