public SenderCredentials(ClientConfig config)
        {
            string envProfileName = !string.IsNullOrEmpty(Environment.GetEnvironmentVariable(SenderCredentials.SenderProfileEnvName))
                ? Environment.GetEnvironmentVariable(SenderCredentials.SenderProfileEnvName)
                : SenderCredentials.DefaultSenderProfile;

            if (string.IsNullOrEmpty(config.ProfileName))
            {
                config.ProfileName = envProfileName;
            }
            if (string.IsNullOrEmpty(config.SenderId))
            {
                config.SenderId = Environment.GetEnvironmentVariable(SenderCredentials.SenderIdEnvName);
            }
            if (string.IsNullOrEmpty(config.SenderPassword))
            {
                config.SenderPassword = Environment.GetEnvironmentVariable(SenderCredentials.SenderPasswordEnvName);
            }

            if (
                string.IsNullOrEmpty(config.SenderId) &&
                string.IsNullOrEmpty(config.SenderPassword) &&
                !string.IsNullOrEmpty(config.ProfileName)
                )
            {
                ClientConfig profile = ProfileCredentialProvider.GetSenderCredentials(config);

                if (!string.IsNullOrEmpty(profile.SenderId))
                {
                    config.SenderId = profile.SenderId;
                }
                if (!string.IsNullOrEmpty(profile.SenderPassword))
                {
                    config.SenderPassword = profile.SenderPassword;
                }
                if (string.IsNullOrEmpty(config.EndpointUrl))
                {
                    // Only set the endpoint URL if it was never passed in to begin with
                    config.EndpointUrl = profile.EndpointUrl;
                }
            }

            if (string.IsNullOrEmpty(config.SenderId))
            {
                throw new ArgumentException("Required Sender ID not supplied in config or env variable \"" + SenderIdEnvName + "\"");
            }
            if (string.IsNullOrEmpty(config.SenderPassword))
            {
                throw new ArgumentException("Required Sender Password not supplied in config or env variable \"" + SenderPasswordEnvName + "\"");
            }

            this.SenderId = config.SenderId;
            this.Password = config.SenderPassword;
            this.Endpoint = new Endpoint(config);
        }
Exemple #2
0
        public LoginCredentials(ClientConfig config, SenderCredentials senderCreds)
        {
            string envProfileName = Environment.GetEnvironmentVariable(LoginCredentials.CompanyProfileEnvName);

            if (string.IsNullOrEmpty(envProfileName))
            {
                envProfileName = LoginCredentials.DefaultCompanyProfile;
            }
            if (string.IsNullOrEmpty(config.ProfileName))
            {
                config.ProfileName = envProfileName;
            }

            if (string.IsNullOrEmpty(config.CompanyId))
            {
                config.CompanyId = Environment.GetEnvironmentVariable(LoginCredentials.CompanyIdEnvName);
            }

            if (string.IsNullOrEmpty(config.EntityId))
            {
                config.EntityId = Environment.GetEnvironmentVariable(LoginCredentials.EntityIdEnvName);
            }
            if (string.IsNullOrEmpty(config.UserId))
            {
                config.UserId = Environment.GetEnvironmentVariable(LoginCredentials.UserIdEnvName);
            }
            if (string.IsNullOrEmpty(config.UserPassword))
            {
                config.UserPassword = Environment.GetEnvironmentVariable(LoginCredentials.UserPasswordEnvName);
            }

            if (
                string.IsNullOrEmpty(config.CompanyId) &&
                string.IsNullOrEmpty(config.UserId) &&
                string.IsNullOrEmpty(config.UserPassword) &&
                !string.IsNullOrEmpty(config.ProfileName)
                )
            {
                ClientConfig profile = ProfileCredentialProvider.GetLoginCredentials(config);

                if (!string.IsNullOrEmpty(profile.CompanyId))
                {
                    config.CompanyId = profile.CompanyId;
                }

                if (!string.IsNullOrEmpty(profile.EntityId))
                {
                    config.EntityId = profile.EntityId;
                }
                if (!string.IsNullOrEmpty(profile.UserId))
                {
                    config.UserId = profile.UserId;
                }
                if (!string.IsNullOrEmpty(profile.UserPassword))
                {
                    config.UserPassword = profile.UserPassword;
                }
            }

            if (string.IsNullOrEmpty(config.CompanyId))
            {
                throw new ArgumentException("Required Company ID not supplied in config or env variable \"" +
                                            LoginCredentials.CompanyIdEnvName + "\"");
            }
            // Entity ID is not required, no Error
            if (string.IsNullOrEmpty(config.UserId))
            {
                throw new ArgumentException("Required User ID not supplied in config or env variable \"" +
                                            LoginCredentials.UserIdEnvName + "\"");
            }
            if (string.IsNullOrEmpty(config.UserPassword))
            {
                throw new ArgumentException("Required User Password not supplied in config or env variable \"" +
                                            LoginCredentials.UserPasswordEnvName + "\"");
            }

            this.CompanyId         = config.CompanyId;
            this.EntityId          = config.EntityId;
            this.UserId            = config.UserId;
            this.Password          = config.UserPassword;
            this.SenderCredentials = senderCreds;
        }