private static DateTime GetFileDateTime(string fname, string mode) { switch (mode.ToUpper()) { case "MOD06": string dt; return(DataProcesser.GetOribitTime(fname, out dt)); case "MOD03": string dt3; return(DataProcesser.GetOribitTime(fname, out dt3)); case "AIRS": string outstr; return(AIRSDataProcesser.GetAIRSDateTimeFromStr(fname, out outstr)); case "ISCCP": string isccpregex = @".(?<year>\d{4}).(?<month>\d{2}).(?<day>\d{2}).(?<utc>\d{4})"; Match match = Regex.Match(fname, isccpregex); if (match.Success) { int year = int.Parse(match.Groups["year"].Value); int month = int.Parse(match.Groups["month"].Value); return(new DateTime(year, month, 1)); } return(DateTime.MinValue); case "CLOUDSAT": string[] parts = fname.Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries); return(OriginData2Database.GetInfoFromCloudSATName(parts[0])); default: return(DateTime.MinValue); } }
private void MODRawDataF2Database(string tableName, List <string> filelist, Action <string> ProBack) { //MOD06_L2.A2011001.0350.hdf //MOD03.A2011001.0350.hdf ProBack("--------------------------------------------------------------------------------------"); ProBack("MOD06数据入库开始:"); string fName, localfName; DateTime fDateTime = DateTime.MinValue; string sensor = "MODIS"; string dt; foreach (string file in filelist) { fName = Path.GetFileName(file); ProBack("\t" + fName + "入库开始:"); fDateTime = DataProcesser.GetOribitTime(file, out dt); if (fDateTime == DateTime.MinValue || string.IsNullOrEmpty(dt)) { ProBack("\t\t解析文件名时间信息失败,入库失败!"); continue; } if (Directory.Exists(new DirectoryInfo(_inputDir).Parent.FullName)) { localfName = file.Replace(new DirectoryInfo(_inputDir).Parent.FullName, "");//Path.Combine(localDir, fName); } else { localfName = file.Replace(_inputDir, ""); } try { //if (_dbConnect.IshasRecord(tableName, "ImageName", fName) == false) if (_dbConnect.IshasRecord(tableName, "ImageData", localfName) == false) { _dbConnect.InsertRawMOD06Table(tableName, fDateTime, fName, localfName, sensor); //插入,insert ProBack("\t\t\t文件入库成功!"); } else { //if (_dbConnect.UpdateRawCLDParatable(tableName, fName, localfName)) // ProBack("\t\t\t文件记录更新成功!"); //else ProBack("\t\t\t文件记录已存在,跳过!"); } } catch (System.Exception ex) { ProBack("入库错误" + ex.Message); } } ProBack("MOD06数据入库结束!"); ProBack("--------------------------------------------------------------------------------------"); }