public BufferFileSummary ProcessFile(string country, HttpPostedFile file) { var returned = new BufferFileSummary(); var fileData = new byte[file.ContentLength]; file.InputStream.Read(fileData, 0, file.ContentLength); var rawBufferDataHolders = new List <RawBufferHolder>(); using (var ms = new MemoryStream(fileData)) { var sr = new StreamReader(ms); var headerLine = sr.ReadLine(); if (string.IsNullOrEmpty(headerLine)) { returned.FilePaseMessage = "Invalid File"; return(returned); } var columns = headerLine.Split(','); if (columns[0] != "Location") { returned.FilePaseMessage = "Invalid Header"; } while (!sr.EndOfStream) { var dataRow = sr.ReadLine(); if (dataRow == null) { continue; } var splitDataRow = dataRow.Split(','); var rawData = new RawBufferHolder { Location = splitDataRow[0].Trim(), CarGroup = splitDataRow[1].Trim(), Number = splitDataRow[2].Trim(), }; rawBufferDataHolders.Add(rawData); } } ParseRawData(rawBufferDataHolders, returned, country); return(returned); }
private void ParseRawData(IEnumerable <RawBufferHolder> rawData, BufferFileSummary bfs, string country) { bfs.Buffers = new List <ResBuffer>(); using (var dataAccess = new BufferDataAccess()) { foreach (var rd in rawData) { var location = dataAccess.GetLocationId(rd.Location); if (location == null || location.country != country) { bfs.RowsSkipped++; continue; } var groupId = dataAccess.GetCarGroupId(location.country, rd.CarGroup); if (groupId == 0) { bfs.RowsSkipped++; continue; } int number; var parseSucceeded = int.TryParse(rd.Number, out number); if (!parseSucceeded) { bfs.RowsSkipped++; continue; } var rAdd = new ResBuffer { LocId = location.dim_Location_id, CarGrpId = groupId, Value = number }; bfs.Buffers.Add(rAdd); bfs.ValidRows++; } } }