PageRenderTime 43ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/src/Microsoft.AspNet.SignalR.Core/Hubs/HubRequestParser.cs

https://github.com/mip1983/SignalR
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
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.md in the project root for license information.
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using Newtonsoft.Json.Linq;
  6. namespace Microsoft.AspNet.SignalR.Hubs
  7. {
  8. internal class HubRequestParser : IHubRequestParser
  9. {
  10. private static readonly IJsonValue[] _emptyArgs = new IJsonValue[0];
  11. public HubRequest Parse(string data)
  12. {
  13. var rawRequest = JObject.Parse(data);
  14. var request = new HubRequest();
  15. // TODO: Figure out case insensitivity in JObject.Parse, this should cover our clients for now
  16. request.Hub = rawRequest.Value<string>("hub") ?? rawRequest.Value<string>("Hub");
  17. request.Method = rawRequest.Value<string>("method") ?? rawRequest.Value<string>("Method");
  18. request.Id = rawRequest.Value<string>("id") ?? rawRequest.Value<string>("Id");
  19. var rawState = rawRequest["state"] ?? rawRequest["State"];
  20. request.State = rawState == null ? new Dictionary<string, object>(StringComparer.OrdinalIgnoreCase) :
  21. rawState.ToObject<IDictionary<string, object>>();
  22. var rawArgs = rawRequest["args"] ?? rawRequest["Args"];
  23. request.ParameterValues = rawArgs == null ? _emptyArgs :
  24. rawArgs.Children().Select(value => new JTokenValue(value)).ToArray();
  25. return request;
  26. }
  27. }
  28. }