예제 #1
0
        /// <summary>
        /// Запрос групп счетов с сервера
        /// </summary>
        /// <returns></returns>
        public IEnumerable <AccountGroupItem> GetAccountGroups(string groupCode = "")
        {
            Logger.Info(String.Format("попытка запросить c сервера все группы счетов и их мапинг в класс {0}", typeof(AccountGroupItem).Name));
            using (var ctx = DatabaseContext.Instance.Make())
            {
                var allDealers = dealerRepository.GetAllDealerDescription(ctx).ToList();
                IEnumerable <AccountGroupItem> result;
                try
                {
                    result = new List <AccountGroupItem>(ctx.GetGroupsWithAccountsWrapped(!String.IsNullOrEmpty(groupCode.Trim()) ? groupCode : null).
                                                         Select(ag => new AccountGroupItem
                    {
                        Code                   = ag.Code,
                        Name                   = ag.Name,
                        IsReal                 = ag.IsReal,
                        BrokerLeverage         = (float)ag.BrokerLeverage,
                        MarginCallPercentLevel = (float)ag.MarginCallPercentLevel,
                        StopoutPercentLevel    = (float)ag.StopoutPercentLevel,
                        AccountsCount          = ag.Accounts.HasValue ? ag.Accounts.Value : 0,
                        Dealer                 = new DealerDescription
                        {
                            Code          = ag.DealerCode,
                            DealerEnabled = ag.DealerEnabled.HasValue && ag.DealerEnabled.Value,
                            FileName      = ag.FileName
                        },
                        MessageQueue        = ag.MessageQueue,
                        SessionName         = ag.SessionName,
                        HedgingAccount      = ag.HedgingAccount,
                        SenderCompId        = ag.SenderCompId,
                        SwapFree            = ag.SwapFree,
                        Markup              = (AccountGroup.MarkupType)ag.MarkupType,
                        DefaultMarkupPoints = (float)ag.DefaultMarkupPoints,
                        DefaultVirtualDepo  = ag.DefaultVirtualDepo.HasValue ? ag.DefaultVirtualDepo.Value : 0,
                        Dealers             = allDealers.Select(x => new SelectListItem
                        {
                            Text     = x.Code,
                            Value    = x.Code,
                            Selected = x.Code == ag.DealerCode
                        }).ToList()
                    }));

                    foreach (var accountGroupRecord in result)
                    {
                        if (accountGroupRecord.Dealer.Code == null)
                        {
                            accountGroupRecord.Dealers.Insert(0, new SelectListItem {
                                Text = Resource.TitleNotSelected, Value = null, Selected = true
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    var info = String.Format("Не удалось получить группы счетов {0}", groupCode);
                    Logger.Error(info, ex);
                    throw new Exception(info);
                }
                return(result);
            }
        }