Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.3/SlaveMainViewBase.cs @ 6945

Last change on this file since 6945 was 6945, checked in by ascheibe, 12 years ago

#1233 slave: catch more errors and log them to the windows event log

File size: 4.3 KB
RevLine 
[5314]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
[5795]22using System;
23using System.Threading;
24using System.Threading.Tasks;
[5314]25using System.Windows.Forms;
[6456]26using HeuristicLab.Clients.Hive.SlaveCore.Views.Properties;
[5314]27using HeuristicLab.Core.Views;
28using HeuristicLab.MainForm;
29
[5599]30namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
[5314]31
[6734]32  [View("HeuristicLab Slave Main View Base")]
[6730]33  [Content(typeof(SlaveItem), IsDefaultView = false)]
34  public partial class SlaveMainViewBase : ItemView {
[5314]35
[6734]36    public event EventHandler VisibilitySwitched;
37    public void OnVisibilitySwitched() {
38      var handler = VisibilitySwitched;
39      if (handler != null) handler(this, new EventArgs());
[6730]40    }
41
[5314]42    public new SlaveItem Content {
43      get { return (SlaveItem)base.Content; }
[5320]44      set {
45        if (base.Content != value) {
46          base.Content = value;
47        }
48      }
[5314]49    }
50
[6730]51    void Content_UserVisibleMessageFired(object sender, Common.EventArgs<string> e) {
52      if (Settings.Default.ShowBalloonTips) {
53        notifyIcon.ShowBalloonTip(2000, "HeuristicLab Hive", e.Value, ToolTipIcon.Info);
[6263]54      }
[6730]55    }
[5826]56
[6730]57    public SlaveMainViewBase() {
58      InitializeComponent();
[5314]59    }
60
61    #region Register Content Events
62    protected override void DeregisterContentEvents() {
[6945]63      Content.CoreConnectionChanged -= new EventHandler<Common.EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
[5320]64      base.DeregisterContentEvents();
[5314]65    }
66
67    protected override void RegisterContentEvents() {
68      base.RegisterContentEvents();
[6945]69      Content.CoreConnectionChanged += new EventHandler<Common.EventArgs<CoreConnection>>(Content_CoreConnectionChanged);
[5314]70    }
[6945]71
72    void Content_CoreConnectionChanged(object sender, Common.EventArgs<CoreConnection> e) {
73      if (e.Value == CoreConnection.Offline) {
74        Connector();
75      }
76    }
[5314]77    #endregion
78
79    protected override void OnContentChanged() {
80      base.OnContentChanged();
[6257]81
[6730]82      logView.Content = Content;
[6823]83      slaveView.Content = Content;
[6730]84      if (Content != null) {
85        Content.UserVisibleMessageFired += new System.EventHandler<Common.EventArgs<string>>(Content_UserVisibleMessageFired);
86        Task.Factory.StartNew(Connector);
[6945]87      } else {
88        Content.UserVisibleMessageFired -= new System.EventHandler<Common.EventArgs<string>>(Content_UserVisibleMessageFired);
[5314]89      }
90    }
91
92    protected override void SetEnabledStateOfControls() {
93      base.SetEnabledStateOfControls();
94    }
95
[6823]96    private void notifyIcon_Click(object sender, MouseEventArgs e) {
97      if (e.Button == MouseButtons.Left) {
98        OnVisibilitySwitched();
99      }
[5314]100    }
101
[6730]102    private void closeToolStripMenuItem_Click(object sender, EventArgs e) {
103      Application.Exit();
[5314]104    }
[6257]105
[6764]106    private void homepageToolStripMenuItem_Click(object sender, EventArgs e) {
107      System.Diagnostics.Process.Start("http://dev.heuristiclab.com");
108    }
109
[6730]110    private void notifyIcon_BalloonTipClicked(object sender, EventArgs e) {
[6734]111      OnVisibilitySwitched();
[5451]112    }
[5602]113
[6730]114    private void Connector() {
[6743]115      ((SlaveItem)base.Content).Open();
[6730]116      bool connected = false;
117      while (!connected) {
[6743]118        connected = ((SlaveItem)base.Content).ReconnectToSlaveCore();
[6257]119
[6730]120        if (!connected) {
121          Thread.Sleep(1000);
[5826]122        }
123      }
[6730]124      this.Invoke(new Action(SetEnabledStateOfControls));
[5826]125    }
[6823]126
127    private void btnAbout_Click(object sender, EventArgs e) {
128      AboutDialog dialog = new AboutDialog();
129      dialog.ShowDialog();
130    }
[5314]131  }
132}
Note: See TracBrowser for help on using the repository browser.