private void AddFakeFigure(Stock stock, Type figureType, Currency currency)
        {
            var figure = Dynamics.CreateFigure(stock, figureType, new DayPeriod(DateTime.UtcNow), currency);

            var requiredProperties = figureType.GetProperties()
                                     // will be set by EF when saving figure
                                     .Where(p => p.Name != "Id")
                                     // set by "CreateFigure" already
                                     .Where(p => p.Name != "Period" && p.Name != "RawPeriod" && p.Name != "Currency" && p.Name != "Company" && p.Name != "Stock")
                                     // updated automatically
                                     .Where(p => p.Name != "Timestamp")
                                     .Where(p => p.GetCustomAttributes(typeof(RequiredAttribute), true).Any());

            foreach (var prop in requiredProperties)
            {
                if (prop.PropertyType == typeof(double) || prop.PropertyType == typeof(double?))
                {
                    prop.SetValue(figure, 42d);
                }
                else if (prop.PropertyType == typeof(string))
                {
                    prop.SetValue(figure, "dummy");
                }
                else
                {
                    throw new NotSupportedException("Don't know how to set required property: " + prop.Name);
                }
            }

            // add to relationship
            var figures = ( IList )Dynamics.GetRelationship(stock, figureType);

            figures.Add(figure);
        }
        protected IFigure CreateEntity(Stock stock, IPeriod period, object value)
        {
            var currency = GetCurrency();

            var figure = Dynamics.CreateFigure(stock, EntityType, period, currency);

            figure.Source = Source;
            figure.Value  = (double)value;

            return(figure);
        }
        public void Initialize(Stock stock)
        {
            Stock = stock;

            myFigures = new List <IFigureSeries>();
            foreach (var figureType in Dynamics.AllFigures.Where(t => t != typeof(Price)))
            {
                myFigures.Add(Dynamics.GetSeries(stock, figureType, false));
            }

            // we might have prices of different currencies - do only add latest
            {
                var series = new FigureSeries(typeof(Price));
                series.EnableCurrencyCheck = false;

                var currentPrice = stock.Prices.OrderByDescending(p => p.Period).FirstOrDefault();
                if (currentPrice != null)
                {
                    series.Add(currentPrice);
                }

                myFigures.Add(series);
            }

            // data sanity - TODO: later move to creation of new DataSheet
            {
                var series = (FigureSeries)myFigures.SeriesOf(typeof(Price));
                if (series.Current <Price>() == null)
                {
                    series.Add(new Price());
                }
            }

            // defaultCurrency could be taken from any figure but Price
            Currency defaultCurrency = null;

            foreach (var type in Dynamics.AllFigures.Where(t => t != typeof(Price)))
            {
                var series = (FigureSeries)myFigures.SeriesOf(type);

                // TODO: today we only support yearly values here
                var currentYear   = DateTime.Now.Year;
                var existingYears = series
                                    .Select(v => ((YearPeriod)v.Period).Year)
                                    .ToList();

                if (defaultCurrency == null)
                {
                    defaultCurrency = series.Currency;
                }

                // select hard coded 11 years here as minimum to allow growth calc based on recent 10 years
                for (int i = currentYear - 10; i <= currentYear; ++i)
                {
                    if (!existingYears.Contains(i))
                    {
                        var figure = Dynamics.CreateFigure(Stock, type, new YearPeriod(i),
                                                           series.Currency != null ? series.Currency : defaultCurrency);
                        series.Add(figure);
                    }
                }
            }

            RaisePropertyChanged(nameof(Price));
            RaisePropertyChanged(nameof(DataSeries));
        }