18 using System.Collections;
19 using System.Collections.Concurrent;
20 using System.Collections.Generic;
32 private readonly ConcurrentDictionary<SubscriptionDataConfig, Subscription> _subscriptions;
33 private bool _sortingSubscriptionRequired;
39 private List<Subscription> _subscriptionsByTickType;
51 _subscriptions =
new ConcurrentDictionary<SubscriptionDataConfig, Subscription>();
52 _subscriptionsByTickType =
new List<Subscription>();
54 _fillForwardResolution =
Ref.Create(() => ffres, res => ffres = res);
64 return _subscriptions.ContainsKey(configuration);
75 if (_subscriptions.TryAdd(subscription.
Configuration, subscription))
77 UpdateFillForwardResolution(FillForwardResolutionOperation.AfterAdd, subscription.
Configuration);
78 _sortingSubscriptionRequired =
true;
92 return _subscriptions.TryGetValue(configuration, out subscription);
103 if (_subscriptions.TryRemove(configuration, out subscription))
107 if (!subscription.EndOfStream)
109 UpdateFillForwardResolution(FillForwardResolutionOperation.AfterRemove, configuration);
111 _sortingSubscriptionRequired =
true;
126 return _subscriptionsByTickType.GetEnumerator();
135 IEnumerator IEnumerable.GetEnumerator()
146 if (configuration !=
null)
148 UpdateFillForwardResolution(FillForwardResolutionOperation.BeforeAdd, configuration);
150 return _fillForwardResolution;
172 private void UpdateFillForwardResolution(FillForwardResolutionOperation operation,
SubscriptionDataConfig configuration)
180 if (ValidateFillForwardResolution(configuration) &&
182 ((FillForwardResolutionOperation.BeforeAdd == operation || FillForwardResolutionOperation.AfterAdd == operation)
183 && configuration.
Increment != _fillForwardResolution.Value)
185 (operation == FillForwardResolutionOperation.AfterRemove
186 && configuration.
Increment == _fillForwardResolution.Value
188 && _subscriptions.Keys.All(x => !ValidateFillForwardResolution(x) || x.Resolution != configuration.
Resolution)))
191 var configurations = (operation == FillForwardResolutionOperation.BeforeAdd)
192 ? _subscriptions.Keys.Concat(
new[] { configuration }) : _subscriptions.Keys;
194 var eventArgs =
new FillForwardResolutionChangedEvent { Old = _fillForwardResolution.Value };
195 _fillForwardResolution.Value = configurations.Where(ValidateFillForwardResolution)
196 .Select(x => x.Resolution)
200 if (_fillForwardResolution.Value != eventArgs.Old)
202 eventArgs.New = _fillForwardResolution.Value;
213 private void SortSubscriptions()
215 if (_sortingSubscriptionRequired)
217 _sortingSubscriptionRequired =
false;
221 _subscriptionsByTickType = _subscriptions
222 .Select(x => x.Value)
223 .OrderBy(x => x.Configuration.SecurityType)
224 .ThenBy(x => x.Configuration.TickType)
225 .ThenBy(x => x.Configuration.Symbol)
230 private enum FillForwardResolutionOperation