public SecurityRepository( IMonitor monitor, IEnumerable <SecurityInfo> securities, CountryRepository countryRepository ) : this( monitor, securities, splitters, new HashSet <String>(skipWords), countryRepository ) { }
public SecurityRepository( IMonitor monitor, IEnumerable <SecurityInfo> securityInfos, IEnumerable <Char> splitters, HashSet <String> skipWords, CountryRepository countryRepository ) { if (!securityInfos.Any()) { throw new ApplicationException("There are no securities."); } this.all = new Dictionary <String, ISecurity>(); this.byShortName = new Dictionary <String, ISecurity>(); this.map = new Dictionary <String, List <ISecurity> >(); var securities = this.CreateSecurities(securityInfos, countryRepository, monitor); foreach (var security in securities) { monitor.SwallowIfFails("Registering a security.", delegate { try { ISecurity existing; if (this.all.TryGetValue(security.Id, out existing)) { throw new ApplicationException("There is a security with the same ID already registered."); } this.all.Add(security.Id, security); this.byShortName.Add(security.ShortName, security); } catch (Exception exception) { throw new ApplicationException("Unable to register a security with the \"" + security.Id + "\" ID.", exception); } }); var tobeIndexed = security.Ticker + " " + security.ShortName + " " + security.Name; var keys = tobeIndexed.Split(splitters.ToArray()).Select(x => x.Trim().ToLower()).Where(x => !String.IsNullOrWhiteSpace(x)).ToList(); if (!String.IsNullOrWhiteSpace(security.Name)) { keys.Add(security.Name.ToLower()); } if (!String.IsNullOrWhiteSpace(security.Ticker)) { keys.Add(security.Ticker.ToLower()); } foreach (var key in keys) { if (skipWords.Contains(key)) { continue; } this.ClaimList(key).Add(security); } } // look through fund this.fundsByLookThroughFund = this.CreateFundsMapByLookupThroughFund(securityInfos, monitor); this.keys = map.Keys.ToArray(); Array.Sort <String>(this.keys); }
private IEnumerable <ISecurity> CreateSecurities( IEnumerable <SecurityInfo> securityInfos, CountryRepository countryRepository, IMonitor monitor ) { var result = new List <ISecurity>(); foreach (var securityInfo in securityInfos) { var securityOpt = monitor.DefaultIfFails("Validating security", delegate { if (String.IsNullOrEmpty(securityInfo.Name)) { throw new ApplicationException("Name is not specified."); } if (String.IsNullOrEmpty(securityInfo.ShortName)) { throw new ApplicationException("Short name is not specified."); } ISecurity security; if (String.IsNullOrWhiteSpace(securityInfo.LookThruFund)) { Country country = null; if (String.IsNullOrEmpty(securityInfo.IsoCountryCode)) { throw new ApplicationException("Country code is not specified."); } try { country = countryRepository.GetCountry(securityInfo.IsoCountryCode); } catch (CountryNotFoundException) { country = new Country(securityInfo.IsoCountryCode, securityInfo.AsecCountryName); } var stock = new CompanySecurity( securityInfo.Id, securityInfo.Ticker, securityInfo.ShortName, securityInfo.Name, country, securityInfo.IssuerId, securityInfo.SecurityType, securityInfo.Currency, securityInfo.Isin, securityInfo.IsoCountryCode ); security = stock; } else { var fund = new Fund( securityInfo.Id, securityInfo.Name, securityInfo.ShortName, securityInfo.Ticker, securityInfo.IssuerId, securityInfo.SecurityType, securityInfo.Currency, securityInfo.Isin, securityInfo.IsoCountryCode ); security = fund; } return(security); }); if (securityOpt == null) { continue; } result.Add(securityOpt); } return(result); }