Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1033 was 1031, checked in by kgrading, 16 years ago

implementation for #438

File size: 3.7 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      hardwareInfo.Login = WcfService.Instance.ConnectedSince;
70      return hardwareInfo;         
71    }
72
73    public ConnectionContainer GetServerIPAndPort() {
74      ConnectionContainer cc = new ConnectionContainer();
75      cc.IPAdress = Settings.Default.ServerIP;
76      cc.Port = Settings.Default.ServerPort;
77      return cc;
78    }
79
80    public void SetServerIPAndPort(ConnectionContainer cc) {
81      Settings.Default.ServerIP = cc.IPAdress;
82      Settings.Default.ServerPort = cc.Port;
83    }
84
85    public StatusCommons GetStatusForClientConsole() {
86      StatusCommons st = new StatusCommons();
87      st.ClientGuid = hardwareInfo.ClientId;
88     
89      st.Status = WcfService.Instance.ConnState;
90      st.ConnectedSince = WcfService.Instance.ConnectedSince;
91
92      st.JobsAborted = ClientStatusInfo.JobsAborted;
93      st.JobsDone = ClientStatusInfo.JobsProcessed;
94      st.JobsFetched = ClientStatusInfo.JobsFetched;     
95
96      Dictionary<long, Executor> engines = Core.GetExecutionEngines();
97      st.Jobs = new List<JobStatus>();
98
99      foreach (KeyValuePair<long, Executor> kvp in engines) {
100        Executor e = kvp.Value;
101        st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
102      }
103      return st;     
104    }
105  }
106}
Note: See TracBrowser for help on using the repository browser.