Exemple #1
0
        internal void Process(string t4Template, string outputFilePath, ITemplateDefinition definition, ProcessorParameters parameters)
        {
            var ttParams = new TextTemplatingParameters(
                t4Template,
                outputFilePath,
                definition.OverrideFileIfExists,
                definition.AddToProject);

            string tmpOutputFilePath;

            try
            {
                var state = this.TextTemplatingEngine.Process(ttParams, out tmpOutputFilePath);

                if (state == ProcessStateEnum.Processed)
                {
                    // SQL scripts...

                    if (definition.ExecuteSqlScript)
                    {
                        bool canExecuted = true;
                        if (definition is TemplateDefinitions.Database.InsertAllStoredProceduresGeneratedSqlTemplateDefinition && !parameters.WithSqlProcedureIntegration)
                        {
                            canExecuted = false;
                        }

                        if (canExecuted)
                        {
                            this.PublishProcessMessage("Executing {0}...", Path.GetFileName(tmpOutputFilePath));

                            try
                            {
                                SmoHelper.RunSqlScript(tmpOutputFilePath, this.SmoContext);
                            }
                            catch
                            {
                                // Create a copy of the tmpOutputFilePath file (for debug) because it will be deleted at the end of the whole process...
                                FileHelper.TryCopy(tmpOutputFilePath, string.Concat(tmpOutputFilePath, ".err"), withOverwrite: true);

                                throw;
                            }
                        }
                    }
                }

                this.HasErrors |= state == ProcessStateEnum.Failed;
            }
            catch (Exception x)
            {
                this.PublishErrorMessage("Failed while processing {0} -> {1}", Path.GetFileName(t4Template), x.Message);
            }

            foreach (CompilerError error in this.TextTemplatingEngine.Errors)
            {
                this.PublishErrorMessage(
                    "Template error: {0}({1},{2}): error {3}: {4}",
                    Path.GetFileName(this.TextTemplatingEngine.Errors.First().FileName), error.Line, error.Column, error.ErrorNumber, error.ErrorText);
            }
        }
Exemple #2
0
 /// <summary>
 /// Executes a SQL script using SMO API.
 /// </summary>
 ///
 /// <param name="scriptPath">
 /// Path of the script to execute.
 /// </param>
 ///
 /// <param name="smoContext">
 /// SmoContext instance.
 /// </param>
 public static void RunSqlScript(string scriptPath, SmoContext smoContext)
 {
     SmoHelper.RunSqlScript(scriptPath, smoContext.DatabaseHost, smoContext.DatabaseName, smoContext.Username, smoContext.Password);
 }