private Exception TryCreateAgent(EtlAgentInfo agentInfo, out IEtlAgent agent) { try { agent = EtlAgents.CreateAgent(agentInfo); return(null); } catch (Exception exc) { agent = null; return(exc); } }
private static EtlDump GetDump(EtlMailSubscription subscription) { var writer = new EtlDumpWriter(new EtlDumpSettings()); foreach (var agentInfo in subscription.EtlAgents) { var query = CreateSessionQuery(subscription); var agent = EtlAgents.CreateAgent(agentInfo); var logParser = agent.GetEtlLogParser(); writer.Write(query, logParser); } var dump = writer.GetDump(); dump.Sessions.Sort(new Comparison <EtlSessionSummary>(SortSessionsDesc)); return(dump); }
private static IEtlAgent GetEtlAgent() { if (SiteConfiguration.EtlAgents.Length == 0) { throw new Exception("At least one EtlAgent has to be configured"); } var agents = from a in SiteConfiguration.EtlAgents select EtlAgents.CreateAgent( new EtlAgentInfo() { ConnectionString = a.ConnectionString, EtlAgentType = a.EtlAgentType, SchemaName = a.SchemaName, }); var multiEtlAgent = new MultiEtlAgent(agents.ToArray()); return(multiEtlAgent); }
//todo: localize log message public void ExecuteCommand(EtlConsoleArguments options) { System.Console.WriteLine("Verifying input parameters..."); var errorMsg = VerifyArguments(options); if (!String.IsNullOrEmpty(errorMsg)) { throw new Exception(String.Format("Input parameters incorrect: {0}", errorMsg)); } var parameters = ParseParameters(options.GetCommandOptionOrNull(PARAM_NAME_VARIABLES)); System.Console.WriteLine("Input parameters are correct"); System.Console.WriteLine("Creating ETL agent..."); var agentInfo = new EtlAgentInfo() { EtlAgentType = options.CommandOptions[PARAM_NAME_AGENT_TYPE], ConnectionString = options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING], SchemaName = options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_SCHEMA) ? options.CommandOptions[PARAM_NAME_AGENT_SCHEMA] : String.Empty, }; var agent = EtlAgents.CreateAgent(agentInfo); if (agent is ILocalEtlAgent) { ((ILocalEtlAgent)agent).AttachLogger(new ConsoleEtlLogger(System.Console.Out)); } System.Console.WriteLine("ETL agent created"); System.Console.WriteLine("Invoking package..."); var result = agent.InvokeEtlPackage(options.CommandOptions[PARAM_NAME_PACKAGE_ID], parameters, null); System.Console.WriteLine(string.Format("Package has been executed with result {0}", result.Status)); }
private static bool Mail(EtlConsoleArguments options) { System.Console.WriteLine("Creating ETL agent..."); var agentInfo = new EtlAgentInfo() { EtlAgentType = options.CommandOptions[PARAM_NAME_AGENT_TYPE], ConnectionString = options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING], SchemaName = options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_SCHEMA) ? options.CommandOptions[PARAM_NAME_AGENT_SCHEMA] : String.Empty, }; var agent = EtlAgents.CreateAgent(agentInfo); System.Console.WriteLine("ETL agent created"); System.Console.WriteLine("Retrieving dump..."); List <EtlStatus> statuses = new List <EtlStatus>(); if (options.CommandOptions.ContainsKey(PARAM_NAME_ETL_STATUSES) && !String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_ETL_STATUSES])) { foreach (var status in options.CommandOptions[PARAM_NAME_ETL_STATUSES].Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { statuses.Add((EtlStatus)Enum.Parse(typeof(EtlStatus), status)); } } List <string> etlPackageIds = new List <string>(); if (options.CommandOptions.ContainsKey(PARAM_NAME_ETL_PACKAGES) && !String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_ETL_PACKAGES])) { foreach (var packageId in options.CommandOptions[PARAM_NAME_ETL_PACKAGES].Split(new char[] { ',', ';' }, StringSplitOptions.RemoveEmptyEntries)) { etlPackageIds.Add(packageId); } } var dump = GetDump(agent, Convert.ToInt32(options.CommandOptions[PARAM_NAME_ON_LAST_SECONDS]), statuses, etlPackageIds); System.Console.WriteLine("Dump has been retrieved"); System.Console.WriteLine("Sending mail..."); var allowEmptyMail = true; if (options.CommandOptions.ContainsKey(PARAM_NAME_ALLOW_EMPTY_MAIL)) { var rc = false; if (Boolean.TryParse(options.CommandOptions[PARAM_NAME_ALLOW_EMPTY_MAIL], out rc)) { allowEmptyMail = rc; } } var result = false; if (dump.Sessions.Count > 0 || (dump.Sessions.Count == 0 && allowEmptyMail)) { var mailBody = GetMailBody(options.CommandOptions[PARAM_NAME_SUBJECT], options.CommandOptions[PARAM_NAME_MAIL_TEMPLATE_PATH], dump); SendMail(options, mailBody); result = true; System.Console.WriteLine("Mail has been sent"); } else { //todo: localize message System.Console.WriteLine("Empty mails is not allowed due to configuration"); System.Console.WriteLine("Mail has not been sent"); } return(result); }