LogicFactory.cs 2.46 KB
Newer Older
Vaclav Svaton's avatar
Vaclav Svaton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
using System;
using System.Collections.Generic;
using HaaSMiddleware.BusinessLogicTier.Logic.AdminUserManagement;
using HaaSMiddleware.BusinessLogicTier.Logic.ClusterInformation;
using HaaSMiddleware.BusinessLogicTier.Logic.DataTransfer;
using HaaSMiddleware.BusinessLogicTier.Logic.FileTransfer;
using HaaSMiddleware.BusinessLogicTier.Logic.JobManagement;
using HaaSMiddleware.BusinessLogicTier.Logic.JobReporting;
using HaaSMiddleware.BusinessLogicTier.Logic.Notifications;
using HaaSMiddleware.BusinessLogicTier.Logic.UserAndLimitationManagement;
using HaaSMiddleware.DataAccessTier.UnitOfWork;

namespace HaaSMiddleware.BusinessLogicTier.Factory {
	public abstract class LogicFactory {
		private static readonly Dictionary<BusinessLogicType, LogicFactory> factoryInstances =
			new Dictionary<BusinessLogicType, LogicFactory>(Enum.GetValues(typeof (BusinessLogicType)).Length);

		#region Instantiation
		public static LogicFactory GetLogicFactory() {
			return GetLogicFactory(BusinessLogicType.Poco);
		}

		public static LogicFactory GetLogicFactory(BusinessLogicType type) {
			lock (factoryInstances)
			{
				if (!factoryInstances.ContainsKey(type))
				{
					factoryInstances.Add(type, CreateLogicFactory(type));
				}
			}
			return factoryInstances[type];
		}

		private static LogicFactory CreateLogicFactory(BusinessLogicType type) {
			switch (type) {
				case BusinessLogicType.Poco:
					return new PocoLogicFactory();
			}
			throw new ArgumentException("Business logic factory for type " + type +
			                            " is not implemented. Check the switch in HaaSMiddleware.BusinessLogicTier.Factory.AbstracLogicFactory.CreateLogicFactory(BusinessLogicType type) method.");
		}
		#endregion

		#region Abstract methods
		public abstract IAdminUserManagementLogic CreateAdminUserManagementLogic(IUnitOfWork unitOfWork);
		public abstract IClusterInformationLogic CreateClusterInformationLogic(IUnitOfWork unitOfWork);
        public abstract IDataTransferLogic CreateDataTransferLogic(IUnitOfWork unitOfWork);
		public abstract IFileTransferLogic CreateFileTransferLogic(IUnitOfWork unitOfWork);
		public abstract IJobManagementLogic CreateJobManagementLogic(IUnitOfWork unitOfWork);
		public abstract IJobReportingLogic CreateJobReportingLogic(IUnitOfWork unitOfWork);
		public abstract INotificationLogic CreateNotificationLogic(IUnitOfWork unitOfWork);
		public abstract IUserAndLimitationManagementLogic CreateUserAndLimitationManagementLogic(IUnitOfWork unitOfWork);
		#endregion
	}
}