public void SyncData(DataSyncConfig dataSyncConfig, DataSyncDirection dataSyncDirection)
        {
            string           outerCurrentPath = string.Empty;
            IList <DBOutput> OutdBOutputs     = null;

            if (dataSyncDirection == DataSyncDirection.InnerDataSync)
            {
                //内网同步时,获取外网文件夹下面是否有需要同步的文件
                outerCurrentPath = dataPathManager.GetDataCaptureSaveDirectory(DataSyncDirection.OuterDataSync);
                OutdBOutputs     = dataSyncConfig.OutDBOutputs;
            }
            else
            {
                outerCurrentPath = dataPathManager.GetDataCaptureSaveDirectory(DataSyncDirection.InnerDataSync);
                OutdBOutputs     = dataSyncConfig.InnerDBOutputs;
            }

            string[] filePaths = Directory.GetFiles(outerCurrentPath).OrderBy(f => Path.GetFileNameWithoutExtension(f)).ToArray();
            if (filePaths.Length > 0)
            {
                foreach (string filePath in filePaths)
                {
                    Logger.Debug("开始同步到" + (DataSyncDirection.InnerDataSync == dataSyncDirection ? "内网" : "外网") + "。同步文件路径:" + filePath);
                    DataSet ds = DatasetSerialize.DataSetDeserialize(filePath);
                    if (ds != null && ds.Tables.Count > 0)
                    {
                        for (int i = 0; i < ds.Tables.Count; i++)
                        {
                            Logger.Debug("开始" + ds.Tables[i].TableName);
                            string tableName = ds.Tables[i].TableName;
                            if (tableName.ToUpper().EndsWith("_HIS"))   // 同步的时候要注意历史
                            {
                                DBOutput deleteDBOutput = GetConfigByTableName(OutdBOutputs, tableName.Replace("_HIS", ""));
                                for (int j = 0; j < ds.Tables[i].Rows.Count; j++)
                                {
                                    DeleteATableRow(dataSyncDirection, ds.Tables[i], j, deleteDBOutput, dataSyncConfig.DirtyField);
                                }
                            }
                            DBOutput dBOutput = GetConfigByTableName(OutdBOutputs, tableName);
                            for (int j = 0; j < ds.Tables[i].Rows.Count; j++)
                            {
                                if (IfExistsData(dataSyncConfig, dataSyncDirection, ds.Tables[i].TableName, dBOutput.KeyColumn, ds.Tables[i].Rows[j][dBOutput.KeyColumn]))
                                {
                                    CreateUpdateATableRow(dataSyncDirection, ds.Tables[i], j, dBOutput, dataSyncConfig.DirtyField);
                                }
                                else
                                {
                                    CreateInsertATableRow(dataSyncDirection, ds.Tables[i], j, dBOutput, dataSyncConfig.DirtyField);
                                }
                            }
                        }
                    }
                    //数据同步之后,再将文件移入已同步
                    File.Move(filePath, dataPathManager.GetDataSyncedSaveDirectory(dataSyncDirection) + "//" + Path.GetFileName(filePath));
                }
            }
        }
Beispiel #2
0
 /// <summary>
 /// 获取脏数据并且将数据保存在文件中
 /// </summary>
 /// <returns></returns>
 public bool CaptureDirtyFromDBAndSave(DataSyncConfig dataSyncConfig, DataSyncDirection dataSyncDirection)
 {
     try
     {
         DataSet ds       = CaptureDirtyFromDB(dataSyncConfig, dataSyncDirection);
         string  savePath = dataPathManager.GetDataCaptureSavePath(dataSyncDirection);
         DatasetSerialize.DataSetSerialize(savePath, ds);
         SetUnDirty(dataSyncConfig, dataSyncDirection);
         return(false);
     }
     catch (Exception ex) {
         Logger.Error("获取脏数据,存储在本地出现错误!", ex);
         throw ex;
     }
 }