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.Linq;
|
---|
23 | using HeuristicLab.Hive.Server.DataAccess;
|
---|
24 | using HeuristicLab.PluginInfrastructure;
|
---|
25 | using System.Runtime.CompilerServices;
|
---|
26 | using HeuristicLab.Hive.Contracts.Interfaces;
|
---|
27 | using HeuristicLab.Hive.Server.Core;
|
---|
28 | using HeuristicLab.Hive.Server.Core.InternalInterfaces;
|
---|
29 | using HeuristicLab.DataAccess.Interfaces;
|
---|
30 | using System.Data.SqlClient;
|
---|
31 | using HeuristicLab.Security.Contracts.Interfaces;
|
---|
32 |
|
---|
33 | /// <summary>
|
---|
34 | /// The service locator for the server core
|
---|
35 | /// </summary>
|
---|
36 | public class ServiceLocator {
|
---|
37 | private static IClientManager clientManager = null;
|
---|
38 |
|
---|
39 | private static IJobManager jobManager = null;
|
---|
40 |
|
---|
41 | private static IClientCommunicator clientCommunicator = null;
|
---|
42 |
|
---|
43 | private static ILifecycleManager lifecycleManager = null;
|
---|
44 |
|
---|
45 | private static ISessionFactory sessionFactory = null;
|
---|
46 |
|
---|
47 | private static IScheduler scheduler = null;
|
---|
48 |
|
---|
49 | private static IPermissionManager permManager = null;
|
---|
50 |
|
---|
51 | private static IHivePermissionManager hivePermManager = null;
|
---|
52 |
|
---|
53 | /// <summary>
|
---|
54 | /// Gets the client manager
|
---|
55 | /// </summary>
|
---|
56 | /// <returns></returns>
|
---|
57 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
58 | public static IClientManager GetClientManager() {
|
---|
59 | if (clientManager == null)
|
---|
60 | clientManager = new ClientManager();
|
---|
61 |
|
---|
62 | return clientManager;
|
---|
63 | }
|
---|
64 |
|
---|
65 | /// <summary>
|
---|
66 | /// Gets the job manager
|
---|
67 | /// </summary>
|
---|
68 | /// <returns></returns>
|
---|
69 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
70 | public static IJobManager GetJobManager() {
|
---|
71 | if (jobManager == null)
|
---|
72 | jobManager = new JobManager();
|
---|
73 |
|
---|
74 | return jobManager;
|
---|
75 | }
|
---|
76 |
|
---|
77 | /// <summary>
|
---|
78 | /// Gets the client Communicator
|
---|
79 | /// </summary>
|
---|
80 | /// <returns></returns>
|
---|
81 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
82 | public static IClientCommunicator GetClientCommunicator() {
|
---|
83 | if (clientCommunicator == null)
|
---|
84 | clientCommunicator = new ClientCommunicator();
|
---|
85 |
|
---|
86 | return clientCommunicator;
|
---|
87 | }
|
---|
88 |
|
---|
89 | /// <summary>
|
---|
90 | /// Gets the lifecycle manager
|
---|
91 | /// </summary>
|
---|
92 | /// <returns></returns>
|
---|
93 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
94 | public static ILifecycleManager GetLifecycleManager() {
|
---|
95 | if (lifecycleManager == null) {
|
---|
96 | lifecycleManager = new LifecycleManager();
|
---|
97 | }
|
---|
98 | return lifecycleManager;
|
---|
99 | }
|
---|
100 |
|
---|
101 | /// <summary>
|
---|
102 | /// Gets the db session factory
|
---|
103 | /// </summary>
|
---|
104 | /// <returns></returns>
|
---|
105 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
106 | public static ISessionFactory GetSessionFactory() {
|
---|
107 | if (sessionFactory == null) {
|
---|
108 | sessionFactory =
|
---|
109 | ApplicationManager.Manager.GetInstances<ISessionFactory>().First();
|
---|
110 |
|
---|
111 | sessionFactory.DbConnectionType =
|
---|
112 | typeof(SqlConnection);
|
---|
113 |
|
---|
114 | sessionFactory.DbConnectionString =
|
---|
115 | HeuristicLab.Hive.Server.Core.Properties.Settings.Default.HiveServerConnectionString;
|
---|
116 | }
|
---|
117 |
|
---|
118 | return sessionFactory;
|
---|
119 | }
|
---|
120 |
|
---|
121 | /// <summary>
|
---|
122 | /// Gets the scheduler
|
---|
123 | /// </summary>
|
---|
124 | /// <returns></returns>
|
---|
125 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
126 | public static IScheduler GetScheduler() {
|
---|
127 | if (scheduler == null) {
|
---|
128 | scheduler = ApplicationManager.Manager.GetInstances<IScheduler>().First();
|
---|
129 | }
|
---|
130 |
|
---|
131 | return scheduler;
|
---|
132 | }
|
---|
133 |
|
---|
134 | /// <summary>
|
---|
135 | /// Gets the permission manager
|
---|
136 | /// </summary>
|
---|
137 | /// <returns></returns>
|
---|
138 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
139 | public static IPermissionManager GetPermissionManager() {
|
---|
140 | if (permManager == null)
|
---|
141 | permManager = ApplicationManager.Manager.GetInstances<IPermissionManager>().First();
|
---|
142 | return permManager;
|
---|
143 |
|
---|
144 | }
|
---|
145 |
|
---|
146 | /// <summary>
|
---|
147 | /// Gets the permission manager
|
---|
148 | /// </summary>
|
---|
149 | /// <returns></returns>
|
---|
150 | [MethodImpl(MethodImplOptions.Synchronized)]
|
---|
151 | public static IHivePermissionManager GetHivePermissionManager() {
|
---|
152 | if (hivePermManager == null)
|
---|
153 | hivePermManager = ApplicationManager.Manager.GetInstances<IHivePermissionManager>().First();
|
---|
154 | return hivePermManager;
|
---|
155 |
|
---|
156 | }
|
---|
157 | } |
---|