Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive.Azure/HeuristicLab.Clients.Hive.Slave/3.3/SlaveClientCom.cs @ 7215

Last change on this file since 7215 was 7215, checked in by spimming, 12 years ago

#1680:

  • merged changes from trunk into branch

' removed pre-build event for multiple app.configs

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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 HeuristicLab.Clients.Hive.SlaveCore.Properties;
24using HeuristicLab.Clients.Hive.SlaveCore.ServiceContracts;
25
26namespace HeuristicLab.Clients.Hive.SlaveCore {
27
28  public enum ClientComType { Pipe, Trace };
29
30  /// <summary>
31  /// Singleton which encapsulates the SlaveCommunicationService
32  /// </summary>
33  public class SlaveClientCom {
34    private static SlaveClientCom instance;
35    private static IClientCom clientComInstance;
36    public ISlaveCommunication ClientCom { get; set; }
37
38    /// <summary>
39    /// Getter for the Instance of the SlaveClientCom
40    /// </summary>
41    /// <returns>the Instance of the SlaveClientCom class</returns>
42    public static SlaveClientCom Instance {
43      get {
44        if (instance == null) {
45          instance = new SlaveClientCom();
46        }
47        return instance;
48      }
49    }
50
51    public static IClientCom ClientComInstance {
52      get {
53        if (clientComInstance != null) {
54          return clientComInstance;
55        }
56        throw new NullReferenceException("No instance of SlaveClientCom<T>");
57      }
58    }
59
60    public void LogMessage(string message) {
61      try {
62        ClientCom.LogMessage(message);
63      }
64      catch (Exception ex) {
65        EventLogManager.LogMessage("Exception on LogMessage: " + ex.ToString() + Environment.NewLine + "Orginal message was: " + message);
66      }
67    }
68
69    public void StatusChanged(StatusCommons status) {
70      try {
71        ClientCom.StatusChanged(status);
72      }
73      catch (Exception ex) {
74        EventLogManager.LogMessage("Exception on StatusChanged: " + ex.ToString());
75      }
76    }
77
78    private SlaveClientCom() {
79      ClientComType type = Settings.Default.ClientComType;
80      if (type == ClientComType.Pipe) {
81        clientComInstance = new PipeCom();
82      } else if (type == ClientComType.Trace) {
83        clientComInstance = new TraceCom();
84      } else {
85        throw new InvalidStateException("Invalid client communication type");
86      }
87
88      ClientCom = clientComInstance.GetSlaveCom();
89    }
90
91    public static void Close() {
92      ClientComInstance.Close();
93    }
94  }
95}
Note: See TracBrowser for help on using the repository browser.