155 lines
5.3 KiB
C#
155 lines
5.3 KiB
C#
|
|
using System.Collections.Concurrent;
|
|||
|
|
using System.Transactions;
|
|||
|
|
using Common;
|
|||
|
|
using Commonlib;
|
|||
|
|
using LiteDB;
|
|||
|
|
|
|||
|
|
namespace ConsoleApp2
|
|||
|
|
{
|
|||
|
|
internal class Program
|
|||
|
|
{
|
|||
|
|
static void ReadData()
|
|||
|
|
{
|
|||
|
|
string hexString = "AA 55 18 00 54 33 53 41 34 08 80 EB 03 6B 24 00 00 00 00 00 00 00 02 00 17 64";
|
|||
|
|
byte[] bbb= Tools.HEXString2ByteArray(hexString.Replace(" ",""));
|
|||
|
|
List<byte> data = bbb.ToList();
|
|||
|
|
List<byte> ID = data.Skip(4).Take(4).ToList();
|
|||
|
|
|
|||
|
|
//命令字
|
|||
|
|
List<byte> CMD = data.Skip(8).Take(1).ToList();
|
|||
|
|
|
|||
|
|
//Frame
|
|||
|
|
List<byte> Frame = data.Skip(9).Take(2).ToList();
|
|||
|
|
|
|||
|
|
|
|||
|
|
//Project_Code
|
|||
|
|
List<byte> Project_Code = data.Skip(11).Take(2).ToList();
|
|||
|
|
|
|||
|
|
ushort hotel_code_o = BitConverter.ToUInt16(Project_Code.ToArray(), 0);
|
|||
|
|
|
|||
|
|
//MAC
|
|||
|
|
List<byte> IP3 = data.Skip(13).Take(1).ToList();
|
|||
|
|
List<byte> IP4 = data.Skip(14).Take(1).ToList();
|
|||
|
|
}
|
|||
|
|
static void Main(string[] args)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
ReadData();
|
|||
|
|
var B = "33\\343\\22";
|
|||
|
|
var AAA = Path.Combine("", $"{B}");
|
|||
|
|
TCLMonitorData c = new TCLMonitorData();
|
|||
|
|
c.HotelCode = "1001";
|
|||
|
|
c.RoomNumber = "2001";
|
|||
|
|
c.RequestTime = "2022-12-13 00:12:23.234";
|
|||
|
|
c.RequestId = "111";
|
|||
|
|
|
|||
|
|
var q1 = System.Text.Json.JsonSerializer.Serialize(c);
|
|||
|
|
Dictionary<string, string> dic = new Dictionary<string, string>();
|
|||
|
|
dic.Add("topic", "aaaaa");
|
|||
|
|
dic.Add("payload", q1);
|
|||
|
|
|
|||
|
|
var q2 = System.Text.Json.JsonSerializer.Serialize(dic);
|
|||
|
|
using (var client = new HttpClient())
|
|||
|
|
{
|
|||
|
|
var parameters = new FormUrlEncodedContent(new[]
|
|||
|
|
{
|
|||
|
|
new KeyValuePair<string, string>("roomTypeID", "2551"),
|
|||
|
|
new KeyValuePair<string, string>("hostid_lists", "[50076]"),
|
|||
|
|
new KeyValuePair<string, string>("upgradefileName", "C1F_A_L4_41_250704_NM.bin")
|
|||
|
|
});
|
|||
|
|
|
|||
|
|
var response = client.PostAsync("http://localhost:1867/api/" + "WebChatUpgrade", parameters).Result;
|
|||
|
|
if (response.IsSuccessStatusCode)
|
|||
|
|
{
|
|||
|
|
string nnnnnn = response.Content.ReadAsStringAsync().Result;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
throw new Exception("调用升级接口失败,状态码:" + response.StatusCode);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
ConcurrentQueue<string> d = new ConcurrentQueue<string>();
|
|||
|
|
d.TryDequeue(out string s);
|
|||
|
|
d.Enqueue("1111");
|
|||
|
|
|
|||
|
|
Dictionary<string, string> aadic = new Dictionary<string, string>();
|
|||
|
|
aadic.Add("aa", "bb");
|
|||
|
|
if (aadic["aa"] != null)
|
|||
|
|
{
|
|||
|
|
aadic["aa"] = "cc";
|
|||
|
|
}
|
|||
|
|
aadic.Values.ToList();
|
|||
|
|
string idaaaa = "12";
|
|||
|
|
idaaaa = idaaaa.PadLeft(10, '0');
|
|||
|
|
|
|||
|
|
Console.ReadLine();
|
|||
|
|
// 打开数据库 (如果不存在则创建)
|
|||
|
|
using (var db = new LiteDatabase(@"MyData.db"))
|
|||
|
|
{
|
|||
|
|
// 获得 customer 集合
|
|||
|
|
var col = db.GetCollection<Customer>("customers");
|
|||
|
|
|
|||
|
|
// 创建你的新 customer 实例
|
|||
|
|
var customer = new Customer
|
|||
|
|
{
|
|||
|
|
Name = Guid.NewGuid().ToString(),
|
|||
|
|
};
|
|||
|
|
|
|||
|
|
// 在 Name 字段上创建唯一索引
|
|||
|
|
col.EnsureIndex(x => x.Name, true);
|
|||
|
|
|
|||
|
|
// 插入新的 customer 文档 (Id 是自增的)
|
|||
|
|
col.Insert(customer);
|
|||
|
|
|
|||
|
|
// 更新集合中的一个文档
|
|||
|
|
//customer.Name = DateTime.Now.ToString();
|
|||
|
|
|
|||
|
|
Console.WriteLine(customer.Id);
|
|||
|
|
|
|||
|
|
col.DeleteMany(A => A.Id < customer.Id);
|
|||
|
|
Console.ReadLine();
|
|||
|
|
for (int i = 0; i < 1000; i++)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
//col.Update(customer);
|
|||
|
|
|
|||
|
|
// 使用 LINQ 查询文档 (未使用索引)
|
|||
|
|
//var results = col.Find(x => x.Age > 20);
|
|||
|
|
|
|||
|
|
// 伪代码示例
|
|||
|
|
using var scope = new TransactionScope(
|
|||
|
|
TransactionScopeOption.Required,
|
|||
|
|
new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted }
|
|||
|
|
);
|
|||
|
|
try
|
|||
|
|
{
|
|||
|
|
//var result1 = await httpClient1.PostAsync(...);
|
|||
|
|
//result1.EnsureSuccessStatusCode();
|
|||
|
|
|
|||
|
|
//var result2 = await httpClient2.PutAsync(...);
|
|||
|
|
//result2.EnsureSuccessStatusCode();
|
|||
|
|
|
|||
|
|
scope.Complete();
|
|||
|
|
}
|
|||
|
|
catch
|
|||
|
|
{
|
|||
|
|
// 自动回滚
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
//Console.WriteLine(JsonConvert.SerializeObject(results, Formatting.Indented));
|
|||
|
|
Console.WriteLine("Hello, World!");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public class Customer
|
|||
|
|
{
|
|||
|
|
public int Id { get; set; }
|
|||
|
|
public string Name { get; set; }
|
|||
|
|
public int Age { get; set; }
|
|||
|
|
public string[] Phones { get; set; }
|
|||
|
|
public bool IsActive { get; set; }
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|