private static SqlEtlAgent CreateAgent() { var settings = ConfigurationManager.ConnectionStrings[_connectionStringName]; var source = new EtlAgentInfo { ConnectionString = settings.ConnectionString }; var provider = new SqlEtlAgent(source); return(provider); }
private Exception TryCreateAgent(EtlAgentInfo agentInfo, out IEtlAgent agent) { try { agent = EtlAgents.CreateAgent(agentInfo); return(null); } catch (Exception exc) { agent = null; return(exc); } }
public FileEtlAgent(EtlAgentInfo agentInfo) { if (agentInfo == null) { throw new ArgumentNullException("agentInfo"); } if (string.IsNullOrEmpty(agentInfo.ConnectionString)) { throw new ArgumentException("Parameter \"connectionString\" cannot be empty", "connectionString"); } _directoryPath = agentInfo.ConnectionString; _logsDirectoryName = DEFAULT_LOGS_DIRECTORY_NAME; _logFileExtension = DEFAULT_LOG_FILE_EXTENSION; }
private void SaveEtlAgentSettings(EtlAgentInfo agentInfo) { var settingsSuffix = this.SettingsSuffix ?? ""; if (agentInfo != null) { Settings.Default["EtlAgentType" + settingsSuffix] = agentInfo.EtlAgentType; Settings.Default["ConnectionString" + settingsSuffix] = agentInfo.ConnectionString; Settings.Default["SchemaName" + settingsSuffix] = agentInfo.SchemaName; } else { Settings.Default["EtlAgentType" + settingsSuffix] = null; Settings.Default["ConnectionString" + settingsSuffix] = null; Settings.Default["SchemaName" + settingsSuffix] = null; } Settings.Default.Save(); }
private void btnConnectAgent_Click(object sender, EventArgs e) { var agentInfo = new EtlAgentInfo { EtlAgentType = cmbEtlAgentType.Text.Trim(), ConnectionString = txtConnectionString.Text.Trim(), SchemaName = txtSchemaName.Text.Trim(), }; IEtlAgent agent; var exc = TryCreateAgent(agentInfo, out agent); if (exc != null) { MessageForm.ShowMessage(MessageFormType.Error, exc.Message, "Cannot connect to ETL agent", new ExceptionInfo(exc), MessageBoxButtons.OK); } else { if (agent is ILocalEtlAgent) { _agentInfo = agentInfo; _agent = (ILocalEtlAgent)agent; SaveEtlAgentSettings(_agentInfo); LoadPackages(); UpdateButtons(); if (this.Connected != null) { this.Connected(this, EventArgs.Empty); } } else { MessageForm.ShowMessage(MessageFormType.Information, "This ETL agent does not supported", "Cannot connect to ETL agent", null, MessageBoxButtons.OK); } } }
public void Show(ILocalEtlAgent agent, EtlAgentInfo agentInfo, string packageId) { if (agent == null) { throw new ArgumentNullException("agent"); } if (agentInfo == null) { throw new ArgumentNullException("agentInfo"); } if (packageId == null) { throw new ArgumentNullException("packageId"); } _agent = agent; _agentInfo = agentInfo; _packageId = packageId; EtlPackage package; var exc = TryGetPackage(_packageId, out package); if (exc != null) { MessageForm.ShowMessage(MessageFormType.Error, exc.Message, "Cannot open package", new ExceptionInfo(exc), MessageBoxButtons.OK); } else { _currentPackage = package; UpdateButtons(); ResetLogView(); ShowCurrentPackage(); this.Show(); } }
//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)); }
public SqlEtlAgent(EtlAgentInfo agentInfo) { if (agentInfo == null) { throw new ArgumentNullException("agentInfo"); } if (string.IsNullOrEmpty(agentInfo.ConnectionString)) { throw new ArgumentException("Parameter \"connectionString\" cannot be empty", "connectionString"); } _connectionString = agentInfo.ConnectionString; _schemaName = agentInfo.SchemaName; if (!string.IsNullOrEmpty(_schemaName)) { _schemaToken = string.Format("[{0}].", _schemaName.TrimStart('[').TrimEnd(']').Replace("]", @"\]")); } else { _schemaToken = ""; } }
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); }