Пример #1
0
        public async Task <IActionResult> Login(IFormFile file)
        {
            CelebrityModel celeb = new CelebrityModel();

            Directory.Delete(_appEnvironment.WebRootPath + "/resources/", true);
            Directory.CreateDirectory(_appEnvironment.WebRootPath + "/resources/");

            if (null != file && file.Length > 0)
            {
                string speechFileName = "notjeff.mp3";
                string speechText     = "Nice try. You're not Jeff, I can't let you in.";

                AmazonRekognitionClient rekognitionClient = new AmazonRekognitionClient();

                RecognizeCelebritiesRequest    recognizeCelebritiesRequest = new RecognizeCelebritiesRequest();
                Amazon.Rekognition.Model.Image img = new Amazon.Rekognition.Model.Image();

                MemoryStream memStream = new MemoryStream();
                file.CopyTo(memStream);
                img.Bytes = memStream;
                recognizeCelebritiesRequest.Image = img;

                RecognizeCelebritiesResponse recognizeCelebritiesResponse = await rekognitionClient.RecognizeCelebritiesAsync(recognizeCelebritiesRequest);

                if (null != recognizeCelebritiesResponse && recognizeCelebritiesResponse.CelebrityFaces.Count > 0)
                {
                    celeb.CelebrityName = recognizeCelebritiesResponse.CelebrityFaces[0].Name;
                    celeb.Confidence    = recognizeCelebritiesResponse.CelebrityFaces[0].MatchConfidence;

                    if (celeb.CelebrityName == "Jeff Bezos")
                    {
                        speechText     = "Hello Boss, Welcome to the Deployment Bot. Please continue to start the deployment.";
                        celeb.IsJeff   = true;
                        speechFileName = "jeff.mp3";
                    }
                }
                else
                {
                    celeb.CelebrityName = "Sure, you're popular among your friends. But that doesn't make you a celebrity.";
                    celeb.Confidence    = 0;
                }

                AmazonPollyClient pollyclient = new AmazonPollyClient();
                Amazon.Polly.Model.SynthesizeSpeechResponse speechResponse =
                    await pollyclient.SynthesizeSpeechAsync(new Amazon.Polly.Model.SynthesizeSpeechRequest()
                {
                    OutputFormat = OutputFormat.Mp3, Text = speechText, VoiceId = VoiceId.Joanna
                });

                var stream = new FileStream(_appEnvironment.WebRootPath + "/resources/" + speechFileName, FileMode.Create);
                await speechResponse.AudioStream.CopyToAsync(stream);

                stream.Close();
            }

            return(View("Login", celeb));
        }
Пример #2
0
        /// <summary>
        /// Prepare celebrity model
        /// </summary>
        /// <param name="model">Celebrity model</param>
        /// <param name="celebrity">Celebrity</param>
        /// <param name="excludeProperties">Whether to exclude populating of some properties of model</param>
        /// <returns>Celebrity model</returns>
        public virtual CelebrityModel PrepareCelebrityModel(CelebrityModel model, Celebrity celebrity, bool excludeProperties = false)
        {
            Action <CelebrityLocalizedModel, int> localizedModelConfiguration = null;

            if (celebrity != null)
            {
                model = celebrity.ToModel <CelebrityModel>();

                //define localized model configuration action
                localizedModelConfiguration = (locale, languageId) =>
                {
                    locale.Name             = _localizationService.GetLocalized(celebrity, entity => entity.Name, languageId, false, false);
                    locale.FullDescription  = _localizationService.GetLocalized(celebrity, entity => entity.FullDescription, languageId, false, false);
                    locale.ShortDescription = _localizationService.GetLocalized(celebrity, entity => entity.ShortDescription, languageId, false, false);
                };

                model.CelebrityTags = string.Join(", ", _celebrityTagService.GetAllCelebrityTagsByCelebrityId(celebrity.Id).Select(tag => tag.Name));

                //prepare localized models
                if (!excludeProperties)
                {
                    model.Locales = _localizedModelFactory.PrepareLocalizedModels(localizedModelConfiguration);
                }
                PrepareCelebrityPictureSearchModel(model.CelebrityPictureSearchModel, celebrity);
            }

            //set default values for the new model
            if (celebrity == null)
            {
            }

            //prepare model stores
            _storeMappingSupportedModelFactory.PrepareModelStores(model, celebrity, excludeProperties);

            var celebrityTags   = _celebrityTagService.GetAllCelebrityTags();
            var celebrityTagsSb = new StringBuilder();

            celebrityTagsSb.Append("var initialCelebrityTags = [");
            for (var i = 0; i < celebrityTags.Count; i++)
            {
                var tag = celebrityTags[i];
                celebrityTagsSb.Append("'");
                celebrityTagsSb.Append(JavaScriptEncoder.Default.Encode(tag.Name));
                celebrityTagsSb.Append("'");
                if (i != celebrityTags.Count - 1)
                {
                    celebrityTagsSb.Append(",");
                }
            }
            celebrityTagsSb.Append("]");

            model.InitialCelebrityTags = celebrityTagsSb.ToString();


            return(model);
        }
Пример #3
0
 public void Post([FromBody] CelebrityModel celebrity)
 {
     var celebrityRepository = new CelebrityRepository();
     var newCelebrity        = celebrityRepository.Save(celebrity);
 }
Пример #4
0
 public void Put(int id, [FromBody] CelebrityModel celebrity)
 {
     var celebrityRepository = new CelebrityRepository();
     var updatedProduct      = celebrityRepository.Save(id, celebrity);
 }