Esempio n. 1
0
        private IList <CategoryWeight> GetWeightDataFromMorningstar(Category category, Security security)
        {
            if (category.Name.Equals("assetallocation", StringComparison.InvariantCultureIgnoreCase))
            {
                var assetAllocation = _scraper.GetAssetAllocation(TranslateSymbol(security));
                var values          = _categoryRepository.GetValues(category).ToList();
                var list            = new List <CategoryWeight>();

                if (!assetAllocation.Any())
                {
                    var value = values.SingleOrDefault(v => v.Name.Equals(NotApplicable));
                    if (value == null)
                    {
                        value = new CategoryValue {
                            Category = category, Name = NotApplicable
                        };
                        _categoryRepository.AddValues(category, new[] { value });
                    }
                    list.Add(new CategoryWeight {
                        Security = security, Weight = 100M, Value = value
                    });
                }
                else
                {
                    foreach (var kvpair in assetAllocation)
                    {
                        var categoryValueName = kvpair.Key;
                        var value             = values.SingleOrDefault(v => v.Name.Equals(categoryValueName));
                        if (value == null)
                        {
                            value = new CategoryValue {
                                Category = category, Name = categoryValueName
                            };
                            _categoryRepository.AddValues(category, new[] { value });
                        }
                        list.Add(new CategoryWeight {
                            Security = security, Weight = kvpair.Value, Value = value
                        });
                    }
                }

                _categoryRepository.AddWeights(category, security, list);
                return(list);
            }

            throw new CategoryNotSupportedException(string.Format("Category not supported: {0}", category.Name));
        }