public static void SaveMail(string clientId, MailItemDto message) { var path = MailsPath; if(!Directory.Exists(path)) { Directory.CreateDirectory(path); } var dateFolder = message.SentOn.ToString("yyyyMMdd"); path = Path.Combine(path, dateFolder); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } string id = string.IsNullOrEmpty(message.Id) ? Guid.NewGuid().ToString() : message.Id; string fileName = string.Format("{0}_{1}.msg", clientId, id); path = Path.Combine(path, fileName); using (var ms = new MemoryStream()) { ms.Write(message.Data, 0, message.Data.Length); ms.Position = 0; using (MemoryStream outStream = new MemoryStream(message.Data.Length*3)) { using (var decompress = new GZipStream(ms, CompressionMode.Decompress)) { decompress.CopyTo(outStream); decompress.Close(); } outStream.Position = 0; message.Data = outStream.GetBuffer(); var realSum = message.CalculatedCheckSum; if (realSum != message.CheckSum) { throw new CheckSumException(); } File.WriteAllBytes(path, message.Data); message.Data = null; } /*using (GZipStream gZipStream = new GZipStream(ms, CompressionMode.Decompress)) { byte[] decompressedBuffer = new byte[10*1024*1024]; // Use the ReadAllBytesFromStream to read the stream. int totalCount = ReadAllBytesFromStream(gZipStream, decompressedBuffer); using (var fs = File.OpenWrite(path)) { fs.Write(decompressedBuffer, 0, totalCount); } }*/ message.Link = string.Join("/", ApplicationSettings.SiteUrl, MESSAGES_FOLDER, dateFolder, fileName); } }
public static MailItemDto FromLogLine(string line) { MailItemDto result = null; List<string> parts = line.SplitCSV().ToList(); if(parts.Count >= 6) { result = new MailItemDto { Id = parts[0], SentOn = DateTime.ParseExact(parts[1], StringHelper.DATE_TIME_FORMAT, DateTimeFormatInfo.CurrentInfo), From = parts[2], Subject = parts[3], SyncStatus = (SyncMessagesMethodResultStatus) Enum.Parse(typeof (SyncMessagesMethodResultStatus), parts[4]), Link = parts[5] }; } return result; }
public static MailItemDto FromLogLine(string line) { MailItemDto result = null; List <string> parts = line.SplitCSV().ToList(); if (parts.Count >= 6) { result = new MailItemDto { Id = parts[0], SentOn = DateTime.ParseExact(parts[1], StringHelper.DATE_TIME_FORMAT, DateTimeFormatInfo.CurrentInfo), From = parts[2], Subject = parts[3], SyncStatus = (SyncMessagesMethodResultStatus)Enum.Parse(typeof(SyncMessagesMethodResultStatus), parts[4]), Link = parts[5] }; } return(result); }