public override void BeforeUpdate() { if (_sqlBatCommand != null) { return; } Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("APP", Settings.AutoUpdateSetting.Default.APP); dictionary.Add("MD", Settings.AutoUpdateSetting.Default.Md); dictionary.Add("TRD", Settings.AutoUpdateSetting.Default.Trd); dictionary.Add("EXH", Settings.AutoUpdateSetting.Default.Exh); _sqlBatCommand = new Dictionary<string, IList<UpdateSqlCommand>>(); foreach (KeyValuePair<string, string> keyValuePair in dictionary) { string dbDir = Path.Combine(Path.Combine(this.UpdateFolderName, this.DirectoryName), keyValuePair.Key); string logDir = Path.Combine(dbDir, "log"); string sqlDir = Path.Combine(dbDir, "batsql"); if (!Directory.Exists(dbDir) || Directory.GetFiles(dbDir).Length == 0) { continue; } #region �ļ��д��� // ������־�ļ��� if (!Directory.Exists(logDir)) { Directory.CreateDirectory(logDir); } // ����sql�������ļ��� if (!Directory.Exists(sqlDir)) { Directory.CreateDirectory(sqlDir); } #endregion #region ��ȡ���ݿ����� string[] dbConnection = GetConnectionStrings(keyValuePair.Value); if (dbConnection == null) { throw new Exception(string.Format("��ȡ{0}���ݿ������ַ���ʧ��", keyValuePair.Value)); } #endregion #region ����SQL�ļ� //SQLִ�� ���Ⱥ�˳�� �����ȶ� ���ļ���װ�ļ��� ���� List<string> files = new List<string>(Directory.GetFiles(dbDir)); files.Sort(); List<UpdateSqlCommand> updateCommands = new List<UpdateSqlCommand>(); foreach (string file in files) { string fileName = new FileInfo(file).Name; fileName = fileName.Substring(0, fileName.IndexOf('.')); // ȥ����չ�� // ������ִ�е�SQL�ļ� string sqlFile = Path.Combine(sqlDir, string.Format("{0}.sql", fileName)); // log ��־�ļ� string logFile = Path.Combine(logDir, string.Format("log_{0}.txt", fileName)); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendFormat("SPOOL {0}", logFile).AppendLine(); stringBuilder.AppendFormat("@{0}", file); stringBuilder.Append(@" SPOOL OFF EXIT EOF "); WriteFile(sqlFile, stringBuilder.ToString()); #region ����ִ������ UpdateSqlCommand sqlCommand = new UpdateSqlCommand(file, string.Format("SQLPLUS {0}/{1}@{2} @{3}", dbConnection[1], dbConnection[2], dbConnection[0], sqlFile), logFile); sqlCommand.SqlConnectionString = dbConnection[3]; sqlCommand.ProviderName = "Oracle.DataAccess.Client"; updateCommands.Add(sqlCommand); #endregion } #endregion _sqlBatCommand.Add(keyValuePair.Key, updateCommands); } }
/// <summary> /// /// </summary> private void LoadDataFormFiles() { Dictionary<string, string> dictionary = new Dictionary<string, string>(); dictionary.Add("APP", Settings.AutoUpdateSetting.Default.APP); dictionary.Add("MD", Settings.AutoUpdateSetting.Default.Md); dictionary.Add("TRD", Settings.AutoUpdateSetting.Default.Trd); dictionary.Add("EXH", Settings.AutoUpdateSetting.Default.Exh); ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = Path.Combine(this.TargetPath, Settings.AutoUpdateSetting.Default.ConfigName); Configuration config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); foreach (KeyValuePair<string, string> keyValuePair in dictionary) { string dbDir = Path.Combine(Path.Combine(this.UpdateFolderName, this.DirectoryName), keyValuePair.Key); if (!Directory.Exists(dbDir) || Directory.GetFiles(dbDir).Length == 0) { continue; } IList<UpdateSqlCommand> updateSqlCommands = new List<UpdateSqlCommand>(); foreach (string file in Directory.GetFiles(dbDir)) { UpdateSqlCommand sqlCommand = new UpdateSqlCommand(file, Util.ReadFile(file), ""); ConnectionStringSettings connectionString = config.ConnectionStrings.ConnectionStrings[keyValuePair.Value]; sqlCommand.SqlConnectionString = connectionString.ConnectionString; sqlCommand.ProviderName = connectionString.ProviderName; updateSqlCommands.Add(sqlCommand); } _sqlBatCommand[keyValuePair.Key] = updateSqlCommands; } }