Ejemplo n.º 1
0
        private async void GetSynonymsButton_Click(object sender, RoutedEventArgs e)
        {
            SynonymsServiceClientLibrary.SynonymsServiceResponse synonymsResponse =
                await synonymsClient.GetSynonymsAsync(Term.Text);

            await DisplaySynonymsResponse(synonymsResponse);
        }
Ejemplo n.º 2
0
        private async System.Threading.Tasks.Task DisplaySynonymsResponse(SynonymsServiceClientLibrary.SynonymsServiceResponse synonymsResponse)
        {
            string synonymsOutput = "";

            if (synonymsResponse.Status == AppServiceResponseStatus.Success)
            {
                foreach (var item in synonymsResponse.Synonyms)
                {
                    synonymsOutput += "|" + item;
                }

                var cd = new ContentDialog();
                cd.Title               = "Synonyms=" + synonymsOutput;
                cd.PrimaryButtonText   = "OK";
                cd.PrimaryButtonClick += (s, a) => cd.Hide();
                await cd.ShowAsync();
            }
            else
            {
                await new MessageDialog("Synonyms API call failed").ShowAsync();
            }
        }
Ejemplo n.º 3
0
        public async Task <SynonymsServiceResponse> GetSynonymsAsync(string term)
        {
            SynonymsServiceResponse callresponse = new SynonymsServiceResponse()
            {
                Status   = AppServiceResponseStatus.Unknown,
                Synonyms = null,
            };

            List <string> synonyms = new List <string>();

            await EnsureConnectionToSynonymsService();

            //Send data to the service
            var message = new ValueSet();

            message.Add("Command", "GetSynonym");
            message.Add("Term", term);

            //Send a message
            AppServiceResponse response = await synonymsServiceConnection.SendMessageAsync(message);

            if (response.Status == AppServiceResponseStatus.Success)
            {
                if (response.Message.ContainsKey("Result"))
                {
                    synonyms = Newtonsoft.Json.JsonConvert.DeserializeObject <List <string> >((string)response.Message["Result"]);
                }
                else if (response.Message.ContainsKey("Error"))
                {
                    throw new Exception("Error:" + response.Message["Error"]);
                }
            }

            callresponse.Status   = response.Status;
            callresponse.Synonyms = synonyms;

            return(callresponse);
        }
Ejemplo n.º 4
0
        public async Task<SynonymsServiceResponse> GetSynonymsAsync(string term)
        {
            SynonymsServiceResponse callresponse = new SynonymsServiceResponse()
            {
                Status = AppServiceResponseStatus.Unknown,
                Synonyms = null,
            };

            List<string> synonyms = new List<string>();

            await EnsureConnectionToSynonymsService();

            //Send data to the service 
            var message = new ValueSet();
            message.Add("Command", "GetSynonym");
            message.Add("Term", term);

            //Send a message  
            AppServiceResponse response = await synonymsServiceConnection.SendMessageAsync(message);
            if (response.Status == AppServiceResponseStatus.Success)
            {
                if (response.Message.ContainsKey("Result"))
                {
                    synonyms = Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>((string)response.Message["Result"]);
                }
                else if (response.Message.ContainsKey("Error"))
                {
                    throw new Exception("Error:" + response.Message["Error"]);
                }
            }

            callresponse.Status = response.Status;
            callresponse.Synonyms = synonyms;

            return callresponse;
        }