duheng
2025-03-28 9be9ba4e159969fb5e32648c2c34e912ccc3ae6d
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using PBS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Yw;
 
namespace IBox.WinFrmUI
{
    public static class IBoxHelper
    {
        public const string startCode = "[&start&]";//开始标识
        public const string endCode = "[&end&]";//结束标识
        public const string paramCode = "[&param&]";//参数标识
        public const string getbaseCode = "getbase";//获取基础信息
        public const string getrealrecordCode = "getrealrecord";//获取实时记录数据
        public const string gethistoryrecordCode = "gethistoryrecord";//获取历史记录数据
        public const string getalarmbydayCode = "getalarmbyday";//获取报警数据
        public const string getbysignalidofdayrangeCode = "getbysignalidofdayrange";//获取指定信号ID的日数据
        public const string getmonitorCode = "getmonitor";//获取所有监测点
        public const string getsignaltypeCode = "getsignaltype";//获取所有监点类型
        public const string getMonitorgroupCode = "getmonitorgroup";//获取所有机组
 
        public const string getfilterCode = "getfilter";//获取数据过滤配置
        public const string savefilterCode = "savefilter";//保存数据过滤配置
 
        public const string getenergyanalyCode = "getenergyanaly";//获取能耗分析数据
        public const string analydayCode = "analyday";//校验能耗分析
 
        public const string getlogCode = "getlog";//获取日志
        public const string clearlogCode = "clearlog";//清除日志
 
        public const string getparamsCode = "getparams";//获取参数
        public const string saveparamsCode = "saveparams";//保存参数
        public const string restartserviceCode = "restartservice";//重启服务
        public const string clearupdataCode = "clearupdata";//清除数据
 
 
        public const string getprotocolCode = "getprotocol";//获取协议配置
        public const string saveprotocolCode = "saveprotocol";//保存协议配置
 
 
        public const string getrulesCode = "getrules";//获取规则配置
        public const string saverulesCode = "saverules";//保存规则配置
        public const string addsignalCode = "addsignal";//新增测点
        public const string deletesignalCode = "deletesignal";//删除测点
        public const string addMonitorgroupCode = "addmonitorgroup";//新增机组
        public const string deletemonitorgroupCode = "deletemonitorgroup";//删除机组
 
 
        public const string getstoreCode = "getstore";//获取基本配置
 
        /// <summary>
        /// 连接类型
        /// </summary>
        public static eConnectionType ConnectionType { get; set; }
 
        /// <summary>
        /// 连接地址,IP地址 OR 蓝牙地址
        /// </summary>
        public static string ConnectionAddress { get; set; }
 
        public static string HttpGet(string content)
        {
            if (string.IsNullOrEmpty(ConnectionAddress))
                throw new Exception("请先配置网络地址!");
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var param = System.Web.HttpUtility.UrlEncode(content, System.Text.Encoding.UTF8);
            var url = "http://" + ConnectionAddress + ":8011/datahave/GetData?msg=";
            try
            {
                var result = Yw.Untity.HttpRequestHelper.Get(url + param);
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("请求失败,请检查网络配置!");
            }
        }
 
        public static string HttpPost(string content)
        {
            if (string.IsNullOrEmpty(ConnectionAddress))
                throw new Exception("请先配置网络地址!");
            var param = content;// System.Web.HttpUtility.UrlEncode(content, System.Text.Encoding.GetEncoding("GB2312"));
            var url = "http://" + ConnectionAddress + ":8011/datahave/PostData";
            var m = new PostViewModel() { msg = param };
            var datastr = JsonHelper.Object2Json(m);
            try
            {
                var result = Yw.Untity.HttpRequestHelper.Post(url, datastr);
 
                return result;
            }
            catch (Exception ex)
            {
                throw new Exception("请求失败,请检查网络配置!");
            }
        }
        public static string GetContent(string content)
        {
            var smsg = content.Split(new string[] { IBoxHelper.paramCode }, StringSplitOptions.RemoveEmptyEntries);
            if (smsg.Length >= 2)
            {
                return smsg[1].Trim();
            }
            return "";
        }
        public static bool Ping()
        {
            if (string.IsNullOrEmpty(ConnectionAddress))
                throw new Exception("请先配置网络地址!");
            var IP = "http://" + ConnectionAddress;
            var param = IP + ":8011/ping";
            try
            {
                var result = Yw.Untity.HttpRequestHelper.Get(param);
                if (result == "true")
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                throw new Exception("请求失败,请检查网络配置!");
            }
        }
 
    }
}