Wait for a thread to finish before passing the value - vb.net

I am coding a telegram bot that can search Wikipedia with telegram api and vb.net. If someone sends a message saying "wiki xyz" (telegram api, Onmessage)bot gives info about xyz. The problem is about simultaneous messages, if a user with a specific chat ID requests a wiki search and while its in progess if a second (or even third) requests the same then the chat ID and the wiki search term gets mixed up. How to wait for the first user's request being processed and sent before processing the second(or even 3rd) request?
Here is the code
Private Async Sub OnMessageReceived(sender As Object, e As MessageEventArgs)
Dim sender As String = e.Message.From.Id.ToString
Dim msg As String = e.Message.Body.toString
If msg.StartsWith("wiki") Then
Dim query as String= msg.replace("wiki","")
'''do Wikipedia search with query and sending the reply to sender
Await sendMessage(sender, formattedWikitxt.ToString)
End If
the problem is that while receiving simultaneous requests, the variables "sender" and "query" gets changed before the message is delivered and users are getting some other query in reply instead. How to make this task wait before the first user receives message before processing the request of the second(or even 3rd)?

Related

Trying to use adminp.DeleteReplicas followed by adminp.ApproveReplicaDeletion gives error "Invalid Approval Request note"

I am trying delete a database and any associated replicas using LotusScript adminp calls. This is basically the code:
Dim session As New NotesSession
Dim adminp As NotesAdministrationProcess
Set adminp = session.CreateAdministrationProcess("Software_Server")
noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1")
If noteid$ <> "" Then
Call adminp.ApproveReplicaDeletion(noteid$) 'This is where the error is thrown
End If
The first adminp call is successful and returns a noteid, and if I look in the admin requests database can see the document. The next call to ApproveReplicateDeletion results in the error "Invalid Approval Request note"
The documentation doesn't contain any examples for the adminp approve methods. I have a feeling that maybe the second request cannot be called until much later when adminp has processed the first request?
Also related question, do I only have to make this request on a single server and it will remove replicas on all other servers, or do I need to make this request for each server?
So this is a bit more complicated than the help gives any indication of, and might explain why I couldn't find any examples on the internet on how to do it. So the Workflow for using AdminP is as Follows:
Create the request to get the noteID for the initial noteid of the DeleteReplicas request. The returned noteID is not the one that is used to approve the delete replica request. noteid$ = adminp.DeleteReplicas("Software_Server", "Guys1")
This creates a document in the admin.nsf db for the initial request, but the approval docs don't yet exist, for the server to create those, the adminp process must run.
So in the code send a Console command to the Server "tell adminp process now"
Sleep the agent for a few seconds to give adminp time to process the request (this will also fire off any other waiting adminp requests unfortunately)
Now new documents will have been created in the admin database, that are awaiting approval by an admin. These documents contain the noteids that should be sent the approvereplicadeletion
To get them, first lookup the notes document by the noteID in the admin db obtained in step 1
Using that noteid for the document, get the field value ProxyOriginatingRequestUNID from the document.
using this UNID value, perform a getalldocumentsbykey on the view ($AllRequestsbyOriginatingUNID)
if the returned document has a ProxyAction field with a value of "82", this is an approval request document. This documents noteid can be passed to approveReplicaDeletion to have adminp remove the database next time it processes requests.
You can either send a console command to process adminp again, or just wait for the database deletions etc. to happen next time around.

How long to wait for get api key or response from developer#support from BestBuy?

How long to wait for get api key or response from developer#support from BestBuy?
I get a message with some text in https://developer.bestbuy.com/secure/dashboard:
"The admin for your company has been notified of your request and you will need to be approved."
I get a new request with my domain email and i get a new api key. You need to specify the domain's mail and no other and you will get a key in a few minutes.

VB.NET: API callback - get caller information

I am accessing a data service that provides an .NET api to retrieve market data. Basically, the request looks like this (simpliefied)...
For Each myID in myListofIDs
myRequest = myDataService.Realtime.GetID(myID, AddressOf ReturnDataFunction, AddressOf ReturnErrorFunction)
Next
I send multiple requests in the same thread, the requests are then done performed assynchronously by the API. At the end the data is recieved from the callbackbackfunction and I can store it.
However, here's my problem: None of the callback functions returns the original IDs but only the data. If I get an error and "ReturnErrorFunction" is called, the only information I get from the error message is, that "the ID cannot be found" - but it wont tell me which ID has caused the error.
Is there any information to include an additional paramater to the callback definition in my code or is there a way to trace the original function that started the call?
Would be glad if you can tell me if I have any options here to avoid this problem... Thanks.
I think you could do something like this:
myRequest = myDataService.Realtime.GetID(myID,
AddressOf ReturnDataFunction,
Sub(myResult As String)
Call ReturnErrorFunction(myResult, myID)
End Sub)
There are some potential technical issues in the event that the callback is stored and potentially called later, after the loop concludes, but I won't get into those unless it's actually relevant to you.

read XML Response from server after POST data

I am sending POST data to PHP webpage from my windows app using VB.net. The code is as follows:
Dim data As String = "this is a test data push"
Dim wc As New WebClient
wc.Headers(HttpRequestHeader.ContentType) = "application/x-www-form-urlencoded"
wc.UploadStringAsync(uri, data)
The data gets stored. In the PHP page, I am sending an XML response back to the phone
header('Content-type: text/xml');
echo '';
echo '<count>';
echo '<',$i,'>'
echo '</count>';
echo '';
How do I use WebClient to read the RESPONSE back? Any help would be appreciated. Thanks alot.
You need to subscribe to the UploadStringCompleted event. See http://msdn.microsoft.com/en-us/library/ms144239.aspx for more details, but here is an excerpt:
This method sends a string to a resource. The string is sent
asynchronously using thread resources that are automatically allocated
from the thread pool. Before uploading the string, this method
converts it to a Byte array using the encoding specified in the
Encoding property. To receive notification when the string upload
completes, you can add an event handler to the UploadStringCompleted
event.
Drilling farther in, you can see that even returns a UploadStringCompletedEventArgs object that includes the results via the Result property. See http://msdn.microsoft.com/en-us/library/system.net.uploadstringcompletedeventargs.aspx for more details.

Negative Testing for PayPal using Sandbox with VB.NET - how to simulate different scenarios?

I have a website written in VB.NET that implements PayPal for payments. This is all working fine for successful payments, but I need to be able to simulate scenarios of a failed transaction, pending transaction, etc.
I have read the documentation, which starts on page 47. I enabled Negative Testing in a business account that I created in a Sandbox, but I am not getting desired results.
To simulate an error, as specified in the documentation, I'm passing an error code to Token, which is then used in a request to DoExpressCheckoutPayment - code below - but instead of this raising the error 10417, the response says Invalid Token:
Dim oldToken As String
With RequestDetails
oldToken = .Token
.Token = "10417"
End With
Dim request As New DoExpressCheckoutPaymentRequestType
request.DoExpressCheckoutPaymentRequestDetails = RequestDetails
Dim response As DoExpressCheckoutPaymentResponseType
response = DirectCast(caller.Call("DoExpressCheckoutPayment", request),
DoExpressCheckoutPaymentResponseType)
Questions:
What am I doing wrong in the code above so that I can't trigger a correct error?
How do I simulate a response where the status is Pending, Processed, Failed, etc.?
I was testing this about a week ago and was receiving the same problem, now, I no longer receive an error:
API Request:
METHOD=DoExpressCheckoutPayment
VERSION=82
token=10755
PayerID=GNT5WLV6WKLYW
PAYMENTACTION=Sale
AMT=456
PAYMENTREQUEST_0_AMT=458
PAYMENTREQUEST_0_ITEMAMT=458.00
PAYMENTREQUEST_0_SHIPPINGAMT=20.00
PAYMENTREQUEST_0_TAXAMT=46.20
PAYMENTREQUEST_0_CURRENCYCODE=USD
PAYMENTREQUEST_0_DESC=test EC payment
L_PAYMENTREQUEST_0_NAME0=Books
L_PAYMENTREQUEST_0_AMT0=154.00
L_PAYMENTREQUEST_0_NUMBER0=ABC123
L_PAYMENTREQUEST_0_QTY0=2
L_PAYMENTREQUEST_0_NAME1=CDs
L_PAYMENTREQUEST_0_AMT1=50.00
L_PAYMENTREQUEST_0_NUMBER1=BY-Z4736
L_PAYMENTREQUEST_0_QTY1=3
API Response:
TIMESTAMP=2011-09-27T20:39:57Z
CORRELATIONID=13126abeb4615
ACK=Failure
VERSION=82
BUILD=2133933
L_ERRORCODE0=10755
L_SHORTMESSAGE0=Unsupported Currency.
L_LONGMESSAGE0=Currency is not supported
L_SEVERITYCODE0=Error
I did find an article on x.com that deals with this issue as well.