public static OnlineCommands InsertOnlineCommand(System.Net.EndPoint endPoint, string com, int hashcode) { try { using (var db = new LiteDatabase(Environment.CurrentDirectory + "/data.db")) { var col = db.GetCollection <OnlineCommands>("onlinecommands"); var command = new OnlineCommands { IP = endPoint.ToString().Split(':')[0], Port = endPoint.ToString().Split(':')[1], HashCode = hashcode, Command = com, Result = string.Empty, Error = string.Empty, Status = false }; col.Insert(command); return(command); } } catch (Exception ex) { return(null); } }
public static OnlineCommands GetOnlineCommand(System.Net.EndPoint endPoint, string com, int hashcode) { try { OnlineCommands commands = null; using (var db = new LiteDatabase(Environment.CurrentDirectory + "/data.db")) { var col = db.GetCollection <OnlineCommands>("onlinecommands"); var coms = col.FindAll().AsQueryable() .Where(x => x.IP == endPoint.ToString().Split(':')[0] && x.Port == endPoint.ToString().Split(':')[1] && x.HashCode == hashcode && x.Command == com) .Select(x => x).ToList(); if (coms.Count() > 0) { commands = coms[coms.Count() - 1]; } return(commands); } } catch (Exception) { return(null); } }
public static void UpdateOnlineCommand(OnlineCommands onlineCommands) { try { using (var db = new LiteDatabase(Environment.CurrentDirectory + "/data.db")) { var col = db.GetCollection <OnlineCommands>("onlinecommands"); col.Update(onlineCommands); } } catch (Exception) { } }