public LoggingServer(IConfig config)
        {
            _config = config;

            if (_config.LoggingEnabled)
            {
                if (_config.LoggingTracePath != "")
                {
                    tr = new TextWriterTraceListener(_config.LoggingTracePath);
                    ts.Listeners.Add(tr);
                }

                if (_config.LoggingConnectionString != "")
                {
                    try
                    {
                        SQLDataExecutor.ExecuteStatement(_config.LoggingConnectionString, "select count(*) from sys.databases", 5);
                        _validTargerServer = true;
                    }
                    catch (Exception ex)
                    {
                        _validTargerServer = false;
                        throw;
                    }
                }
            }
        }
        public void OnNext(List <Log> value)
        {
            if (_config.LoggingEnabled)
            {
                foreach (Log log in value)
                {
                    if (tr != null)
                    {
                        tr.WriteLine(log.GetBaseMessage());
                        ts.Flush();
                    }

                    if (_validTargerServer)
                    {
                        SQLDataExecutor.ExecuteStatement(_config.LoggingConnectionString, "dbo.Insert_Log ", log.GetSQLParameters());
                    }
                }
            }
        }
Exemple #3
0
        public List <Log> Execute(DataManager dm, Dictionary <string, ITaskVariable> taskVariables, Log returnLog)
        {
            var        tempQueryList = QueryList.Copy();
            List <Log> returnLogs    = new List <Log>();

            foreach (ReplacementValue strv in Replacements)
            {
                var temp = dm.GetValueFromMacro(strv.Value, taskVariables);
                for (int i = 0; i < tempQueryList.Count; i++)
                {
                    tempQueryList[i].Statement = dm.GetValueFromMacro(tempQueryList[i].Statement, taskVariables);
                    if (strv.Global)
                    {
                        tempQueryList[i].Statement = Regex.Replace(tempQueryList[i].Statement, strv.Pattern, temp);
                    }
                    else
                    {
                        tempQueryList[i].Statement = dm.GetValueFromMacro(tempQueryList[i].Statement, strv, taskVariables);
                    }
                }
            }

            for (int i = 0; i < tempQueryList.Count; i++)
            {
                Log sqlLog = new Log()
                {
                    Type = returnLog.Type, Source = returnLog.Source
                };
                try
                {
                    sqlLog.StartTime = DateTime.Now;
                    sqlLog.Source   += "-" + i;
                    sqlLog.Statement = dm.GetValueFromMacro(tempQueryList[i].Statement, taskVariables);

                    if (tempQueryList[i].OutputType == SqlStatementOutputType.None)
                    {
                        SQLDataExecutor.ExecuteStatement(tempQueryList[i].ConnectionString, sqlLog.Statement);
                    }
                    else
                    {
                        object output = null;

                        if (tempQueryList[i].OutputType == SqlStatementOutputType.Scalar)
                        {
                            output = SQLDataExecutor.ExecuteScalar(tempQueryList[i].ConnectionString, sqlLog.Statement);
                        }

                        if (tempQueryList[i].OutputList.Count > 0 && output != null)
                        {
                            dm.SetOutputValues(output, tempQueryList[i].OutputList, ref taskVariables);
                        }
                    }


                    sqlLog.Message = "Completed successfully";
                    sqlLog.EndTime = DateTime.Now;
                }
                catch (Exception ex)
                {
                    sqlLog.EndTime    = DateTime.Now;
                    sqlLog.Successful = false;
                    sqlLog.Message    = ex.Message;
                }

                returnLogs.Add(sqlLog);
            }


            return(returnLogs);
        }