コード例 #1
0
ファイル: Config.cs プロジェクト: w1r2p1/Core-2
        /// <summary>
        /// Appends the configuration file.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="I"></typeparam>
        /// <param name="data">The data.</param>
        /// <param name="item">The item.</param>
        /// <returns></returns>
        public static T AppendConfigFile <T, I>(T data, I item)
            where T : class
        {
            if (typeof(T) == typeof(CurrencyRatesConfig[]))
            {
                //get input
                IEnumerable <CurrencyRatesConfig> rates = data as CurrencyRatesConfig[];
                CurrencyRatesConfig added = item as CurrencyRatesConfig;

                //add item
                var tolist = rates.ToList();
                tolist.Add(added);
                rates = tolist;

                //save
                string newJson = JsonConvert.SerializeObject(rates);
                File.WriteAllText(ConfigCache.GetConfigPath(ConfigFileType.CurrencyRates), newJson);

                //Return what we currently have
                Cachedconfig.Put(ConfigFileType.CurrencyRates, rates);
                return(CurrencyConfig as T);
            }
            else
            {
                throw new Exception($"Append config does not have an implementation for config of type {data.GetType().FullName}");
            }
        }
コード例 #2
0
 public CurrencyViewerController(ICurrencyRatesQueryService currencyRatesQueryService,
                                 ICurrencyRatesBetweenDatesReceiver currencyRatesBetweenDatesReceiver,
                                 ICurrencyRatesCommandService commandService,
                                 IOptions <CurrencyRatesConfig> config)
 {
     _currencyRatesQueryService         = currencyRatesQueryService;
     _currencyRatesBetweenDatesReceiver = currencyRatesBetweenDatesReceiver;
     _commandService = commandService;
     _config         = config.Value;
 }
コード例 #3
0
        public static IOptions <CurrencyRatesConfig> GetConfig(CurrencyRatesConfig expectedResult = null)
        {
            var options = new Mock <IOptions <CurrencyRatesConfig> >();

            var returnValue = expectedResult ?? new CurrencyRatesConfig()
            {
                BaseUrl = "http://api.nbp.pl", CurrencyCodes = new string[] { "usd", "eur" }
            };

            options.SetupGet(x => x.Value).Returns(returnValue);

            return(options.Object);
        }
コード例 #4
0
ファイル: BaseCurrency.cs プロジェクト: w1r2p1/Core-2
        /// <summary>
        /// Update current config file with new information
        /// </summary>
        /// <param name="date"></param>
        /// <param name="base"></param>
        /// <param name="rate"></param>
        private void UpdateConfig(DateTime date, CurrencyType @base, CurrencyRatesConfig rate)
        {
            //Set proper date
            date = date.Date;

            //Get current config
            var currentconfig = GetFromConfig();

            //Check if we need to add
            var current = currentconfig[@base.ToString()];

            if (!current.ContainsKey(date))
            {
                Config.AppendConfigFile(currentconfig, rate);
            }
        }
コード例 #5
0
ファイル: ConfigTests.cs プロジェクト: w1r2p1/Core-2
        public void Config_AppendConfig()
        {
            //Arrange
            var currentitems = Config.CurrencyConfig.ToArray();
            var addeditem    = new CurrencyRatesConfig
            {
                Base  = "EUR",
                date  = DateTime.UtcNow.Date.ToString("yyyy-MM-dd"),
                Date  = DateTime.UtcNow.Date,
                Rates = Enum.GetValues(typeof(CurrencyType)).Cast <CurrencyType>().ToDictionary(x => x.ToString(), x => 0.91m)
            };

            //Act
            Config.AppendConfigFile(Config.CurrencyConfig, addeditem);

            //Assert
            Config.CurrencyConfig.Length.Should().BeGreaterThan(currentitems.Length);
        }
コード例 #6
0
ファイル: BaseCurrency.cs プロジェクト: w1r2p1/Core-2
        /// <summary>
        /// Updates the specified date.
        /// </summary>
        /// <param name="date">The date.</param>
        /// <param name="base">The base.</param>
        /// <param name="rate">The rate.</param>
        protected void Update(DateTime date, CurrencyType @base, CurrencyRatesConfig rate)
        {
            //Update locally
            string basecurrency = @base.ToString();

            if (!History.TryGetValue(basecurrency, out Dictionary <DateTime, CurrencyRatesConfig> rates))
            {
                rates[date.Date] = rate;
            }
            else
            {
                History.Add(basecurrency, new Dictionary <DateTime, CurrencyRatesConfig>
                {
                    { date.Date, rate }
                });
            }

            //Update config file
            UpdateConfig(date, @base, rate);
            UpdateRange();
        }
コード例 #7
0
 public CurrencyRatesReceiver(IOptions <CurrencyRatesConfig> options, IHttpClientFactory clientFactory)
 {
     _config        = options.Value;
     _clientFactory = clientFactory;
 }