Пример #1
0
        private void Publish(string replyTo, RemoteException exception)
        {
            // TODO UGLY!
            string blobstoreID = null;

            if (null != exception.Blob)
            {
                string tmpFile = Path.GetTempFileName();
                try
                {
                    File.WriteAllText(tmpFile, exception.Blob);
                    IBlobstoreClient bsc = blobstoreClientFactory.Create();
                    blobstoreID = bsc.Create(tmpFile);
                }
                finally
                {
                    if (File.Exists(tmpFile))
                    {
                        File.Delete(tmpFile);
                    }
                }
            }
            var    pMessage     = new JProperty("message", exception.Message);
            var    pBacktrace   = new JProperty("backtrace", exception.Backtrace);
            var    pBlobstoreID = new JProperty("blobstore_id", blobstoreID);
            var    jobj         = new JObject(new JProperty("exception", new JObject(pMessage, pBacktrace, pBlobstoreID)));
            string json;

            using (var sw = new StringWriter())
            {
                using (var writer = new JsonTextWriter(sw))
                {
                    jobj.WriteTo(writer);
                }
                json = sw.ToString();
            }
            Publish(replyTo, json);
        }
Пример #2
0
 private void Publish(string replyTo, RemoteException exception)
 {
     // TODO UGLY!
     string blobstoreID = null;
     if (null != exception.Blob)
     {
         string tmpFile = Path.GetTempFileName();
         try
         {
             File.WriteAllText(tmpFile, exception.Blob);
             IBlobstoreClient bsc = blobstoreClientFactory.Create();
             blobstoreID = bsc.Create(tmpFile);
         }
         finally
         {
             if (File.Exists(tmpFile))
             {
                 File.Delete(tmpFile);
             }
         }
     }
     var pMessage = new JProperty("message", exception.Message);
     var pBacktrace = new JProperty("backtrace", exception.Backtrace);
     var pBlobstoreID = new JProperty("blobstore_id", blobstoreID);
     var jobj = new JObject(new JProperty("exception", new JObject(pMessage, pBacktrace, pBlobstoreID)));
     string json;
     using (var sw = new StringWriter())
     {
         using (var writer = new JsonTextWriter(sw))
         {
             jobj.WriteTo(writer);
         }
         json = sw.ToString();
     }
     Publish(replyTo, json);
 }
Пример #3
0
        private void HandleAgentMessage(string message, string reply)
        {
            JObject j = JObject.Parse(message);

            string replyTo = (string)j["reply_to"];

            if (replyTo.IsNullOrWhiteSpace())
            {
                log.Error(Resources.BoshAgent_MissingReplyTo_Fmt, message);
                return;
            }

            log.Debug(Resources.BoshAgent_AgentMessage_Fmt, message);

            // encryption code here if @credentials

            string method = (string)j["method"];

            if (method == "get_state")
            {
                method = "state";
            }

            /*
             * NB: long running tasks get a task ID that is sent to the director,
             * if processor
             * Thread.new { process_in_thread(processor, reply_to, method, args) }
             * elsif method == "get_task"
             * handle_get_task(reply_to, args.first)
             * elsif method == "shutdown"
             * handle_shutdown(reply_to)
             * else
             * re = RemoteException.new("unknown message #{msg.inspect}")
             * publish(reply_to, re.to_hash)
             * def process_long_running(reply_to, processor, args)
             * agent_task_id = generate_agent_task_id
             *
             * @long_running_agent_task = [agent_task_id]
             *
             * payload = {:value => {:state => "running", :agent_task_id => agent_task_id}}
             * publish(reply_to, payload)
             *
             * result = process(processor, args)
             * @results << [Time.now.to_i, agent_task_id, result]
             * @long_running_agent_task = []
             * end
             */

            try
            {
                using (IMessageHandler handler = ioc.GetInstance <IMessageHandler>(method))
                {
                    HandlerResponse response = handler.Handle(j);
                    Publish(replyTo, response);
                    handler.OnPostReply();
                }
            }
            catch (StructureMapException ex)
            {
                log.Error(ex, Resources.BoshAgent_MissingHandlerForMethod_Fmt, method);
                return;
            }
            catch (Exception ex)
            {
                log.Error(ex, Resources.BoshAgent_ExceptionHandlingMethod_Fmt, method);
                var remoteException = RemoteException.From(ex);
                Publish(replyTo, remoteException);
            }
        }