private void DeletePaste(object paste) { Paste mPaste = (Paste)paste; _pasteList.Remove(mPaste); sQLiteHelper.DeletePaste(mPaste.ID); NotifyPropertyChanged("Pastes"); }
public void InsertPaste(Paste paste) { using (SQLiteCommand cmd = sqlConnection.CreateCommand()) { cmd.CommandText = @"INSERT INTO [Paste] ([PasteString] ,[ReceivedTime] ,[DeviceName]) VALUES (@PasteString ,@ReceivedTime ,@DeviceName);"; cmd.Parameters.AddWithValue("@PasteString", paste.pasteString); cmd.Parameters.AddWithValue("@ReceivedTime", String.Format("{0:G}", paste.receivedTime)); cmd.Parameters.AddWithValue("@DeviceName", paste.deviceName); cmd.ExecuteNonQuery(); } }
public List <Paste> LoadPasteByOffset(int start, int offset) { List <Paste> nList = new List <Paste>(); using (SQLiteCommand cmd = sqlConnection.CreateCommand()) { cmd.CommandText = @"SELECT * FROM [Paste] ORDER BY [ReceivedTime] DESC LIMIT (@OFFSET) OFFSET (@START)"; cmd.Parameters.AddWithValue("@OFFSET", offset); cmd.Parameters.AddWithValue("@START", start); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { Paste nPaste = new Paste( reader.GetString(reader.GetOrdinal("PasteString")), DateTime.Parse(reader.GetString(reader.GetOrdinal("ReceivedTime"))), reader.GetString(reader.GetOrdinal("DeviceName")) ); nPaste.ID = reader.GetInt64(reader.GetOrdinal("Id")); nList.Add(nPaste); } } return(nList); }
public void ReadingThread() { NetworkStream networkStream = new NetworkStream(mSocket); bool terminationCodeReceived = false; String s; try { while (!terminationCodeReceived) { StreamReader sr = new StreamReader(networkStream); if ((s = sr.ReadLine()) != null) { Console.WriteLine("Received: " + s); Dispatcher.BeginInvoke(new Action(() => { Paste newPaste = new Paste ( s, DateTime.Now, clientName ); listView.Items.Insert(0, newPaste); sqliteHelper.InsertPaste(newPaste); })); } else { DisconnectAndShowMain(); } } } catch (IOException e) { Console.WriteLine("Unable to reach remote endpoint"); } }