public SessionCredentials(ClientConfig config, SenderCredentials senderCreds)
        {
            if (string.IsNullOrEmpty(config.SessionId))
            {
                throw new ArgumentException("Required Session ID not supplied in config");
            }

            this.SessionId = config.SessionId;

            this.Endpoint = !string.IsNullOrEmpty(config.EndpointUrl)
                ? new Endpoint(config)
                : senderCreds.Endpoint;

            this.SenderCredentials = senderCreds;
        }
예제 #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;
        }