using System;
|
using System.Linq;
|
|
namespace ZigBee.Droid.Common
|
{
|
public class OwnCodes
|
{
|
|
#region set/get
|
[Newtonsoft.Json.JsonIgnore]
|
/// <summary>
|
/// 开光状态:0=关,1=开,
|
/// <para>0:</para>
|
/// </summary>
|
public int OnOffStatus
|
{
|
get
|
{
|
//if (DeviceStatusReport != null && DeviceStatusReport.CluterID == 6)
|
//{
|
// var attriButeList = DeviceStatusReport.AttriBute;
|
// foreach (var attriBute1 in attriButeList)
|
// {
|
// return attriBute1.AttriButeData;
|
// }
|
//}
|
return 0;
|
}
|
set
|
{
|
//if (DeviceStatusReport != null && DeviceStatusReport.CluterID == 6)
|
//{
|
// var attriButeList = DeviceStatusReport.AttriBute;
|
// foreach (var attriBute1 in attriButeList)
|
// {
|
// attriBute1.AttriButeData = value;
|
// }
|
//}
|
}
|
}
|
#endregion
|
|
#region json格式,发数据中列表有数组的情况
|
//public static void hdlButtonSetBind(ZigBee.Device.ZbGateway gateway, ZigBee.Device.HDLbutton.BindListDeviceInfo bindListObj, string buttonMacAddr, int epoint, int buttonMode, int buttonType)
|
//{
|
// var jobject = new JObject { { "DeviceAddr", buttonMacAddr }, { "Epoint", epoint }, { "Cluster_ID", 64528 }, { "Command", 6 } };
|
|
// var bindList = new JArray{
|
// new JObject {{ "BindType", bindListObj.BindType},{ "BindMacAddr", bindListObj.BindMacAddr},{ "BindEpoint", bindListObj.BindEpoint }}
|
// };
|
// var data = new JObject { { "ButtonEpoint", epoint },
|
// { "ButtonMode", buttonMode },{ "ButtonType", buttonType },
|
// { "BindList", bindList }
|
// };
|
|
// jobject.Add("Data", data);
|
// gateway.Send(("hdlButton/SetBind"), Common.SecuritySet.Encryption((jobject.ToString())));
|
//}
|
#endregion
|
|
#region Int 与byte的运算
|
// (1)
|
//int count = 5;
|
//int homeId = 112;
|
// byte[] byteHomeId = new byte[4];
|
//for (int i = 0; i < byteHomeId.Length; i++)
|
//{
|
// byteHomeId[i] = (byte)((homeId >> (i * 8)) & 0xFF);
|
//}
|
//byteHomeId[0] = (byte)((homeId >> 24) & 0xff);//H
|
//byteHomeId[1] = (byte)((homeId >> 16) & 0xff);
|
//byteHomeId[2] = (byte)((homeId >> 8) & 0xff);
|
//byteHomeId[3] = (byte)(homeId & 0xff);//L
|
|
//(2)、
|
// int homeID = (bytes[7] & 0xff) << 24 | (bytes[8] & 0xff) << 16 | (bytes[9] & 0xff) << 8 | (bytes[10] & 0xff);
|
#endregion
|
|
#region 进度显示
|
//Application.RunOnMainThread(() =>
|
//{
|
// int pro = (int)(index * 1.0 / backuplist.Count * 100);
|
// MainPage.Loading.Text = pro.ToString() + "%";
|
//};
|
#endregion
|
|
/// <summary>
|
/// 方式一:使用lambda表达式筛选过滤掉数组中空字符串
|
/// </summary>
|
/// <param name="args"></param>
|
static void FilterOutEmptyStrings1()
|
{
|
string[] strArray = { "", "111", "", "222", "", "333" };
|
Console.WriteLine("输出带有空字符串的数组:");
|
foreach (string str in strArray)
|
{
|
Console.WriteLine(str);
|
}
|
Console.WriteLine("-------------------------------------------");
|
//使用lambda表达式过滤掉空字符串
|
strArray = strArray.Where(s => !string.IsNullOrEmpty(s)).ToArray();
|
Console.WriteLine("输出过滤掉空字符串的数组:");
|
foreach (string str in strArray)
|
{
|
Console.WriteLine(str);
|
}
|
Console.Read();
|
}
|
|
/// <summary>
|
/// 方式二:使用泛型集合List<string>的ForEach循环,过滤获取正确的字符串,重新添加到新字符串数组中
|
/// </summary>
|
/// <param name="args"></param>
|
public void FilterOutEmptyStrings2()
|
{
|
string[] strArray = { "", "111", "", "222", "", "333" };
|
|
/*
|
*使用List泛型集合的ForEach方法循环获取非空空字符串
|
*这里使用了匿名方法
|
*/
|
var list = new System.Collections.Generic.List<string>();
|
|
strArray.ToList().ForEach(
|
(s) =>
|
{
|
if (string.IsNullOrEmpty(s))
|
{
|
list.Add(s);
|
}
|
});
|
|
foreach (string str in strArray)
|
{
|
Console.WriteLine(str);
|
}
|
Console.Read();
|
}
|
|
/// <summary>
|
/// 使用传统循环方式来排除和删除字符串数组中的空字符串
|
/// </summary>
|
public void FilterOutEmptyStrings3()
|
{
|
string[] strArray = { "", "111", "", "222", "", "333" };
|
Console.WriteLine("输出带有空字符串的数组:");
|
foreach (string str in strArray)
|
{
|
Console.WriteLine(str);
|
}
|
Console.WriteLine("-------------------------------------------");
|
|
//使用循环排除和过滤掉空字符串
|
var list = new System.Collections.Generic.List<string>();
|
foreach (string s in strArray)
|
{
|
if (!string.IsNullOrEmpty(s))
|
{
|
list.Add(s);
|
}
|
}
|
strArray = list.ToArray();
|
|
Console.WriteLine("输出过滤掉空字符串的数组:");
|
foreach (string str in strArray)
|
{
|
Console.WriteLine(str);
|
}
|
Console.Read();
|
}
|
|
#region &GPS位置变化事件
|
/// <summary>
/// GPS位置变化事件
/// </summary>
|
//public static Action<double, double> LocationAction;
|
//LocationAction = (arg1, arg2) => {
|
// LocationAction = null;
|
// System.Threading.Tasks.Task.Run(() => {
|
// while (true) {
|
// try {
|
// Shared.SimpleControl.CommonPage.AirQuality = new service.hdlcontrol.com_WebServiceAirQuality.WebServiceAirQuality().GetAirQuality(arg2.ToString (), arg1.ToString ());
|
// if (Shared.SimpleControl.CommonPage.AirQuality != null)
|
// break;
|
// } catch { }
|
// }
|
// Shared.Application.RunOnMainThread(() => {
|
// if (CommonPage.RefreshAir != null)
|
// CommonPage.RefreshAir();
|
// } );
|
// } );
|
//} ;
|
#endregion
|
|
#region 电话号码写法
|
// EditText etPhoneNumber = new EditText()
|
// {
|
// X = btnPhoneZone.Right + Application.GetRealWidth(10),
|
// Width = Application.GetRealWidth(410),
|
// TextAlignment = TextAlignment.Center,
|
// };
|
// phoneNumView.AddChidren(etPhoneNumber);
|
|
//etPhoneNumber.TextChangeEventHandler += (sender, e) => {
|
// if (e.Length > 11)
|
// {
|
// etPhoneNumber.Text = e.Remove(11);
|
// }
|
// else if (e.Length == 11)
|
// {
|
// var reg = new Regex("^[1]+[3,5,7,8]+\\d{9}");
|
// var mFalg = reg.Match(etPhoneNumber.Text.Trim());
|
// if (mFalg.Success)
|
// {
|
// btnNext.IsSelected = btnNext.Enable = true;
|
// }
|
// else
|
// {
|
// new Tip() { CloseTime = 3, Text = "号码错误", Direction = AMPopTipDirection.Down } .Show(etPhoneNumber);
|
|
// }
|
// }
|
// else if (e.Length< 11)
|
// {
|
// btnNext.IsSelected = btnNext.Enable = false;
|
// }
|
//} ;
|
#endregion
|
|
#region 进度显示
|
#endregion
|
}
|
}
|