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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Hive.Contracts.BusinessObjects;
|
---|
27 | using HeuristicLab.Hive.Client.ExecutionEngine;
|
---|
28 | using HeuristicLab.Hive.Client.Core.ClientConsoleService;
|
---|
29 | using HeuristicLab.Hive.Client.Communication;
|
---|
30 | using HeuristicLab.Hive.Client.Core.Properties;
|
---|
31 |
|
---|
32 | namespace 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 | hardwareInfo = new ClientInfo();
|
---|
55 |
|
---|
56 | if (Settings.Default.Guid == Guid.Empty) {
|
---|
57 | hardwareInfo.ClientId = Guid.NewGuid();
|
---|
58 | Settings.Default.Guid = hardwareInfo.ClientId;
|
---|
59 | Settings.Default.Save();
|
---|
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 | /// <summary>
|
---|
69 | /// Get all the Information about the client
|
---|
70 | /// </summary>
|
---|
71 | /// <returns>the ClientInfo object</returns>
|
---|
72 | public ClientInfo GetClientInfo() {
|
---|
73 | hardwareInfo.Login = WcfService.Instance.ConnectedSince;
|
---|
74 | return hardwareInfo;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /// <summary>
|
---|
78 | /// Returns the connectioncontainer with the IP and Port, storred in the Settings framework
|
---|
79 | /// </summary>
|
---|
80 | /// <returns>The IP and Port of the server</returns>
|
---|
81 | public ConnectionContainer GetServerIPAndPort() {
|
---|
82 | ConnectionContainer cc = new ConnectionContainer();
|
---|
83 | cc.IPAdress = Settings.Default.ServerIP;
|
---|
84 | cc.Port = Settings.Default.ServerPort;
|
---|
85 | return cc;
|
---|
86 | }
|
---|
87 |
|
---|
88 | /// <summary>
|
---|
89 | /// Sets and saves IP and Port in the Settings framework
|
---|
90 | /// </summary>
|
---|
91 | /// <param name="cc"></param>
|
---|
92 | public void SetServerIPAndPort(ConnectionContainer cc) {
|
---|
93 | Settings.Default.ServerIP = cc.IPAdress;
|
---|
94 | Settings.Default.ServerPort = cc.Port;
|
---|
95 | Settings.Default.Save();
|
---|
96 | }
|
---|
97 | /// <summary>
|
---|
98 | /// collects and returns information that get displayed by the Client Console
|
---|
99 | /// </summary>
|
---|
100 | /// <returns></returns>
|
---|
101 | public StatusCommons GetStatusForClientConsole() {
|
---|
102 | StatusCommons st = new StatusCommons();
|
---|
103 | st.ClientGuid = hardwareInfo.ClientId;
|
---|
104 |
|
---|
105 | st.Status = WcfService.Instance.ConnState;
|
---|
106 | st.ConnectedSince = WcfService.Instance.ConnectedSince;
|
---|
107 |
|
---|
108 | st.JobsAborted = ClientStatusInfo.JobsAborted;
|
---|
109 | st.JobsDone = ClientStatusInfo.JobsProcessed;
|
---|
110 | st.JobsFetched = ClientStatusInfo.JobsFetched;
|
---|
111 |
|
---|
112 | Dictionary<long, Executor> engines = Core.GetExecutionEngines();
|
---|
113 | st.Jobs = new List<JobStatus>();
|
---|
114 |
|
---|
115 | foreach (KeyValuePair<long, Executor> kvp in engines) {
|
---|
116 | Executor e = kvp.Value;
|
---|
117 | st.Jobs.Add(new JobStatus { JobId = e.JobId, Progress = e.Progress, Since = e.CreationTime });
|
---|
118 | }
|
---|
119 | return st;
|
---|
120 | }
|
---|
121 |
|
---|
122 | public Dictionary<long, double> GetProgressOfAllJobs() {
|
---|
123 | Dictionary<long,double> prog = new Dictionary<long,double>();
|
---|
124 | Dictionary<long, Executor> engines = Core.GetExecutionEngines();
|
---|
125 | foreach (KeyValuePair<long, Executor> kvp in engines) {
|
---|
126 | Executor e = kvp.Value;
|
---|
127 | prog[e.JobId] = e.Progress;
|
---|
128 | }
|
---|
129 | return prog;
|
---|
130 | }
|
---|
131 |
|
---|
132 | }
|
---|
133 | }
|
---|