Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AWorker"></param>
        private void UpdateUI()
        {
            int WorkerIndex = 0;

            foreach (ListViewItem AnItem in Resources.Items)
            {
                Worker AWorker = _TheWorkspace.Workers[WorkerIndex];

                AnItem.Tag  = AWorker;
                AnItem.Text = AWorker.Trigram;

                WorkerIndex++;
            }

            {
                Worker AWorker = GetSelectedWorker();

                if (AWorker != null)
                {
                    int ModuleIndex = 0;

                    foreach (ListViewItem AnItem in Modules.Items)
                    {
                        WorkerModule AWorkerModule = AWorker.EfficiencyList[ModuleIndex];

                        AnItem.Tag = AWorkerModule;
                        AnItem.SubItems[0].Text = AWorkerModule.ModuleName;
                        AnItem.SubItems[1].Text = AWorkerModule.PercentEfficiency.ToString();

                        ModuleIndex++;
                    }
                }
            }
        }
Exemplo n.º 2
0
        public override void Configure(IFunctionsHostBuilder builder)
        {
            var azureServiceTokenProvider = new AzureServiceTokenProvider();
            var keyVaultClient            = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(azureServiceTokenProvider.KeyVaultTokenCallback));

            var configuration = new ConfigurationBuilder()
                                .AddEnvironmentVariables()
                                .AddUserSecrets(typeof(Startup).Assembly)
                                .AddAzureKeyVault("https://screentimetracker.vault.azure.net/", keyVaultClient, new DefaultKeyVaultSecretManager())
                                .AddInMemoryCollection(new List <KeyValuePair <string, string> >()
            {
                new KeyValuePair <string, string>("AccountsTableName", "Accounts"),
                new KeyValuePair <string, string>("WorkTimesTableName", "WorkTimes"),
                new KeyValuePair <string, string>("RefreshTokensTableName", "RefreshTokens")
            })
                                .Build();

            Log.Logger = new LoggerConfiguration()
                         .WriteTo.Console()
                         .CreateLogger();

            builder.Services.AddSingleton <IConfiguration>(configuration);
            builder.Services.AddLogging(x => x.AddSerilog());

            WorkerModule.RegisterServices(builder.Services);
        }
Exemplo n.º 3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="AWorkspace"></param>
        /// <param name="AWorkerModule"></param>
        public WorkerModuleDialog(Workspace AWorkspace, WorkerModule AWorkerModule)
        {
            InitializeComponent();

            PopulateModuleNames(AWorkspace);

            ModuleName.Text = AWorkerModule.ModuleName;
            Efficiency.Text = AWorkerModule.PercentEfficiency.ToString();
        }
Exemplo n.º 4
0
        public void ShouldUpdateWorkerResourceTypeID()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;

            database = new MockedDatabase <Worker>(false, 1, (t) => new Worker()
            {
                WorkerID = t, PlanetID = 0
            });
            module = new WorkerModule(NullLogger.Instance, database);
            module.UpdateWorker(1, ResourceTypeIDs.Wood);
            Assert.AreEqual(1, database.UpdatedCount);
        }
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            BundleConfig.RegisterBundles(BundleTable.Bundles);

            NinjectModule workerModule  = new WorkerModule();
            NinjectModule serviceModule = new ServiceModule("DefaultConnection");
            var           kernel        = new StandardKernel(workerModule, serviceModule);

            kernel.Unbind <ModelValidatorProvider>();
            DependencyResolver.SetResolver(new NinjectDependencyResolver(kernel));
        }
Exemplo n.º 6
0
        public void ShouldGetWorker()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;
            Worker result;

            database = new MockedDatabase <Worker>(false, 1, (t) => new Worker()
            {
                WorkerID = t
            });
            module = new WorkerModule(NullLogger.Instance, database);
            result = module.GetWorker(1);
            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.WorkerID);
        }
Exemplo n.º 7
0
        public void ShouldNotGetWorkersAndLogError()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;
            MemoryLogger            logger;


            logger   = new MemoryLogger();
            database = new MockedDatabase <Worker>(true, 3, (t) => new Worker()
            {
                WorkerID = t
            });
            module = new WorkerModule(logger, database);
            Assert.ThrowsException <PIODataException>(() => module.GetWorkers(1));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));
        }
Exemplo n.º 8
0
        public void ShouldNotUpdateWorkerResourceTypeIDAndLogError()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;
            MemoryLogger            logger;


            logger   = new MemoryLogger();
            database = new MockedDatabase <Worker>(true, 1, (t) => new Worker()
            {
                WorkerID = t, PlanetID = 0
            });
            module = new WorkerModule(logger, database);
            Assert.ThrowsException <PIODataException>(() => module.UpdateWorker(0, ResourceTypeIDs.Wood));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));
        }
Exemplo n.º 9
0
        public void ShouldNotCreateWorkerAndLogError()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;
            MemoryLogger            logger;


            logger   = new MemoryLogger();
            database = new MockedDatabase <Worker>(true, 1, (t) => new Worker()
            {
                WorkerID = t
            });
            module = new WorkerModule(logger, database);
            Assert.ThrowsException <PIODataException>(() => module.CreateWorker(1, 7, 9));
            Assert.IsNotNull(logger.Logs.FirstOrDefault(item => (item.Level == LogLevels.Error) && (item.ComponentName == module.ModuleName)));

            Assert.AreEqual(0, database.InsertedCount);
        }
Exemplo n.º 10
0
        public void ShouldCreateWorker()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;
            Worker result;

            database = new MockedDatabase <Worker>(false, 1, (t) => new Worker()
            {
                WorkerID = t
            });
            module = new WorkerModule(NullLogger.Instance, database);
            result = module.CreateWorker(1, 7, 9);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.PlanetID);
            Assert.AreEqual(7, result.X);
            Assert.AreEqual(9, result.Y);

            Assert.AreEqual(1, database.InsertedCount);
        }
Exemplo n.º 11
0
        public void ShouldGetAllWorkers()
        {
            MockedDatabase <Worker> database;
            WorkerModule            module;

            Worker[] results;

            database = new MockedDatabase <Worker>(false, 3, (t) => new Worker()
            {
                WorkerID = t, PlanetID = 2
            });
            module  = new WorkerModule(NullLogger.Instance, database);
            results = module.GetWorkers();
            Assert.IsNotNull(results);
            Assert.AreEqual(3, results.Length);
            for (int t = 0; t < 3; t++)
            {
                Assert.IsNotNull(results[t]);
                Assert.AreEqual(t, results[t].WorkerID);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Modules_DoubleClick(object sender, EventArgs e)
        {
            WorkerModule AWorkerModule = GetSelectedWorkerModule();

            if (AWorkerModule != null)
            {
                WorkerModuleDialog ADialog = new WorkerModuleDialog(_TheWorkspace, AWorkerModule);

                if (ADialog.ShowDialog(this) == DialogResult.OK)
                {
                    double Efficiency;

                    if (Double.TryParse(ADialog.Efficiency.Text, out Efficiency))
                    {
                        AWorkerModule.ModuleName        = ADialog.ModuleName.Text;
                        AWorkerModule.PercentEfficiency = Efficiency;

                        UpdateUI();
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddModule_Click(object sender, EventArgs e)
        {
            Worker AWorker = GetSelectedWorker();

            if (AWorker != null)
            {
                WorkerModuleDialog ADialog = new WorkerModuleDialog(_TheWorkspace);

                if (ADialog.ShowDialog(this) == DialogResult.OK)
                {
                    double Efficiency;

                    if (Double.TryParse(ADialog.Efficiency.Text, out Efficiency))
                    {
                        WorkerModule NewModule = new WorkerModule(ADialog.ModuleName.Text, Efficiency);
                        AWorker.EfficiencyList.Add(NewModule);

                        BuildWorkerInfo();
                    }
                }
            }
        }
Exemplo n.º 14
0
Arquivo: Program.cs Projeto: 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);
        }