dsuryd / dotNetify

Simple, lightweight, yet powerful way to build real-time web apps.
https://dotnetify.net
Other
1.17k stars 164 forks source link

[bug] MsgPack support #227

Closed MrImpossibru closed 4 years ago

MrImpossibru commented 4 years ago

Hi, There is a bug with MsgPack support. There is no data conversion in the Update_VM method in the DotNetifyLib.SignalR\DotNetifyHub.cs.

My solution:

      private object ConvertData(object data)
      {
        if (data == null)
          return null;
        else if (data is JsonElement)
          // System.Text.Json protocol.
          return JObject.Parse(((JsonElement)data).GetRawText());
        else if (data is JObject)
          // Newtonsoft.Json protocol.
          return data as JObject;
        else if (data.GetType().IsPrimitive || data is string)
          return data;
        else
          // MessagePack protocol.
          return JObject.FromObject(data);
      }
      public void Request_VM(string vmId, object vmArg)
      {
         var data = ConvertData(vmArg);

      ......
      public void Update_VM(string vmId, Dictionary<string, object> vmData)
      {
         try
         {
            _callerContext = Context;
            if (vmData != null)
            {
               var keys = vmData.Keys.ToArray();
               foreach (var key in keys)
               {
                  vmData[key] = ConvertData(vmData[key]);
               }
            }

          .......