Пример #1
0
        static async Task <MessageResponse> ModuleLoadedMessageHandler(Message msg, object ctx)
        {
            try
            {
                AzureModule module    = (AzureModule)ctx;
                var         msgBytes  = msg.GetBytes();
                var         msgString = Encoding.UTF8.GetString(msgBytes);
                Log.WriteLine("loadModule msg received: '{0}'", msgString);
                var loadMsg = JsonConvert.DeserializeObject <ModuleLoadedMessage>(msgString);
                await module.ProcessModuleLoadedMessage(loadMsg);

                return(MessageResponse.Completed);
            }
            catch (Exception e)
            {
                Log.WriteLine("Exception in ModuleLoadedMessageHandler: '{0}'", e.ToString());
            }
            Environment.Exit(3);
            return(MessageResponse.Abandoned);
        }
Пример #2
0
        private async Task <MethodResponse> SetModuleLoaded(MethodRequest req, object context)
        {
            try
            {
                string data = Encoding.UTF8.GetString(req.Data);
                Log.WriteLine("Direct Method SetModuleLoaded {0}", data);
                var         loadMsg = JsonConvert.DeserializeObject <ModuleLoadedMessage>(data);
                AzureModule module  = (AzureModule)context;
                await module.ProcessModuleLoadedMessage(loadMsg);

                // Acknowlege the direct method call with a 200 success message
                string result = "{\"result\":\"Executed direct method: " + req.Name + "\"}";
                return(new MethodResponse(Encoding.UTF8.GetBytes(result), 200));
            }
            catch (Exception e)
            {
                Log.WriteLine("Exception in SetModuleLoaded: '{0}'", e.ToString());
            }
            Environment.Exit(3);
            return(null);
        }