CreateLogEvent() public method

Creates the log event which can be used to render layouts during installation/uninstallations.
public CreateLogEvent ( ) : LogEventInfo
return LogEventInfo
Esempio n. 1
0
        private void RunInstallCommands(InstallationContext installationContext, IEnumerable<DatabaseCommandInfo> commands)
        {
            // create log event that will be used to render all layouts
            LogEventInfo logEvent = installationContext.CreateLogEvent();

            try
            {
                foreach (var commandInfo in commands)
                {
                    string cs;

                    if (commandInfo.ConnectionString != null)
                    {
                        // if there is connection string specified on the command info, use it
                        cs = commandInfo.ConnectionString.Render(logEvent);
                    }
                    else if (this.InstallConnectionString != null)
                    {
                        // next, try InstallConnectionString
                        cs = this.InstallConnectionString.Render(logEvent);
                    }
                    else
                    {
                        // if it's not defined, fall back to regular connection string
                        cs = this.BuildConnectionString(logEvent);
                    }

                    this.EnsureConnectionOpen(cs);

                    var command = this.activeConnection.CreateCommand();
                    command.CommandType = commandInfo.CommandType;
                    command.CommandText = commandInfo.Text.Render(logEvent);

                    try
                    {
                        installationContext.Trace("Executing {0} '{1}'", command.CommandType, command.CommandText);
                        command.ExecuteNonQuery();
                    }
                    catch (Exception exception)
                    {
                        if (exception.MustBeRethrown())
                        {
                            throw;
                        }

                        if (commandInfo.IgnoreFailures || installationContext.IgnoreFailures)
                        {
                            installationContext.Warning(exception.Message);
                        }
                        else
                        {
                            installationContext.Error(exception.Message);
                            throw;
                        }
                    }
                }
            }
            finally 
            {
                this.CloseConnection();
            }
        }