Exemplo n.º 1
0
        /// <summary>
        /// Method to validate the media can be read by the application.
        /// </summary>
        /// <param name="mediaType">The media type; N for none, I for images, A for audio files, and V for video files.</param>
        /// <param name="mediaFileName">The media file name.</param>
        public void ValidateAndSetMedia(Constants.MediaType mediaType, string mediaFileName)
        {
            if (mediaType == Constants.MediaType.N)
            {
                if (!mediaFileName.ToLowerInvariant().Equals("null"))
                {
                    throw new ArgumentException("Filename should be NULL.");
                }
            }
            else
            {
                if (mediaFileName.ToLowerInvariant().Equals("null") || String.IsNullOrEmpty(mediaFileName))
                {
                    throw new ArgumentException("Missing media file name.");
                }
                switch (mediaType)
                {
                case Constants.MediaType.A:
                {
                    Regex regex = new Regex(@"^[\w\- ]+(.mp3)$");
                    if (!regex.Match(mediaFileName).Success)
                    {
                        throw new ArgumentException("Media format not supported for that media type.");
                    }
                    break;
                }

                case Constants.MediaType.I:
                {
                    Regex regex = new Regex(@"^[\w\- ]+(.jpg|.png)$");
                    if (!regex.Match(mediaFileName).Success)
                    {
                        throw new ArgumentException("Media format not supported for that media type.");
                    }
                    break;
                }

                case Constants.MediaType.V:
                {
                    Regex regex = new Regex(@"^[\w\- ]+(.mpg|.mpeg|.mp4)$");
                    if (!regex.Match(mediaFileName).Success)
                    {
                        throw new ArgumentException("Media format not supported for that media type.");
                    }
                    break;
                }

                default:
                {
                    throw new ArgumentException("Unsupported media type.");
                }
                }
                MediaType     = mediaType;
                MediaFileName = mediaFileName;
            }
        }
Exemplo n.º 2
0
 /// <summary>
 /// Constructor for adding multiple choice and true/false questions.
 /// </summary>
 /// <param name="questionType">The question type: KeyTerm, MultipleChoice, TrueFalse.</param>
 /// <param name="question">The final test question. Determined by code and settings for key terms/definitions.</param>
 /// <param name="mediaType">The media type: None, Audio, Image, Video.</param>
 /// <param name="mediaFileName">The media file name or null if no media is associated with the question.</param>
 /// <param name="numberOfChoices">The final number of possible answers for the question. Must be less than six.</param>
 /// <param name="choices">An array of possible answers to the test question.</param>
 /// <param name="correctAnswerIndex">The location of the correct answer in the choices array.</param>
 /// <param name="explanation">The explanation for the correct answer of the test question.</param>
 public TestQuestion(Constants.QuestionType questionType, string question, Constants.MediaType mediaType, string mediaFileName, int numberOfChoices, List <string> choices, int correctAnswerIndex, string explanation)
 {
     QuestionType       = questionType;
     Question           = question;
     MediaType          = mediaType;
     MediaFileName      = mediaFileName;
     NumberOfChoices    = numberOfChoices;
     Choices            = choices;
     CorrectAnswerIndex = correctAnswerIndex;
     Explanation        = explanation;
 }
        public async Task <ScreenTextResult> ScreenTextAsync(string content, Constants.MediaType mediaType,
                                                             string language, bool autocorrect, bool urls, bool pii, string listIds)
        {
            List <KeyValue> metaData = new List <KeyValue>();

            metaData.Add(new KeyValue()
            {
                Key   = "language",
                Value = language
            });
            metaData.Add(new KeyValue()
            {
                Key   = "autocorrect",
                Value = autocorrect.ToString()
            });
            metaData.Add(new KeyValue()
            {
                Key   = "urls",
                Value = urls.ToString()
            });
            metaData.Add(new KeyValue()
            {
                Key   = "PII",
                Value = pii.ToString()
            });
            metaData.Add(new KeyValue()
            {
                Key   = "listId",
                Value = listIds
            });

            metaData.Add(new KeyValue()
            {
                Key   = "subscription-key",
                Value = _subscriptionKey
            });

            return
                (await
                 InvokeTextModeratorAsync <string, ScreenTextResult>(content, Constants.Operations.Screen.ToString(),
                                                                     metaData, mediaType).ConfigureAwait(false));
        }
        private async Task <S> InvokeTextModeratorAsync <T, S>(dynamic textRequest, string operation, List <KeyValue> metaData, Constants.MediaType mediaType)
        {
            StringBuilder requestUrl = new StringBuilder(string.Concat(_apiRoot, $"/ProcessText/{operation}?"));

            foreach (var k in metaData)
            {
                requestUrl.Append(string.Concat(k.Key, "=", k.Value));
                requestUrl.Append("&");
            }
            var request = WebRequest.Create(requestUrl.ToString());

            request.ContentType = ModeratorHelper.GetEnumDescription(mediaType);

            return
                (await
                 this.SendAsync <T, S>("POST", textRequest, request)
                 .ConfigureAwait(false));
        }
        public async Task <IdentifyLanguageResult> IdentifyLanguageAsync(string content, Constants.MediaType mediaType)
        {
            List <KeyValue> metaData = new List <KeyValue>();

            metaData.Add(new KeyValue()
            {
                Key   = "subscription-key",
                Value = _subscriptionKey
            });

            return
                (await
                 InvokeTextModeratorAsync <string, IdentifyLanguageResult>(content, Constants.Operations.DetectLanguage.ToString(),
                                                                           metaData, mediaType).ConfigureAwait(false));
        }
Exemplo n.º 6
0
 public async Task <IdentifyLanguageResult> IdentifyLanguageAsync(string content, Constants.MediaType mediaType)
 {
     return
         (await this.InvokeTextModeratorAsync <string, IdentifyLanguageResult>(content, Constants.Operations.DetectLanguage.ToString(),
                                                                               mediaType));
 }