Exemplo n.º 1
0
        public void ThrowIfRequiredFileNotFound()
        {
            var fileSource = new JsonFileSource("abc.json", true);

            fileSource
            .Invoking(source => source.TryGet(out _))
            .Should().Throw <FileNotFoundException>();
        }
Exemplo n.º 2
0
 public async Task LoadAsync(
     ISystemService systems,
     string jsonFilePath,
     CancellationToken cancellationToken = default)
 {
     using var source = new JsonFileSource <Actor>(_converters, _descriptions, jsonFilePath);
     await LoadAsync(systems, source, cancellationToken);
 }
 public void Should_work_correctly()
 {
     using (var temporaryFile = new TemporaryFile(TestCase.Json))
     {
         var source = new JsonFileSource(temporaryFile.FileName);
         source.Observe()
         .ShouldStartWithIn(1.Seconds(), (TestCase.SettingsNode, null as Exception));
     }
 }
Exemplo n.º 4
0
        static void Main(string[] args)
        {
            SetupConfigurationProvider();

            var configSource = new JsonFileSource("config.json");

            var source = configSource
                         .CombineWith(new EnvironmentVariablesSource())
                         .CombineWith(new CommandLineSource(args));

            provider.SetupSourceFor <ApplicationSettings>(source);

            SetupApplication();

            PrintOptions(configSource);

            Console.ReadKey();
        }
Exemplo n.º 5
0
        public void ReturnValidValues(BigObject values)
        {
            var fileName = $"{nameof(ReturnValidValues)}.json";

            CreateFile(fileName, values);

            try
            {
                var fileSource = new JsonFileSource(fileName, true);
                fileSource.TryGet(out var jsonObject);

                var converter = BuildConvertersCollection().Get <BigObject>();
                converter.Read(jsonObject).Should().BeEquivalentTo(values);
            }
            catch
            {
                File.Delete(fileName);
            }
        }
Exemplo n.º 6
0
        public string PrepareInvestmentChart(InvestmentChart investmentChart)
        {
            try
            {
                DataModel model = new DataModel();
                List <ChartDataValues> _data = new List <ChartDataValues>();

                var a = _dbContext.CurrencyRateHistory.ToList();
                var b = _dbContext.Currencies.ToList();

                var data1 = _dbContext.CurrencyRateHistory
                            .Include(a => a.Currency)
                            .OrderBy(x => x.Date)
                            .Where(x => x.CurrencyId == investmentChart.FirstCurrency &&
                                   x.Date >= investmentChart.StartingDate)
                            .ToList();

                var data2 = _dbContext.CurrencyRateHistory
                            .Include(a => a.Currency)
                            .OrderBy(x => x.Date)
                            .Where(x => x.CurrencyId == investmentChart.SecondCurrency &&
                                   x.Date >= investmentChart.StartingDate)
                            .ToList();

                int previousValues = data2.Count();

                for (int i = 0; i < previousValues; i++)
                {
                    if (i != previousValues - 1)
                    {
                        _data.Add(new ChartDataValues()
                        {
                            Date = data1[i].Date.ToString("dd.MM.yyyy"),
                            FirstCurrencyValue  = data1[i].Rate * 100,
                            SecondCurrencyValue = data2[i].Rate * 100
                        });
                    }
                    else
                    {
                        double temp = 0;
                        if (data1[i].Rate > data2[i].Rate)
                        {
                            temp = data1[i].Rate * 100;
                        }
                        else
                        {
                            temp = data2[i].Rate * 100;
                        }
                        _data.Add(new ChartDataValues()
                        {
                            Date = data1[i].Date.ToString("dd.MM.yyyy"),
                            FirstCurrencyValue  = data1[i].Rate * 100,
                            SecondCurrencyValue = data2[i].Rate * 100,
                            ThirdCurrencyValue  = temp
                        });
                    }
                }

                if (investmentChart.RadioResponse.Equals("LinearPrediction"))
                {
                    TimeSpan span      = investmentChart.EndingDate.Subtract(DateTime.Now);
                    TimeSpan decrement = DateTime.Now.Subtract(investmentChart.StartingDate);

                    double FirstIncrement =
                        (data1[previousValues - 1].Rate - data1[0].Rate) / decrement.Days;
                    double SecondIncrement =
                        (data2[previousValues - 1].Rate - data2[0].Rate) / decrement.Days;

                    for (int i = 1; i <= span.Days; i++)
                    {
                        _data.Add(new ChartDataValues()
                        {
                            Date = data1[previousValues - 1].Date.AddDays(i).ToString("dd.MM.yyyy"),
                            FirstCurrencyValue  = data1[previousValues - 1].Rate * 100 + FirstIncrement * i,
                            SecondCurrencyValue = data2[previousValues - 1].Rate * 100 + SecondIncrement * i
                        });
                    }
                }

                if (investmentChart.RadioResponse.Equals("LinearRegression"))
                {
                    TimeSpan span      = investmentChart.EndingDate.Subtract(DateTime.Now);
                    TimeSpan decrement = DateTime.Now.Subtract(investmentChart.StartingDate);

                    double        alpha1, beta1;
                    List <double> rates1 = new List <double>();
                    for (int i = 0; i < previousValues; i++)
                    {
                        rates1.Add(data1[i].Rate * 100);
                    }

                    alpha1 = LinearRegression(previousValues, rates1).ElementAt(0);
                    beta1  = LinearRegression(previousValues, rates1).ElementAt(1);

                    double        alpha2, beta2;
                    List <double> rates2 = new List <double>();
                    for (int i = 0; i < previousValues; i++)
                    {
                        rates2.Add(data2[i].Rate * 100);
                    }

                    alpha2 = LinearRegression(previousValues, rates2).ElementAt(0);
                    beta2  = LinearRegression(previousValues, rates2).ElementAt(1);


                    for (int i = 1; i <= span.Days; i++)
                    {
                        _data.Add(new ChartDataValues()
                        {
                            Date = data1[previousValues - 1].Date.AddDays(i).ToString("dd.MM.yyyy"),
                            FirstCurrencyValue  = alpha1 + beta1 * (decrement.Days + i),
                            SecondCurrencyValue = alpha2 + beta2 * (decrement.Days + i)
                        });
                    }
                }

                if (investmentChart.RadioResponse.Equals("ExponentialSmoothing"))
                {
                    TimeSpan span = investmentChart.EndingDate.Subtract(DateTime.Now);

                    List <double> parameters      = AlphaParameters(investmentChart.Alpha);
                    int           countParameters = parameters.Count();
                    if (countParameters > data1.Count())
                    {
                        countParameters = data1.Count();
                    }

                    var values1 = data1.TakeLast(countParameters).Reverse().ToList();
                    var values2 = data2.TakeLast(countParameters).Reverse().ToList();
                    for (int i = 1; i < span.Days; i++)
                    {
                        double firstValue  = 0;
                        double secondValue = 0;
                        for (int j = 1; j < countParameters; j++)
                        {
                            firstValue  += parameters.ElementAt(j - 1) * values1[j - 1].Rate;
                            secondValue += parameters.ElementAt(j - 1) * values2[j - 1].Rate;
                        }
                        values1.Insert(0, new BusinessModels.CurrencyRateHistory {
                            Rate = firstValue
                        });
                        values2.Insert(0, new BusinessModels.CurrencyRateHistory {
                            Rate = secondValue
                        });

                        _data.Add(new ChartDataValues()
                        {
                            Date = data1[previousValues - 1].Date.AddDays(i).ToString("dd.MM.yyyy"),
                            FirstCurrencyValue  = firstValue * 100,
                            SecondCurrencyValue = secondValue * 100
                        });
                    }
                }

                string json = JsonConvert.SerializeObject(_data.ToArray());
                //string filePath = @"D:\eBanking\eBanking\eBanking\investmentChartData.json";
                string filePath = "./investmentChartData.json";
                Log.Information("ChartService, PrepareInvestmentChart(): Check if investmentChartData.json exists");
                if (!System.IO.File.Exists(filePath))
                {
                    Log.Information("ChartService, PrepareInvestmentChart(): investmentChartData.json doesn't exist");
                    var fs = System.IO.File.Create(filePath);
                    fs.Close();
                    Log.Information("ChartService, PrepareInvestmentChart(): investmentChartData.json created");
                }
                System.IO.File.WriteAllText(filePath, json);
                JsonFileSource jsonFileSource = new JsonFileSource(filePath);
                model.DataSources.Add(jsonFileSource);

                Charts.CombinationChart combiChart = new Charts.CombinationChart("mscombi2d");
                combiChart.Data.Source = model;
                combiChart.Data.LinePlots("FirstCurrencyValue");
                combiChart.Data.LinePlots("SecondCurrencyValue");
                combiChart.Data.ColumnPlots("ThirdCurrencyValue");
                combiChart.XAxis.Text   = "Date";
                combiChart.Caption.Text = "Investment consulting";
                combiChart.Width.Pixel(800);
                combiChart.Height.Pixel(500);

                combiChart.Data.SecondaryYAxisAsParent("SecondCurrencyValue");
                combiChart.PrimaryYAxis.Text   = data1[0].Currency.Name.ToString();
                combiChart.SecondaryYAxis.Text = data2[0].Currency.Name.ToString();
                combiChart.DualY = true;

                combiChart.ThemeName = FusionChartsTheme.ThemeName.FUSION;

                return(combiChart.Render());
            }
            catch (Exception ex)
            {
                Log.Error(ex, "ChartService, PrepareInvestmentChart()");
                throw ex;
            }
        }
Exemplo n.º 7
0
        public void ReturnValues()
        {
            var fileSource = new JsonFileSource("Settings/appsettings.json", true);

            fileSource.TryGet(out _).Should().BeTrue();
        }