AddinModule_OnSendMessage() not getting called after SendMessage() is invoked

Add-in Express™ Support Service
That's what is more important than anything else

AddinModule_OnSendMessage() not getting called after SendMessage() is invoked
 
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;
        }
Posted 06 Apr, 2021 18:25:09 Top
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
Posted 07 Apr, 2021 02:12:37 Top
Premkumar Elangovan




Posts: 14
Joined: 2018-12-28
Thanks Andrei. It works now.
Posted 07 Apr, 2021 06:03:17 Top
Andrei Smolin


Add-in Express team


Posts: 18821
Joined: 2006-05-11
Welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 07 Apr, 2021 06:04:35 Top