Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Views/3.4/ExperimentManager/StateLogGanttChartListView.cs @ 6004

Last change on this file since 6004 was 6004, checked in by ascheibe, 13 years ago

#1233

  • fix pause/stop bug when serializing big experiments
  • use proper newlines
  • use GetPlugin(..) instead of GetPlugins()
File size: 4.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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
22using System;
23using System.Drawing;
24using System.Linq;
25using HeuristicLab.Core.Views;
26using HeuristicLab.MainForm;
27
28namespace HeuristicLab.Clients.Hive.Views {
29  [View("StateLogGanttChartList View")]
30  [Content(typeof(StateLogListList), true)]
31  public sealed partial class StateLogGanttChartListView : ItemView {
32    public new StateLogListList Content {
33      get { return (StateLogListList)base.Content; }
34      set { base.Content = value; }
35    }
36
37    public StateLogGanttChartListView() {
38      InitializeComponent();
39    }
40
41    protected override void DeregisterContentEvents() {
42      // Deregister your event handlers here
43      base.DeregisterContentEvents();
44    }
45
46    protected override void RegisterContentEvents() {
47      base.RegisterContentEvents();
48      // Register your event handlers here
49    }
50
51    #region Event Handlers (Content)
52    // Put event handlers of the content here
53    #endregion
54
55    protected override void OnContentChanged() {
56      base.OnContentChanged();
57      if (Content == null) {
58        // Add code when content has been changed and is null
59        ganttChart.Reset();
60      } else {
61        // Add code when content has been changed and is not null
62        ganttChart.Reset();
63        SetupCategories(ganttChart);
64        if (Content.Count > 0) {
65          DateTime maxValue = Content.Max(x => x.Count > 0 ? x.Max(y => y.DateTime) : DateTime.MinValue);
66          var upperLimit = DateTime.FromOADate(Math.Min(DateTime.Now.AddSeconds(10).ToOADate(), maxValue.AddSeconds(10).ToOADate()));
67
68          for (int i = 0; i < Content.Count; i++) {
69            for (int j = 0; j < Content[i].Count - 1; j++) {
70              if (Content[i][j].State != JobState.Offline)
71                AddData(ganttChart, i.ToString(), Content[i][j], Content[i][j + 1], upperLimit);
72            }
73            if (Content[i].Count > 0) {
74              AddData(ganttChart, i.ToString(), Content[i][Content[i].Count - 1], null, upperLimit);
75            }
76          }
77        }
78      }
79    }
80
81    public static void SetupCategories(GanttChart ganttChart) {
82      ganttChart.AddCategory(JobState.Offline.ToString(), Color.Gainsboro);
83      ganttChart.AddCategory(JobState.Waiting.ToString(), Color.NavajoWhite);
84      ganttChart.AddCategory(JobState.Paused.ToString(), Color.PaleVioletRed);
85      ganttChart.AddCategory(JobState.Transferring.ToString(), Color.CornflowerBlue);
86      ganttChart.AddCategory(JobState.Calculating.ToString(), Color.DarkGreen);
87      ganttChart.AddCategory(JobState.Finished.ToString(), Color.White);
88      ganttChart.AddCategory(JobState.Aborted.ToString(), Color.Orange);
89      ganttChart.AddCategory(JobState.Failed.ToString(), Color.Red);
90    }
91
92    public static void AddData(GanttChart ganttChart, string name, StateLog from, StateLog to, DateTime upperLimit) {
93      DateTime until = to != null ? to.DateTime : upperLimit;
94      TimeSpan duration = until - from.DateTime;
95      string tooltip = string.Format("State: {0} " + Environment.NewLine + " Duration: {1} " + Environment.NewLine + " {2} - {3}", from.State, duration, from.DateTime, until);
96      if (!string.IsNullOrEmpty(from.Exception))
97        tooltip += Environment.NewLine + from.Exception;
98      ganttChart.AddData(name, from.State.ToString(), from.DateTime, until, tooltip, false);
99    }
100
101    protected override void SetEnabledStateOfControls() {
102      base.SetEnabledStateOfControls();
103      // Enable or disable controls based on whether the content is null or the view is set readonly
104    }
105
106    #region Event Handlers (child controls)
107    // Put event handlers of child controls here.
108    #endregion
109  }
110}
Note: See TracBrowser for help on using the repository browser.