Beispiel #1
0
        /// <summary>
        /// To get a board by its code. If board with the passed name does not exist, then it will be created.
        /// </summary>
        /// <param name="code">Board code.</param>
        /// <param name="createBoard">The handler creating a board, if it is not found. If the value is <see langword="null" />, then the board is created by default initialization.</param>
        /// <returns>Exchange board.</returns>
        public static ExchangeBoard GetOrCreateBoard(string code, Func <string, ExchangeBoard> createBoard = null)
        {
            if (code.IsEmpty())
            {
                throw new ArgumentNullException(nameof(code));
            }

            if (code.CompareIgnoreCase("RTS"))
            {
                return(Forts);
            }

            var board = ExchangeInfoProvider.GetExchangeBoard(code);

            if (board != null)
            {
                return(board);
            }

            if (createBoard == null)
            {
                var exchange = ExchangeInfoProvider.GetExchange(code);

                if (exchange == null)
                {
                    exchange = new Exchange {
                        Name = code
                    };
                    ExchangeInfoProvider.Save(exchange);
                }

                board = new ExchangeBoard
                {
                    Code     = code,
                    Exchange = exchange
                };
            }
            else
            {
                board = createBoard(code);

                if (ExchangeInfoProvider.GetExchange(board.Exchange.Name) == null)
                {
                    ExchangeInfoProvider.Save(board.Exchange);
                }
            }

            SaveBoard(board);

            return(board);
        }
Beispiel #2
0
        ///// <summary>
        ///// Все площадки.
        ///// </summary>
        //public static ExchangeBoard[] AllBoards
        //{
        //	get { return ExchangeInfoProvider.Boards; }
        //}

        /// <summary>
        /// To get a board by its code.
        /// </summary>
        /// <param name="code">Board code.</param>
        /// <returns>Found board. If board with the passed name does not exist, then <see langword="null" /> will be returned.</returns>
        public static ExchangeBoard GetBoard(string code)
        {
            return(code.CompareIgnoreCase("RTS") ? Forts : ExchangeInfoProvider.GetExchangeBoard(code));
        }