19 using System.Collections;
21 using System.Collections.Generic;
22 using System.Collections.Specialized;
40 private readonly Dictionary<Symbol, Security> _securityManager;
41 private readonly Dictionary<Symbol, Security> _completeSecuritiesCollection;
43 private List<Symbol> _enumeratorKeys;
44 private List<Security> _enumeratorValues;
45 private List<KeyValuePair<Symbol, Security>> _enumerator;
53 get {
return _timeKeeper.UtcTime; }
62 _timeKeeper = timeKeeper;
63 _securityManager =
new();
64 _completeSecuritiesCollection =
new();
77 lock (_securityManager)
79 changed = _securityManager.TryAdd(symbol, security);
82 _completeSecuritiesCollection[symbol] = security;
89 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Add, security));
107 public void Add(KeyValuePair<Symbol, Security> pair)
109 Add(pair.Key, pair.Value);
118 lock (_securityManager)
121 _enumeratorKeys =
null;
122 _enumeratorValues =
null;
123 _securityManager.Clear();
124 _completeSecuritiesCollection.Clear();
134 public bool Contains(KeyValuePair<Symbol, Security> pair)
136 lock (_securityManager)
138 return _completeSecuritiesCollection.Contains(pair);
150 lock (_securityManager)
152 return _completeSecuritiesCollection.ContainsKey(symbol);
162 public void CopyTo(KeyValuePair<Symbol, Security>[] array,
int number)
164 lock (_securityManager)
166 ((IDictionary<Symbol, Security>)_securityManager).CopyTo(array, number);
178 lock (_securityManager)
180 return _securityManager.Count;
191 get {
return false; }
200 public bool Remove(KeyValuePair<Symbol, Security> pair)
213 lock (_securityManager)
215 _securityManager.
Remove(symbol, out security);
218 if (security !=
null)
220 OnCollectionChanged(
new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, security));
230 public ICollection<Symbol>
Keys
234 var result = _enumeratorKeys;
237 lock (_securityManager)
239 _enumeratorKeys = result = _securityManager.Keys.ToList();
255 lock (_securityManager)
257 return _completeSecuritiesCollection.TryGetValue(symbol, out security);
283 public ICollection<Security>
Values
287 var result = _enumeratorValues;
290 lock (_securityManager)
292 _enumeratorValues = result = _securityManager.Values.ToList();
302 public ICollection<Security>
Total
306 ICollection<Security> result;
307 lock (_securityManager)
309 result = _completeSecuritiesCollection.Values.ToList();
320 IEnumerator<KeyValuePair<Symbol, Security>> IEnumerable<KeyValuePair<Symbol, Security>>.GetEnumerator()
322 return GetEnumeratorImplementation();
330 IEnumerator IEnumerable.GetEnumerator()
332 return GetEnumeratorImplementation();
335 private List<KeyValuePair<Symbol, Security>>.Enumerator GetEnumeratorImplementation()
337 var result = _enumerator;
340 lock (_securityManager)
342 _enumerator = result = _securityManager.ToList();
345 return result.GetEnumerator();
354 public override Security
this[Symbol symbol]
359 lock (_securityManager)
361 if (!_completeSecuritiesCollection.TryGetValue(symbol, out security))
371 lock (_securityManager)
373 if (_securityManager.TryGetValue(symbol, out existing) && existing != value)
380 if (existing ==
null)
394 _enumeratorKeys =
null;
395 _enumeratorValues =
null;
404 _securityService = securityService;
414 List<SubscriptionDataConfig> subscriptionDataConfigList,
415 decimal leverage = 0,
416 bool addToSymbolCache =
true,
419 return _securityService.CreateSecurity(symbol, subscriptionDataConfigList, leverage, addToSymbolCache, underlying);
431 decimal leverage = 0,
432 bool addToSymbolCache =
true,
436 return _securityService.CreateSecurity(symbol, subscriptionDataConfig, leverage, addToSymbolCache, underlying);