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 @ 5636

Last change on this file since 5636 was 5636, checked in by cneumuel, 13 years ago

#1233

  • updated jobstates documentation
  • enhanced ganttChart
  • fixed setting of jobstates
  • added option to force lifecycle-trigger (mainly for testing purposes)
File size: 4.9 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;
26using HeuristicLab.Core.Views;
27using HeuristicLab.MainForm;
28
29namespace HeuristicLab.Clients.Hive.Views {
30  [View("StateLogGanttChartList View")]
31  [Content(typeof(IItemList<StateLogList>), IsDefaultView = true)]
32  public sealed partial class StateLogGanttChartListView : ItemView {
33    public new IItemList<StateLogList> Content {
34      get { return (IItemList<StateLogList>)base.Content; }
35      set { base.Content = value; }
36    }
37
38    public StateLogGanttChartListView() {
39      InitializeComponent();
40    }
41
42    protected override void DeregisterContentEvents() {
43      // Deregister your event handlers here
44      base.DeregisterContentEvents();
45    }
46
47    protected override void RegisterContentEvents() {
48      base.RegisterContentEvents();
49      // Register your event handlers here
50    }
51
52    #region Event Handlers (Content)
53    // Put event handlers of the content here
54    #endregion
55
56    protected override void OnContentChanged() {
57      base.OnContentChanged();
58      if (Content == null) {
59        // Add code when content has been changed and is null
60        ganttChart.Reset();
61      } else {
62        // Add code when content has been changed and is not null
63        ganttChart.Reset();
64        SetupCategories(ganttChart);
65
66        DateTime maxValue = Content.Max(x => x.Max(y => y.DateTime));
67        var upperLimit = DateTime.FromOADate(Math.Min(DateTime.Now.AddSeconds(10).ToOADate(), maxValue.AddSeconds(10).ToOADate()));
68
69        for (int i = 0; i < Content.Count; i++) {
70          for (int j = 0; j < Content[i].Count - 1; j++) {
71            if(Content[i][j].State != JobState.Offline && Content[i][j].State != JobState.Finished)
72              AddData(ganttChart, i.ToString(), Content[i][j], Content[i][j+1], upperLimit);
73          }
74          if(Content[i].Count > 0) {
75            AddData(ganttChart, i.ToString(), Content[i][Content[i].Count - 1], null, upperLimit);
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.Transferring.ToString(), Color.CornflowerBlue);
85      ganttChart.AddCategory(JobState.Calculating.ToString(), Color.DarkGreen);
86      ganttChart.AddCategory(JobState.Finished.ToString(), Color.White);
87      ganttChart.AddCategory(JobState.Aborted.ToString(), Color.Orange);
88      ganttChart.AddCategory(JobState.Failed.ToString(), Color.Red);
89    }
90
91    //private void AddData(int i, int j, DateTime upperLimit) {
92    //  DateTime until = j < Content[i].Count - 1 ? Content[i][j + 1].DateTime : upperLimit;
93    //  TimeSpan duration = until - Content[i][j].DateTime;
94    //  string tooltip = string.Format("State: {0}\nDuration: {1}\n{2} - {3}", Content[i][j].State, Content[i][j].DateTime, duration, until);
95    //  if (!string.IsNullOrEmpty(Content[i][j].Exception))
96    //    tooltip += "\n" + Content[i][j].Exception;
97    //  ganttChart.AddData(i + 1, Content[i][j].State.ToString(), Content[i][j].DateTime, until, tooltip, false);
98    //}
99
100    public static void AddData(GanttChart ganttChart, string name, StateLog from, StateLog to, DateTime upperLimit) {
101      DateTime until = to != null ? to.DateTime : upperLimit;
102      TimeSpan duration = until - from.DateTime;
103      string tooltip = string.Format("State: {0}\nDuration: {1}\n{2} - {3}", from.State, from.DateTime, duration, until);
104      if (!string.IsNullOrEmpty(from.Exception))
105        tooltip += "\n" + from.Exception;
106      ganttChart.AddData(name, from.State.ToString(), from.DateTime, until, tooltip, false);
107    }
108   
109    protected override void SetEnabledStateOfControls() {
110      base.SetEnabledStateOfControls();
111      // Enable or disable controls based on whether the content is null or the view is set readonly
112    }
113
114    #region Event Handlers (child controls)
115    // Put event handlers of child controls here.
116    #endregion
117  }
118}
Note: See TracBrowser for help on using the repository browser.