コード例 #1
0
        protected override void ConfigureContainer()
        {
            base.ConfigureContainer();

            // Register the IUnityContainer so that we can access services from the
            // HTTP server's module handlers.
            ServiceRegistry.RegisterContainer(Container);

            var serializer = new ConfigurationFileSerializer();

            var config      = serializer.Read();
            var sourceMgr   = new FacialDetectionSourceManager(config);
            var sessionMgr  = new RtspSessionManager();
            var rtspHandler = new RtspRequestHandler(sourceMgr, sessionMgr);

            var dispatcher = new DefaultRequestDispatcher();

            dispatcher.RegisterHandler("/stream", rtspHandler);

            var rtspServer = new RtspServer(config.RtspPort, dispatcher);
            var httpServer = new HttpServer(config.HttpPort);

            Container.RegisterInstance(config);
            Container.RegisterInstance(sessionMgr);
            Container.RegisterInstance(rtspServer);
            Container.RegisterInstance(httpServer);
            Container.RegisterInstance <IDetectionSourceManager>(sourceMgr);
            Container.RegisterType <IDataSourcesManager, DataSourcesManager>(new ContainerControlledLifetimeManager());
            Container.RegisterInstance <ISerenityService>(new SerenityService(), new ContainerControlledLifetimeManager());
        }
        public void Deserialize_ShouldReturnAConfigurationFileSerializerObjectForExistingConfigurationFile()
        {
            // Arrange
            const string fileName = "Deserialize_ShouldReturn_ForExistingConfigurationFile.json";
            var          filePath = Path.Combine(Environment.CurrentDirectory, fileName);

            const string         walletFileName          = "TestWallet.json";
            var                  testNetwork             = Network.Main;
            const ConnectionType testConnectionType      = ConnectionType.Http;
            const bool           testCanSpendUnconfirmed = false;
            const string         expectedFileContents    = "{\"WalletFileName\":\"TestWallet.json\",\"Network\":\"Main\",\"ConnectionType\":\"Http\",\"CanSpendUnconfirmed\":\"False\"}";

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            File.WriteAllText(filePath, expectedFileContents);
            File.Exists(filePath).Should().BeTrue();

            // Act
            var result = ConfigurationFileSerializer.Deserialize(filePath);

            // Assert
            result.Should().NotBeNull();
            result.WalletFileName.Should().Be(walletFileName);
            result.Network.Should().Be(testNetwork.ToString());
            result.ConnectionType.Should().Be(testConnectionType.ToString());
            result.CanSpendUnconfirmed.Should().Be(testCanSpendUnconfirmed.ToString());

            // Clean up
            File.Delete(filePath);
        }
        public void Deserialize_ShouldThrowAnExceptionWhenFileDoesNotExist()
        {
            // Arrange
            const string fileName = "Deserialize_ShouldThrowAnExceptionWhenFileDoesNotExist.json";
            var          filePath = Path.Combine(Environment.CurrentDirectory, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            File.Exists(filePath).Should().BeFalse();

            // Act
            try
            {
                ConfigurationFileSerializer.Deserialize(filePath);

                // Should not get here - force a fail.
                fileName.Should().BeEmpty();
            }
            catch (FileNotFoundException ex)
            {
                // Assert
                ex.Message.Should().Contain("Configuration file does not exist. Create ");
            }
            catch (Exception ex)
            {
                // Something else went wrong
                ex.Should().BeNull();
            }
        }
コード例 #4
0
        public MainUserControlViewModel(Core.Configuration config, IDataSourcesManager dsMgr)
        {
            _rtspPort       = config.RtspPort;
            _httpPort       = config.HttpPort;
            _scaleFactor    = config.ScaleFactor;
            _minNeighbors   = config.MinimumNeighbors;
            _serenityIp     = config.SerenityAddress;
            _serenityUser   = config.SerenityUser;
            _serenityPass   = config.SerenityPassword;
            _serializer     = new ConfigurationFileSerializer();
            _datasourcesMgr = dsMgr;

            SelectedDataSources      = new ObservableCollection <DataSource>();
            AvailableDataSources     = new ObservableCollection <DataSource>();
            SaveCommand              = new DelegateCommand(Save);
            AddDataSourcesCommand    = new DelegateCommand <IList>(selected => AddDataSources(selected));
            RemoveDataSourcesCommand = new DelegateCommand <IList>(selected => RemoveDataSources(selected));

            InitDatasources(config.SelectedDatasources);
        }
        public void Serialize_ShouldCreateADefaultJsonFileWhenNoParametersSent()
        {
            Thread.Sleep(1000); // This delay is to avoid conflicts with the file access. Needs reviewing and improving.

            // Arrange
            var fileName = $"Serialize_ShouldCreateADefaultJsonFileWhenNoParametersSent_{DateTime.Now:HH-mm-ss}.json";
            var filePath = Path.Combine(Environment.CurrentDirectory, fileName);

            if (File.Exists(filePath))
            {
                File.Delete(filePath);
            }

            File.Exists(filePath).Should().BeFalse();

            const string         walletFileName          = "TestWallet.json";
            var                  testNetwork             = Network.Main;
            const ConnectionType testConnectionType      = ConnectionType.Http;
            const bool           testCanSpendUnconfirmed = false;
            const string         expectedFileContents    = "{\"WalletFileName\":\"TestWallet.json\",\"Network\":\"Main\",\"ConnectionType\":\"Http\",\"CanSpendUnconfirmed\":\"False\"}";

            // Act
            ConfigurationFileSerializer.Serialize(
                walletFileName,
                testNetwork.ToString(),
                testConnectionType.ToString(),
                testCanSpendUnconfirmed.ToString(),
                filePath);

            // Assert
            File.Exists(filePath).Should().BeTrue();
            File.ReadAllText(filePath).Should().Be(expectedFileContents);

            // Clean up
            File.Delete(filePath);
        }