Esempio n. 1
0
        public async Task <MessageResponse> UploadFileHandler(Message message, object context)
        {
            try
            {
                string sourcePath     = message.Properties["path"];
                string sourceFilename = message.Properties["filename"];
                string contentType    = message.Properties["contentType"];
                string containerName  = message.Properties.ContainsKey("blobPath") ? message.Properties["blobPath"] : null;
                string targetFilename = message.Properties.ContainsKey("blobFilename") ? message.Properties["blobFilename"] : null;
                string sasUri         = message.Properties.ContainsKey("sasUri") ? message.Properties["sasUri"] : null;
                bool   append         = message.Properties.ContainsKey("append") ? Convert.ToBoolean(message.Properties["append"]) : false;

                if (sasUri == null)
                {
                    await local.UploadFile(sourcePath, sourceFilename, containerName, targetFilename, contentType, append);
                }
                else
                {
                    await local.UploadFile(sourcePath, sourceFilename, sasUri, contentType, append);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: EdgeHub-EdgeHub-UploadFileHandler '{0}'", ex.Message);
            }
            finally
            {
                ModuleClient mc = (ModuleClient)context;
                await mc.CompleteAsync(message);
            }

            return(MessageResponse.Completed);
        }
Esempio n. 2
0
        public async Task <MessageResponse> GetFileHandler(Message message, object context)
        {
            try
            {
                string sourcePath     = message.Properties["path"];
                string sourceFilename = message.Properties["filename"];
                byte[] content        = await local.GetFile(sourcePath, sourceFilename);

                //return the output
                Message output = new Message(content);
                output.Properties.Add("path", sourcePath);
                output.Properties.Add("filename", sourceFilename);
                await client.SendEventAsync("getFileOutput", output);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: EdgeHub-GetFileHandler '{0}'", ex.Message);
            }
            finally
            {
                ModuleClient mc = (ModuleClient)context;
                await mc.CompleteAsync(message);
            }

            return(MessageResponse.Completed);
        }
Esempio n. 3
0
        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);
        }
Esempio n. 4
0
        public async Task <MessageResponse> RemoveFileHandler(Message message, object context)
        {
            try
            {
                string sourcePath     = message.Properties["path"];
                string sourceFilename = message.Properties["filename"];
                await local.RemoveFile(sourcePath, sourceFilename);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: EdgeHub-RemoveFileHandler '{0}'", ex.Message);
            }
            finally
            {
                ModuleClient mc = (ModuleClient)context;
                await mc.CompleteAsync(message);
            }

            return(MessageResponse.Completed);
        }
Esempio n. 5
0
        public async Task <MessageResponse> WriteFileHandler(Message message, object context)
        {
            try
            {
                string sourcePath     = message.Properties["path"];
                string sourceFilename = message.Properties["filename"];
                bool   append         = message.Properties.ContainsKey("append") ? Convert.ToBoolean(message.Properties["append"]) : false;
                byte[] content        = message.GetBytes();
                await local.WriteFile(sourcePath, sourceFilename, content, append);
            }
            catch (Exception ex)
            {
                Console.WriteLine("ERROR: EdgeHub-WriteFileHandler '{0}'", ex.Message);
            }
            finally
            {
                ModuleClient mc = (ModuleClient)context;
                await mc.CompleteAsync(message);
            }

            return(MessageResponse.Completed);
        }