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
RevLine 
[932]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;
[944]30using HeuristicLab.Hive.Client.Core.Properties;
[2107]31using HeuristicLab.Hive.Contracts;
[932]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>
[1132]54    private ConfigManager() {     
[1034]55      hardwareInfo = new ClientInfo();
[944]56
[1034]57      if (Settings.Default.Guid == Guid.Empty) {
[1449]58        hardwareInfo.Id = Guid.NewGuid();
59        Settings.Default.Guid = hardwareInfo.Id;
[1034]60        Settings.Default.Save();
61      } else
[1449]62        hardwareInfo.Id = Settings.Default.Guid;
[944]63     
[932]64      hardwareInfo.NrOfCores = Environment.ProcessorCount;
65      hardwareInfo.Memory = 1024;
66      hardwareInfo.Name = Environment.MachineName;
67    }
68
[1132]69    /// <summary>
70    /// Get all the Information about the client
71    /// </summary>
72    /// <returns>the ClientInfo object</returns>
[932]73    public ClientInfo GetClientInfo() {
[993]74      hardwareInfo.Login = WcfService.Instance.ConnectedSince;
[932]75      return hardwareInfo;         
76    }
77
[1132]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>
[944]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
[1132]89    /// <summary>
90    /// Sets and saves IP and Port in the Settings framework
91    /// </summary>
92    /// <param name="cc"></param>
[944]93    public void SetServerIPAndPort(ConnectionContainer cc) {
94      Settings.Default.ServerIP = cc.IPAdress;
95      Settings.Default.ServerPort = cc.Port;
[1034]96      Settings.Default.Save();
[944]97    }
[1132]98    /// <summary>
99    /// collects and returns information that get displayed by the Client Console
100    /// </summary>
101    /// <returns></returns>
[932]102    public StatusCommons GetStatusForClientConsole() {
[1379]103      //Todo: Locking
[932]104      StatusCommons st = new StatusCommons();
[1449]105      st.ClientGuid = hardwareInfo.Id;
[932]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
[1449]114      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
[968]115      st.Jobs = new List<JobStatus>();
[1031]116
[1379]117      lock (engines) {
[1449]118        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
[1379]119          Executor e = kvp.Value;
120          st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
121        }
[932]122      }
123      return st;     
124    }
[1119]125
[1449]126    public Dictionary<Guid, double> GetProgressOfAllJobs() {
127      Dictionary<Guid, double> prog = new Dictionary<Guid, double>();
128      Dictionary<Guid, Executor> engines = Core.GetExecutionEngines();
[1379]129      lock (engines) {
[1449]130        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
[1379]131          Executor e = kvp.Value;
[2108]132          if (!e.JobIsFinished)
[2107]133            prog[e.JobId] = e.Progress;
[1379]134        }
[1119]135      }
136      return prog;
137    }
138
[1755]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
[932]150  }
151}
Note: See TracBrowser for help on using the repository browser.