Free cookie consent management tool by TermsFeed Policy Generator

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

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

fixed bug (#432)

File size: 3.6 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;
31
32namespace HeuristicLab.Hive.Client.Core.ConfigurationManager {
33  /// <summary>
34  /// accesses the Server and sends his data (uuid, uptimes, hardware config)
35  /// </summary>
36  public class ConfigManager {
37    private static ConfigManager instance = null;
38    public static ConfigManager Instance {
39      get {
40        if (instance == null) {
41          instance = new ConfigManager();
42        }
43        return instance;
44      }
45    }
46
47    public Core Core { get; set; }   
48    private ClientInfo hardwareInfo;       
49
50    /// <summary>
51    /// Constructor for the singleton, must recover Guid, Calendar, ...
52    /// </summary>
53    private ConfigManager() {
54      //retrive GUID from XML file, or burn in hell. as in hell. not heaven.
55      //this won't work this way. We need a plugin for XML Handling.     
56      hardwareInfo = new ClientInfo();     
57
58      if (Settings.Default.Guid == Guid.Empty)
59        hardwareInfo.ClientId = Guid.NewGuid();
60      else
61        hardwareInfo.ClientId = Settings.Default.Guid;
62     
63      hardwareInfo.NrOfCores = Environment.ProcessorCount;
64      hardwareInfo.Memory = 1024;
65      hardwareInfo.Name = Environment.MachineName;
66    }
67
68    public ClientInfo GetClientInfo() {
69      return hardwareInfo;         
70    }
71
72    public ConnectionContainer GetServerIPAndPort() {
73      ConnectionContainer cc = new ConnectionContainer();
74      cc.IPAdress = Settings.Default.ServerIP;
75      cc.Port = Settings.Default.ServerPort;
76      return cc;
77    }
78
79    public void SetServerIPAndPort(ConnectionContainer cc) {
80      Settings.Default.ServerIP = cc.IPAdress;
81      Settings.Default.ServerPort = cc.Port;
82    }
83
84    public StatusCommons GetStatusForClientConsole() {
85      StatusCommons st = new StatusCommons();
86      st.ClientGuid = hardwareInfo.ClientId;
87     
88      st.Status = WcfService.Instance.ConnState;
89      st.ConnectedSince = WcfService.Instance.ConnectedSince;
90
91      st.JobsAborted = ClientStatusInfo.JobsAborted;
92      st.JobsDone = ClientStatusInfo.JobsProcessed;
93      st.JobsFetched = ClientStatusInfo.JobsFetched;     
94
95      Dictionary<long, Executor> engines = Core.GetExecutionEngines();
96      st.Jobs = new List<JobStatus>();
97      foreach (KeyValuePair<long, Executor> kvp in engines) {
98        Executor e = kvp.Value;
99        st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
100      }
101      return st;     
102    }
103  }
104}
Note: See TracBrowser for help on using the repository browser.