/// <summary> /// Retrieves the localized absolute url of the specified path. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="urlHelper">The URL helper.</param> /// <param name="path">The path.</param> /// <returns></returns> public static string ContentLocalized <T>(this UrlHelpers <T> urlHelper, string path) { var currentCulture = urlHelper.RenderContext.Context.Culture; if (string.IsNullOrWhiteSpace(path) || currentCulture == null) { return(urlHelper.Content(path)); } if (currentCulture.Name.StartsWith("en", StringComparison.InvariantCultureIgnoreCase) || currentCulture.Name.Equals("en")) { return(urlHelper.Content(path)); } string currName; if (currentCulture.Name.Length > 2) { currName = currentCulture.Name.Substring(0, 2); } else { currName = currentCulture.Name; } if (path.StartsWith("/", StringComparison.InvariantCultureIgnoreCase)) { var localizedPath = string.Concat("/", currName, path); return(urlHelper.Content(localizedPath)); } if (path.StartsWith("~/", StringComparison.InvariantCultureIgnoreCase)) { var localizedPath = string.Concat("~/", currName, path.Substring(1)); return(urlHelper.Content(localizedPath)); } return(urlHelper.Content(path)); }
/// <summary> /// Asynchronously detect multiple faces with gender and age from a stream of picture /// </summary> public async Task <Face[]> DetectFacesFromPictureAsync(string imagePath) { // Makes face detection string url = (UrlHelpers.Content(Global.Host, imagePath)); Face[] faces = await _faceServiceClient.DetectAsync(url, returnFaceAttributes : new[] { FaceAttributeType.Age, FaceAttributeType.Gender, FaceAttributeType.Glasses, FaceAttributeType.FacialHair }); // If there aren't at least one face in picture if (!faces.Any()) { throw new FaceAPIException("NotFaceDetected", "No face detected in picture", HttpStatusCode.BadRequest); } return(faces); }
/// <summary> /// Asynchronously recognize emotions from a picture /// </summary> public async Task <EmotionScores> RecognizeEmotions(string imageUrl, FaceRectangle faceRectangle) { Emotion emotion = (await _emotionServiceClient.RecognizeAsync( UrlHelpers.Content(Global.Host, imageUrl), new[] { new Rectangle { Height = faceRectangle.Height, Left = faceRectangle.Left, Top = faceRectangle.Top, Width = faceRectangle.Width } })).FirstOrDefault(); return(emotion.ToEmotionScores()); }
/// <summary> /// Asynchronously add face in oxford for a person and link it with a profile picture /// <see cref="PersonCreationFallBack(Guid?)"/> /// </summary> public async Task <bool> AddFaceToPersonInOxford(Person person, ProfilePicture picture, Face face, string temporaryImage) { Guid faceApiId = default(Guid); try { // if the person has reached the limit of 64 faces in oxford if (person.HasReachedMaxLimitOfFaces()) { await RemoveFaceFromOxford(person); } AddPersistedFaceResult result = await _faceServiceClient.AddPersonFaceAsync(Global.OxfordPersonGroupId, person.PersonApiId, UrlHelpers.Content(Global.Host, temporaryImage), targetFace : face.FaceRectangle); faceApiId = result.PersistedFaceId; // Link profile picture with face on oxford api picture.FaceApiId = faceApiId; return(true); } catch (FaceAPIException e) { LogManager.GetLogger(GetType()).Info("Error occured during adding od face to person", e); // If is a new person we rollback its creation to avoid person without face if (person.Id == 0) { await PersonCreationFallBack(person.PersonApiId); File.Delete(MapPath(temporaryImage)); return(false); } return(true); } }