コード例 #1
0
        public void ShouldUnsubscribe()
        {
            MemoryLogger        logger;
            TaskCallbackService module;
            ITaskCallBack       callback;

            logger = new MemoryLogger();

            callback = new MockedCallback(false);
            module   = new TaskCallbackService(logger, new MockedSchedulerModule(false));
            Assert.IsFalse(module.Unsubscribe(callback));
            module.Subscribe(callback);
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName)));
            Assert.IsTrue(module.Unsubscribe(callback));
        }        //
コード例 #2
0
        public void ShouldNotifySubscribers()
        {
            MemoryLogger          logger;
            TaskCallbackService   module;
            MockedCallback        callback;
            MockedSchedulerModule mockedSchedulerModule;

            logger = new MemoryLogger();

            mockedSchedulerModule = new MockedSchedulerModule(false);
            callback = new MockedCallback(false);
            module   = new TaskCallbackService(logger, mockedSchedulerModule);
            Assert.IsTrue(module.Subscribe(callback));

            Assert.AreEqual(0, callback.StartedCount);
            mockedSchedulerModule.InvokeTaskStarted();
            Assert.AreEqual(1, callback.StartedCount);

            Assert.AreEqual(0, callback.EndedCount);
            mockedSchedulerModule.InvokeTaskEnded();
            Assert.AreEqual(1, callback.EndedCount);
        }
コード例 #3
0
        public void ShouldNNotNotifySubscribersAndLogError()
        {
            MemoryLogger          logger;
            TaskCallbackService   module;
            MockedCallback        callback;
            MockedSchedulerModule mockedSchedulerModule;

            logger = new MemoryLogger();

            mockedSchedulerModule = new MockedSchedulerModule(false);
            callback = new MockedCallback(true);
            module   = new TaskCallbackService(logger, mockedSchedulerModule);
            Assert.IsTrue(module.Subscribe(callback));

            Assert.AreEqual(0, callback.StartedCount);
            mockedSchedulerModule.InvokeTaskStarted();
            Assert.AreEqual(0, callback.StartedCount);
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName)));

            Assert.AreEqual(0, callback.EndedCount);
            mockedSchedulerModule.InvokeTaskEnded();
            Assert.AreEqual(0, callback.EndedCount);
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Warning) && (item.ComponentName == module.ModuleName)));
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: dfgs/PIO
        static void Main(string[] args)
        {
            ILogger logger;
            VersionControlModule versionControlModule;
            ServiceHostModule    pioServiceHostModule;
            ServiceHostModule    taskCallbackServiceHostModule;
            SchedulerModule      schedulerModule;

            IPIOService          pioService;
            ITaskCallbackService taskCallbackService;
            IDatabase            database;
            IConnectionFactory   connectionFactory;
            ICommandBuilder      commandBuilder;
            IDatabaseCreator     databaseCreator;

            IPlanetGeneratorModule planetGeneratorModule;

            IPhraseModule       phraseModule;
            IPlanetModule       planetModule;
            ICellModule         cellModule;
            IBuildingModule     buildingModule;
            IWorkerModule       workerModule;
            IBuilderModule      factoryBuilderModule;
            IStackModule        stackModule;
            IResourceTypeModule resourceTypeModule;
            IBuildingTypeModule buildingTypeModule;
            ITaskTypeModule     taskTypeModule;
            IMaterialModule     materialModule;
            IIngredientModule   ingredientModule;
            IProductModule      productModule;
            ITaskModule         taskModule;

            IIdlerModule           idlerModule;
            IResourceCheckerModule resourceCheckerModule;
            ILocationCheckerModule locationCheckerModule;
            IProducerModule        producerModule;
            IHarvesterModule       harvesterModule;
            IMoverModule           moverModule;
            ITakerModule           takerModule;
            IStorerModule          storerModule;

            quitEvent = new AutoResetEvent(false);
            Console.CancelKeyPress += new ConsoleCancelEventHandler(Console_CancelKeyPress);

            //logger = new ConsoleLogger(new DefaultLogFormatter());
            logger = new UnicastLogger(IPAddress.Loopback, Properties.Settings.Default.UnicastPort);
            //logger = new FileLogger(new DefaultLogFormatter(), "PIO.ServerHost.Log");

            databaseCreator   = new SqlDatabaseCreator(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName);
            connectionFactory = new SqlConnectionFactory(Properties.Settings.Default.Server, Properties.Settings.Default.DatabaseName);
            commandBuilder    = new SqlCommandBuilder();
            database          = new Database(connectionFactory, commandBuilder);

            versionControlModule = new VersionControlModule(logger, databaseCreator, new PIOVersionControl(database));
            if (!versionControlModule.InitializeDatabase(Properties.Settings.Default.DropDatabase))
            {
                return;
            }


            phraseModule       = new PhraseModule(logger, database);
            planetModule       = new PlanetModule(logger, database);
            cellModule         = new CellModule(logger, database);
            buildingModule     = new BuildingModule(logger, database);
            workerModule       = new WorkerModule(logger, database);
            stackModule        = new StackModule(logger, database);
            resourceTypeModule = new ResourceTypeModule(logger, database);
            buildingTypeModule = new BuildingTypeModule(logger, database);
            taskTypeModule     = new TaskTypeModule(logger, database);
            materialModule     = new MaterialModule(logger, database);
            ingredientModule   = new IngredientModule(logger, database);
            productModule      = new ProductModule(logger, database);
            taskModule         = new TaskModule(logger, database);


            factoryBuilderModule  = new BuilderModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, materialModule);;
            idlerModule           = new IdlerModule(logger, taskModule, workerModule);
            resourceCheckerModule = new ResourceCheckerModule(logger, buildingModule, stackModule, ingredientModule, materialModule);
            locationCheckerModule = new LocationCheckerModule(logger, workerModule, buildingModule);
            producerModule        = new ProducerModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, ingredientModule, productModule);
            harvesterModule       = new HarvesterModule(logger, taskModule, workerModule, buildingModule, buildingTypeModule, stackModule, productModule);
            moverModule           = new MoverModule(logger, taskModule, workerModule, buildingModule);
            takerModule           = new TakerModule(logger, taskModule, workerModule, buildingModule, stackModule);
            storerModule          = new StorerModule(logger, taskModule, workerModule, buildingModule, stackModule);

            planetGeneratorModule = new PlanetGeneratorModule(logger, phraseModule, resourceTypeModule, buildingTypeModule, taskTypeModule, materialModule, ingredientModule, productModule, planetModule, cellModule, buildingModule, workerModule);
            if (!planetGeneratorModule.Generate())
            {
                return;
            }

            schedulerModule = new SchedulerModule(logger, taskModule, idlerModule, producerModule, harvesterModule, moverModule, takerModule, storerModule, factoryBuilderModule);
            schedulerModule.Start();


            pioService = new PIOService(
                logger, phraseModule, planetModule, cellModule, buildingModule, workerModule,
                stackModule, resourceTypeModule,
                buildingTypeModule, taskTypeModule, materialModule, ingredientModule, productModule, taskModule,
                schedulerModule,
                resourceCheckerModule, locationCheckerModule, idlerModule, producerModule, harvesterModule, moverModule, takerModule, storerModule,
                factoryBuilderModule);

            pioServiceHostModule = new ServiceHostModule(logger, pioService);
            pioServiceHostModule.Start();

            taskCallbackService           = new TaskCallbackService(logger, schedulerModule);
            taskCallbackServiceHostModule = new ServiceHostModule(logger, taskCallbackService);
            taskCallbackServiceHostModule.Start();

            WaitHandle.WaitAny(new WaitHandle[] { quitEvent }, -1);

            taskCallbackServiceHostModule.Stop();
            pioServiceHostModule.Stop();
            schedulerModule.Stop();

            Console.CancelKeyPress -= new ConsoleCancelEventHandler(Console_CancelKeyPress);
        }