Beispiel #1
0
        /// <summary>
        /// Load settings.
        /// </summary>
        /// <param name="storage">Settings storage.</param>
        public void Load(SettingsStorage storage)
        {
            var drives = storage
                         .GetValue <IEnumerable <SettingsStorage> >(nameof(Drives))
                         .Select(s => s.LoadEntire <IMarketDataDrive>())
                         .ToArray();

            lock (_drives.SyncRoot)
            {
                foreach (var drive in drives)
                {
                    _drives.TryAdd(CreatePair(drive.Path), drive);
                }
            }

            if (storage.ContainsKey(nameof(DefaultDrive)))
            {
                var pair = CreatePair(storage.GetValue <string>(nameof(DefaultDrive)));

                if (_drives.TryGetValue(pair, out var drive))
                {
                    DefaultDrive = drive;
                }
            }
        }
Beispiel #2
0
            protected override void OnAdded(T item)
            {
                base.OnAdded(item);

                if (_items.TryAdd(GetKey(item), item))
                {
                    Write(item);
                }
            }
Beispiel #3
0
        private long?Upload(Guid operationId, FileInfoMessage file, Action <long, long> progress, Func <bool> cancel)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            var sentCount = 0L;

            var body = file.Body;

            if (Compression)
            {
                body = body.DeflateTo();
            }

            foreach (var part in body.Batch(PartSize))
            {
                if (cancel?.Invoke() == true)
                {
                    Invoke(f => f.FinishUpload(operationId, true));
                    return(null);
                }

                var arr = part.ToArray();

                ValidateError(Invoke(f => f.ProcessUpload(operationId, arr)));

                sentCount += arr.Length;
                progress?.Invoke(sentCount, body.Length);
            }

            var id = Invoke(f => f.FinishUpload(operationId, false));

            if (id < 0)
            {
                ValidateError((byte)-id);
            }

            // temp upload
            if (id == 0)
            {
                return(0);
            }

            if (file.Id == 0)
            {
                file.Id = id;
            }

            _cache.TryAdd(id, file);

            return(id);
        }
        /// <summary>
        /// To save the exchange.
        /// </summary>
        /// <param name="exchange">Exchange.</param>
        public virtual void Save(Exchange exchange)
        {
            if (exchange == null)
            {
                throw new ArgumentNullException(nameof(exchange));
            }

            lock (_exchanges.SyncRoot)
            {
                if (!_exchanges.TryAdd(exchange.Name, exchange))
                {
                    return;
                }
            }

            ExchangeAdded?.Invoke(exchange);
        }
        /// <summary>
        /// To save the board.
        /// </summary>
        /// <param name="board">Trading board.</param>
        public virtual void Save(ExchangeBoard board)
        {
            if (board == null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            lock (_boards.SyncRoot)
            {
                if (!_boards.TryAdd(board.Code, board))
                {
                    return;
                }
            }

            BoardAdded?.Invoke(board);
        }
Beispiel #6
0
            void IExchangeInfoProvider.Save(Exchange exchange)
            {
                if (exchange == null)
                {
                    throw new ArgumentNullException(nameof(exchange));
                }

                lock (_exchanges.SyncRoot)
                {
                    if (!_exchanges.TryAdd(exchange.Name, exchange))
                    {
                        return;
                    }
                }

                ExchangeAdded.SafeInvoke(exchange);
            }
Beispiel #7
0
            void IExchangeInfoProvider.Save(ExchangeBoard board)
            {
                if (board == null)
                {
                    throw new ArgumentNullException(nameof(board));
                }

                lock (_boards.SyncRoot)
                {
                    if (!_boards.TryAdd(board.Code, board))
                    {
                        return;
                    }
                }

                BoardAdded.SafeInvoke(board);
            }
Beispiel #8
0
        /// <summary>
        /// Получить информацию о пользователях в комнате.
        /// </summary>
        /// <param name="room">Комната.</param>
        /// <returns>Пользователи.</returns>
        public IEnumerable <User> GetAuthors(ChatRoom room)
        {
            if (room == null)
            {
                throw new ArgumentNullException("room");
            }

            var ids    = Invoke(f => f.GetAuthors(SessionId, room.Id));
            var newIds = ids.Where(id => !_users.ContainsKey(id)).ToArray();

            if (!newIds.IsEmpty())
            {
                Invoke(f => f.GetUsers(SessionId, newIds)).ForEach(u => _users.TryAdd(u.Id, u));
            }

            return(ids.Select(GetUser));
        }
Beispiel #9
0
        /// <summary>
        /// To save the exchange.
        /// </summary>
        /// <param name="exchange">Exchange.</param>
        public void Save(Exchange exchange)
        {
            if (exchange == null)
            {
                throw new ArgumentNullException(nameof(exchange));
            }

            _entityRegistry.Exchanges.Save(exchange);

            lock (_exchanges.SyncRoot)
            {
                if (!_exchanges.TryAdd(exchange.Name, exchange))
                {
                    return;
                }
            }

            ExchangeAdded.SafeInvoke(exchange);
        }
Beispiel #10
0
        /// <summary>
        /// To save the board.
        /// </summary>
        /// <param name="board">Trading board.</param>
        public void Save(ExchangeBoard board)
        {
            if (board == null)
            {
                throw new ArgumentNullException(nameof(board));
            }

            _entityRegistry.ExchangeBoards.Save(board);

            lock (_boards.SyncRoot)
            {
                if (!_boards.TryAdd(board.Code, board))
                {
                    return;
                }
            }

            BoardAdded.SafeInvoke(board);
        }
Beispiel #11
0
        /// <summary>
        /// Загрузить настройки.
        /// </summary>
        /// <param name="storage">Хранилище настроек.</param>
        public void Load(SettingsStorage storage)
        {
            var drives = storage
                         .GetValue <IEnumerable <SettingsStorage> >("Drives")
                         .Select(s => s.LoadEntire <IMarketDataDrive>())
                         .ToArray();

            lock (_drives.SyncRoot)
            {
                foreach (var drive in drives)
                {
                    _drives.TryAdd(drive.Path, drive);
                }
            }

            if (storage.ContainsKey("DefaultDrive"))
            {
                DefaultDrive = _drives[storage.GetValue <string>("DefaultDrive")];
            }
        }
 /// <inheritdoc />
 public virtual void SetAdapter(string portfolioName, IMessageAdapter adapter)
 {
     lock (_adapters.SyncRoot)
         _adapters.TryAdd(portfolioName, adapter);
 }