Пример #1
0
        /// <summary>
        /// 读
        /// </summary>
        /// <returns></returns>
        public SyncConfig Read()
        {
            SyncConfig SyncSetting = new SyncConfig();
            RegistryKey root = GetRoot();
            if (regHelper.KeyExists(root, SysConfig.SyncServiceName))
            {
                RegistryKey serviceKey = root.OpenSubKey(SysConfig.SyncServiceName);
                SyncSetting.TimerInterval = regHelper.GetValue<int>(serviceKey, SysConfig.RegistryTimerInterval);
                SyncSetting.WriteLog = regHelper.GetValue<bool>(serviceKey, SysConfig.RegistryWriteLog);
                SyncSetting.SyncType = regHelper.GetValue<int>(serviceKey, SysConfig.RegistrySyncType);
                SyncSetting.SyncGisData = regHelper.GetValue<bool>(serviceKey, SysConfig.RegistrySyncGisData);
                SyncSetting.ServiceUrl = regHelper.GetValue<string>(serviceKey, SysConfig.RegistryServiceUrl);
                SyncSetting.ServiceMethod = regHelper.GetValue<string>(serviceKey, SysConfig.RegistryServiceMethod);

                RegistryKey localKey = serviceKey.OpenSubKey(SysConfig.RegistryLocals);
                foreach (var keyName in localKey.GetSubKeyNames())
                {
                    RegistryKey localCodeKey = localKey.OpenSubKey(keyName);
                    SyncConfigLocal localSetting = new SyncConfigLocal()
                    {
                        Code = keyName,
                        Name = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryName),
                        DbConfig = new DbConfig()
                        {
                            Ip = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryDbIp),
                            Name = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryDbName),
                            Username = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryDbUsername),
                            Password = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryDbPassword)
                        },
                        FtpConfig = new FtpConfig()
                        {
                            Ip = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryFtpIp),
                            Port = regHelper.GetValue<int>(localCodeKey, SysConfig.RegistryFtpPort),
                            Username = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryFtpUsername),
                            Password = regHelper.GetValue<string>(localCodeKey, SysConfig.RegistryFtpPassword)
                        }
                    };
                    SyncSetting.LocalData.Add(localSetting);
                }
                RegistryKey targetKey = serviceKey.OpenSubKey(SysConfig.RegistryTargets);
                foreach (var keyName in targetKey.GetSubKeyNames())
                {
                    RegistryKey targetCodeKey = targetKey.OpenSubKey(keyName);
                    SyncConfigTarget targetSetting = new SyncConfigTarget()
                    {
                        Code = keyName,
                        Name = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryName),
                        DbConfig = new DbConfig()
                        {
                            Ip = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryDbIp),
                            Name = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryDbName),
                            Username = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryDbUsername),
                            Password = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryDbPassword)
                        },
                        FtpConfig = new FtpConfig()
                        {
                            Ip = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryFtpIp),
                            Port = regHelper.GetValue<int>(targetCodeKey, SysConfig.RegistryFtpPort),
                            Username = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryFtpUsername),
                            Password = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryFtpPassword)
                        },
                        Jg = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryJg),
                        Time = regHelper.GetValue<string>(targetCodeKey, SysConfig.RegistryTime)
                    };
                    SyncSetting.TargetData.Add(targetSetting);
                }
            }
            return SyncSetting;
        }
Пример #2
0
        /// <summary>
        /// 同步。
        /// </summary>
        /// <param name="setting">同步配置。</param>
        /// <param name="log">日志信息。</param>
        /// <returns>同步是否成功。</returns>
        public bool Sync(SyncConfig syncConfig, SyncConfigTarget targetConfig, SyncConfigLocal localConfig, ref StringBuilder sbLog)
        {
            bool result = false;

            LogOperation.Append(sbLog, string.Format("开始同步数据:{0}({1})  开始时间:{2}", targetConfig.Name, targetConfig.Code, DateTime.Now));

            OracleDbOperation localDb = new OracleDbOperation(localConfig.DbConfig.ConnStr);
            FtpHelper localFtp = new FtpHelper(localConfig.FtpConfig.Ip, localConfig.FtpConfig.Port, localConfig.FtpConfig.Username, localConfig.FtpConfig.Password);

            OracleDbOperation targetDb = new OracleDbOperation(targetConfig.DbConfig.ConnStr);
            FtpHelper targetFtp = new FtpHelper(targetConfig.FtpConfig.Ip, targetConfig.FtpConfig.Port, targetConfig.FtpConfig.Username, targetConfig.FtpConfig.Password);
            try
            {
                targetDb.BeginTransaction();
                localDb.BeginTransaction();

                List<SyncData> syncDataList = new List<SyncData>();
                ////系统数据
                syncDataList.Add(new SyncDataSystemInfo(targetDb, localDb, targetConfig.Code, localConfig.Code, targetFtp, localFtp, sbLog));
                ////项目数据
                syncDataList.Add(new SyncDataItem(syncConfig, targetDb, localDb, targetConfig.Code, localConfig.Code, targetFtp, localFtp, sbLog));
                ////流程数据
                syncDataList.Add(new SyncDataWorkflow(targetDb, localDb, targetConfig.Code, localConfig.Code, targetFtp, localFtp, sbLog));
                ////Syncs.Add(new SyncXtxx(targetDbOperation, localDbOperation, targetSetting.Code, localSetting.Code, targetFtpOperation, localFtpOperation, sbLog));

                foreach (var syncData in syncDataList)
                {
                    syncData.Sync();
                }

                targetDb.Commit();
                localDb.Commit();
                result = true;
            }
            catch (Exception e)
            {
                targetDb.Rollback();
                localDb.Rollback();
                LogOperation.WriteExceptionLog(sbLog, e);
            }

            sbLog.AppendLine();
            sbLog.AppendLine("结束时间:" + DateTime.Now);
            return result;
        }