Exemple #1
0
        public void CanGenEtlSessionResultsWork()
        {
            var agent     = CreateAgent();
            var logParser = agent.GetEtlLogParser();

            var query = new EtlSessionQuery
            {
                FromDateTime  = DateTime.Now.Subtract(_sessionTimeSpan),
                ToDateTime    = DateTime.Now,
                EtlPackageIds =
                {
                    Guid.Empty.ToString()
                },
                Variables =
                {
                    new EtlVariableFilter("aaa", "bbb"),
                    new EtlVariableFilter("ccc", "ddd")
                },
                MaxSessionCount = 10,
            };
            var sessions = logParser.GetEtlSessions(query);

            Assert.IsNotNull(sessions);
            Assert.AreEqual(0, sessions.Length);
        }
Exemple #2
0
        private EtlSession[] GetEtlSessions(EtlSessionListModel model)
        {
            var dateTo   = DateTime.ParseExact(model.DateTo, SharedStrings.DateFormat, null);
            var dateFrom = DateTime.ParseExact(model.DateFrom, SharedStrings.DateFormat, null);
            var oneDay   = dateTo == dateFrom;

            dateTo = dateTo.AddDays(1);

            var query = new EtlSessionQuery
            {
                FromDateTime    = dateFrom,
                ToDateTime      = dateTo,
                MaxSessionCount = model.DefaultMaxSessionCount,
            };

            if (model.Status > 0)
            {
                query.EtlStatuses.Add(model.Status);
            }

            var agent     = SiteConfiguration.GetEtlAgent();
            var logParser = agent.GetEtlLogParser();
            var sessions  = logParser.GetEtlSessions(query);

            return(sessions);
        }
Exemple #3
0
        private static EtlSessionQuery CreateSessionQuery(EtlMailSubscription subscription)
        {
            var query = new EtlSessionQuery
            {
                ToDateTime   = DateTime.Now,
                FromDateTime = DateTime.Now.Subtract(TimeSpan.FromSeconds(subscription.OnLastSeconds)),
            };

            query.EtlStatuses.AddRange(subscription.EtlStatuses);

            return(query);
        }
            public EtlSession[] GetEtlSessions(EtlSessionQuery query)
            {
                var result = new List <EtlSession>();

                foreach (var agent in _etlAgents)
                {
                    var logParser = agent.GetEtlLogParser();
                    result.AddRange(logParser.GetEtlSessions(query));
                }

                return(result.ToArray());
            }
        public EtlSession[] GetEtlSessions(EtlSessionQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (!IsGuids(query.EtlPackageIds))
            {
                return new EtlSession[0];
            }

            var sessions = SelectEtlSessions(query);
            return sessions.ToArray();
        }
Exemple #6
0
        public void CanGetEtlSessionResults()
        {
            var agent     = CreateAgent();
            var logParser = agent.GetEtlLogParser();

            var query = new EtlSessionQuery
            {
                FromDateTime = DateTime.Now.Subtract(_sessionTimeSpan),
                ToDateTime   = DateTime.Now,
            };
            var sessions = logParser.GetEtlSessions(query);

            Assert.IsNotNull(sessions);
            Assert.IsTrue(sessions.Length > 0);
        }
Exemple #7
0
        public EtlSession[] GetEtlSessions(EtlSessionQuery query)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (!IsGuids(query.EtlPackageIds))
            {
                return(new EtlSession[0]);
            }

            var sessions = SelectEtlSessions(query);

            return(sessions.ToArray());
        }
Exemple #8
0
        public void CannotGetEtlSessionResultsByAbsentId()
        {
            var agent     = CreateAgent();
            var logParser = agent.GetEtlLogParser();

            var query = new EtlSessionQuery
            {
                FromDateTime  = DateTime.Now.Subtract(_sessionTimeSpan),
                ToDateTime    = DateTime.Now,
                EtlPackageIds =
                {
                    Guid.Empty.ToString()
                },
            };
            var sessions = logParser.GetEtlSessions(query);

            Assert.IsNotNull(sessions);
            Assert.AreEqual(0, sessions.Length);
        }
        private static EtlDump GetDump(IEtlAgent agent, int lastSeconds, List <EtlStatus> etlStatuses, List <string> etlPackageIds)
        {
            var writer = new EtlDumpWriter(new EtlDumpSettings());
            var query  = new EtlSessionQuery
            {
                ToDateTime   = DateTime.Now,
                FromDateTime = DateTime.Now.Subtract(TimeSpan.FromSeconds(lastSeconds)),
            };

            query.EtlStatuses.AddRange(etlStatuses);
            query.EtlPackageIds.AddRange(etlPackageIds);

            var logParser = agent.GetEtlLogParser();

            writer.Write(query, logParser);

            var dump = writer.GetDump();

            dump.Sessions.Sort(new Comparison <EtlSessionSummary>(SortSessionsDesc));
            return(dump);
        }
        public void Write(EtlSessionQuery query, IEtlLogParser logParser)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (logParser == null)
            {
                throw new ArgumentNullException("logParser");
            }

            InitDump();

            var sessions = logParser.GetEtlSessions(query);
            foreach (var session in sessions)
            {
                var sessionSummary = GetEtlSessionSummary(session, logParser);
                _dump.Sessions.Add(sessionSummary);
            }
        }
Exemple #11
0
        private List <EtlSession> SelectEtlSessions(EtlSessionQuery query)
        {
            var cmd      = CreateSelectEtlSessionsCommand(query);
            var sessions = new List <EtlSession>();

            using (var conn = CreateConnection())
            {
                conn.Open();
                cmd.Connection = conn;

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var session = ReadEtlSession(reader);
                        sessions.Add(session);
                    }
                }
            }

            return(sessions);
        }
Exemple #12
0
        public void Write(EtlSessionQuery query, IEtlLogParser logParser)
        {
            if (query == null)
            {
                throw new ArgumentNullException("query");
            }

            if (logParser == null)
            {
                throw new ArgumentNullException("logParser");
            }

            InitDump();

            var sessions = logParser.GetEtlSessions(query);

            foreach (var session in sessions)
            {
                var sessionSummary = GetEtlSessionSummary(session, logParser);
                _dump.Sessions.Add(sessionSummary);
            }
        }
Exemple #13
0
        private SqlCommand CreateSelectEtlSessionsCommand(EtlSessionQuery query)
        {
            var sql = @"
select {1}
    s.[EtlPackageId],
    s.[EtlPackageName],
    s.[EtlSessionId],
    s.[StartDateTime],
    s.[StartUtcDateTime],
    s.[EndDateTime],
    s.[EndUtcDateTime],
    s.[Status],
    s.[UserName]
from 
	{0}[EtlSessions] s with (nolock)
where 
    {2} {3} {4} s.[StartDateTime] between @DateFrom and @DateTo
order by
    s.[StartDateTime] desc
			"            ;

            var cmd = new SqlCommand();

            var topToken = "";

            if (query.MaxSessionCount.HasValue)
            {
                topToken = string.Concat("top ", query.MaxSessionCount);
            }

            var packageIdsToken = "";

            if (query.EtlPackageIds.Count > 0)
            {
                for (var i = 0; i < query.EtlPackageIds.Count; i++)
                {
                    var paramName = string.Concat("@pid", i);

                    if (i == 0)
                    {
                        packageIdsToken = string.Concat("s.[EtlPackageId] in (", paramName);
                    }
                    else
                    {
                        packageIdsToken = string.Concat(packageIdsToken, ", ", paramName);
                    }

                    cmd.Parameters.AddWithValue(paramName, query.EtlPackageIds[i]);
                }

                packageIdsToken = string.Concat(packageIdsToken, ") and ");
            }

            var variablesToken = "";

            if (query.Variables.Count > 0)
            {
                for (var i = 0; i < query.Variables.Count; i++)
                {
                    var nameParam  = string.Concat("@vn", i);
                    var valueParam = string.Concat("@vv", i);

                    if (i > 0)
                    {
                        variablesToken = string.Concat(variablesToken, " or ");
                    }

                    variablesToken = string.Concat
                                     (
                        variablesToken,
                        "(sv.[Name] = ",
                        nameParam,
                        " and sv.[Value] = ",
                        valueParam,
                        ")"
                                     );

                    cmd.Parameters.AddWithValue(nameParam, query.Variables[i].Name);
                    cmd.Parameters.AddWithValue(valueParam, query.Variables[i].Value);
                }

                variablesToken = string.Concat
                                 (
                    String.Format("exists (select 1 from {0}[EtlVariables] sv with (nolock) where (sv.[EtlPackageId] = s.[EtlPackageId]) and (sv.[EtlSessionId] = s.[EtlSessionId]) and ", _schemaToken),
                    variablesToken,
                    ") and "
                                 );
            }

            var etlStatusesToken = "";

            if (query.EtlStatuses.Count > 0)
            {
                for (var i = 0; i < query.EtlStatuses.Count; i++)
                {
                    var paramName = string.Concat("@etlstatus", i);

                    if (i == 0)
                    {
                        etlStatusesToken = string.Concat("s.[Status] in (", paramName);
                    }
                    else
                    {
                        etlStatusesToken = string.Concat(etlStatusesToken, ", ", paramName);
                    }

                    cmd.Parameters.AddWithValue(paramName, query.EtlStatuses[i]);
                }

                etlStatusesToken = string.Concat(etlStatusesToken, ") and ");
            }

            cmd.CommandText = string.Format
                              (
                sql,
                _schemaToken,
                topToken,
                packageIdsToken,
                variablesToken,
                etlStatusesToken
                              );

            cmd.Parameters.AddWithValue("@DateFrom", query.FromDateTime);
            cmd.Parameters.AddWithValue("@DateTo", query.ToDateTime);

            return(cmd);
        }
        private List<EtlSession> SelectEtlSessions(EtlSessionQuery query)
        {
            var cmd = CreateSelectEtlSessionsCommand(query);
            var sessions = new List<EtlSession>();

            using (var conn = CreateConnection())
            {
                conn.Open();
                cmd.Connection = conn;

                using (var reader = cmd.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        var session = ReadEtlSession(reader);
                        sessions.Add(session);
                    }
                }
            }

            return sessions;
        }
        private SqlCommand CreateSelectEtlSessionsCommand(EtlSessionQuery query)
        {
            var sql = @"
            select {1}
            s.[EtlPackageId],
            s.[EtlPackageName],
            s.[EtlSessionId],
            s.[StartDateTime],
            s.[StartUtcDateTime],
            s.[EndDateTime],
            s.[EndUtcDateTime],
            s.[Status],
            s.[UserName]
            from
            {0}[EtlSessions] s with (nolock)
            where
            {2} {3} {4} s.[StartDateTime] between @DateFrom and @DateTo
            order by
            s.[StartDateTime] desc
            ";

            var cmd = new SqlCommand();

            var topToken = "";
            if (query.MaxSessionCount.HasValue)
            {
                topToken = string.Concat("top ", query.MaxSessionCount);
            }

            var packageIdsToken = "";
            if (query.EtlPackageIds.Count > 0)
            {
                for (var i = 0; i < query.EtlPackageIds.Count; i++)
                {
                    var paramName = string.Concat("@pid", i);

                    if (i == 0)
                    {
                        packageIdsToken = string.Concat("s.[EtlPackageId] in (", paramName);
                    }
                    else
                    {
                        packageIdsToken = string.Concat(packageIdsToken, ", ", paramName);
                    }

                    cmd.Parameters.AddWithValue(paramName, query.EtlPackageIds[i]);
                }

                packageIdsToken = string.Concat(packageIdsToken, ") and ");
            }

            var variablesToken = "";
            if (query.Variables.Count > 0)
            {
                for (var i = 0; i < query.Variables.Count; i++)
                {
                    var nameParam = string.Concat("@vn", i);
                    var valueParam = string.Concat("@vv", i);

                    if (i > 0)
                    {
                        variablesToken = string.Concat(variablesToken, " or ");
                    }

                    variablesToken = string.Concat
                    (
                        variablesToken,
                        "(sv.[Name] = ",
                        nameParam,
                        " and sv.[Value] = ",
                        valueParam,
                        ")"
                    );

                    cmd.Parameters.AddWithValue(nameParam, query.Variables[i].Name);
                    cmd.Parameters.AddWithValue(valueParam, query.Variables[i].Value);
                }

                variablesToken = string.Concat
                (
                    String.Format("exists (select 1 from {0}[EtlVariables] sv with (nolock) where (sv.[EtlPackageId] = s.[EtlPackageId]) and (sv.[EtlSessionId] = s.[EtlSessionId]) and ", _schemaToken),
                    variablesToken,
                    ") and "
                );
            }

            var etlStatusesToken = "";
            if (query.EtlStatuses.Count > 0)
            {
                for (var i = 0; i < query.EtlStatuses.Count; i++)
                {
                    var paramName = string.Concat("@etlstatus", i);

                    if (i == 0)
                    {
                        etlStatusesToken = string.Concat("s.[Status] in (", paramName);
                    }
                    else
                    {
                        etlStatusesToken = string.Concat(etlStatusesToken, ", ", paramName);
                    }

                    cmd.Parameters.AddWithValue(paramName, query.EtlStatuses[i]);
                }

                etlStatusesToken = string.Concat(etlStatusesToken, ") and ");
            }

            cmd.CommandText = string.Format
            (
                sql,
                _schemaToken,
                topToken,
                packageIdsToken,
                variablesToken,
                etlStatusesToken
            );

            cmd.Parameters.AddWithValue("@DateFrom", query.FromDateTime);
            cmd.Parameters.AddWithValue("@DateTo", query.ToDateTime);

            return cmd;
        }