in docker_images/csharp/wrapper/src/Glue/ModuleGlue.cs [133:171]
public async Task<EventBody> WaitForInputMessageAsync(string connectionId, string inputName)
{
Console.WriteLine("WaitForInputMessageAsync received for {0} with inputName {1}", connectionId, inputName);
var mutex = new System.Threading.SemaphoreSlim(1);
await mutex.WaitAsync().ConfigureAwait(false); // Grab the mutex. The handler will release it later
byte[] bytes = null;
var client = objectMap[connectionId];
MessageHandler handler = async (msg, context) =>
{
Console.WriteLine("message received");
bytes = msg.GetBytes();
await client.SetInputMessageHandlerAsync(inputName, null, null).ConfigureAwait(false);
Console.WriteLine("releasing inputMessage mutex");
mutex.Release();
return MessageResponse.Completed;
};
Console.WriteLine("Setting input handler");
await client.SetInputMessageHandlerAsync(inputName, handler, null).ConfigureAwait(false);
Console.WriteLine("Waiting for inputMessage mutex to release");
await mutex.WaitAsync().ConfigureAwait(false);
Console.WriteLine("mutex triggered.");
string s = Encoding.UTF8.GetString(bytes);
Console.WriteLine("message = {0}", s as object);
object result;
try
{
result = JsonConvert.DeserializeObject(s);
}
catch(JsonReaderException)
{
result = s;
}
return new Models.EventBody
{
Body = result
};
}