private bool CanExecuteMarketMonitor()
        {
            bool emptyCurrentMarketID = CurrentMarketID == "";
            bool alreadyInMonitoring  = MarketsAreInMonitoring.ContainsKey(CurrentMarketID);

            return(!emptyCurrentMarketID && !alreadyInMonitoring);
        }
        private void ExecuteMarketMonitor()
        {
            if (MarketsAreInMonitoring.ContainsKey(CurrentMarketID))
            {
                return;
            }

            MarketMonitoringWindow win = new MarketMonitoringWindow();

            MarketInformation         m  = model.MarketInformationDict[CurrentMarketID];
            MarketMonitoringViewModel vm = new MarketMonitoringViewModel(CurrentMarketID, m, OneSecIntervalTimer);

            win.DataContext = vm;

            //добавляем рынок в список окон мониторинга
            MarketsAreInMonitoring.Add(CurrentMarketID, new Tuple <MarketMonitoringWindow, MarketMonitoringViewModel>(win, vm));

            //при закрытии окна удаляем CurrentMarketID из списка мониторинга
            win.Closed += (sender, e) =>
            {
                MarketMonitoringWindow window = sender as MarketMonitoringWindow;

                string s = string.Empty;
                foreach (var item in MarketsAreInMonitoring)
                {
                    if (item.Value.Item1 != window)
                    {
                        continue;
                    }

                    s = item.Key;
                    break;
                }

                if (s == string.Empty)
                {
                    return;
                }

                MarketsAreInMonitoring[s].Item2.Dispose();
                MarketsAreInMonitoring.Remove(s);
            };

            win.Show();
        }
Example #3
0
        private void UpdateGrid()
        {
            SolidColorBrush BlueColor   = Brushes.Blue;
            SolidColorBrush BlackColor  = Brushes.Black;
            SolidColorBrush PurpleColor = Brushes.Purple;

            int           i    = 0;
            List <string> keys = MarketInformationDict.Select(x => x.MarketId).ToList();

            foreach (string key in keys)
            {
                string suffix;
                if (MarketsAreInMonitoring.ContainsKey(key) && key != "")
                {
                    suffix = " *";
                }
                else
                {
                    suffix = "";
                }

                var i1 = i;
                Grid[i, 0].Dispatcher.Invoke(() => Grid[i1, 0].Text = key + suffix);

                var m   = MarketInformationDict.Where(x => x.MarketId == key).FirstOrDefault();
                int idx = MarketInformationDict.IndexOf(m);
                var a   = MarketInformationDict[idx].Mbi.Last().CasesAnalisys;

                Gaps gaps = Gaps.empty;

                if (a[TradeCases.BL1B2].Gap == 0 && a[TradeCases.BL2B1].Gap == 0)
                {
                    gaps = Gaps.none;
                }

                if (gaps != Gaps.none && a[TradeCases.BL1B2].Gap < 2 && a[TradeCases.BL2B1].Gap < 2)
                {
                    gaps = Gaps.one;
                }

                if (gaps == Gaps.empty)
                {
                    gaps = Gaps.more;
                }

                switch (gaps)
                {
                case Gaps.one:
                    var i2 = i;
                    Grid[i, 1].Dispatcher.Invoke(() => Grid[i2, 1].Foreground = BlueColor);
                    break;

                case Gaps.more:
                    var i3 = i;
                    Grid[i, 1].Dispatcher.Invoke(() => Grid[i3, 1].Foreground = PurpleColor);
                    break;

                default:
                    var i4 = i;
                    Grid[i, 1].Dispatcher.Invoke(() => Grid[i4, 1].Foreground = BlackColor);
                    break;
                }

                string str = MarketInformationDict[idx].TotalMatched.ToString("N0", CultureInfo.CurrentCulture);
                var    i5  = i;
                Grid[i, 1].Dispatcher.Invoke(() => Grid[i5, 1].Text = str);

                i++;
            }
        }