public async Task <FindPersonResponse> FindPerson([FromBody] FindPersonRequest model)
        {
            var client = new KairosClient();

            var clientResponse = await client.Recognise(new RecogniseRequestModel
            {
                Image       = model.Image,
                GalleryName = "MyGallery"
            });

            var subjectId = CheckCandidates(clientResponse);

            var matchedMember = Services.MemberService.GetMembersByPropertyValue("subjectId", subjectId).FirstOrDefault();

            if (matchedMember == null)
            {
                return(new FindPersonResponse {
                    IsSuccess = false
                });
            }
            //var mark = ApplicationContext.Current.Services.MemberService.GetMembersByPropertyValue("subjectId", "Mark").FirstOrDefault();
            //var someMedia = new UmbracoHelper(Umbraco.UmbracoContext).TypedMedia(mark.GetValue("initialImage"));
            var personResponse = new FindPersonResponse
            {
                ImageUrl     = new UmbracoHelper(Umbraco.UmbracoContext).TypedMedia(matchedMember.GetValue("initialImage"))?.Url,
                GreetingText = matchedMember.GetValue <string>("greetingMessage"),
                IsSuccess    = true
            };

            return(personResponse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Remove subject from gallery
        /// </summary>
        /// <param name="kairosClient"></param>
        /// <param name="subjectId"></param>
        /// <param name="galleryId"></param>
        /// <returns></returns>
        public static GalleryRemoveResponse RemoveSubject(this KairosClient kairosClient, string subjectId, string galleryId)
        {
            var restClient   = new RestClient("https://api.kairos.com");
            var restRequest1 = new RestRequest(Method.POST)
            {
                Resource      = "gallery/remove_subject",
                RequestFormat = DataFormat.Json
            };

            restRequest1.AddHeader("app_id", kairosClient.ApplicationID);
            restRequest1.AddHeader("app_key", kairosClient.ApplicationKey);
            restRequest1.AddHeader("Content-Type", "application/json");
            var jsonDeserializer = new JsonDeserializer();

            restRequest1.AddBody(new
            {
                gallery_name = galleryId,
                subject_id   = subjectId
            });
            var restRequest2 = restRequest1;
            var restResponse = restClient.Execute <GalleryRemoveResponse>((IRestRequest)restRequest2);

            try
            {
                return(jsonDeserializer.Deserialize <GalleryRemoveResponse>((IRestResponse)restResponse));
            }
            catch (SerializationException ex)
            {
                throw new SerializationException("Error serializing JSON string. JSON string: " + restResponse.Content);
            }
        }
        private void MemberService_Saved(IMemberService sender, SaveEventArgs <IMember> e)
        {
            foreach (IMember member in e.SavedEntities)
            {
                var subjectId = member.GetValue <string>("subjectId");
                if (subjectId == null)
                {
                    return;
                }

                var kairosClient = new KairosClient();
                if (!kairosClient.CheckPerson(subjectId))
                {
                    //todo: instead of using e.SavedEntities, use sender to get the member and then get its values instead!
                    var initialMemberImage = new UmbracoHelper(UmbracoContext.Current).TypedMedia(member.GetValue("initialImage"));
                    var imageUrl           = initialMemberImage.Url;

                    var enrollResult = System.Threading.Tasks.Task.Run(async() => await kairosClient.Enroll(new EnrollRequestModel
                    {
                        SubjectId   = subjectId,
                        GalleryName = "MyGallery",
                        Image       = $"{ConfigurationManager.AppSettings["PublicUrl"]}{imageUrl}"
                    })
                                                                       ).Result;
                }
            }
        }
Ejemplo n.º 4
0
 public KairosService()
 {
     _kairosClient = new KairosClient
     {
         ApplicationID  = Configurations.Config.ApplicationId,
         ApplicationKey = Configurations.Config.ApplicationKey
     };
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Enroll advanced - accepts MultipleFaces
        /// </summary>
        /// <param name="kairosClient"></param>
        /// <param name="imageUrlOrBase64String"></param>
        /// <param name="subjectId"></param>
        /// <param name="galleryId"></param>
        /// <param name="selector"></param>
        /// <param name="multipleFaces"></param>
        /// <returns></returns>
        public static EnrollResponse Enroll(
            this KairosClient kairosClient,
            string imageUrlOrBase64String,
            string subjectId,
            string galleryId,
            string selector,
            bool multipleFaces)
        {
            var restClient   = new RestClient("https://api.kairos.com");
            var restRequest1 = new RestRequest(Method.POST)
            {
                Resource = "enroll", RequestFormat = DataFormat.Json
            };

            restRequest1.AddHeader("app_id", kairosClient.ApplicationID);
            restRequest1.AddHeader("app_key", kairosClient.ApplicationKey);
            restRequest1.AddHeader("Content-Type", "application/json");
            var jsonDeserializer = new JsonDeserializer();

            restRequest1.AddBody(new
            {
                image          = imageUrlOrBase64String,
                subject_id     = subjectId,
                gallery_name   = galleryId,
                multiple_faces = multipleFaces ? "true" : "false",
                selector       = selector.ToUpper()
            });
            var restRequest2 = restRequest1;
            var restResponse = restClient.Execute <EnrollResponse>(restRequest2);

            try
            {
                return(jsonDeserializer.Deserialize <EnrollResponse>(restResponse));
            }
            catch (SerializationException ex)
            {
                throw new SerializationException("Error serializing JSON string. JSON string: " + restResponse.Content);
            }
        }