Beispiel #1
0
        private CloudMessage InvokeRawRequest(CloudMessage requestMessage)
        {
            try
            {
                var jsonRequestPayload = Encoding.UTF8.GetString(requestMessage.Payload);
                var jsonRequest        = JObject.Parse(jsonRequestPayload);
                var pythonDictionary   = PythonConvert.ToPythonDictionary(jsonRequest);

                CloudMessageHandler cloudMessageHandler;
                lock (_rawMessageHandlers)
                {
                    if (!_rawMessageHandlers.TryGetValue(pythonDictionary.GetValueOr("type", string.Empty), out cloudMessageHandler))
                    {
                        throw new NotSupportedException("RAW message type handler not supported.");
                    }
                }

                var responseContent = cloudMessageHandler.Invoke(pythonDictionary);

                var jsonResponse = PythonConvert.FromPythonToJson(responseContent);

                return(new CloudMessage()
                {
                    CorrelationId = requestMessage.CorrelationId,
                    Payload = Encoding.UTF8.GetBytes(jsonResponse.ToString())
                });
            }
            catch (Exception exception)
            {
                return(_cloudMessageFactory.Create(exception));
            }
        }
        public string serialize_indented(object value)
        {
            var json = PythonConvert.FromPythonToJson(value);

            return(json.ToString(Formatting.Indented));
        }