示例#1
0
        private async Task UploadCustomerImageToAzureStorageAsync(Stream stream, NewsFeedPost newsFeedPost)
        {
            var customerImageName = GetCustomerImageName(newsFeedPost.Username, DateTime.UtcNow);
            await CustomerImageService.UploadCustomerImageAsync(customerImageName, stream, "image/jpeg");

            newsFeedPost.ImageUrl = CustomerImageService.GetCustomerImageUrl(customerImageName);
        }
示例#2
0
 private void PopulateDescriptionTagsProperty(NewsFeedPost newsFeedPost)
 {
     if (newsFeedPost != null && newsFeedPost.ImageVisionResults != null &&
         newsFeedPost.ImageVisionResults.DescriptionTags != null)
     {
         newsFeedPost.DescriptionTags = string.Join(", ", newsFeedPost.ImageVisionResults.DescriptionTags);
     }
 }
示例#3
0
        private async Task RunContentModeratorServicesOnNewsFeedPostAsync(NewsFeedPost newsFeedPost)
        {
            if (IsMessageEditorTextValid(newsFeedPost.Message))
            {
                var contentModeratorTextResults = await ContentModeratorService.ScreenTextAsync(newsFeedPost.Message, TermListId);

                ValidatePostMessage(contentModeratorTextResults);
                newsFeedPost.MessageModeratorResults = contentModeratorTextResults;
            }
        }
示例#4
0
        private void PopulateCaptionProperty(NewsFeedPost newsFeedPost)
        {
            if (newsFeedPost != null && newsFeedPost.ImageVisionResults != null && newsFeedPost.ImageVisionResults.Captions != null)
            {
                var captionBuilder = new StringBuilder();

                foreach (var caption in newsFeedPost.ImageVisionResults.Captions)
                {
                    captionBuilder.Append(caption.Name + ". ");
                }

                newsFeedPost.Caption = captionBuilder.ToString().TrimEnd();
            }
        }
示例#5
0
        private void PopulateBrandsProperty(NewsFeedPost newsFeedPost)
        {
            if (newsFeedPost != null && newsFeedPost.ImageVisionResults != null &&
                newsFeedPost.ImageVisionResults.Landmarks != null)
            {
                var brandBuilder = new StringBuilder();

                foreach (var brand in newsFeedPost.ImageVisionResults.Brands)
                {
                    brandBuilder.Append(brand.Name + ". ");
                }

                newsFeedPost.Brands = brandBuilder.ToString().TrimEnd();
            }
        }
示例#6
0
        private void PopulateLandmarksProperty(NewsFeedPost newsFeedPost)
        {
            if (newsFeedPost != null && newsFeedPost.ImageVisionResults != null &&
                newsFeedPost.ImageVisionResults.Landmarks != null)
            {
                var landmarkBuilder = new StringBuilder();

                foreach (var landmark in newsFeedPost.ImageVisionResults.Landmarks)
                {
                    landmarkBuilder.Append(landmark.Name + ". ");
                }

                newsFeedPost.Landmarks = landmarkBuilder.ToString().TrimEnd();
            }
        }
示例#7
0
        private void PopulateCelebritiesProperty(NewsFeedPost newsFeedPost)
        {
            if (newsFeedPost != null && newsFeedPost.ImageVisionResults != null &&
                newsFeedPost.ImageVisionResults.Celebrities != null)
            {
                var celebrityBuilder = new StringBuilder();

                foreach (var celebrity in newsFeedPost.ImageVisionResults.Celebrities)
                {
                    celebrityBuilder.Append(celebrity.Name + ". ");
                }

                newsFeedPost.Celebrities = celebrityBuilder.ToString().TrimEnd();
            }
        }
        public async Task CreateNewsFeedPostAsync(NewsFeedPost newsFeedPost)
        {
            try
            {
                using (var cosmosClient = new CosmosClient(_endpoint, _key))
                {
                    var cosmosContainer = cosmosClient.GetContainer(_databaseId, _containerId);

                    var result = await cosmosContainer.CreateItemAsync(newsFeedPost, partitionKey : new PartitionKey(newsFeedPost.Username));
                }
            }
            catch (CosmosException e)
            {
                throw new Exception("The news feed post could not be uploaded.", e);
            }
        }
示例#9
0
        private async Task RunCognitiveServicesOnNewsFeedPostAsync(Stream stream, NewsFeedPost newsFeedPost)
        {
            Task <ContentModeratorTextResults> contentModeratorTextTask = null;

            if (IsMessageEditorTextValid(newsFeedPost.Message))
            {
                contentModeratorTextTask = ContentModeratorService.ScreenTextAsync(newsFeedPost.Message, TermListId);
            }

            var computerVisionTask = ComputerVisionService.GetComputerVisionResultsAsync(stream);

            var tasks = new List <Task>()
            {
                computerVisionTask
            };

            if (contentModeratorTextTask != null)
            {
                tasks.Add(contentModeratorTextTask);
            }

            await Task.WhenAll(tasks);

            if (computerVisionTask.IsFaulted)
            {
                throw new Exception("Something went wrong with your image upload.  Please try again later.");
            }

            ValidatePostImage(computerVisionTask.Result);
            newsFeedPost.ImageVisionResults = computerVisionTask.Result;
            PopulateCaptionProperty(newsFeedPost);
            PopulateDescriptionTagsProperty(newsFeedPost);
            PopulateCelebritiesProperty(newsFeedPost);
            PopulateLandmarksProperty(newsFeedPost);
            PopulateBrandsProperty(newsFeedPost);

            if (contentModeratorTextTask != null)
            {
                if (contentModeratorTextTask.IsFaulted)
                {
                    throw new Exception("Something went wrong with your message post.  Please try again later.");
                }

                ValidatePostMessage(contentModeratorTextTask.Result);
                newsFeedPost.MessageModeratorResults = contentModeratorTextTask.Result;
            }
        }