private DataRow[] DtFilesVersions(SQLiteCommand command) { IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(IPAddres), Port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipPoint); //добавление в модель данных CommandSQL commandSend = new CommandSQL(); commandSend.CommandText = command.CommandText; foreach (SQLiteParameter par in command.Parameters) { commandSend.Parameters += "$" + par.ParameterName + "$" + par.Value; } //сериализация для отправки команды JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = int.MaxValue; string json = serializer.Serialize(commandSend); //отправка byte[] data = Encoding.Unicode.GetBytes(json); socket.Send(data); // получаем ответ data = new byte[256]; // буфер для ответа StringBuilder builder = new StringBuilder(); int bytes = 0; // количество полученных байт do { bytes = socket.Receive(data, data.Length, 0); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); }while (socket.Available > 0); string test = builder.ToString(); string[] mystring = test.Split('$'); DataTable table = new DataTable(); table.Columns.Add("AppVersion"); table.Columns.Add("FileHash"); table.Columns.Add("CreationDate"); table.Columns.Add("FileSize"); table.Columns.Add("FilePath"); table.Columns.Add("DateCreateDB"); table.Columns.Add("Applications"); //dataRows[0].Table.Columns.Add("AppVersions",Type. ); for (int i = 1; i < mystring.Length; i++) { JavaScriptSerializer serializer1 = new JavaScriptSerializer(); serializer1.MaxJsonLength = int.MaxValue; FilesVersions meta = serializer1.Deserialize <FilesVersions>(mystring[i]); table.Rows.Add(new object[] { meta.AppVersions, meta.FileHash, meta.CreationDate, meta.FileSize, meta.FilePath, meta.DateCreateDB, meta.Applications }); } socket.Shutdown(SocketShutdown.Both); socket.Close(); DataRow[] dataRows = table.Rows.Cast <DataRow>().ToArray(); return(dataRows); }
private DataRow[] DtApplicationInfo(SQLiteCommand command) { IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(IPAddres), Port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipPoint); //добавление в модель данных CommandSQL commandSend = new CommandSQL(); commandSend.CommandText = command.CommandText; foreach (SQLiteParameter par in command.Parameters) { commandSend.Parameters += "$" + par.ParameterName + "$" + par.Value; } //сериализация для отправки команды JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = int.MaxValue; string json = serializer.Serialize(commandSend); //отправка byte[] data = Encoding.Unicode.GetBytes(json); socket.Send(data); // получаем ответ data = new byte[256]; // буфер для ответа StringBuilder builder = new StringBuilder(); int bytes = 0; // количество полученных байт do { bytes = socket.Receive(data, data.Length, 0); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); }while (socket.Available > 0); string test = builder.ToString(); string[] mystring = test.Split('$'); DataRow[] dataRows = null; for (int i = 1; i < mystring.Length; i++) { JavaScriptSerializer serializer1 = new JavaScriptSerializer(); serializer1.MaxJsonLength = int.MaxValue; ApplicationInfo meta = serializer1.Deserialize <ApplicationInfo>(mystring[i]); dataRows[i].ItemArray = new Object[] { meta.Application, meta.AppVersion, meta.AppDiscription, meta.Flag }; } socket.Shutdown(SocketShutdown.Both); socket.Close(); return(dataRows); }
public bool Insert(SQLiteCommand command) { IPEndPoint ipPoint = new IPEndPoint(IPAddress.Parse(IPAddres), Port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipPoint); CommandSQL commandSend = new CommandSQL(); commandSend.CommandText = command.CommandText; foreach (SQLiteParameter par in command.Parameters) { commandSend.Parameters += "$" + par.ParameterName + "$" + par.Value; } JavaScriptSerializer serializer = new JavaScriptSerializer(); serializer.MaxJsonLength = int.MaxValue; string json = serializer.Serialize(commandSend); byte[] data = Encoding.Unicode.GetBytes(json); socket.Send(data); data = new byte[256]; // буфер для ответа StringBuilder builder = new StringBuilder(); int bytes = 0; // количество полученных байт do { bytes = socket.Receive(data, data.Length, 0); builder.Append(Encoding.Unicode.GetString(data, 0, bytes)); }while (socket.Available > 0); string test = builder.ToString(); if (test == "True") { socket.Shutdown(SocketShutdown.Both); socket.Close(); return(true); } else { socket.Shutdown(SocketShutdown.Both); socket.Close(); return(false); } }