public MonitoringService CreateMonitoringService()
        {
            var dataContext          = new Data.UnitTestContext();
            var providerManager      = new MachineProviderManager(machine => null);
            var machineManager       = new Mock <IMachineManager>();
            var configurationManager = new Mock <IConfigurationManager>();

            configurationManager.Setup(x => x.GetApplicationSettings()).Returns(new ApplicationSettings());

            return(new MonitoringService(machineManager.Object, configurationManager.Object, providerManager));
        }
Exemplo n.º 2
0
        public void ShouldFindTypeForEachPrinterType()
        {
            var type = MachineProviderManager.GetProviderType(new OctoprintMachine());

            Assert.IsNotNull(type);
            Assert.AreEqual(typeof(OctoprintMachineProvider), type);

            type = MachineProviderManager.GetProviderType(new RepRapFirmwareMachine());
            Assert.IsNotNull(type);
            Assert.AreEqual(typeof(RepRapFirmwareMachineProvider), type);

            Assert.Throws <InvalidOperationException>(() => MachineProviderManager.GetProviderType(new InvalidMachine()));
        }
Exemplo n.º 3
0
        protected override void ConfigureApplicationContainer(TinyIoCContainer container)
        {
            base.ConfigureApplicationContainer(container);

            container.Register((c, n) => _context);
            container.Register <Func <Machine, IMachineProvider> >((c, n) => machine =>
            {
                var machineType = MachineProviderManager.GetProviderType(machine);
                var provider    = (IMachineProvider)Activator.CreateInstance(machineType, machine);

                return(provider);
            });

            container.Register <IAuthenticationManager, AuthenticationManager>();
            container.Register <IAuthorizationManager, AuthorizationManager>();
            container.Register <IConfigurationManager, ConfigurationManager>();
            container.Register <IUserManager, UserManager>();
            container.Register <IMachineManager, MachineManager>();
            container.Register <IControlManager, ControlManager>();

            container.Register <IMonitoringService>((c, n) =>
            {
                if (_monitoringService == null)
                {
                    _monitoringService = new MonitoringService(
                        c.Resolve <MachineManager>(),
                        c.Resolve <ConfigurationManager>(),
                        c.Resolve <MachineProviderManager>());

                    _monitoringService.StatusUpdate += (sender, args) =>
                    {
                        c.Resolve <Action <MachineStatus> >()?.Invoke(args.Data);
                    };
                }

                return(_monitoringService);
            });

            container.Register <StatusHubService>();
            container.Register <AuthenticationModule>();
            container.Register <AuthorizationModule>();
            container.Register <ConfigurationModule>();
            container.Register <ControlModule>();
            container.Register <MachinesModule>();
            container.Register <UsersModule>();

            _certificateExceptionHandler = container.Resolve <CertificateExceptionHandler>();
            _certificateExceptionHandler.Initialize();
        }
        public async Task ShouldPollProviders()
        {
            var statuses             = new List <MachineStatus>();
            var dataContext          = new Data.UnitTestContext();
            var configurationManager = new Mock <IConfigurationManager>();

            var providerManager = new MachineProviderManager(machine =>
            {
                var mock = new Mock <IMachineProvider>();
                mock.Setup(x => x.GetStatus(It.IsAny <CancellationToken>()))
                .Returns(() =>
                {
                    return(Task.FromResult(new MachineStatus {
                        MachineId = machine.Id
                    }));
                });

                return(mock.Object);
            });

            var machineCount = 10;
            var machines     = dataContext.GetRepository <Machine>();

            for (int i = 0; i < machineCount; i++)
            {
                machines.Create(new OctoprintMachine
                {
                    Name = "machine_" + i
                });
            }

            var monitoringService = new MonitoringService(new MachineManager(dataContext, providerManager), configurationManager.Object, providerManager);

            monitoringService.StatusUpdate += (sender, args) =>
            {
                statuses.Add(args.Data);
            };

            monitoringService.PollProviders();
            //The poll providers method is configured to run the task in the back ground and then
            //push the updates with an event. So wait a big to let the tasks complete.
            await Task.Delay(machineCount * 10);

            Assert.AreEqual(machineCount, statuses.Count);
            for (var i = 1; i <= machineCount; i++)
            {
                Assert.True(statuses.Any(status => status.MachineId == i));
            }
        }
Exemplo n.º 5
0
        public MonitoringService(IMachineManager machineManager, IConfigurationManager configurationManager, MachineProviderManager providerManager)
        {
            _machineManager       = machineManager;
            _providerManager      = providerManager;
            _configurationManager = configurationManager;

            _configurationManager.ApplicationSettingsUpdated += (sender, args) =>
            {
                if (_timer == null)
                {
                    return;
                }

                _timer.Interval = args.Data.Interval;
            };
        }
Exemplo n.º 6
0
 public MachineManager(IDataContext context, MachineProviderManager machineProviderManager)
 {
     _machines = context.GetRepository <Machine>();
     _machineProviderManager = machineProviderManager;
 }
Exemplo n.º 7
0
 public void SetUpFixture()
 {
     _context         = new UnitTestContext();
     _machines        = _context.GetRepository <Machine>();
     _providerManager = new MachineProviderManager(ProviderFactoryFunction);
 }
Exemplo n.º 8
0
 public ControlManager(IMachineManager machineManager, MachineProviderManager machineProviderManager)
 {
     _machineManager         = machineManager;
     _machineProviderManager = machineProviderManager;
 }