Пример #1
0
        public async Task <IActionResult> CreateHitList([FromBody] HitListModel model)
        {
            if (!this.ModelState.IsValid)
            {
                return(BadRequest(this.ModelState));
            }

            var parameters = new Dictionary <string, object>
            {
                { "largeFaceListId", model.Id },
                { "name", model.Name }
            };

            if (!string.IsNullOrEmpty(model.Metadata))
            {
                parameters.Add("userData", model.Metadata);
            }

            await _faceRecognition.CreateCollection(model.Id, parameters);

            await _storage.CreateContainer(model.Id);

            return(Ok());
        }
Пример #2
0
        /// <inheritdoc />
        public async Task <Guid> SignUp(string email, string givenName, string familyName, Stream faceStream)
        {
            List <Face> detectedFaces = await _faceRecognition.Detect(faceStream);

            // If more than one face is detected, throw a fit
            if (detectedFaces.Count > 1)
            {
                throw new Exception("More than one face detected. Please try again with only one person in the picture.");
            }

            Guid personId             = Guid.Empty;
            Guid faceId               = Guid.Empty;
            var  additionalParameters = new Dictionary <string, object>
            {
                { "largePersonGroupId", _group.ToLower().Replace(' ', '-') },
                { "name", $"{givenName} {familyName}" }
            };

            var collectionExists = await _faceRecognition.GetCollection(_group, additionalParameters);

            if (collectionExists == null)
            {
                await _faceRecognition.CreateCollection(_group, additionalParameters);
            }

            string result = await _faceRecognition.AddFace(_group, faceStream, additionalParameters);

            if (result.IndexOf('|') > -1)
            {
                personId = Guid.Parse(result.Split('|')[0]);
                faceId   = Guid.Parse(result.Split('|')[1]);
                additionalParameters.Add("personId", personId.ToString());
            }
            else
            {
                faceId = Guid.Parse(result);
            }

            var document = await LoadUserData();

            if (document == null)
            {
                document = new XmlDocument();
                document.LoadXml("<users></users>");
                var header = document.CreateXmlDeclaration("1.0", "utf-8", null);
                document.InsertBefore(header, document.DocumentElement);
            }

            using (var xmlStream = new MemoryStream())
            {
                using (var xmlWriter = XmlWriter.Create(xmlStream))
                {
                    this.SaveUser(document, personId, email, givenName, familyName, faceId);
                    document.WriteTo(xmlWriter);
                }

                await _storage.WriteUserData(_group, USER_DATA, xmlStream);

                await _storage.SaveFace(_group, faceId.ToString(), faceStream);

                return(personId);
            }
        }