Ejemplo n.º 1
0
        public async void RequestContainsExistedWords()
        {
            // arrange
            int userId  = 1;
            int otherId = 2;

            using InWordsDataContext context = InWordsDataContextFactory.Create();
            await context.AddAccount(userId);

            await context.AddAccount(otherId);

            await context.SaveChangesAsync();

            context.Add(CreateUserWordPair(userId, "0", "0-0", 1));
            context.Add(CreateUserWordPair(userId, "1", "1-1", 2));
            context.Add(CreateUserWordPair(otherId, "2", "2-2", 3));
            context.Add(CreateUserWordPair(userId, "3", "3-3", 4));
            await context.SaveChangesAsync();

            // act
            var service     = new GetUserWords(context);
            var requestData = new GetWordsRequest();

            requestData.UserWordpairIds.Add(new int[] { 1, 2, 99, 100 });
            var request = new AuthReq <GetWordsRequest, WordsReply>(requestData)
            {
                UserId = userId
            };
            var reply = await service.HandleRequest(request, default);

            // assert
            Assert.Equal(4, reply.ToAdd[0].UserWordPair);
            Assert.Equal(new int[] { 99, 100 }, reply.ToDelete.ToArray());
        }
Ejemplo n.º 2
0
        public async void GetUserWords()
        {
            // arrange
            int userId  = 1;
            int otherId = 2;

            using InWordsDataContext context = InWordsDataContextFactory.Create();
            await context.AddAccount(userId);

            await context.AddAccount(otherId);

            await context.SaveChangesAsync();

            context.Add(CreateUserWordPair(userId, "0", "0-0"));
            context.Add(CreateUserWordPair(userId, "1", "1-1"));
            context.Add(CreateUserWordPair(userId, "3", "3-3"));
            context.Add(CreateUserWordPair(otherId, "2", "2-2"));
            await context.SaveChangesAsync();

            // act
            var service     = new GetUserWords(context);
            var requestData = new GetWordsRequest();
            var request     = new AuthReq <GetWordsRequest, WordsReply>(requestData)
            {
                UserId = userId
            };
            var reply = await service.HandleRequest(request, default);

            // assert
            Assert.Equal(context.UserWordPairs.Where(d => d.UserId == userId).Count(), reply.ToAdd.Count());
            Assert.Empty(reply.ToDelete);
        }
Ejemplo n.º 3
0
        public override async Task <WordsReply> GetWords(GetWordsRequest request, ServerCallContext context)
        {
            var reqestObject = new AuthorizedRequestObject <GetWordsRequest, WordsReply>(request)
            {
                UserId = context.GetHttpContext().User.GetUserId()
            };
            WordsReply reply = await mediator.Send(reqestObject).ConfigureAwait(false);

            return(reply);
        }
Ejemplo n.º 4
0
        public async Task <IActionResult> GetWords([FromBody] GetWordsRequest request)
        {
            var reqestObject = new AuthorizedRequestObject <GetWordsRequest, WordsReply>(request)
            {
                UserId = User.GetUserId()
            };
            WordsReply reply = await mediator.Send(reqestObject).ConfigureAwait(false);

            return(Ok(reply));
        }
Ejemplo n.º 5
0
        public ViewResult Index(int? pageSize, int? page)
        {
            var size = pageSize ?? 15;
            var pageNumber = page ?? 1;

            var request = new GetWordsRequest(size, pageNumber);

            var response = _facade.Query<GetWordsResponse, GetWordsRequest>(request);

            var viewModel = new WordsViewModel(response.Words, size, pageNumber, response.Total);

            return View(viewModel);
        }
Ejemplo n.º 6
0
 public GetWordsResponse GetWords(GetWordsRequest request)
 {
     try
     {
         return(DB.GetWords(request.SongId));
     }
     catch (Exception ex)
     {
         var x = new GetWordsResponse()
         {
             Words = new List <Tuple <Guid, string> >()
         };
         x.Words.Add(new Tuple <Guid, string>(Guid.Empty, ex.ToString()));
         return(x);
     }
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Get words in input string Get the component words in an input string
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="input">String to process</param>
        /// <returns>Task of ApiResponse (GetWordsResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <GetWordsResponse> > SegmentationGetWordsAsyncWithHttpInfo(GetWordsRequest input)
        {
            // verify the required parameter 'input' is set
            if (input == null)
            {
                throw new ApiException(400, "Missing required parameter 'input' when calling SegmentationApi->SegmentationGetWords");
            }

            var    localVarPath         = "./nlp-v2/segmentation/words";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(this.Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json",
                "text/json",
                "application/xml",
                "text/xml",
                "application/x-www-form-urlencoded"
            };
            String localVarHttpContentType = this.Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = this.Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (input != null && input.GetType() != typeof(byte[]))
            {
                localVarPostBody = this.Configuration.ApiClient.Serialize(input); // http body (model) parameter
            }
            else
            {
                localVarPostBody = input; // byte array
            }

            // authentication (Apikey) required
            if (!String.IsNullOrEmpty(this.Configuration.GetApiKeyWithPrefix("Apikey")))
            {
                localVarHeaderParams["Apikey"] = this.Configuration.GetApiKeyWithPrefix("Apikey");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await this.Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                            Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                            localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("SegmentationGetWords", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <GetWordsResponse>(localVarStatusCode,
                                                      localVarResponse.Headers.ToDictionary(x => x.Key, x => x.Value.ToString()),
                                                      (GetWordsResponse)this.Configuration.ApiClient.Deserialize(localVarResponse, typeof(GetWordsResponse))));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Get words in input string Get the component words in an input string
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="input">String to process</param>
        /// <returns>Task of GetWordsResponse</returns>
        public async System.Threading.Tasks.Task <GetWordsResponse> SegmentationGetWordsAsync(GetWordsRequest input)
        {
            ApiResponse <GetWordsResponse> localVarResponse = await SegmentationGetWordsAsyncWithHttpInfo(input);

            return(localVarResponse.Data);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Get words in input string Get the component words in an input string
        /// </summary>
        /// <exception cref="Cloudmersive.APIClient.NETCore.NLP.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="input">String to process</param>
        /// <returns>GetWordsResponse</returns>
        public GetWordsResponse SegmentationGetWords(GetWordsRequest input)
        {
            ApiResponse <GetWordsResponse> localVarResponse = SegmentationGetWordsWithHttpInfo(input);

            return(localVarResponse.Data);
        }