Exemplo n.º 1
0
        /// <summary>
        /// Adds images to an image list.
        /// </summary>
        /// <param name="client">The Content Moderator client.</param>
        /// <param name="listId">The list identifier.</param>
        /// <param name="imagesToAdd">The images to add.</param>
        /// <param name="label">The label to apply to each image.</param>
        /// <remarks>Images are assigned content IDs when they are added to the list.
        /// Track the content ID assigned to each image.</remarks>
        private static void AddImages(
            ContentModeratorClient client, int listId,
            IEnumerable <string> imagesToAdd, string label)
        {
            foreach (var imageUrl in imagesToAdd)
            {
                WriteLine();
                WriteLine($"Adding {imageUrl} to list {listId} with label {label}.", true);
                try
                {
                    var result = client.ListManagementImage.AddImageUrlInput(
                        listId.ToString(), "application/json", new BodyModel("URL", imageUrl), null, label);

                    ImageIdMap.Add(imageUrl, Int32.Parse(result.ContentId));

                    WriteLine("Response:");
                    WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
                }
                catch (Exception ex)
                {
                    WriteLine($"Unable to add image to list. Caught {ex.GetType().FullName}: {ex.Message}", true);
                }
                finally
                {
                    Thread.Sleep(throttleRate);
                }
            }
        }
Exemplo n.º 2
0
        public void AddTerm()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    //if (allTermLists.Count == 1)
                    //{
                    //    CreateTermLists();
                    //}
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    api = ContentModeratorAPI.ADD_TERM;
                    HttpMockServer.Initialize("TextListManagement", "AddTerm");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetResponse(client, api, "67");

                    var addTermToListId = results.AddTerm;
                    Assert.NotNull(addTermToListId);
                    Assert.Equal(HttpStatusCode.Created, addTermToListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 3
0
        public void DeleteAllTerms()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    api = ContentModeratorAPI.DELETE_ALL_TERM;
                    HttpMockServer.Initialize("TextListManagement", "DeleteAllTerms");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId);
                    results = Constants.GetResponse(client, api, "67");

                    var deleteAllTermFromListId = results.DeleteTerms;
                    Assert.NotNull(deleteAllTermFromListId);
                    Assert.Equal(HttpStatusCode.NoContent, deleteAllTermFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        /// <summary>
        /// Analyzes activity text with Content Moderator and adds result to Bot Context. Run on each turn of the conversation.
        /// </summary>
        /// <param name="context">The Bot Context object.</param>
        /// <param name="next">The next middleware component to run.</param>
        /// <param name="cancellationToken">The cancellation token for the task.</param>
        /// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
        public async Task OnTurnAsync(ITurnContext context, NextDelegate next, CancellationToken cancellationToken = default(CancellationToken))
        {
            BotAssert.ContextNotNull(context);

            if (context.Activity.Type == ActivityTypes.Message)
            {
                var byteArray  = Encoding.UTF8.GetBytes(context.Activity.Text);
                var textStream = new MemoryStream(byteArray);

                var client = new ContentModeratorClient(new ApiKeyServiceClientCredentials(this.subscriptionKey));
                client.Endpoint = $"{this.region}.api.cognitive.microsoft.com";

                var screenResult = client.TextModeration.ScreenText(
                    language: "eng",
                    textContentType: "text/plain",
                    textContent: textStream,
                    autocorrect: true,
                    pII: true,
                    listId: null,
                    classify: true);

                context.TurnState.Add(TextModeratorResultKey, screenResult);
            }

            await next(cancellationToken).ConfigureAwait(false);
        }
Exemplo n.º 5
0
        public void RefreshIndexTermList()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    api = ContentModeratorAPI.REFRESH_INDEX_TERM_LIST;
                    TermListIdToUpdate = ((int)allTermLists[1].Id).ToString();
                    HttpMockServer.Initialize("TextListManagement", "RefreshIndexTermList");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListIdToUpdate);
                    results = Constants.GetResponse(client, api, "67");
                    var refreshIndexTermList = results.RefreshIndexTermList;

                    Assert.NotNull(refreshIndexTermList);
                    Assert.Equal(HttpStatusCode.OK, refreshIndexTermList.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyRefreshIndex(refreshIndexTermList.Body));
                    Assert.Equal("RefreshIndex successfully completed.", refreshIndexTermList.Body.Status.Description);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 6
0
        public void AddTranscripts()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    rvwStatus = ReviewStatus.UNPUBLISHED;
                    //CreateVideoReview();

                    api = ReviewAPI.TRANSCRIPTS_ADD;
                    using (Stream s = new FileStream(currentExecutingDirectory + @"\TestDataSources\vttF.vtt", FileMode.Open, FileAccess.Read))
                    {
                        HttpMockServer.Initialize("ReviewAPIs", "AddTranscripts");
                        client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());

                        //results = Constants.GetTranscriptReviewResponse(client, api, Content.VIDEO, MIMETypes.TEXT_PLAIN.GetDescription(), teamName, ReviewIds[0], s);
                        results = Constants.GetTranscriptReviewResponse(client, api, Content.VIDEO, MIMETypes.TEXT_PLAIN.GetDescription(), teamName, "201712v67b52dea7aa94a669c766af506fd55d5", s);
                    }
                    var addTransacripts = results.AddTranscripts;
                    Assert.NotNull(addTransacripts);
                    Assert.Equal(HttpStatusCode.NoContent, addTransacripts.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 7
0
        public void CreateTextJob()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    content = Content.TEXT;
                    api     = ReviewAPI.JOB_CREATE;
                    HttpMockServer.Initialize("ReviewAPIs", "CreateTextJob");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, "Public", Workflow.TEXT_WORKFLOW.GetDescription(), content.GetDescription() + " Review");

                    var job = results.CreateJob;
                    Assert.NotNull(job);
                    Assert.Equal(HttpStatusCode.OK, job.Response.StatusCode);
                    Job = job.Body;
                    Assert.NotNull(Job);
                    Assert.NotNull(Job.JobIdProperty);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 8
0
        public void Evaluate()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "Evaluate");
                    //GetImageLists();

                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    api     = ContentModeratorAPI.EVALUATE;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);

                    var evaluate = results.Evaluate;
                    Assert.NotNull(evaluate);
                    Assert.Equal(HttpStatusCode.OK, evaluate.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
        // </snippet_review_vars>

        static void Main(string[] args)
        {
            // CLIENTS - each API call needs its own client
            // <snippet_client>
            // Create an image review client
            ContentModeratorClient clientImage = Authenticate(SubscriptionKey, Endpoint);
            // Create a text review client
            ContentModeratorClient clientText = Authenticate(SubscriptionKey, Endpoint);
            // Create a human reviews client
            ContentModeratorClient clientReviews = Authenticate(SubscriptionKey, Endpoint);

            // </snippet_client>

            // <snippet_imagemod_call>
            // Moderate images from list of image URLs
            ModerateImages(clientImage, ImageUrlFile, ImageOutputFile);
            // </snippet_imagemod_call>

            // <snippet_textmod_call>
            // Moderate text from text in a file
            ModerateText(clientText, TextFile, TextOutputFile);
            // </snippet_textmod_call>

            // <snippet_review_call>
            // Create image reviews for human reviewers
            CreateReviews(clientReviews, IMAGE_URLS_FOR_REVIEW, TEAM_NAME, ReviewsEndpoint);
            // </snippet_review_call>

            Console.WriteLine();
            Console.WriteLine("End of the quickstart.");
        }
Exemplo n.º 10
0
        public void OCR()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "OCR");
                    //GetImageLists();
                    //imageListId = ((int)allImageLists[1].Id).ToString();

                    api     = ContentModeratorAPI.OCR;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);

                    var ocr = results.OCR;
                    Assert.NotNull(ocr);
                    Assert.Equal(HttpStatusCode.OK, ocr.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyOCR(ocr.Body), TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 11
0
        public void OCRRaw()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "OCRRaw");
                    //wait(2);
                    Stream imgStream = new FileStream(rawImageCurrentPath, FileMode.Open, FileAccess.Read);
                    api    = ContentModeratorAPI.OCR;
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());

                    results = Constants.GetImageResponseRaw(client, api, "", imgStream, MIMETypes.IMAGE_JPEG.GetDescription());
                    if (results.InnerException == null)
                    {
                        var ocr = results.OCR;
                        Assert.NotNull(ocr);
                        Assert.Equal(HttpStatusCode.OK, ocr.Response.StatusCode);
                        Assert.True(Helpers.Utilities.VerifyOCR(ocr.Body), TestBase.ErrorMessage);
                    }
                    else
                    {
                        var ex = results.InnerException;
                        Assert.NotNull(ex);
                        Assert.Equal(HttpStatusCode.BadRequest, ex.Response.StatusCode);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 12
0
        public void Match()
        {
            try
            {
                using (MockContext context = MockContext.Start("ImageModerator"))
                {
                    HttpMockServer.Initialize("ImageModerator", "Match");

                    api     = ContentModeratorAPI.MATCH;
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetImageResponse(client, api, "", ImageUrlToModerate);
                    if (results != null)
                    {
                        var match = results.MatchImage;
                        Assert.NotNull(match);
                        Assert.Equal(HttpStatusCode.OK, match.Response.StatusCode);
                        Assert.True(Helpers.Utilities.VerifyMatchResponse(match.Body), TestBase.ErrorMessage);
                    }
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 13
0
        static void Main(string[] args)
        {
            using (ContentModeratorClient client = NewClient())
            {
                // Create a review with the content pointing to a streaming endpoint (manifest)
                var    streamingcontent = "https://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest";
                string review_id        = CreateReview(client, "review1", streamingcontent);

                var frame1_url = "https://blobthebuilder.blob.core.windows.net/sampleframes/ams-video-frame1-00-17.PNG";
                var frame2_url = "https://blobthebuilder.blob.core.windows.net/sampleframes/ams-video-frame-2-01-04.PNG";
                var frame3_url = "https://blobthebuilder.blob.core.windows.net/sampleframes/ams-video-frame-3-02-24.PNG";

                // Add the frames from 17, 64, and 144 seconds.
                AddFrame(client, review_id, frame1_url, "17");
                AddFrame(client, review_id, frame2_url, "64");
                AddFrame(client, review_id, frame3_url, "144");

                // Get frames information and show
                GetFrames(client, review_id);
                GetReview(client, review_id);

                // Publish the review
                PublishReview(client, review_id);

                Console.WriteLine("Open your Content Moderator Dashboard and select Review > Video to see the review.");
                Console.WriteLine("Press any key to close the application.");
                Console.Read();
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Removes images from an image list.
        /// </summary>
        /// <param name="client">The Content Moderator client.</param>
        /// <param name="listId">The list identifier.</param>
        /// <param name="imagesToRemove">The images to remove.</param>
        /// <remarks>Images are assigned content IDs when they are added to the list.
        /// Use the content ID to remove the image.</remarks>
        private static void RemoveImages(
            ContentModeratorClient client, int listId,
            IEnumerable <string> imagesToRemove)
        {
            foreach (var imageUrl in imagesToRemove)
            {
                if (!ImageIdMap.ContainsKey(imageUrl))
                {
                    continue;
                }
                int imageId = ImageIdMap[imageUrl];

                WriteLine();
                WriteLine($"Removing entry for {imageUrl} (ID = {imageId}) from list {listId}.", true);

                var result = client.ListManagementImage.DeleteImage(
                    listId.ToString(), imageId.ToString());
                Thread.Sleep(throttleRate);

                ImageIdMap.Remove(imageUrl);

                WriteLine("Response:");
                WriteLine(JsonConvert.SerializeObject(result, Formatting.Indented));
            }
        }
Exemplo n.º 15
0
        public void AddURLFramesVideoReview()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    rvwStatus = ReviewStatus.UNPUBLISHED;
                    //CreateVideoReview();

                    api = ReviewAPI.FRAMES_ADD;
                    HttpMockServer.Initialize("ReviewAPIs", "AddURLFramesVideoReview");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetVideoFramesReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, ReviewIds[0]);
                    results = Constants.GetVideoFramesReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, "201712v1f35675ed4d8457cbf84f4890ce59c58");

                    var review = results.AddFrames;
                    Assert.NotNull(review);
                    Assert.Equal(HttpStatusCode.NoContent, review.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 16
0
        public static ContentModeratorClient Authenticate(string key, string endpoint)
        {
            ContentModeratorClient client = new ContentModeratorClient(new ApiKeyServiceClientCredentials(key));

            client.Endpoint = endpoint;
            return(client);
        }
Exemplo n.º 17
0
        public void GetFramesVideoReview()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    rvwStatus = ReviewStatus.UNPUBLISHED;
                    //CreateVideoReview();
                    api = ReviewAPI.FRAMES_GET;
                    HttpMockServer.Initialize("ReviewAPIs", "GetFramesVideoReview");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetVideoFramesReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, ReviewIds[0]);
                    results = Constants.GetVideoFramesReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, "201712vbb90cbd620c0433dbecf70ad51e5563d");

                    var frames = results.GetFrames;
                    Assert.NotNull(frames);
                    Assert.Equal(HttpStatusCode.OK, frames.Response.StatusCode);
                    Assert.True(Helpers.Utilities.VerifyGetFrames(frames.Body), "Frames verification failed" + TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 18
0
        public static bool ModerateText(ContentModeratorClient client, string text)
        {
            Console.WriteLine("TEXT MODERATION");


            // Remove carriage returns
            text = text.Replace(Environment.NewLine, " ");
            // Convert string to a byte[], then into a stream (for parameter in ScreenText()).
            byte[]       textBytes = Encoding.UTF8.GetBytes(text);
            MemoryStream stream    = new MemoryStream(textBytes);


            using (client)
            {
                // Moderate the text
                var screenResult = client.TextModeration.ScreenText("text/plain", stream, "eng", true, true, null, true);
                //var badWords = JsonConvert.SerializeObject(screenResult, Formatting.Indented);
                if (screenResult.Terms == null)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
        }
Exemplo n.º 19
0
        public void AddTranscriptsModerationResult()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    rvwStatus = ReviewStatus.UNPUBLISHED;
                    //CreateVideoReview();
                    AddTranscripts();

                    api = ReviewAPI.TRANSCRIPTS_ADD_MODERATION_RESULT;
                    HttpMockServer.Initialize("ReviewAPIs", "AddTranscriptsModerationResult");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, ReviewIds[0]);
                    results = Constants.GetReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, "201712v67b52dea7aa94a669c766af506fd55d5");

                    var review = results.AddTranscriptsModerationResult;
                    Assert.NotNull(review);
                    Assert.Equal(HttpStatusCode.NoContent, review.Response.StatusCode);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 20
0
        /*
         * IMAGE MODERATION
         * This example moderates images from URLs.
         */
        public static void ModerateImages(ContentModeratorClient client, string urlFile, string outputFile)
        {
            Console.WriteLine("--------------------------------------------------------------");
            Console.WriteLine();
            Console.WriteLine("IMAGE MODERATION");
            Console.WriteLine();
            // Create an object to store the image moderation results.
            List <EvaluationData> evaluationData = new List <EvaluationData>();

            using (client)
            {
                // Read image URLs from the input file and evaluate each one.
                using (StreamReader inputReader = new StreamReader(urlFile))
                {
                    while (!inputReader.EndOfStream)
                    {
                        string line = inputReader.ReadLine().Trim();
                        if (line != String.Empty)
                        {
                            Console.WriteLine("Evaluating {0}...", Path.GetFileName(line));
                            var imageUrl  = new BodyModel("URL", line.Trim());
                            var imageData = new EvaluationData
                            {
                                ImageUrl = imageUrl.Value,

                                // Evaluate for adult and racy content.
                                ImageModeration =
                                    client.ImageModeration.EvaluateUrlInput("application/json", imageUrl, true)
                            };
                            Thread.Sleep(1000);

                            // Detect and extract text.
                            imageData.TextDetection =
                                client.ImageModeration.OCRUrlInput("eng", "application/json", imageUrl, true);
                            Thread.Sleep(1000);

                            // Detect faces.
                            imageData.FaceDetection =
                                client.ImageModeration.FindFacesUrlInput("application/json", imageUrl, true);
                            Thread.Sleep(1000);

                            // Add results to Evaluation object
                            evaluationData.Add(imageData);
                        }
                    }
                }
                // Save the moderation results to a file.
                using (StreamWriter outputWriter = new StreamWriter(outputFile, false))
                {
                    outputWriter.WriteLine(JsonConvert.SerializeObject(
                                               evaluationData, Formatting.Indented));

                    outputWriter.Flush();
                    outputWriter.Close();
                }
                Console.WriteLine();
                Console.WriteLine("Image moderation results written to output file: " + outputFile);
                Console.WriteLine();
            }
        }
Exemplo n.º 21
0
        public void GetImageJob()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    //CreateImageJob();
                    //wait(2);
                    content = Content.IMAGE;
                    //string Jobid = Job.JobIdProperty;
                    api = ReviewAPI.JOB_GET;
                    HttpMockServer.Initialize("ReviewAPIs", "GetImageJob");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, null, null, null, Jobid);
                    results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, null, null, null, "201712471f16b6733748a69e3cf66126d337fb");

                    var jobdetails = results.GetJobDetails;
                    Assert.NotNull(jobdetails);
                    var job = jobdetails.Body;
                    Assert.Equal("201712471f16b6733748a69e3cf66126d337fb", job.Id);
                    //Assert.Equal(Jobid, job.Id);
                    Assert.True(Helpers.Utilities.VerifyJob(Content.IMAGE, job), " " + TestBase.ErrorMessage);
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemplo n.º 22
0
        public void GetTextJob()
        {
            try
            {
                using (MockContext context = MockContext.Start("ReviewAPIs"))
                {
                    //CreateTextJob();
                    wait(2);
                    content = Content.TEXT;
                    //string Jobid = Job.JobIdProperty;
                    api = ReviewAPI.JOB_GET;
                    HttpMockServer.Initialize("ReviewAPIs", "GetTextJob");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, null, null, null, Jobid);
                    results = Constants.GetReviewResponse(client, api, content, MIMETypes.JSON.GetDescription(), teamName, null, null, null, "201712b43444e4be70470b80bff6605a33e77d");

                    var jobdetails = results.GetJobDetails;
                    Assert.NotNull(jobdetails);
                    var job = jobdetails.Body;
                    Assert.Equal("201712b43444e4be70470b80bff6605a33e77d", job.Id);
                    //Assert.Equal(Jobid, job.Id);
                    Assert.True(Helpers.Utilities.VerifyJob(Content.TEXT, job), " " + TestBase.ErrorMessage);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 23
0
 public void GetDetailsTermList()
 {
     try
     {
         using (MockContext context = MockContext.Start("TextListManagement"))
         {
             //GetTermLists();
             // wait(2);
             api = ContentModeratorAPI.GET_DETAILS_TERM_LIST;
             //TermListIdToUpdate = ((int)allTermLists[1].Id).ToString();
             HttpMockServer.Initialize("TextListManagement", "GetDetailsTermList");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetResponse(client, api, TermListIdToUpdate);
             results = Constants.GetResponse(client, api, "67");
             var getdetailsTermList = results.GetDetailsTermList;
             Assert.NotNull(getdetailsTermList);
             Assert.Equal(HttpStatusCode.OK, getdetailsTermList.Response.StatusCode);
             Assert.Equal("67", getdetailsTermList.Body.Id.ToString());
             //Assert.Equal(TermListIdToUpdate, getdetailsTermList.Body.Id.ToString());
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 24
0
 public void GetTextReview()
 {
     try
     {
         using (MockContext context = MockContext.Start("ReviewAPIs"))
         {
             //CreateTextReview();
             wait(2);
             //string reviewid = ReviewIds.Count > 0 ? ReviewIds[0] : null;
             api = ReviewAPI.REVIEW_GET;
             HttpMockServer.Initialize("ReviewAPIs", "GetTextReview");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetReviewResponse(client, api, Content.TEXT, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, reviewid);
             results = Constants.GetReviewResponse(client, api, Content.TEXT, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, "201712t9c7880135e834a939e4902ab82b5e97e");
             Review r = results.GetReview.Body;
             Assert.NotNull(r);
             Assert.Equal(HttpStatusCode.OK, results.GetReview.Response.StatusCode);
             Assert.Equal("201712t9c7880135e834a939e4902ab82b5e97e", r.ReviewId);
             //Assert.Equal(reviewid, r.ReviewId);
             Assert.True(Helpers.Utilities.VerifyReview(Content.TEXT, r), " " + TestBase.ErrorMessage);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
Exemplo n.º 25
0
        public void GetAllTerms()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetTermLists();
                    //wait(2);
                    api = ContentModeratorAPI.GET_ALL_TERMS;
                    //TermListId = ((int)allTermLists[1].Id).ToString();

                    HttpMockServer.Initialize("TextListManagement", "GetAllTerms");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId);
                    results = Constants.GetResponse(client, api, "67");
                    var getAllTermsFromListId = results.GetAllTerms;


                    allTerms = getAllTermsFromListId.Body;
                    Assert.NotNull(getAllTermsFromListId);
                    Assert.NotNull(getAllTermsFromListId.Body.Data);
                    Assert.NotNull(getAllTermsFromListId.Body.Paging);
                    Assert.Equal(HttpStatusCode.OK, getAllTermsFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 26
0
        /// <summary>
        /// Evaluates an image using the Image Moderation APIs.
        /// </summary>
        /// <param name="client">The Content Moderator API wrapper to use.</param>
        /// <param name="imageUrl">The URL of the image to evaluate.</param>
        /// <returns>Aggregated image moderation results for the image.</returns>
        /// <remarks>This method throttles calls to the API.
        /// Your Content Moderator service key will have a requests per second (RPS)
        /// rate limit, and the SDK will throw an exception with a 429 error code
        /// if you exceed that limit. A free tier key has a 1 RPS rate limit.
        /// </remarks>
        private static EvaluationData EvaluateImage(
            ContentModeratorClient client, string imageUrl)
        {
            var url = new BodyModel("URL", imageUrl.Trim());

            var imageData = new EvaluationData();

            imageData.ImageUrl = url.Value;

            // Evaluate for adult and racy content.
            imageData.ImageModeration =
                client.ImageModeration.EvaluateUrlInput("application/json", url, true);
            Thread.Sleep(1000);

            // Detect and extract text.
            imageData.TextDetection =
                client.ImageModeration.OCRUrlInput("eng", "application/json", url, true);
            Thread.Sleep(1000);

            // Detect faces.
            imageData.FaceDetection =
                client.ImageModeration.FindFacesUrlInput("application/json", url, true);
            Thread.Sleep(1000);

            return(imageData);
        }
Exemplo n.º 27
0
        public void DeleteTerm()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    //GetAllTerms();
                    //wait(2);
                    //if (allTerms.Data.Terms.Count == 0)
                    //{
                    //    AddTerm();
                    //    GetAllTerms();
                    //}

                    api = ContentModeratorAPI.DELETE_TERM;

                    HttpMockServer.Initialize("TextListManagement", "DeleteTerm");
                    client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    //results = Constants.GetResponse(client, api, TermListId, MIMETypes.JSON.GetDescription(), "eng", "test");
                    results = Constants.GetResponse(client, api, "67", MIMETypes.JSON.GetDescription(), "eng", "test");


                    var deleteTermFromListId = results.DeleteTerm;
                    Assert.NotNull(deleteTermFromListId);
                    Assert.Equal(HttpStatusCode.NoContent, deleteTermFromListId.Response.StatusCode);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
Exemplo n.º 28
0
 public void GetVideoReview()
 {
     try
     {
         using (MockContext context = MockContext.Start("ReviewAPIs"))
         {
             //CreateVideoReview();
             wait(2);
             //string reviewid = ReviewIds.Count > 0 ? ReviewIds[0] : null;
             api = ReviewAPI.REVIEW_GET;
             HttpMockServer.Initialize("ReviewAPIs", "GetVideoReview");
             client = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
             //results = Constants.GetReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, reviewid);
             results = Constants.GetReviewResponse(client, api, Content.VIDEO, MIMETypes.JSON.GetDescription(), teamName, null, null, null, null, "201712ve9d5eb16c9a247389ed371dbbf380b3c");
             Review r = results.GetReview.Body;
             Assert.NotNull(r);
             Assert.Equal(HttpStatusCode.OK, results.GetReview.Response.StatusCode);
             Assert.Equal("201712ve9d5eb16c9a247389ed371dbbf380b3c", r.ReviewId);
             //Assert.Equal(reviewid, r.ReviewId);
             Assert.True(Helpers.Utilities.VerifyReview(Content.VIDEO, r), " " + TestBase.ErrorMessage);
         }
     }
     catch (Exception e)
     {
         throw e;
     }
 }
Exemplo n.º 29
0
        public void GetTermLists()
        {
            try
            {
                using (MockContext context = MockContext.Start("TextListManagement"))
                {
                    api = ContentModeratorAPI.GET_ALL_TERM_LIST;
                    HttpMockServer.Initialize("TextListManagement", "GetTermLists");
                    client  = Constants.GenerateClient(api, HttpMockServer.CreateInstance());
                    results = Constants.GetResponse(client, api, string.Empty);
                    Assert.NotNull(results.GetAllTermLists);
                    Assert.Equal(HttpStatusCode.OK, results.GetAllTermLists.Response.StatusCode);

                    allTermLists = results.GetAllTermLists.Body.ToList();
                    if (allTermLists.Count > 0)
                    {
                        Assert.True(allTermLists.TrueForAll(x => !string.IsNullOrEmpty(((int)x.Id).ToString()) && !string.IsNullOrEmpty(x.Name) && x.Metadata != null), "Failed to get the result");
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        static void Main(string[] args)
        {
            using (ContentModeratorClient client = NewClient())
            {
                // Create a review with the content pointing to a streaming endpoint (manifest)
                var    streamingcontent = "https://amssamples.streaming.mediaservices.windows.net/91492735-c523-432b-ba01-faba6c2206a2/AzureMediaServicesPromo.ism/manifest";
                string review_id        = CreateReview(client, "review1", streamingcontent);

                var transcript = @"WEBVTT

                01:01.000 --> 02:02.000
                First line with a crap word in a transcript.

                02:03.000 --> 02:25.000
                This is another line in the transcript.
                ";

                AddTranscript(client, review_id, transcript);

                AddTranscriptModerationResult(client, review_id, transcript);

                // Publish the review
                PublishReview(client, review_id);

                Console.WriteLine("Open your Content Moderator Dashboard and select Review > Video to see the review.");
                Console.WriteLine("Press any key to close the application.");
                Console.Read();
            }
        }