Example #1
0
        private string VerifyArguments(EtlConsoleArguments options)
        {
            var sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_TYPE]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_TYPE);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_CONNECTION_STRING);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PACKAGE_ID) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PACKAGE_ID]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_PACKAGE_ID);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_VARIABLES))
            {
                sb.AppendFormat("{0};", PARAM_NAME_VARIABLES);
            }

            return(sb.ToString());
        }
Example #2
0
        private string VerifyArguments(EtlConsoleArguments options)
        {
            StringBuilder sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_CONNECTION_STRING]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_CONNECTION_STRING);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PROVIDER_NAME) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PROVIDER_NAME]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_PROVIDER_NAME);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PACKAGE_QUERY) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PACKAGE_QUERY]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_PACKAGE_QUERY);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_LOGGER_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_LOGGER_TYPE]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_LOGGER_TYPE);
            }

            var result = sb.ToString();

            return(sb.ToString());
        }
Example #3
0
        private static void SendMail(EtlConsoleArguments options, string body)
        {
            var message = new MailMessage
            {
                From         = new MailAddress(options.CommandOptions[PARAM_NAME_FROM]),
                Subject      = options.CommandOptions[PARAM_NAME_SUBJECT],
                Body         = body,
                IsBodyHtml   = true,
                BodyEncoding = Encoding.UTF8,
            };

            message.To.Add(options.CommandOptions[PARAM_NAME_TO]);

            var enableSsl = false;

            if (options.CommandOptions.ContainsKey(PARAM_NAME_ENABLE_SSL))
            {
                var rc = false;
                if (Boolean.TryParse(options.CommandOptions[PARAM_NAME_ENABLE_SSL], out rc))
                {
                    enableSsl = rc;
                }
            }

            var client = new SmtpClient();

            client.EnableSsl = enableSsl;
            client.Send(message);
        }
        //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));
        }
Example #5
0
        public void ExecuteCommand(EtlConsoleArguments options)
        {
            //todo: localize message
            System.Console.WriteLine("Verifying input parameters...");

            var sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_FROM) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_FROM]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_FROM);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_TO) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_TO]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_TO);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_SUBJECT) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_SUBJECT]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_SUBJECT);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_MAIL_TEMPLATE_PATH) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_MAIL_TEMPLATE_PATH]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_MAIL_TEMPLATE_PATH);
            }

            var rc = 0;

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_ON_LAST_SECONDS) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_ON_LAST_SECONDS]) || !Int32.TryParse(options.CommandOptions[PARAM_NAME_ON_LAST_SECONDS], out rc))
            {
                sb.AppendFormat("{0};", PARAM_NAME_ON_LAST_SECONDS);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_TYPE]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_TYPE);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_CONNECTION_STRING);
            }

            var result = sb.ToString();

            if (String.IsNullOrEmpty(result))
            {
                System.Console.WriteLine("Input parameters are correct");
            }
            else
            {
                throw new Exception(String.Format("Incorrect input parameters: {0}", result));
            }

            Mail(options);
        }
Example #6
0
        public void ExecuteCommand(EtlConsoleArguments options)
        {
            var commandNameToHelp = options.GetCommandOptionOrNull(PARAM_NAME_COMMAND);

            if (commandNameToHelp == null)
            {
                ShowAllHelp();
            }
            else
            {
                ShowHelp(commandNameToHelp);
            }
        }
Example #7
0
        public static EtlConsoleArguments Parse(string[] commandLineArgs)
        {
            var options = new EtlConsoleArguments();

            if (commandLineArgs == null || commandLineArgs.Length == 0)
            {
                return(options);
            }

            int firstOptionIndex;

            var possibleCommandName = commandLineArgs[0] != null ? commandLineArgs[0].Trim() : null;

            if (possibleCommandName != null && possibleCommandName.StartsWith(OptionPrefix))
            {
                firstOptionIndex = 0;
            }
            else
            {
                firstOptionIndex    = 1;
                options.CommandName = possibleCommandName;
            }

            for (var i = firstOptionIndex; i < commandLineArgs.Length; i++)
            {
                var arg = commandLineArgs[i];
                if (string.IsNullOrEmpty(arg))
                {
                    continue;
                }

                if (arg[0] != OptionPrefix[0])
                {
                    options.CommandOptions.Add(arg.ToLower(), null);
                }
                else
                {
                    arg = arg.Substring(1);
                    var argArr = arg.Split(OptionValueDelimiter.ToCharArray(), 2);
                    options.CommandOptions.Add(argArr[0].ToLower(), ((argArr.Length > 1) && (argArr[1].Length > 0)) ? argArr[1] : null);
                }
            }

            if (options.CommandOptions.ContainsKey(InteractiveModeOption))
            {
                options.InteractiveMode = true;
                options.CommandOptions.Remove(InteractiveModeOption);
            }

            return(options);
        }
Example #8
0
        public void ExecuteCommand(EtlConsoleArguments options)
        {
            //todo: localize message
            System.Console.WriteLine("Reading mail configuration...");

            //todo: handle exception KeyNotFound
            var configFilePath = options.CommandOptions[CONFIGFILEPATH_PARAM_NAME];
            var config         = ReadConfiguration(configFilePath);

            //todo: localize message
            System.Console.WriteLine("Mail configuration has been read");

            Mail(config);
        }
        public static EtlConsoleArguments Parse(string[] commandLineArgs)
        {
            var options = new EtlConsoleArguments();

            if (commandLineArgs == null || commandLineArgs.Length == 0)
            {
                return options;
            }

            int firstOptionIndex;

            var possibleCommandName = commandLineArgs[0] != null ? commandLineArgs[0].Trim() : null;
            if (possibleCommandName != null && possibleCommandName.StartsWith(OptionPrefix))
            {
                firstOptionIndex = 0;
            }
            else
            {
                firstOptionIndex = 1;
                options.CommandName = possibleCommandName;
            }

            for (var i = firstOptionIndex; i < commandLineArgs.Length; i++)
            {
                var arg = commandLineArgs[i];
                if (string.IsNullOrEmpty(arg))
                {
                    continue;
                }

                if (arg[0] != OptionPrefix[0])
                {
                    options.CommandOptions.Add(arg.ToLower(), null);
                }
                else
                {
                    arg = arg.Substring(1);
                    var argArr = arg.Split(OptionValueDelimiter.ToCharArray(), 2);
                    options.CommandOptions.Add(argArr[0].ToLower(), ((argArr.Length > 1) && (argArr[1].Length > 0)) ? argArr[1] : null);
                }
            }

            if (options.CommandOptions.ContainsKey(InteractiveModeOption))
            {
                options.InteractiveMode = true;
                options.CommandOptions.Remove(InteractiveModeOption);
            }

            return options;
        }
        public void ExecuteCommand(EtlConsoleArguments options)
        {
            //todo: localize message
            System.Console.WriteLine("Reading mail configuration...");

            //todo: handle exception KeyNotFound
            var configFilePath = options.CommandOptions[CONFIGFILEPATH_PARAM_NAME];
            var config = ReadConfiguration(configFilePath);

            //todo: localize message
            System.Console.WriteLine("Mail configuration has been read");

            Mail(config);
        }
Example #11
0
        //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));
        }
Example #12
0
        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);
        }
        private static void Main1(EtlConsoleArguments args)
        {
            //todo: throw exception on unknown args

            try
            {
                if (string.IsNullOrEmpty(args.CommandName))
                {
                    EtlHelpCommand.ShowAllHelp();
                }
                else
                {
                    var commandHandler = EtlConsoleCommandProvider.FindCommand(args.CommandName);
                    if (commandHandler == null)
                    {
                        System.Console.WriteLine("Command \"{0}\" is not supported.", args.CommandName);
                        EtlHelpCommand.ShowAllHelp();
                    }
                    else
                    {
                        commandHandler.ExecuteCommand(args);
                    }
                }

                System.Console.WriteLine(_delimiterLine);
                System.Console.WriteLine("RapidSoft.Etl.Console finished at {0}", DateTime.Now);
            }
            catch (Exception e)
            {
                var sb = new StringBuilder(String.Format("Console parameters:{0}", Environment.NewLine));
                foreach (var param in args.CommandOptions.Keys)
                {
                    sb.AppendFormat("{0}={1}{2}", param, args.CommandOptions[param], Environment.NewLine);
                }

                sb.Append(Environment.NewLine);
                sb.Append(e.ToString());

                System.Console.WriteLine(sb.ToString());

                if (Config.EventLogEnabled)
                {
                    if (!EventLog.SourceExists(Config.EventSourceName))
                    {
                        try
                        {
                            EventLog.CreateEventSource(Config.EventSourceName, Config.EventLogName);
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine(String.Format("Unable to create event log{0}{1}", Environment.NewLine, ex.ToString()));
                        }
                    }

                    if (EventLog.SourceExists(Config.EventSourceName))
                    {
                        EventLog eventLog = new EventLog();
                        eventLog.Source = Config.EventSourceName;
                        eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                    }
                    else
                    {
                        System.Console.WriteLine("Event log {0} doesnt exist", Config.EventSourceName);
                    }
                }
            }

            if (args.InteractiveMode)
            {
                System.Console.WriteLine("Press any key to exit");
                System.Console.ReadKey();
            }
        }
        public void ExecuteCommand(EtlConsoleArguments options)
        {
            //todo: localize message
            System.Console.WriteLine("Verifying input parameters...");

            var sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_FROM) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_FROM]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_FROM);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_TO) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_TO]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_TO);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_SUBJECT) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_SUBJECT]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_SUBJECT);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_MAIL_TEMPLATE_PATH) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_MAIL_TEMPLATE_PATH]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_MAIL_TEMPLATE_PATH);
            }

            var rc = 0;
            if (!options.CommandOptions.ContainsKey(PARAM_NAME_ON_LAST_SECONDS) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_ON_LAST_SECONDS]) || !Int32.TryParse(options.CommandOptions[PARAM_NAME_ON_LAST_SECONDS], out rc))
            {
                sb.AppendFormat("{0};", PARAM_NAME_ON_LAST_SECONDS);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_TYPE]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_TYPE);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_CONNECTION_STRING);
            }

            var result = sb.ToString();

            if (String.IsNullOrEmpty(result))
            {
                System.Console.WriteLine("Input parameters are correct");
            }
            else
            {
                throw new Exception(String.Format("Incorrect input parameters: {0}", result));
            }

            Mail(options);
        }
        private string VerifyArguments(EtlConsoleArguments options)
        {
            StringBuilder sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_CONNECTION_STRING]))
                sb.AppendFormat("{0};", PARAM_NAME_CONNECTION_STRING);

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PROVIDER_NAME) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PROVIDER_NAME]))
                sb.AppendFormat("{0};", PARAM_NAME_PROVIDER_NAME);

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PACKAGE_QUERY) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PACKAGE_QUERY]))
                sb.AppendFormat("{0};", PARAM_NAME_PACKAGE_QUERY);

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_LOGGER_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_LOGGER_TYPE]))
                sb.AppendFormat("{0};", PARAM_NAME_LOGGER_TYPE);

            var result = sb.ToString();

            return sb.ToString();
        }
        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;
        }
        private string VerifyArguments(EtlConsoleArguments options)
        {
            var sb = new StringBuilder();

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_TYPE) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_TYPE]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_TYPE);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_AGENT_CONNECTION_STRING) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_AGENT_CONNECTION_STRING]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_AGENT_CONNECTION_STRING);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_PACKAGE_ID) || String.IsNullOrEmpty(options.CommandOptions[PARAM_NAME_PACKAGE_ID]))
            {
                sb.AppendFormat("{0};", PARAM_NAME_PACKAGE_ID);
            }

            if (!options.CommandOptions.ContainsKey(PARAM_NAME_VARIABLES))
            {
                sb.AppendFormat("{0};", PARAM_NAME_VARIABLES);
            }

            return sb.ToString();
        }
Example #18
0
        private static void Main1(EtlConsoleArguments args)
        {
            //todo: throw exception on unknown args

            try
            {
                if (string.IsNullOrEmpty(args.CommandName))
                {
                    EtlHelpCommand.ShowAllHelp();
                }
                else
                {
                    var commandHandler = EtlConsoleCommandProvider.FindCommand(args.CommandName);
                    if (commandHandler == null)
                    {
                        System.Console.WriteLine("Command \"{0}\" is not supported.", args.CommandName);
                        EtlHelpCommand.ShowAllHelp();
                    }
                    else
                    {
                        commandHandler.ExecuteCommand(args);
                    }
                }

                System.Console.WriteLine(_delimiterLine);
                System.Console.WriteLine("RapidSoft.Etl.Console finished at {0}", DateTime.Now);
            }
            catch (Exception e)
            {
                var sb = new StringBuilder(String.Format("Console parameters:{0}", Environment.NewLine));
                foreach (var param in args.CommandOptions.Keys)
                {
                    sb.AppendFormat("{0}={1}{2}", param, args.CommandOptions[param], Environment.NewLine);
                }

                sb.Append(Environment.NewLine);
                sb.Append(e.ToString());

                System.Console.WriteLine(sb.ToString());

                if (Config.EventLogEnabled)
                {
                    if (!EventLog.SourceExists(Config.EventSourceName))
                    {
                        try
                        {
                            EventLog.CreateEventSource(Config.EventSourceName, Config.EventLogName);
                        }
                        catch (Exception ex)
                        {
                            System.Console.WriteLine(String.Format("Unable to create event log{0}{1}", Environment.NewLine, ex.ToString()));
                        }
                    }

                    if (EventLog.SourceExists(Config.EventSourceName))
                    {
                        EventLog eventLog = new EventLog();
                        eventLog.Source = Config.EventSourceName;
                        eventLog.WriteEntry(sb.ToString(), EventLogEntryType.Error);
                    }
                    else
                    {
                        System.Console.WriteLine("Event log {0} doesnt exist", Config.EventSourceName);
                    }
                }
            }

            if (args.InteractiveMode)
            {
                System.Console.WriteLine("Press any key to exit");
                System.Console.ReadKey();
            }
        }
        private static void SendMail(EtlConsoleArguments options, string body)
        {
            var message = new MailMessage
            {
                From = new MailAddress(options.CommandOptions[PARAM_NAME_FROM]),
                Subject = options.CommandOptions[PARAM_NAME_SUBJECT],
                Body = body,
                IsBodyHtml = true,
                BodyEncoding = Encoding.UTF8,
            };

            message.To.Add(options.CommandOptions[PARAM_NAME_TO]);

            var enableSsl = false;
            if (options.CommandOptions.ContainsKey(PARAM_NAME_ENABLE_SSL))
            {
                var rc = false;
                if (Boolean.TryParse(options.CommandOptions[PARAM_NAME_ENABLE_SSL], out rc))
                    enableSsl = rc;
            }

            var client = new SmtpClient();
            client.EnableSsl = enableSsl;
            client.Send(message);
        }
        //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 providerFactory = DbProviderFactories.GetFactory(options.CommandOptions[PARAM_NAME_PROVIDER_NAME]);

            var packageText = String.Empty;

            System.Console.WriteLine("Receiving package text");

            using (var connection = providerFactory.CreateConnection())
            {
                connection.ConnectionString = options.CommandOptions[PARAM_NAME_CONNECTION_STRING];

                var command = connection.CreateCommand();

                command.CommandText = options.CommandOptions[PARAM_NAME_PACKAGE_QUERY];
                command.CommandTimeout = 60; // 1 minute
                command.CommandType = System.Data.CommandType.Text;

                connection.Open();

                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        if (reader.FieldCount == 1)
                        {
                            packageText = reader[0].ToString();
                        }
                        else
                        {
                            throw new Exception("Package text query result contains more than one element");
                        }
                    }
                    else
                    {
                        throw new Exception("Package text query result contains no rows");
                    }

                    if (reader.Read())
                    {
                        throw new Exception("Package text query result contains multiple rows");
                    }
                }
            }

            if (String.IsNullOrEmpty(packageText))
            {
                throw new Exception("Package text cannot be null or empty");
            }

            System.Console.WriteLine("Deserializing package");

            var etlPackageSerializer = new EtlPackageXmlSerializer();
            var package = etlPackageSerializer.Deserialize(packageText);

            var etlLoggerInfo = new EtlLoggerInfo()
            {
                ConnectionString = options.CommandOptions[PARAM_NAME_CONNECTION_STRING],
                LoggerType = options.CommandOptions[PARAM_NAME_LOGGER_TYPE],
                SchemaName = options.CommandOptions.ContainsKey(PARAM_NAME_SCHEMA) ? options.CommandOptions[PARAM_NAME_SCHEMA] : String.Empty,
            };

            var packageLogger = EtlLoggers.GetLogger(etlLoggerInfo);

            System.Console.WriteLine("Executing package in a sub-session");
            var result = package.Invoke(packageLogger);
            System.Console.WriteLine("Package has been executed");
        }
 public void ExecuteCommand(EtlConsoleArguments options)
 {
     var commandNameToHelp = options.GetCommandOptionOrNull(PARAM_NAME_COMMAND);
     if (commandNameToHelp == null)
     {
         ShowAllHelp();
     }
     else
     {
         ShowHelp(commandNameToHelp);
     }
 }
Example #22
0
        //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 providerFactory = DbProviderFactories.GetFactory(options.CommandOptions[PARAM_NAME_PROVIDER_NAME]);

            var packageText = String.Empty;

            System.Console.WriteLine("Receiving package text");

            using (var connection = providerFactory.CreateConnection())
            {
                connection.ConnectionString = options.CommandOptions[PARAM_NAME_CONNECTION_STRING];

                var command = connection.CreateCommand();

                command.CommandText    = options.CommandOptions[PARAM_NAME_PACKAGE_QUERY];
                command.CommandTimeout = 60; // 1 minute
                command.CommandType    = System.Data.CommandType.Text;

                connection.Open();

                using (var reader = command.ExecuteReader())
                {
                    if (reader.Read())
                    {
                        if (reader.FieldCount == 1)
                        {
                            packageText = reader[0].ToString();
                        }
                        else
                        {
                            throw new Exception("Package text query result contains more than one element");
                        }
                    }
                    else
                    {
                        throw new Exception("Package text query result contains no rows");
                    }

                    if (reader.Read())
                    {
                        throw new Exception("Package text query result contains multiple rows");
                    }
                }
            }

            if (String.IsNullOrEmpty(packageText))
            {
                throw new Exception("Package text cannot be null or empty");
            }

            System.Console.WriteLine("Deserializing package");

            var etlPackageSerializer = new EtlPackageXmlSerializer();
            var package = etlPackageSerializer.Deserialize(packageText);

            var etlLoggerInfo = new EtlLoggerInfo()
            {
                ConnectionString = options.CommandOptions[PARAM_NAME_CONNECTION_STRING],
                LoggerType       = options.CommandOptions[PARAM_NAME_LOGGER_TYPE],
                SchemaName       = options.CommandOptions.ContainsKey(PARAM_NAME_SCHEMA) ? options.CommandOptions[PARAM_NAME_SCHEMA] : String.Empty,
            };

            var packageLogger = EtlLoggers.GetLogger(etlLoggerInfo);

            System.Console.WriteLine("Executing package in a sub-session");
            var result = package.Invoke(packageLogger);

            System.Console.WriteLine("Package has been executed");
        }