private void ParseAow1() { _gameType = AowGameType.Aow1; using (BinaryReader input = new BinaryReader(_theAttachment.GetMemoryStream())) { if (_fetch_compressed_data) { if (CheckSignature(input, compressed_part_signature)) { DataCompressor compressed_data = new DataCompressor(input, true); compressed_data.Compressed = false; // decompression happens here using (BinaryReader main_input = new BinaryReader(new MemoryStream(compressed_data.Data))) { if (CheckSignature(main_input, aow1map_signature)) { int possible_class_id = main_input.ReadInt32(); main_input.BaseStream.Position += 3; // skip field list of root offsetmap, moving straight to the contents OffsetMap map_om = new OffsetMap(main_input.BaseStream); _mapTitle = map_om.ReadShortPascalString(0x19); _turnNumber = map_om.ReadInt32(0x13); OffsetMap section_15 = map_om.GetSubFieldOffsetMap(0x15); OffsetMap s_15_1 = section_15.GetSubFieldOffsetMap(0x01); OffsetMap s_15_1_1 = s_15_1.GetSubFieldOffsetMap(0x01, true); OffsetMap s_15_1_1_36 = s_15_1_1.GetSubFieldOffsetMap(0x36); OffsetMap s_15_1_1_36_15 = s_15_1_1_36.GetSubFieldOffsetMap(0x15); _gameTitle = s_15_1_1_36_15.ReadShortPascalString(0x14); } else { _isValid = false; } } } else { _isValid = false; } } } }
public void processAttachment(MimeData att, Configuration config, string mailAddress) { if (att.FileName.Contains("xls") || att.FileName.Contains("xlsx") || att.FileName.Contains("csv") || att.FileName.Contains("xml")) { Guid guid = Guid.NewGuid(); using (var unit = GetUnitOfWork()) { //BAS.EDI.Objects.Mail.MailLog mailLog = new MailLog(); //mailLog.Mailaddress = imail.From.First().Address; //mailLog.Filename = att.FileName; //mailLog.ReceiveDate = System.DateTime.Now; string ext = ".unknown"; if (att.FileName.Contains(".xlsx")) { ext = ".xlsx"; } else if (att.FileName.Contains(".xls")) { ext = ".xls"; } else if (att.FileName.Contains(".csv")) { ext = ".csv"; } string fileName = att.FileName; if (fileName.Contains(")")) { fileName = fileName.Replace(")", "-"); } if (fileName.Contains("(")) { fileName = fileName.Replace("(", "-"); } if (fileName.Contains("_")) { fileName = fileName.Replace("_", "-"); } Regex reg = new Regex("([0-9a-z_-]+[\\.][0-9a-z_-]{1,6})$"); fileName = reg.Match(fileName).Value; if (string.IsNullOrEmpty(fileName)) { fileName = ext; } //mailLog.UniqueCode = guid.ToString() + "-" + fileName; //context.MailLogs.InsertOnSubmit(mailLog); //context.SubmitChanges(); //if (!Directory.Exists(ConfigurationManager.AppSettings["ExcelMailDirectory"])) // Directory.CreateDirectory(ConfigurationManager.AppSettings["ExcelMailDirectory"]); string filepath = config.AppSettings.Settings["EdiOrderDir"].Value + guid.ToString() + "-" + fileName; using (MemoryStream ms = att.GetMemoryStream()) { FileStream outStream = File.OpenWrite(filepath); ms.WriteTo(outStream); outStream.Flush(); outStream.Close(); } ExcelReader excel = new ExcelReader(config.AppSettings.Settings["EdiOrderDir"].Value, log, unit); excel.ProcessFile(filepath, mailAddress); } } }