/src/Microsoft.AspNet.SignalR.Core/Hubs/HubRequestParser.cs
C# | 36 lines | 26 code | 8 blank | 2 comment | 2 complexity | 858f31c6682656434af7f5d8b10e7dfd MD5 | raw file
Possible License(s): Apache-2.0, CC-BY-SA-3.0
- // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using Newtonsoft.Json.Linq;
- namespace Microsoft.AspNet.SignalR.Hubs
- {
- internal class HubRequestParser : IHubRequestParser
- {
- private static readonly IJsonValue[] _emptyArgs = new IJsonValue[0];
- public HubRequest Parse(string data)
- {
- var rawRequest = JObject.Parse(data);
- var request = new HubRequest();
- // TODO: Figure out case insensitivity in JObject.Parse, this should cover our clients for now
- request.Hub = rawRequest.Value<string>("hub") ?? rawRequest.Value<string>("Hub");
- request.Method = rawRequest.Value<string>("method") ?? rawRequest.Value<string>("Method");
- request.Id = rawRequest.Value<string>("id") ?? rawRequest.Value<string>("Id");
- var rawState = rawRequest["state"] ?? rawRequest["State"];
- request.State = rawState == null ? new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) :
- rawState.ToObject<IDictionary<string, object>>();
- var rawArgs = rawRequest["args"] ?? rawRequest["Args"];
- request.ParameterValues = rawArgs == null ? _emptyArgs :
- rawArgs.Children().Select(value => new JTokenValue(value)).ToArray();
- return request;
- }
- }
- }