예제 #1
0
        private void StartModule(IServerModule module)
        {
            // Check for any failed dependencies
            var hasfailedDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies
                                       .Any(item => item.RepresentedModule.State == ServerModuleState.Failure);

            // Don't try to start modules which initialization has been failed or for which dependency initializations have failed
            if (module.State == ServerModuleState.Failure || hasfailedDependecies)
            {
                return;
            }

            // Now we check for any not running dependencies and start them
            var awaitingDependecies = _dependencyManager.GetDependencyBranch(module).Dependencies
                                      .Where(item => !item.RepresentedModule.State.HasFlag(ServerModuleState.Running))
                                      .Select(item => item.RepresentedModule).ToArray();

            if (awaitingDependecies.Any())
            {
                EnqueServiceAndStartDependencies(awaitingDependecies, module);
            }
            else
            {
                ThreadPool.QueueUserWorkItem(ExecuteModuleStart, module);
            }
        }
예제 #2
0
        /// <summary>
        /// Stop this plugin and all required dependencies
        /// </summary>
        /// <param name="module"></param>
        public void Stop(IServerModule module)
        {
            if (!AvailableModules.Contains(module))
            {
                return;
            }

            // First we have to find all running modules that depend on this service
            var dependingServices = _dependencyManager.GetDependencyBranch(module).Dependends.Select(item => item.RepresentedModule);

            // Now we will stop all of them recursivly
            foreach (var dependingService in dependingServices.Where(dependend => dependend.State.HasFlag(ServerModuleState.Running) ||
                                                                     dependend.State == ServerModuleState.Starting))
            {
                // We will enque the service to make sure it is restarted later on
                AddWaitingService(module, dependingService);
                Stop(dependingService);
            }

            // Since stop is synchron we don't need an event
            try
            {
                module.Stop();
            }
            catch
            {
                Console.WriteLine("Failed to stop service <{0}>", module.Name);
            }
        }
 /// <summary>
 /// Get the start dependencies of the given module.
 /// </summary>
 /// <param name="service">The server module for which the dependencies should be fetched.</param>
 /// <returns>An amount of start dependencies for the requested module.</returns>
 public IEnumerable <IServerModule> StartDependencies(IServerModule service)
 {
     return(_dependencyManager.GetDependencyBranch(service)?.Dependencies.Select(item => item.RepresentedModule)
            ?? Enumerable.Empty <IServerModule>());
 }