2021-05-28 20:53:14 +05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace DataClient.Struct
|
|
|
|
|
{
|
|
|
|
|
public struct server
|
|
|
|
|
{
|
|
|
|
|
public string name;
|
|
|
|
|
public string ip;
|
|
|
|
|
public int port;
|
|
|
|
|
public string dir;
|
|
|
|
|
public server(string Ip, int Port, string Dir)
|
|
|
|
|
{
|
|
|
|
|
name = "default";
|
|
|
|
|
ip = Ip;
|
|
|
|
|
port = Port;
|
|
|
|
|
dir = Dir;
|
|
|
|
|
}
|
|
|
|
|
public server(string Name, string Ip, int Port, string Dir)
|
|
|
|
|
{
|
|
|
|
|
name = Name;
|
|
|
|
|
ip = Ip;
|
|
|
|
|
port = Port;
|
|
|
|
|
dir = Dir;
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-06-03 16:43:40 +05:00
|
|
|
|
public class NetStatus
|
2021-06-05 17:00:11 +05:00
|
|
|
|
{
|
2021-06-03 16:43:40 +05:00
|
|
|
|
public enum Status
|
2021-06-05 17:00:11 +05:00
|
|
|
|
{
|
2021-06-03 16:43:40 +05:00
|
|
|
|
wait = 0,
|
|
|
|
|
in_progress = 1,
|
|
|
|
|
complete = 2
|
2021-06-05 17:00:11 +05:00
|
|
|
|
}
|
2021-06-03 16:43:40 +05:00
|
|
|
|
public uint fullSize = 0;
|
|
|
|
|
public uint size = 0;
|
|
|
|
|
public Status stat = Status.wait;
|
2021-06-05 17:00:11 +05:00
|
|
|
|
}
|
|
|
|
|
public class Pasport
|
|
|
|
|
{
|
|
|
|
|
//functions
|
|
|
|
|
private DateTime? ByteToDate(byte[] arr)
|
|
|
|
|
{
|
|
|
|
|
if (arr == null || arr.Length != 7) return null;
|
|
|
|
|
return new DateTime(arr[0] | arr[1] << 8, arr[2], arr[3], arr[4], arr[5], arr[6]);
|
|
|
|
|
}
|
|
|
|
|
private byte[] DateToByte(DateTime? date)
|
|
|
|
|
{
|
|
|
|
|
if (!date.HasValue) return null;
|
|
|
|
|
return new byte[]
|
|
|
|
|
{
|
|
|
|
|
BitConverter.GetBytes(date.Value.Year)[0],
|
|
|
|
|
BitConverter.GetBytes(date.Value.Year)[1],
|
|
|
|
|
(byte)date.Value.Month,
|
|
|
|
|
(byte)date.Value.Day,
|
|
|
|
|
(byte)date.Value.Hour,
|
|
|
|
|
(byte)date.Value.Minute,
|
|
|
|
|
(byte)date.Value.Second
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
private byte[] StringToByte(uint? size = null, string str = null)
|
|
|
|
|
{
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
|
var enc = Encoding.GetEncoding(866);
|
|
|
|
|
var szArr = size ?? ((!string.IsNullOrEmpty(str)) ? (uint)(str.Length + 1) : 0);
|
|
|
|
|
var strArr = (string.IsNullOrEmpty(str)) ? Array.Empty<byte>() : enc.GetBytes(str);
|
|
|
|
|
var res = new byte[szArr];
|
|
|
|
|
for (var i = 0; i < res.Length; i++)
|
|
|
|
|
res[i] = (byte)((i == res.Length - 1) ? 0x00 : (i < strArr.Length) ? strArr[i] : 0x00);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//params
|
|
|
|
|
public bool HasData { get { return numVDP.HasValue && dStart.HasValue && dEnd.HasValue; } }
|
|
|
|
|
public byte? numVDP = null;
|
|
|
|
|
public DateTime? dStart = null;
|
|
|
|
|
public DateTime? dEnd = null;
|
|
|
|
|
|
|
|
|
|
public bool hasPasport = false;
|
|
|
|
|
public int kod_npl = 0;
|
|
|
|
|
public string nplav = null; //12
|
|
|
|
|
public string rm = null; //11
|
|
|
|
|
public string splav = null; //101
|
|
|
|
|
public string iS = null; //51
|
|
|
|
|
public ushort notd = 0;
|
|
|
|
|
public ushort vessl = 0;
|
|
|
|
|
public ushort diam = 0;
|
|
|
|
|
public ushort prpl = 0;
|
|
|
|
|
public string tin = null; //9
|
|
|
|
|
public string dzap = null; //9
|
|
|
|
|
public short dlog = 0;
|
|
|
|
|
public short last = 0;
|
|
|
|
|
public short dlper = 0;
|
|
|
|
|
public string nazn = null; //51
|
|
|
|
|
public ushort kompl = 0;
|
|
|
|
|
public ushort izl = 0;
|
|
|
|
|
public float robm = 0;
|
|
|
|
|
public float rizol = 0;
|
|
|
|
|
public ushort dkr = 0;
|
|
|
|
|
public string nkon = null; //51
|
|
|
|
|
public string pos = null; //6
|
|
|
|
|
public string ukaz = null; //51
|
|
|
|
|
public string zakaz = null; //51
|
|
|
|
|
public string kat = null; //51
|
|
|
|
|
public string pril = null; //3
|
|
|
|
|
public string rezerved = null; //1023
|
|
|
|
|
|
|
|
|
|
public byte[] PaspByte
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
var res = new List<byte>();
|
|
|
|
|
|
|
|
|
|
res.Add((byte)(HasData ? 0x01 : 0x00));
|
|
|
|
|
if (!HasData) return res.ToArray();
|
|
|
|
|
|
|
|
|
|
res.Add(numVDP.Value);
|
|
|
|
|
res.AddRange(DateToByte(dStart));
|
|
|
|
|
res.AddRange(DateToByte(dEnd));
|
|
|
|
|
res.Add((byte)(hasPasport ? 0x01 : 0x00));
|
|
|
|
|
if (!hasPasport) return res.ToArray();
|
|
|
|
|
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(kod_npl));
|
|
|
|
|
res.AddRange(StringToByte(12, nplav));
|
|
|
|
|
res.AddRange(StringToByte(11, rm));
|
|
|
|
|
res.AddRange(StringToByte(101, splav));
|
|
|
|
|
res.AddRange(StringToByte(51, iS));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(notd));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(vessl));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(diam));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(prpl));
|
|
|
|
|
res.AddRange(StringToByte(9, tin));
|
|
|
|
|
res.AddRange(StringToByte(9, dzap));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(dlog));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(last));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(dlper));
|
|
|
|
|
res.AddRange(StringToByte(51, nazn));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(kompl));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(izl));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(robm));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(rizol));
|
|
|
|
|
res.AddRange(BitConverter.GetBytes(dkr));
|
|
|
|
|
res.AddRange(StringToByte(51, nkon));
|
|
|
|
|
res.AddRange(StringToByte(6, pos));
|
|
|
|
|
res.AddRange(StringToByte(51, ukaz));
|
|
|
|
|
res.AddRange(StringToByte(51, zakaz));
|
|
|
|
|
res.AddRange(StringToByte(51, kat));
|
|
|
|
|
res.AddRange(StringToByte(3, pril));
|
|
|
|
|
res.AddRange(StringToByte(1023, rezerved));
|
|
|
|
|
|
|
|
|
|
return res.ToArray();
|
|
|
|
|
}
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
|
|
|
|
|
var enc = Encoding.GetEncoding(866);
|
|
|
|
|
var count = 0;
|
|
|
|
|
var tmpArr = Array.Empty<byte>();
|
|
|
|
|
if (value == null) return;
|
|
|
|
|
if (value.Length < (count + 1) || value[count] != 0x01) return;
|
|
|
|
|
count++;
|
|
|
|
|
if (value.Length < (count + 1)) return;
|
|
|
|
|
numVDP = value[count];
|
|
|
|
|
count++;
|
|
|
|
|
if (value.Length < (count + 7)) return;
|
|
|
|
|
tmpArr = new byte[7];
|
|
|
|
|
Array.Copy(value, count, tmpArr, 0, 7);
|
|
|
|
|
dStart = ByteToDate(tmpArr);
|
|
|
|
|
count += 7;
|
|
|
|
|
if (value.Length < (count + 7)) return;
|
|
|
|
|
tmpArr = new byte[7];
|
|
|
|
|
Array.Copy(value, count, tmpArr, 0, 7);
|
|
|
|
|
dEnd = ByteToDate(tmpArr);
|
|
|
|
|
count += 7;
|
|
|
|
|
if (value.Length < (count + 1) || value[count] != 0x01) { hasPasport = false; return; }
|
|
|
|
|
hasPasport = true;
|
|
|
|
|
count++;
|
|
|
|
|
if (value.Length < (count + 4)) return;
|
|
|
|
|
tmpArr = new byte[4];
|
|
|
|
|
Array.Copy(value, count, tmpArr, 0, 4);
|
|
|
|
|
kod_npl = BitConverter.ToInt32(tmpArr);
|
|
|
|
|
count += 4;
|
|
|
|
|
if (value.Length < (count + 12)) return;
|
|
|
|
|
nplav = enc.GetString(value, count, 12);
|
|
|
|
|
count += 12;
|
|
|
|
|
if (value.Length < (count + 11)) return;
|
|
|
|
|
rm = enc.GetString(value, count, 11);
|
|
|
|
|
count += 11;
|
|
|
|
|
if (value.Length < (count + 101)) return;
|
|
|
|
|
splav = enc.GetString(value, count, 101);
|
|
|
|
|
count += 101;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
iS = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
notd = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
vessl = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
diam = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
prpl = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 9)) return;
|
|
|
|
|
tin = enc.GetString(value, count, 9);
|
|
|
|
|
count += 9;
|
|
|
|
|
if (value.Length < (count + 9)) return;
|
|
|
|
|
dzap = enc.GetString(value, count, 9);
|
|
|
|
|
count += 9;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
dlog = BitConverter.ToInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
last = BitConverter.ToInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
dlper = BitConverter.ToInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
nazn = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
kompl = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
izl = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 4)) return;
|
|
|
|
|
robm = BitConverter.ToSingle(value, count);
|
|
|
|
|
count += 4;
|
|
|
|
|
if (value.Length < (count + 4)) return;
|
|
|
|
|
rizol = BitConverter.ToSingle(value, count);
|
|
|
|
|
count += 4;
|
|
|
|
|
if (value.Length < (count + 2)) return;
|
|
|
|
|
dkr = BitConverter.ToUInt16(value, count);
|
|
|
|
|
count += 2;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
nkon = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 6)) return;
|
|
|
|
|
pos = enc.GetString(value, count, 6);
|
|
|
|
|
count += 6;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
ukaz = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
zakaz = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 51)) return;
|
|
|
|
|
kat = enc.GetString(value, count, 51);
|
|
|
|
|
count += 51;
|
|
|
|
|
if (value.Length < (count + 3)) return;
|
|
|
|
|
pril = enc.GetString(value, count, 3);
|
|
|
|
|
count += 3;
|
|
|
|
|
if (value.Length < (count + 1023)) return;
|
|
|
|
|
rezerved = enc.GetString(value, count, 1023);
|
|
|
|
|
count += 1023;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2021-05-28 20:53:14 +05:00
|
|
|
|
}
|
2021-06-05 17:00:11 +05:00
|
|
|
|
|