예제 #1
0
        public async Task <MatchResult> MatchImageAsync(Stream content, bool cacheImage, string listid)
        {
            var imageType = ModeratorHelper.GetImageFormat(content);

            if (imageType.Equals(ModeratorHelper.ImageFormat.unknown))
            {
                throw new Exception($"Image type: {imageType} not supported");
            }
            content.Position = 0;
            List <KeyValue> metaData = new List <KeyValue>();

            metaData.Add(new KeyValue()
            {
                Key   = "CacheImage",
                Value = cacheImage.ToString()
            });

            metaData.Add(new KeyValue()
            {
                Key   = "listid",
                Value = listid
            });

            return(await this.InvokeImageModeratorAsync <Stream, MatchResult>(content, Constants.Operations.Match.ToString(), metaData).ConfigureAwait(false));
        }
예제 #2
0
        public async Task <CreateJobResult> CreateJob(string teamName, Stream content, ContentType contentType,
                                                      string contentId, string workFlowName,
                                                      string callBackEndpoint)
        {
            var imageType = ModeratorHelper.GetImageFormat(content);

            if (imageType.Equals(ModeratorHelper.ImageFormat.unknown))
            {
                throw new Exception($"Image type: {imageType} not supported");
            }
            content.Position = 0;
            List <KeyValue> metaData = new List <KeyValue>();

            metaData.Add(new KeyValue()
            {
                Key   = "ContentType",
                Value = contentType.ToString()
            });

            metaData.Add(new KeyValue()
            {
                Key   = "ContentId",
                Value = contentId
            });

            metaData.Add(new KeyValue()
            {
                Key   = "WorkflowName",
                Value = workFlowName
            });

            metaData.Add(new KeyValue()
            {
                Key   = "CallBackEndpoint",
                Value = callBackEndpoint
            });

            return
                (await
                 InvokeAsync <Stream, CreateJobResult>(content,
                                                       string.Format(Constants.CREATE_JOB, teamName), Constants.HttpMethod.POST, metaData)
                 .ConfigureAwait(false));
        }
예제 #3
0
        private async Task <S> InvokeTextModeratorAsync <T, S>(dynamic textRequest, string operation, Constants.MediaType mediaType, List <KeyValue> metaData = null)
        {
            StringBuilder requestUrl = new StringBuilder(string.Concat(this.ApiRoot, $"/ProcessText/{operation}?"));

            if (metaData != null)
            {
                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));
        }