void UpdateUI()
        {
            if (tradeAnalyzer == null)
            {
                return;
            }

            List<ToolStripButton> sessionsButtons = GetSessionsButtons();

            foreach(AnalyzerSession session in tradeAnalyzer.SessionManager.Sessions)
            {
                bool sessionFound = false;
                foreach(ToolStripButton button in sessionsButtons)
                {
                    if (((AnalyzerSessionControl)button.Tag).AnalyzerSession == session)
                    {// Session found and presented, continue.
                        sessionsButtons.Remove(button);
                        sessionFound = true;
                        break;
                    }
                }

                if (sessionFound)
                {
                    continue;
                }

                // Session not found, create new button for it.
                AnalyzerSessionControl control = new AnalyzerSessionControl();
                control.Visible = false;
                control.Dock = DockStyle.Fill;
                control.Parent = this;
                control.BringToFront();
                control.AnalyzerSession = session;
                control.CreateControl();

                ((DataProvider)session.DataProvider).IsAddCandle = true;
                ((DataProvider)session.DataProvider).Process(null, null);

                ToolStripButton newButton = new ToolStripButton(session.SessionInfo.Id, Properties.Resources.coins3);

                //ToolStripButton newButton = new TimerButton(session.SessionInfo.Id, Properties.Resources.PIN_GREY);
                newButton.Tag = control;
                newButton.Click += new EventHandler(toolStripButton_Click);
                newButton.Enabled = true;
                newButton.BackColor = Color.Yellow;
                this.toolStrip.Items.Add(newButton);

                btnOriFont = newButton.Font;
                //newButton.BackColor = Color.Pink;
                btnBOriColor = newButton.BackColor;
                btnFOriColor = newButton.ForeColor;
                //this.toolStrip.RenderMode = ToolStripRenderMode.Custom;

                // Show newly created session.
                toolStripButton_Click(newButton, EventArgs.Empty);

            }

            // Those buttons no longer have corresponding sessions and must be removed.
            foreach(ToolStripButton button in sessionsButtons)
            {
                ((AnalyzerSessionControl)(button.Tag)).AnalyzerSession = null;
                ((AnalyzerSessionControl)(button.Tag)).Visible = false;
                ((AnalyzerSessionControl)(button.Tag)).Dispose();

                button.Click -= new EventHandler(toolStripButton_Click);
                toolStrip.Items.Remove(button);
            }

            // Make sure there is at least one visibile session if there are any.
            sessionsButtons = GetSessionsButtons();
            bool visibleSessionFound = false;
            foreach (ToolStripButton button in sessionsButtons)
            {
                if (((AnalyzerSessionControl)(button.Tag)).Visible)
                {
                    visibleSessionFound = true;
                    break;
                }
            }

            if (visibleSessionFound == false && sessionsButtons.Count > 0)
            {// Show the first available session.
                toolStripButton_Click(sessionsButtons[0], EventArgs.Empty);
            }
        }
Example #2
0
        void UpdateUI()
        {
            if (tradeAnalyzer == null)
            {
                return;
            }

            List <ToolStripButton> sessionsButtons = GetSessionsButtons();

            foreach (AnalyzerSession session in tradeAnalyzer.SessionManager.Sessions)
            {
                bool sessionFound = false;
                foreach (ToolStripButton button in sessionsButtons)
                {
                    if (((AnalyzerSessionControl)button.Tag).AnalyzerSession == session)
                    {// Session found and presented, continue.
                        sessionsButtons.Remove(button);
                        sessionFound = true;
                        break;
                    }
                }

                if (sessionFound)
                {
                    continue;
                }

                // Session not found, create new button for it.
                AnalyzerSessionControl control = new AnalyzerSessionControl();
                control.Visible = false;
                control.Dock    = DockStyle.Fill;
                control.Parent  = this;
                control.BringToFront();
                control.AnalyzerSession = session;
                control.CreateControl();

                ((DataProvider)session.DataProvider).IsAddCandle = true;
                ((DataProvider)session.DataProvider).Process(null, null);

                ToolStripButton newButton = new ToolStripButton(session.SessionInfo.Id, Properties.Resources.coins3);

                //ToolStripButton newButton = new TimerButton(session.SessionInfo.Id, Properties.Resources.PIN_GREY);
                newButton.Tag       = control;
                newButton.Click    += new EventHandler(toolStripButton_Click);
                newButton.Enabled   = true;
                newButton.BackColor = Color.Yellow;
                this.toolStrip.Items.Add(newButton);

                btnOriFont = newButton.Font;
                //newButton.BackColor = Color.Pink;
                btnBOriColor = newButton.BackColor;
                btnFOriColor = newButton.ForeColor;
                //this.toolStrip.RenderMode = ToolStripRenderMode.Custom;


                // Show newly created session.
                toolStripButton_Click(newButton, EventArgs.Empty);
            }

            // Those buttons no longer have corresponding sessions and must be removed.
            foreach (ToolStripButton button in sessionsButtons)
            {
                ((AnalyzerSessionControl)(button.Tag)).AnalyzerSession = null;
                ((AnalyzerSessionControl)(button.Tag)).Visible         = false;
                ((AnalyzerSessionControl)(button.Tag)).Dispose();

                button.Click -= new EventHandler(toolStripButton_Click);
                toolStrip.Items.Remove(button);
            }

            // Make sure there is at least one visibile session if there are any.
            sessionsButtons = GetSessionsButtons();
            bool visibleSessionFound = false;

            foreach (ToolStripButton button in sessionsButtons)
            {
                if (((AnalyzerSessionControl)(button.Tag)).Visible)
                {
                    visibleSessionFound = true;
                    break;
                }
            }

            if (visibleSessionFound == false && sessionsButtons.Count > 0)
            {// Show the first available session.
                toolStripButton_Click(sessionsButtons[0], EventArgs.Empty);
            }
        }