예제 #1
0
        private void CloudSATRawDataF2Database(string tableName, List <string> filelist, Action <string> ProBack)
        {
            ProBack("--------------------------------------------------------------------------------------");
            ProBack("CloudSAT原始数据入库开始:");
            string   fName, localfName, prdsIndicate, datatype;
            int      granuleNO;
            DateTime fDateTime = DateTime.MinValue;

            string[] fNameParts;
            long     clousatID = 0;
            Dictionary <string, long> file2ID = new Dictionary <string, long>();

            foreach (string file in filelist)
            {
                #region 文件入库
                try
                {
                    fName = Path.GetFileName(file);
                    ProBack("\t" + fName + "入库开始:");
                    //2007101052404_05066_CS_MODIS-AUX_GRANULE_P_R04_E02.hdf
                    fNameParts = Path.GetFileNameWithoutExtension(file).Split(new char[] { '_' }, StringSplitOptions.RemoveEmptyEntries);
                    if (fNameParts.Length != 8 || (fNameParts.Length >= 2 && fNameParts[2] != "CS"))
                    {
                        ProBack("\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, "");//Path.Combine(localDir, fName);
                    }
                    fDateTime = GetInfoFromCloudSATName(fNameParts[0]);
                    if (fDateTime == DateTime.MinValue)
                    {
                        ProBack("\t\t解析文件名时间信息失败,入库失败!");
                        continue;
                    }
                    granuleNO    = int.Parse(fNameParts[1]);
                    prdsIndicate = fNameParts[3].ToUpper();
                    datatype     = fNameParts[4];
                    //if (_dbConnect.IshasRecord(tableName, "ImageName", fName) == false)//新增
                    if (_dbConnect.IshasRecord(tableName, "ImageData", localfName) == false)                                                     //新增
                    {
                        clousatID = _dbConnect.InsertCloudSAT2Table(tableName, fDateTime, fName, localfName, granuleNO, prdsIndicate, datatype); //插入,insert
                        ProBack("\t\t\t文件记录入库成功!");
                        if (clousatID != 0)
                        {
                            if (!file2ID.ContainsKey(file))
                            {
                                file2ID.Add(file, clousatID);
                            }
                        }
                        clousatID = 0;
                    }
                    else
                    {
                        //_dbConnect.DeleteCLDParatableRecord(tableName, "ImageName", fName);
                        //clousatID = _dbConnect.InsertCloudSAT2Table(tableName, fDateTime, fName, localfName, granuleNO, prdsIndicate, datatype);  //插入,insert
                        //ProBack("\t\t\t文件记录更新成功!");
                        //if (clousatID != 0)
                        //{
                        //    if (!file2ID.ContainsKey(file))
                        //    {
                        //        file2ID.Add(file, clousatID);
                        //    }
                        //}
                        //clousatID = 0;
                        //if (_dbConnect.UpdateRawCLDParatable(tableName, fName, localfName))
                        //    ProBack("\t\t\t文件记录更新成功!");
                        //else
                        ProBack("\t\t\t文件记录已存在,跳过!");
                    }
                }
                catch (System.Exception ex)
                {
                    ProBack(file + "入库失败!" + ex.Message);
                }
                #endregion
            }
            try
            {
                _dbConnect.UpdateLink();
                //ProBack("CloudSAT文件与区域关联记录更新开始:");
                #region CloudSAT与region关联
                if (file2ID.Count != 0)
                {
                    Dictionary <long, PrjEnvelopeItem> allRegions = _dbConnect.GetAllRegion();
                    ConnectCloudSAT2Region             c2r        = new ConnectCloudSAT2Region(file2ID, allRegions);
                    c2r.Compute(ProBack);
                }
                ProBack("CloudSAT文件与区域关联更新完成!");
                #endregion
            }
            catch (System.Exception ex)
            {
                ProBack("错误!" + ex.Message);
            }
            ProBack("CloudSAT原始数据入库结束!");
            ProBack("--------------------------------------------------------------------------------------");
        }