public async Task <byte[]> ConvertMailBodyIntoBytes(MailBodyModel bodyModel) { var face = encoding.GetBytes(bodyModel.Mail_Face_ID).ToList(); var body = bodyModel.Mail_Body.ToList(); while (face.Count < MAXIMUM_FACE_BYTES) { face.Add(0x00); } while (body.Count < MAXIMUM_BODY_SIZE) { body.Add(0x00); } var m = new MemoryStream(); await m.WriteAsync(BitConverter.GetBytes(5), 0, 4); await m.WriteAsync(BitConverter.GetBytes(0), 0, 2); await m.WriteAsync(body.ToArray(), 0, body.Count); await m.WriteAsync(BitConverter.GetBytes(0), 0, 2); await m.WriteAsync(face.ToArray(), 0, face.Count); return(m.ToArray()); }
public async Task SaveMailAsync(byte[] data) { var receiver_accountID = new byte[4]; var receiver = new byte[16]; var sender_accountID = new byte[4]; var sender = new byte[16]; var subject = new byte[32]; var body = new byte[1200]; var face = new byte[25]; logger.Debug("Taking data block and breaking it out..."); Buffer.BlockCopy(data, 4, receiver_accountID, 0, 4); Buffer.BlockCopy(data, 8, receiver, 0, 16); Buffer.BlockCopy(data, 26, sender_accountID, 0, 4); Buffer.BlockCopy(data, 30, sender, 0, 16); Buffer.BlockCopy(data, 48, subject, 0, 32); Buffer.BlockCopy(data, 176, body, 0, 1200); Buffer.BlockCopy(data, 1378, face, 0, 25); logger.Debug("...completed; dumping primative information"); logger.Debug("Receiving Account ID: " + swap32(BitConverter.ToUInt32(receiver_accountID))); logger.Debug("Receiver Name: " + encoding.GetString(receiver)); logger.Debug("Sender Account ID: " + swap32(BitConverter.ToUInt32(sender_accountID))); logger.Debug("Sender Name: " + encoding.GetString(sender)); logger.Debug("Subject Line: " + encoding.GetString(subject)); logger.Debug("Message Body: " + encoding.GetString(body)); logger.Debug("Face ID: " + encoding.GetString(face)); var metaModel = new MailMetaModel { Receiver_Account_ID = (int)swap32(BitConverter.ToUInt32(receiver_accountID)), Receiver_Name = receiver, Sender_Account_ID = (int)swap32(BitConverter.ToUInt32(sender_accountID)), Sender_Name = sender, Mail_Subject = subject, date = DateTime.UtcNow, Mail_Delivered = false }; var bodyModel = new MailBodyModel { Mail_Body = body, Mail_Face_ID = encoding.GetString(face) }; logger.Information($"An email has been sent by {sender} to {receiver}. Saving...", sender, receiver); await Task.Run(() => DBAccess.getInstance().CreateNewMail(metaModel, bodyModel)); logger.Information("The email has been saved to the database"); }
public void CreateNewMail(MailMetaModel metaModel, MailBodyModel bodyModel) { using ISession session = _sessionFactory.OpenSession(); using ITransaction transaction = session.BeginTransaction(); session.Save(metaModel); bodyModel.Mail_ID = metaModel.Mail_ID; session.Save(bodyModel); transaction.Commit(); session.Close(); }
public MailBodyModel GetMailBodyByMailId(int mail_ID) { MailBodyModel bodyModel = new MailBodyModel(); using (ISession session = _sessionFactory.OpenSession()) { using ITransaction transaction = session.BeginTransaction(); bodyModel = session.Query <MailBodyModel>() .SingleOrDefault(x => x.Mail_ID == mail_ID); transaction.Commit(); session.Close(); } return(bodyModel); }