Exemplo n.º 1
0
        public void CTOR()
        {
            var configuration = new FaceDetectionConfiguration("key", "url", TimeSpan.FromMilliseconds(1D));

            Assert.Equal("key", configuration.Key);
            Assert.Equal("url", configuration.URL);
            Assert.Equal(TimeSpan.FromMilliseconds(1D), configuration.Delay);
        }
Exemplo n.º 2
0
        static async Task Main(string[] args)
        {
            _faceDetectionConfiguration = new FaceDetectionConfiguration()
            {
                ScaleFactor          = 1.2,
                MinimumNeighbors     = 5,
                MinimumFaceWidth     = 20,
                MinimumFaceHeight    = 20,
                FaceTimeoutInSeconds = 5
            };
            Console.WriteLine("Hello World!");
            CancellationTokenSource cts = new CancellationTokenSource();

            Console.CancelKeyPress += (sender, a) =>
            {
                a.Cancel = true;
                cts.Cancel();
            };

            string configurationFilePath;

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                configurationFilePath = @"/share/JAVS.Hypnos.Pi.Detector/PiSettings.json";
            }
            else
            {
                configurationFilePath = @"./PiSettings.json";
            }

            _piSettings = await JSONFile.LoadAsync <PiSettings>(configurationFilePath);

            FaceDetectionService faceDetectionService = new FaceDetectionService(_piSettings);

            await faceDetectionService.Init();

            faceDetectionService.ListenFor <ClientGroupStats>((stats) =>
            {
                foreach (var group in stats.ConnectedClientGroupCounts)
                {
                    Console.WriteLine($"{group.Key}: {group.Value} Clients Connected.");
                    _clientGroupStats = stats;
                }
            });

            faceDetectionService.ListenFor <FaceDetectionConfiguration>((config) =>
            {
                _faceDetectionConfiguration = config;
            });

            await faceDetectionService.Join(new JoinGroupRequest()
            {
                IsDetector = true,
                Password   = "******"
            });

            RunFacialDetection(cts, faceDetectionService);
        }
Exemplo n.º 3
0
        public async Task <SignalRServerResponse> UpdateFaceDetectionConfiguration(FaceDetectionConfiguration faceDetectionConfiguration)
        {
            if (_clientIDGroupNameHash[Context.ConnectionId] != CONTROL_GROUP)
            {
                return new SignalRServerResponse()
                       {
                           Success = false,
                           Error   = new Exception("Nice try.")
                       }
            }
            ;

            var groupNames = new List <string>()
            {
                CONTROL_GROUP, SPECTATOR_GROUP, DETECTOR_GROUP
            };

            await Clients.Groups(groupNames).SendAsync(nameof(FaceDetectionConfiguration), faceDetectionConfiguration);

            return(new SignalRServerResponse()
            {
                Success = true
            });
        }
Exemplo n.º 4
0
        public void Start(string slackToken, SlackUser adminUser, FaceDetectionConfiguration faceDetectionConfiguration, BlobStorageConfiguration blobStorageConfiguration)
        {
            if (string.IsNullOrEmpty(slackToken))
            {
                throw new ArgumentException(nameof(slackToken));
            }

            if (string.IsNullOrEmpty(adminUser.Id))
            {
                throw new ArgumentException(nameof(adminUser.Id));
            }

            var serviceContainer = CompositionRoot(slackToken, adminUser, faceDetectionConfiguration, blobStorageConfiguration);

            profilebot = serviceContainer.GetInstance <ProfilebotImplmentation>();
            profilebot
            .Connect()
            .ContinueWith(task => {
                if (!task.IsCompleted || task.IsFaulted)
                {
                    Console.WriteLine($"Error connecting to Slack: {task.Exception}");
                }
            });
        }
Exemplo n.º 5
0
 /// <summary>
 ///     Constructor.
 /// </summary>
 /// <param name="faceServiceClient">Client for calling Azure Cognitive Services.</param>
 /// <param name="faceWhitelist">Knows about whitelisted users.</param>
 /// <param name="configuration">The configuration to use.</param>
 public FaceDetectionClient(IFaceServiceClient faceServiceClient, IFaceWhitelist faceWhitelist, FaceDetectionConfiguration configuration)
 {
     this.faceServiceClient = faceServiceClient ?? throw new ArgumentNullException(nameof(faceServiceClient));
     this.faceWhitelist     = faceWhitelist ?? throw new ArgumentNullException(nameof(faceWhitelist));
     delay = configuration.Delay.Milliseconds;
 }
Exemplo n.º 6
0
        static IServiceContainer CompositionRoot(string slackToken, SlackUser adminUser, FaceDetectionConfiguration faceDetectionConfiguration, BlobStorageConfiguration blobStorageConfiguration)
        {
            var serviceContainer = new ServiceContainer();

            serviceContainer.RegisterInstance(slackToken);
            serviceContainer.RegisterInstance(adminUser);

            if (string.IsNullOrEmpty(faceDetectionConfiguration.Key))
            {
                serviceContainer.Register <IFaceDetectionClient, FaceServiceClientDummy>();
                serviceContainer.Register <IFaceWhitelist, FaceWhitelistDummy>();
            }
            else
            {
                serviceContainer.RegisterInstance(faceDetectionConfiguration);
                serviceContainer.RegisterInstance <IFaceServiceClient>(new FaceServiceClient(faceDetectionConfiguration.Key, faceDetectionConfiguration.URL));
                serviceContainer.Register <IFaceDetectionClient, FaceDetectionClient>();
                serviceContainer.RegisterInstance <IFaceWhitelist>(new FaceWhitelist(blobStorageConfiguration));
            }

            serviceContainer.Register <ISlackProfileValidator, SlackProfileValidator>();
            serviceContainer.Register <ISlackConnector, SlackConnector.SlackConnector>();
            serviceContainer.Register <ISlackIntegration, SlackIntegration>();
            serviceContainer.Register <ProfilebotImplmentation>();

            return(serviceContainer);
        }