Example #1
0
        private static async Task Broadcast(string type, IJsonObject value, bool useDuringCatchup, bool onlySaveLatestForCatchup)
        {
            // Broadcast to client
            await _socketHandler.Broadcast(new WebSocketMessage(type, value.ToJson()), WebSocketType.Client, useDuringCatchup, onlySaveLatestForCatchup);

            // Broadcast to frontend
            await _socketHandler.Broadcast(new WebSocketMessage(type, value.ToJson()), WebSocketType.FrontEnd, useDuringCatchup, onlySaveLatestForCatchup);

            // Broadcast to plugin
            if (new [] { "Event", "Cargo", "Modules", "Outfitting", "Shipyard", "Status", "NavRoute", "Backpack", "Market" }.Contains(type))
            {
                var variables = _variableService.GetVariables(value);
                var name      = type;
                if (type != "Event")
                {
                    variables = variables.Select(x => new Variable($"{type}.{x.Name.Replace(".Value", "")}", x.Value, x.Type)).ToList();
                }
                else
                {
                    name      = variables.First(x => x.Name == "Event").Value.ToString();
                    variables = variables.Select(x => new Variable($"{name}.{x.Name.Replace(".Value", "")}", x.Value, x.Type)).ToList();
                }

                await _socketHandler.Broadcast(new WebSocketMessage(type, new Models.Event(name, variables)), WebSocketType.Plugin, useDuringCatchup, onlySaveLatestForCatchup);

                //await _socketHandler.Broadcast(new WebSocketMessage($"{type}-plugin", variables), WebSocketType.FrontEnd, useDuringCatchup, onlySaveLatestForCatchup);
            }
            else
            {
                await _socketHandler.Broadcast(new WebSocketMessage(type, value), WebSocketType.Plugin, useDuringCatchup, onlySaveLatestForCatchup);
            }
        }
Example #2
0
        public void InjectTo(HttpRequestMessage request)
        {
            var jsonAsString = _jsonObject.ToJson();

            if (!string.IsNullOrEmpty(jsonAsString))
            {
                request.Content = new StringContent(
                    _jsonObject.ToJson(),
                    Encoding.UTF8,
                    "application/json"
                    );
            }
        }
        internal void OutputJson(IJsonObject jsonObject)
        {
            var json = jsonObject.ToJson();

            this.Output.WriteLine("JSON");
            this.Output.WriteLine(String.Empty);
            this.Output.WriteLine(json);
        }
 private HttpContent ToContent(IJsonObject jsonObject)
 {
     return(new StringContent(
                jsonObject.ToJson(),
                Encoding.UTF8,
                "application/json"
                ));
 }
        public void ToJson()
        {
            const string Json = "{ objects: [ 1, 3, { name: \"User 0\" } ] }";
            IJsonObject  tree = serializer.Deserialize(Json);
            string       json = tree.ToJson();

            Assert.AreEqual(Json, json);
        }