private bool ValidateCredentials(CredentialsConfiguration credentials)
        {
            using (var client = new HttpClient())
            {
                client.BaseAddress = new Uri(_configuration.BaseUrl);
                client.DefaultRequestHeaders.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("Authorization", $"token {credentials.ApiKey}");

                string accountUrl = _configuration.AccountUrl.Replace("{AccountId}", credentials.AccountId.ToString());

                try
                {
                    HttpResponseMessage response = client.GetAsync(accountUrl).Result;

                    if (response.IsSuccessStatusCode)
                    {
                        return(true);
                    }
                    else
                    {
                        string result = response.Content.ReadAsStringAsync().Result;
                        _logger.Info($"Validate credentials fail:{result}");
                        return(false);
                    }
                }
                catch (Exception e)
                {
                    _logger.Error($"Validate credentials error -- {e}");

                    return(false);
                }
            }
        }
Exemple #2
0
        public SystemService(
            ILogger <SystemService> logger,
            IServiceProvider serviceProvider,
            IXNodeConnectionRepository xNodeConnectionRepository,
            SystemIOService systemIOService,
            TenantIOService tenantIOService,
            ProducerIOService producerIOService,
            ConsumerIOService consumerIOService,
            MessageIOService messageIOService2)
        {
            _logger          = logger;
            _serviceProvider = serviceProvider;

            _xNodeConnectionRepository = xNodeConnectionRepository;
            _systemIOService           = systemIOService;
            _tenantIOService           = tenantIOService;
            _producerIOService         = producerIOService;
            _consumerIOService         = consumerIOService;
            _messageIOService2         = messageIOService2;
            nodes       = _serviceProvider.GetService(typeof(List <XNodeConfiguration>)) as List <XNodeConfiguration>;
            dataStorage = _serviceProvider.GetService(typeof(DataStorageConfiguration)) as DataStorageConfiguration;
            agent       = _serviceProvider.GetService(typeof(AgentConfiguration)) as AgentConfiguration;
            partition   = _serviceProvider.GetService(typeof(PartitionConfiguration)) as PartitionConfiguration;
            credentials = _serviceProvider.GetService(typeof(CredentialsConfiguration)) as CredentialsConfiguration;


            DoFileConfiguration();

            UpdateXNodesConfiguration();
            UpdateDataStorageConfiguration();
            UpdateCredentials();

            InitializeServices();
        }
Exemple #3
0
        private static void BindCredentialsConfiguration(this IServiceCollection services, IConfiguration configuration)
        {
            var credentialsConfiguration = new CredentialsConfiguration();

            configuration.Bind("Credentials", credentialsConfiguration);
            services.AddSingleton(credentialsConfiguration);
        }
        public CredentialsConfiguration Clone()
        {
            var credentialsConfiguration = new CredentialsConfiguration();

            credentialsConfiguration.AccountId = this.AccountId;
            credentialsConfiguration.Email     = this.Email;
            credentialsConfiguration.Password  = this.Password;
            credentialsConfiguration.ApiKey    = this.ApiKey;

            return(credentialsConfiguration);
        }
 public static bool WriteCredentialsConfigurationFromFile(CredentialsConfiguration credentialsConfiguration)
 {
     if (File.Exists(SystemLocations.GetCredentialsConfigFile()))
     {
         File.Delete(SystemLocations.GetCredentialsConfigFile());
     }
     try
     {
         File.WriteAllText(SystemLocations.GetCredentialsConfigFile(), credentialsConfiguration.ToJsonAndEncrypt());
         return(true);
     }
     catch (System.Exception)
     {
         return(false);
     }
 }
Exemple #6
0
        private void UpdateCredentials()
        {
            CredentialsConfiguration newConfig = credentials;

            if (File.Exists(SystemLocations.GetCredentialsConfigFile()))
            {
                var actualConfig = SystemConfigurationReader.ReadCredentialsConfigurationFromFile();
                if (newConfig.Username != actualConfig.Username || newConfig.Password != actualConfig.Password)
                {
                    SystemConfigurationWriter.WriteCredentialsConfigurationFromFile(newConfig);
                }
            }
            else
            {
                SystemConfigurationWriter.WriteCredentialsConfigurationFromFile(newConfig);
            }
        }
Exemple #7
0
 public StorageHub(ILogger <StorageHub> logger,
                   CredentialsConfiguration credentialsConfiguration,
                   IStorageHubRepository storageHubRepository,
                   ITenantRepository tenantMemoryRepository,
                   IStorageFactory storageFactory,
                   IAgentFactory agentFactory,
                   IConsumerHubService consumerHubService,
                   IProducerHubService producerHubService)
 {
     this.logger = logger;
     this.credentialsConfiguration = credentialsConfiguration;
     this.storageHubRepository     = storageHubRepository;
     this.tenantMemoryRepository   = tenantMemoryRepository;
     this.storageFactory           = storageFactory;
     this.agentFactory             = agentFactory;
     this.consumerHubService       = consumerHubService;
     this.producerHubService       = producerHubService;
 }
Exemple #8
0
        protected override void SendRecipientsList(List <ApiRecipient> recipients, string resultsFileName, char separator, ProcessResult result, CredentialsConfiguration credentials)
        {
            ApiRecipient recipient = null;
            int          count     = recipients.Count();

            if (count == _configuration.BulkEmailCount)
            {
                count    -= 1;
                recipient = recipients[count];
            }

            using (StreamWriter sw = new StreamWriter(resultsFileName, true))
            {
                for (int i = 0; i < count; i++)
                {
                    if (!recipients[i].HasError)
                    {
                        SendEmail(credentials.ApiKey, credentials.AccountId, recipients[i], separator, result);

                        Thread.Sleep(_configuration.DeliveryInterval);
                    }
                    sw.WriteLine(recipients[i].ResultLine);
                    sw.Flush();
                }
            }

            recipients.Clear();

            if (recipient != null)
            {
                recipients.Add(recipient);
            }
        }
        protected virtual void SendRecipientsList(List <ApiRecipient> recipients, string resultsFileName, char separator, ProcessResult result, CredentialsConfiguration credentials)
        {
            using (StreamWriter sw = new StreamWriter(resultsFileName, true))
            {
                foreach (ApiRecipient recipient in recipients)
                {
                    if (!recipient.HasError)
                    {
                        SendEmail(credentials.ApiKey, credentials.AccountId, recipient, separator, result);

                        Thread.Sleep(_configuration.DeliveryInterval);
                    }
                    sw.WriteLine(recipient.ResultLine);
                    sw.Flush();
                }
            }

            recipients.Clear();
        }