Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Hive.Client.Core/3.2/ConfigurationManager/ConfigManager.cs @ 2108

Last change on this file since 2108 was 2108, checked in by kgrading, 15 years ago

various updates (#467)

File size: 5.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Collections.Generic;
24using System.Linq;
25using System.Text;
26using HeuristicLab.Hive.Contracts.BusinessObjects;
27using HeuristicLab.Hive.Client.ExecutionEngine;
28using HeuristicLab.Hive.Client.Core.ClientConsoleService;
29using HeuristicLab.Hive.Client.Communication;
30using HeuristicLab.Hive.Client.Core.Properties;
31using HeuristicLab.Hive.Contracts;
32
33namespace HeuristicLab.Hive.Client.Core.ConfigurationManager {
34  /// <summary>
35  /// accesses the Server and sends his data (uuid, uptimes, hardware config)
36  /// </summary>
37  public class ConfigManager {
38    private static ConfigManager instance = null;
39    public static ConfigManager Instance {
40      get {
41        if (instance == null) {
42          instance = new ConfigManager();
43        }
44        return instance;
45      }
46    }
47
48    public Core Core { get; set; }   
49    private ClientInfo hardwareInfo;       
50
51    /// <summary>
52    /// Constructor for the singleton, must recover Guid, Calendar, ...
53    /// </summary>
54    private ConfigManager() {     
55      hardwareInfo = new ClientInfo();
56
57      if (Settings.Default.Guid == Guid.Empty) {
58        hardwareInfo.Id = Guid.NewGuid();
59        Settings.Default.Guid = hardwareInfo.Id;
60        Settings.Default.Save();
61      } else
62        hardwareInfo.Id = Settings.Default.Guid;
63     
64      hardwareInfo.NrOfCores = Environment.ProcessorCount;
65      hardwareInfo.Memory = 1024;
66      hardwareInfo.Name = Environment.MachineName;
67    }
68
69    /// <summary>
70    /// Get all the Information about the client
71    /// </summary>
72    /// <returns>the ClientInfo object</returns>
73    public ClientInfo GetClientInfo() {
74      hardwareInfo.Login = WcfService.Instance.ConnectedSince;
75      return hardwareInfo;         
76    }
77
78    /// <summary>
79    /// Returns the connectioncontainer with the IP and Port, storred in the Settings framework
80    /// </summary>
81    /// <returns>The IP and Port of the server</returns>
82    public ConnectionContainer GetServerIPAndPort() {
83      ConnectionContainer cc = new ConnectionContainer();
84      cc.IPAdress = Settings.Default.ServerIP;
85      cc.Port = Settings.Default.ServerPort;
86      return cc;
87    }
88
89    /// <summary>
90    /// Sets and saves IP and Port in the Settings framework
91    /// </summary>
92    /// <param name="cc"></param>
93    public void SetServerIPAndPort(ConnectionContainer cc) {
94      Settings.Default.ServerIP = cc.IPAdress;
95      Settings.Default.ServerPort = cc.Port;
96      Settings.Default.Save();
97    }
98    /// <summary>
99    /// collects and returns information that get displayed by the Client Console
100    /// </summary>
101    /// <returns></returns>
102    public StatusCommons GetStatusForClientConsole() {
103      //Todo: Locking
104      StatusCommons st = new StatusCommons();
105      st.ClientGuid = hardwareInfo.Id;
106     
107      st.Status = WcfService.Instance.ConnState;
108      st.ConnectedSince = WcfService.Instance.ConnectedSince;
109
110      st.JobsAborted = ClientStatusInfo.JobsAborted;
111      st.JobsDone = ClientStatusInfo.JobsProcessed;
112      st.JobsFetched = ClientStatusInfo.JobsFetched;     
113
114      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
115      st.Jobs = new List<JobStatus>();
116
117      lock (engines) {
118        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
119          Executor e = kvp.Value;
120          st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
121        }
122      }
123      return st;     
124    }
125
126    public Dictionary<Guid, double> GetProgressOfAllJobs() {
127      Dictionary<Guid, double> prog = new Dictionary<Guid, double>();
128      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
129      lock (engines) {
130        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
131          Executor e = kvp.Value;
132          if (!e.JobIsFinished)
133            prog[e.JobId] = e.Progress;
134        }
135      }
136      return prog;
137    }
138
139    public int GetUsedCores() {
140      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
141      Dictionary<Guid, Job> jobs = Core.GetJobs();
142      int usedCores = 0;
143      lock (engines) {       
144        foreach (KeyValuePair<Guid, Job> kvp in jobs)
145          usedCores += kvp.Value.CoresNeeded;
146      }
147      return usedCores;
148    }
149
150  }
151}
Note: See TracBrowser for help on using the repository browser.