Ejemplo n.º 1
0
        public IObservable <AccountData> GetPortfolioSnapshot(string accountName, Action <bool> enable)
        {
            lock (_accountUpdatesGate)
            {
                if (_portfolioSubj != null && _portfolioLiveSubj == _portfolioSubj) // pre-empt live update
                {
                    StopAccountUpdates(_enableLiveAccountUpdates);
                }

                if (_activeSnapshotAccountName == null) // no update in progress, start a new one
                {
                    _portfolioSubj                = new ReplaySubject <AccountData>();
                    _activeSnapshotAccountName    = accountName;
                    _enableSnapshotAccountUpdates = enable;
                    enable(true); // start
                    return(_portfolioSubj.MergeErrors(Errors));
                }
                else if (_activeSnapshotAccountName == accountName) // reuse the one in progress
                {
                    return(_portfolioSubj.MergeErrors(Errors));
                }
                else // queue request
                {
                    ISubject <AccountData> newPortfolioSubj = new ReplaySubject <AccountData>();
                    _accountSnapshotRequestsQueue.Enqueue(Tuple.Create(newPortfolioSubj, accountName, enable));
                    return(newPortfolioSubj.MergeErrors(Errors));
                }
            }
        }