public async Task <MessageResponse> ListFilesHandler(Message message, object context) { try { string sourcePath = message.Properties["path"]; string[] files = await local.ListFiles(sourcePath); //return the output string jsonString = JsonConvert.SerializeObject(files); Message output = new Message(Encoding.UTF8.GetBytes(jsonString)); output.Properties.Add("path", sourcePath); await client.SendEventAsync("listFilesOutput", output); } catch (Exception ex) { Console.WriteLine("ERROR: EdgeHub-ListFilesHandler '{0}'", ex.Message); } finally { ModuleClient mc = (ModuleClient)context; await mc.CompleteAsync(message); } return(MessageResponse.Completed); }
public async Task <HttpResponseMessage> ListFiles(string path) { try { string[] fileList = await local.ListFiles(path); return(new HttpResponseMessage(System.Net.HttpStatusCode.OK) { Content = new ObjectContent <string[]>(fileList, new JsonMediaTypeFormatter()) }); } catch (Exception ex) { Console.WriteLine(ex.Message); return(new HttpResponseMessage(System.Net.HttpStatusCode.InternalServerError)); //{ ReasonPhrase = ex.Message }; } }