Exemplo n.º 1
0
 //Add unexecuted script file name to Version table
 public void AddScriptRecords(UnexecutedScript scripts, string ConnString)
 {
     using (SqlConnection sqlCon = new SqlConnection(@ConnString))
     {
         sqlCon.Open();
         string sql = $"INSERT INTO [dbo].[versions]" +
                      $"VALUES (@scriptName,@AppliedDate)";
         using (SqlCommand command = new SqlCommand(sql, sqlCon))
         {
             command.Parameters.AddWithValue("@scriptName", scripts.ScriptName);
             SqlParameter parameter = command.Parameters.AddWithValue("@AppliedDate", SqlDbType.DateTime);
             parameter.Value = DateTime.Now;
             command.ExecuteNonQuery();
         }
     }
 }
Exemplo n.º 2
0
        private ChromelyResponse runScripts(ChromelyRequest request)
        {
            var filePath = request.PostData.ToString();

            Console.WriteLine(filePath);
            UnexecutedScript script = new UnexecutedScript(filePath);
            Options          opts   = ConfigService.getConfig().opts;
            var scriptExecutor      = ConfigService.getConfig().scriptExecutor;

            script.LoadScript();
            var result   = scriptExecutor.RunSignleScriptBatchs(script, opts.ConnString, opts.SubsituteList);
            var response = new ChromelyResponse(request.Id);

            response.Data = result;

            return(response);
        }
Exemplo n.º 3
0
        public ScriptExecutionResult RunSignleScriptBatchs(UnexecutedScript script, string ConnString, IEnumerable <string> substituteList)
        {
            var executionResult = new ScriptExecutionResult(script.ScriptName);

            try
            {
                using (var sqlCon = new SqlConnection(@ConnString))
                {
                    sqlCon.Open();
                    int rows = 0;
                    foreach (string batch in script.Batches)
                    {
                        if (!string.IsNullOrEmpty(batch))
                        {
                            string replacedBatch = batch;
                            //Substitute Variable
                            foreach (string sub in substituteList)
                            {
                                string[] var = sub.Split(':');
                                replacedBatch = replacedBatch.Replace($"${var[0]}$", var[1]);
                            }

                            using (var command = new SqlCommand(replacedBatch, sqlCon))
                            {
                                rows += command.ExecuteNonQuery() < 0 ? 0 : command.ExecuteNonQuery();
                            }
                        }
                    }
                    AddScriptRecords(script, ConnString);
                    executionResult.IsSuccess    = true;
                    executionResult.rowsEffected = rows;
                }
                return(executionResult);
            }
            catch (Exception ex)
            {
                executionResult.IsSuccess    = false;
                executionResult.errorMessage = ex.ToString();
                return(executionResult);
            }
        }