Exemplo n.º 1
0
        public ResponseStatus CreatePersonRequest(FaceAPIReg _FaceAPIReg)
        {
            var client = new HttpClient();

            // Request headers - replace this example key with your valid key.
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ConfigurationManager.AppSettings["FaceAPIPrimaryKey"]);

            // Request URI string.
            var uri = ConfigurationManager.AppSettings["FaceAPIURL"] + "persongroups/" + _FaceAPIReg.AWCCode + "/persons";

            // Here "name" is for display and doesn't have to be unique. Also, "userData" is optional.
            var json = new
            {
                name     = _FaceAPIReg.BeneName,
                userData = _FaceAPIReg.BeneCode + "-" + _FaceAPIReg.MotherName
            };

            string      Data    = new JavaScriptSerializer().Serialize(json);
            HttpContent content = new StringContent(Data);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");

            var             FaceResult = client.PostAsync(uri, content).Result;
            var             xx         = FaceResult.Content.ReadAsStringAsync();
            FaceAPIResponse Response   = JsonConvert.DeserializeObject <FaceAPIResponse>(xx.Result);
            ResponseStatus  Result     = new ResponseStatus();

            if (Response.PersonID != "" && Response.PersonID != null)
            {
                Result.PersonID   = Response.PersonID;
                Result.statusCode = "000";
                Result.message    = "Person Registered Successfully & PersonID :" + Response.PersonID;
                return(Result);
            }
            else
            {
                Result            = Response.error;
                Result.statusCode = Response.error.code == null ? Response.error.statusCode : Response.error.code;
                return(Result);
            }
        }
Exemplo n.º 2
0
        public ResponseStatus EnrollPersonRequest(FaceAPIReg _FaceAPIReg)
        {
            var client = new HttpClient();

            // Request headers - replace this example key with your valid key.
            client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "37315d4c2c684d8083797477bff4646c");

            // Request parameters and URI string.
            string queryString = "userData=001Image";
            var    uri         = ConfigurationManager.AppSettings["FaceAPIURL"] + "persongroups/" + _FaceAPIReg.AWCCode + "/persons/" + _FaceAPIReg.PersonID + "/persistedFaces";

            // Request body. Try this sample with a locally stored JPEG image.
            byte[] byteData = GetImageAsByteArray(System.Web.HttpContext.Current.Server.MapPath(@"~/Content/images/officials/modi.png"));

            using (var content = new ByteArrayContent(byteData))
            {
                // This example uses content type "application/octet-stream".
                // The other content types you can use are "application/json" and "multipart/form-data".
                content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
                var             FaceResult = client.PostAsync(uri, content).Result;
                var             xx         = FaceResult.Content.ReadAsStringAsync();
                FaceAPIResponse Response   = JsonConvert.DeserializeObject <FaceAPIResponse>(xx.Result);
                ResponseStatus  Result     = new ResponseStatus();
                if (Response.persistedFaceId != "" && Response.persistedFaceId != null)
                {
                    Result.PersonID   = Response.persistedFaceId;
                    Result.statusCode = "000";
                    Result.message    = "Person Enrolled Successfully & persistedFaceId :" + Response.persistedFaceId;
                    return(Result);
                }
                else
                {
                    Result            = Response.error;
                    Result.statusCode = Response.error.code == null ? Response.error.statusCode : Response.error.code;
                    return(Result);
                }
            }
        }