Exemplo n.º 1
0
        /// <summary>
        /// Handles incoming Response_VM message.
        /// </summary>
        private void OnResponse_VM(object payload)
        {
            if (payload is JArray == false)
            {
                return;
            }

            // SignalR .NET Core is sending an array of arguments.
            var vmId    = $"{(payload as JArray)[0]}";
            var rawData = (payload as JArray)[1].ToString();
            var data    = JsonConvert.DeserializeObject <Dictionary <string, object> >(rawData);

            var eventArgs = new ResponseVMEventArgs {
                VMId = vmId, Data = data
            };
            var args = new object[] { this, eventArgs };

            foreach (Delegate d in Response_VM?.GetInvocationList())
            {
                d.DynamicInvoke(args);
                if (eventArgs.Handled)
                {
                    break;
                }
            }

            // If we get to this point, that means the server holds a view model instance
            // whose view no longer existed.  So, tell the server to dispose the view model.
            if (!eventArgs.Handled)
            {
                var task = Dispose_VM(vmId);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Handles incoming Response_VM message.
        /// </summary>
        private void OnResponse_VM(object[] payload)
        {
            var eventArgs = BuildResponseVMEventArgs(payload);
            var args      = new object[] { this, eventArgs };

            foreach (Delegate d in Response_VM?.GetInvocationList())
            {
                d.DynamicInvoke(args);
                if (eventArgs.Handled)
                {
                    break;
                }
            }

            // If we get to this point, that means the server holds a view model instance
            // whose view no longer existed.  So, tell the server to dispose the view model.
            if (!eventArgs.Handled && !string.IsNullOrWhiteSpace(eventArgs.VMId))
            {
                _ = Dispose_VM(eventArgs.VMId);
            }
        }