Exemple #1
0
        internal ServiceThread(IServerManagerService serverManagerService, ILogging logging,
                               IClientMessage sendClientMessage, TimeSpan runInterval)
            : base(null, runInterval)
        {
            _serverManagerService = serverManagerService ?? throw new ArgumentNullException(nameof(serverManagerService));
            _logging           = logging ?? throw new ArgumentNullException(nameof(logging));
            _sendClientMessage = sendClientMessage ?? throw new ArgumentNullException(nameof(sendClientMessage));

            _lockObject = new object();
        }
        /// <summary>
        /// Loads and configures all registered services
        /// </summary>
        /// <param name="serviceName"></param>
        internal void LoadService(string serviceName)
        {
            try
            {
                Assembly pluginAssembly = LoadAssembly(serviceName);

                foreach (Type type in pluginAssembly.GetTypes())
                {
                    if (type.GetInterface("IServerManagerService") != null)
                    {
                        IServerManagerService pluginService = (IServerManagerService)Activator.CreateInstance(type);
                        pluginService.ServiceInitialize(_eventManager, _logging, _sendReport, _sendClientMessage);

                        ServiceThread serviceThread = new ServiceThread(pluginService, _logging, _sendClientMessage, pluginService.ServiceRunInterval());
                        _registeredServices.Add(serviceThread);

                        IEventListner listner = pluginService.GetEventListner();

                        if (listner == null)
                        {
                            continue;
                        }

                        foreach (string eventName in listner.GetEvents())
                        {
                            using (TimedLock.Lock(_lockObject))
                            {
                                if (!_eventList.ContainsKey(eventName.ToUpper()))
                                {
                                    _eventList.Add(eventName.ToUpper(), new List <ServiceThread>());
                                }

                                List <ServiceThread> keyValue = _eventList[eventName.ToUpper()];
                                keyValue.Add(serviceThread);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                _logging.AddToLog(err, serviceName);
            }
        }
 public ServerController(IServerManagerService serverManagerService, ServerQuery serverQuery)
 {
     ServerManagerService = serverManagerService;
     ServerQuery          = serverQuery;
 }