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 = "[¶m&]";//参数标识
|
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("请求失败,请检查网络配置!");
|
}
|
}
|
|
}
|
}
|