コード例 #1
0
        public static IEtlAgent CreateAgent(EtlAgentInfo agentInfo)
        {
            if (agentInfo == null)
            {
                throw new ArgumentNullException("agentInfo");
            }

            var providerType = Type.GetType(agentInfo.EtlAgentType);
            if (providerType == null)
            {
                throw new InvalidOperationException(string.Format("Type {0} was not found", agentInfo.EtlAgentType));
            }

            if (!typeof(IEtlAgent).IsAssignableFrom(providerType))
            {
                throw new InvalidOperationException(string.Format("Type {0} must implements {1} interface", providerType.FullName, typeof(IEtlAgent).FullName));
            }

            var ctorWithSource = providerType.GetConstructor(new[] { typeof(EtlAgentInfo) });
            var ctorWithoutParams = providerType.GetConstructor(Type.EmptyTypes);

            if (ctorWithSource != null)
            {
                return (IEtlAgent)ctorWithSource.Invoke(new object[] { agentInfo });
            }
            else if (ctorWithoutParams != null)
            {
                return (IEtlAgent)ctorWithoutParams.Invoke(null);
            }
            else
            {
                throw new InvalidOperationException(string.Format("{0} must have parameterless constructor or constructor with parameter of type {1}", providerType.FullName, typeof(IEtlAgent).FullName));
            }
        }
コード例 #2
0
        public static IEtlAgent CreateAgent(EtlAgentInfo agentInfo)
        {
            if (agentInfo == null)
            {
                throw new ArgumentNullException("agentInfo");
            }

            var providerType = Type.GetType(agentInfo.EtlAgentType);

            if (providerType == null)
            {
                throw new InvalidOperationException(string.Format("Type {0} was not found", agentInfo.EtlAgentType));
            }

            if (!typeof(IEtlAgent).IsAssignableFrom(providerType))
            {
                throw new InvalidOperationException(string.Format("Type {0} must implements {1} interface", providerType.FullName, typeof(IEtlAgent).FullName));
            }

            var ctorWithSource    = providerType.GetConstructor(new[] { typeof(EtlAgentInfo) });
            var ctorWithoutParams = providerType.GetConstructor(Type.EmptyTypes);

            if (ctorWithSource != null)
            {
                return((IEtlAgent)ctorWithSource.Invoke(new object[] { agentInfo }));
            }
            else if (ctorWithoutParams != null)
            {
                return((IEtlAgent)ctorWithoutParams.Invoke(null));
            }
            else
            {
                throw new InvalidOperationException(string.Format("{0} must have parameterless constructor or constructor with parameter of type {1}", providerType.FullName, typeof(IEtlAgent).FullName));
            }
        }
コード例 #3
0
        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();
            }
        }
コード例 #4
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));
        }
コード例 #5
0
 private Exception TryCreateAgent(EtlAgentInfo agentInfo, out IEtlAgent agent)
 {
     try
     {
         agent = EtlAgents.CreateAgent(agentInfo);
         return null;
     }
     catch (Exception exc)
     {
         agent = null;
         return exc;
     }
 }
コード例 #6
0
        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();
        }
コード例 #7
0
        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);
                }
            }
        }
コード例 #8
0
        private static SqlEtlAgent CreateAgent()
        {
            var settings = ConfigurationManager.ConnectionStrings[_connectionStringName];

            var source = new EtlAgentInfo
            {
                ConnectionString = settings.ConnectionString
            };

            var provider = new SqlEtlAgent(source);
            return provider;
        }
コード例 #9
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;
        }