public List <OCMessage> GetOCMessage(Contact contract, DateTime dtStart, DateTime dtEnd) { List <OCMessage> list = new List <OCMessage>(); lock (locker) { using (var repository = StorageEngine.FromFile(DATABASE_NAME)) { var table = repository.Scheme.CreateOrOpenXTable <long, OCMessage>( new Locator(contract.ContactName)); repository.Scheme.Commit(); var ocMessages = table.Where(w => w.Record.MessageTime >= dtStart && w.Record.MessageTime < dtEnd) .Select(s => s.Record); if (ocMessages != null) { foreach (var v in ocMessages) { var msg = new OCMessage() { ContactId = v.ContactId, MessageText = v.IsCompressed ? SevenZip.Decompress(v.MessageText) : v.MessageText, MessageTime = v.MessageTime }; list.Add(msg); } } } } return(list); }
public List<OCMessage> GetOCMessage(Contact contract, DateTime dtStart, DateTime dtEnd) { List<OCMessage> list = new List<OCMessage>(); using (SqlConnection connection = new SqlConnection(connectionString)) { using (SqlCommand command = new SqlCommand("GetOCMessage", connection)) { connection.Open(); command.CommandType = System.Data.CommandType.StoredProcedure; command.Parameters.AddWithValue("@ContactId", contract.Id); command.Parameters.AddWithValue("@dtStart", dtStart == DateTime.MinValue ? new DateTime(1753, 1, 1) : dtStart); command.Parameters.AddWithValue("@dtEnd", dtEnd); using (SqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { OCMessage message = new OCMessage(); message.ContactId = int.Parse(reader["ContactId"].ToString()); message.MessageText = reader["MessageText"].ToString(); message.MessageTime = DateTime.Parse(reader["MessageTime"].ToString()); message.IsCompressed = bool.Parse(reader["IsCompressed"].ToString()); if (message.IsCompressed) { message.MessageText = SevenZip.Decompress(message.MessageText); } list.Add(message); } } } } return list; }
private void SaveMessage( Contact contract, string messageBody, DateTime dtBeginTime, bool isCompressed) { var message = new OCMessage { ContactId = contract.Id, MessageText = messageBody, MessageTime = dtBeginTime, IsCompressed = isCompressed }; lock (locker) { using (var repository = StorageEngine.FromFile(DATABASE_NAME)) { var table = repository.Scheme.CreateOrOpenXTable <long, OCMessage>( new Locator(contract.ContactName)); repository.Scheme.Commit(); var msg = table.FirstOrDefault(f => f.Record.MessageTime == dtBeginTime); if (msg == null) { long id = table.Count == 0 ? 0 : table.LastRow.Key + 1; table[id] = message; } else { table[msg.Key] = message; } table.Commit(); table.Close(); } } }
public List <OCHEntity.OCMessage> GetOCMessage(Contact contract, DateTime dtStart, DateTime dtEnd) { List <OCMessage> list = new List <OCMessage>(); try { lock (locker) { using (var connection = new SqliteConnection(DATABASE_NAME)) { using (var command = connection.CreateCommand()) { connection.Open(); command.CommandText = string.Format(@"SELECT * from Message where ContactId = '{0}' and MessageTime >= '{1}' and MessageTime < '{2}' order by strftime('%s',MessageTime)", contract.Id, DateTime2String(dtStart == DateTime.MinValue ? new DateTime(1970, 1, 1) : dtStart), DateTime2String(dtEnd)); using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { OCMessage message = new OCMessage(); message.ContactId = int.Parse(reader["ContactId"].ToString()); message.MessageText = reader["MessageText"].ToString(); message.MessageTime = DateTime.Parse(reader["MessageTime"].ToString()); message.IsCompressed = bool.Parse(reader["IsCompressed"].ToString()); if (message.IsCompressed) { message.MessageText = SevenZip.Decompress(message.MessageText); } list.Add(message); } } reader.Close(); reader.Dispose(); } command.Dispose(); } connection.Close(); connection.Dispose(); } } } catch (SqliteException exp) { logger.Error(exp); } return(list); }