Premkumar Elangovan
Posts: 14
Joined: 2018-12-28
|
I am trying to call an asynchronous function (paraPhraseApi) upon clicking the Button (rewordButton) in the Ribbon. From the previous blogs, I understand that it is recommended to use SendMessage/OnSendMessage to safely update the GUI upon completion of the asynchronous function. The problem I am having is that the AddinModule_OnSendMessage() function is not getting called after SendMessage() is invoked. I don't know what I am missing here, I would appreciate some help.
private async void rewordButton_OnClick(object sender, IRibbonControl control, bool pressed)
{
int x = await paraPhraseApi(selectText);
this.SendMessage(1);
}
public async Task<int> paraPhraseApi(string selectText)
{
this.paraphraseApiText = selectText;
string text = Regex.Replace(selectText, @" |
|
", " ");
var client = new HttpClient();
var request = new HttpRequestMessage
{
Method = HttpMethod.Post,
RequestUri = new Uri("https://xxxxx.p.rapidapi.com/api/rewrite"),
Headers =
{
{ "x-rapidapi-key", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" },
{ "x-rapidapi-host", "xxx.x.rapidapi.com" },
},
Content = new StringContent("{
"sourceText": "" + text + ""
}")
{
Headers =
{
ContentType = new MediaTypeHeaderValue("application/json")
}
}
};
using (var response = await client.SendAsync(request))
{
try
{
response.EnsureSuccessStatusCode();
// Handle success
var body = await response.Content.ReadAsStringAsync();
this.paraphraseApiText = body.ToString();
return 1;
}
catch (HttpRequestException)
{
return 0;
}
}
}
private void AddinModule_OnSendMessage(object sender, ADXSendMessageEventArgs e)
{
ResultsWordTaskPaneNew taskPane = (ResultsWordTaskPaneNew)this.adxWordTaskPanesCollectionResults.CurrentTaskPaneInstance;
taskPane.RegionState = AddinExpress.WD.ADXRegionState.Hidden;
taskPane.Hide();
taskPane.TextBox_update(this.paraphraseApiText);
taskPane.Show();
taskPane.RegionState = AddinExpress.WD.ADXRegionState.Normal;
}
|
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Hello Premkumar,
Premkumar Elangovan writes:
this.SendMessage(1);
The constant passed to that method should be greater than 1024.
Andrei Smolin
Add-in Express Team Leader |
|
Premkumar Elangovan
Posts: 14
Joined: 2018-12-28
|
Thanks Andrei. It works now. |
|
Andrei Smolin
Add-in Express team
Posts: 18821
Joined: 2006-05-11
|
Welcome!
Andrei Smolin
Add-in Express Team Leader |
|