Example #1
0
        public static BigSqlRunner FromConfig(string configFilePath)
        {
            if (string.IsNullOrWhiteSpace(configFilePath))
            {
                throw new ArgumentException($"{nameof(configFilePath)} cannot be null or whitespace", nameof(configFilePath));
            }
            else if (false == NetPatch.FileExists(configFilePath))
            {
                return(null);
            }

            var config       = BigSqlRunnerConfig.FromFile(configFilePath);
            var bigSqlRunner = new BigSqlRunner(config);

            return(bigSqlRunner);
        }
Example #2
0
        private async void Btn_Run_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                ToggleRunCancelButtonEnabledState(true);
                DisableInputs();
                BigSqlRunner = await CreateBigSqlRunner();

                var configFilePath = await Library.BigSqlRunner.GetConfigFilePath_ByConnStrAndSqlFile(
                    BigSqlRunner.Config.ConnectionString, BigSqlRunner.Config.BigSqlFilePath);

                BigSqlRunner.SaveConfig(configFilePath);

                await Run();
            }
            catch (Exception ex)
            {
                await new MessageDialog(ex.Message).ShowAsync();

                EnableInputs();
                ToggleRunCancelButtonEnabledState(false);
            }
        }
Example #3
0
        protected async Task <Library.BigSqlRunner> CreateBigSqlRunner()
        {
            var connectionString = Tb_ConnectionStr.Text;

            if (string.IsNullOrWhiteSpace(connectionString))
            {
                throw new ArgumentException($"db connection string cannot be empty", nameof(Tb_ConnectionStr));
            }

            var bigSqlFilePath = Tb_SqlFilePath.Text;

            if (string.IsNullOrWhiteSpace(bigSqlFilePath))
            {
                throw new ArgumentException($"big sql file path cannot be empty", nameof(Tb_SqlFilePath));
            }

            var    logToFile   = Cb_LogToFile.IsChecked.Value;
            string logFilePath = null;

            if (logToFile)
            {
                logFilePath = await Library.BigSqlRunner.GetLogFilePath_ByConnStrAndSqlFile(connectionString, bigSqlFilePath, RunnerStartTime);

                if (false == NetPatch.FileExists(logFilePath))
                {
                    RunnerStartTime = DateTime.Now;
                    logFilePath     = await Library.BigSqlRunner.GetLogFilePath_ByConnStrAndSqlFile(connectionString, bigSqlFilePath, RunnerStartTime);
                }
            }
            var compactLog = Cb_CompactLog.IsChecked.Value;

            var sqlUnitEndingLine = Tb_SqlUnitEndingLine.Text;

            if (string.IsNullOrWhiteSpace(sqlUnitEndingLine))
            {
                throw new ArgumentException($"sql unit ending line cannot be empty", nameof(Tb_SqlUnitEndingLine));
            }

            int batchSize;

            if (false == int.TryParse(Tb_BatchSize.Text, out batchSize))
            {
                throw new ArgumentException($"the value specified for batch size is not a number", nameof(Tb_BatchSize));
            }
            else if (batchSize <= 0)
            {
                throw new ArgumentException($"batch size must be >= 1", nameof(Tb_BatchSize));
            }

            var sessionSaveType         = (SessionSaveTypeEnum)Cmb_SessionSaveType.SelectedValue;
            var continueFromLastSession = Cb_ContinueFromLastSession.IsChecked.Value;

            int retryIntervalSeconds;

            if (false == int.TryParse(Tb_RetryIntervalSeconds.Text, out retryIntervalSeconds))
            {
                throw new ArgumentException($"the value specified for retry interval is not a number", nameof(Tb_RetryIntervalSeconds));
            }
            else if (retryIntervalSeconds < 0)
            {
                throw new ArgumentException($"retry interval must be >= 0", nameof(Tb_RetryIntervalSeconds));
            }

            int retryNumber;

            if (false == int.TryParse(Tb_RetryNumber.Text, out retryNumber))
            {
                throw new ArgumentException($"the value specified for retry number is not a number", nameof(Tb_RetryNumber));
            }
            else if (retryNumber < 0)
            {
                throw new ArgumentException($"retry number must be >= 0", nameof(Tb_RetryNumber));
            }

            var bigSqlRunner = new Library.BigSqlRunner(
                connectionString: connectionString, bigSqlFilePath: bigSqlFilePath,
                enableLogging: logToFile, logFilePath: logFilePath, compactLog: compactLog,
                batchSize: batchSize, sqlUnitEndingLine: sqlUnitEndingLine,
                continueFromLastSessionWhenStarted: continueFromLastSession, sessionSaveType: sessionSaveType,
                retryIntervalWhenError_Seconds: retryIntervalSeconds, retryNumberWhenError: retryNumber);
            await bigSqlRunner.LoadLogFile();

            return(bigSqlRunner);
        }