Ejemplo n.º 1
0
        public async Task <string> ImportDt2GFile(string path)
        {
            var fields    = path.Replace(".csv", "").GetSplittedFields('\\');
            var tableName = fields[fields.Length - 1].DtFileNameEncode();
            var reader    = new StreamReader(path, Encoding.GetEncoding("GB2312"));
            var infos     = CsvContext.Read <FileRecord2GCsv>(reader, CsvFileDescription.CommaDescription).ToList();

            if (infos.FirstOrDefault(x => x.EcIo != null) == null)
            {
                var dingliInfos = CsvContext.Read <FileRecord2GDingli>(reader, CsvFileDescription.CommaDescription).ToList();
                if (dingliInfos.FirstOrDefault(x => x.EcIo != null) == null)
                {
                    throw new Exception("不是有效的2G数据文件!");
                }
                infos = dingliInfos.MapTo <List <FileRecord2GCsv> >();
            }
            reader.Close();
            var filterInfos =
                infos.GetFoshanGeoPoints().ToList();

            if (!filterInfos.Any())
            {
                throw new Exception("无数据或格式错误!");
            }
            _dtFileInfoRepository.UpdateCsvFileInfo(tableName, filterInfos[0].StatTime, "2G");
            var stats = filterInfos.MergeRecords();

            _rasterTestInfoRepository.UpdateRasterInfo(stats, tableName, "2G");
            var count = await _fileRecordService.InsertFileRecord2Gs(stats, tableName);

            return("完成2G路测文件导入:" + path + "(" + tableName + ")" + count + "条");
        }
Ejemplo n.º 2
0
        public string ImportDt2GFile(string path)
        {
            bool fileExisted;
            var  tableName = _fileRecordRepository.GetFileNameExisted(path, out fileExisted);

            if (fileExisted)
            {
                return("数据文件已存在于数据库中。请确认是否正确。");
            }
            var reader = new StreamReader(path, Encoding.GetEncoding("GB2312"));
            var infos  = CsvContext.Read <FileRecord2GCsv>(reader, CsvFileDescription.CommaDescription).ToList();

            if (infos.FirstOrDefault(x => x.EcIo != null) == null)
            {
                var dingliInfos = CsvContext.Read <FileRecord2GDingli>(reader, CsvFileDescription.CommaDescription).ToList();
                if (dingliInfos.FirstOrDefault(x => x.EcIo != null) == null)
                {
                    throw new Exception("不是有效的2G数据文件!");
                }
                infos = dingliInfos.MapTo <List <FileRecord2GCsv> >();
            }
            reader.Close();
            var filterInfos =
                infos.GetFoshanGeoPoints().ToList();

            if (!filterInfos.Any())
            {
                throw new Exception("无数据或格式错误!");
            }
            _dtFileInfoRepository.UpdateCsvFileInfo(tableName, filterInfos[0].StatTime);
            var stats = filterInfos.MergeRecords();

            _rasterTestInfoRepository.UpdateRasterInfo(stats, tableName, "2G");
            var count = _fileRecordRepository.InsertFileRecord2Gs(stats, tableName);

            return("完成2G路测文件导入:" + path + "(" + tableName + ")" + count + "条");
        }