Esempio n. 1
0
        public static HubDescriptor EnsureHub(this IHubManager hubManager, string hubName, params IPerformanceCounter[] counters)
        {
            if (hubManager == null)
            {
                throw new ArgumentNullException("hubManager");
            }

            if (String.IsNullOrEmpty(hubName))
            {
                throw new ArgumentNullException("hubName");
            }

            if (counters == null)
            {
                throw new ArgumentNullException("counters");
            }

            var descriptor = hubManager.GetHub(hubName);

            if (descriptor == null)
            {
                for (var i = 0; i < counters.Length; i++)
                {
                    counters[i].Increment();
                }
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resources.Error_HubCouldNotBeResolved, hubName));
            }

            return(descriptor);
        }
Esempio n. 2
0
        public static HubDescriptor EnsureHub(this IHubManager hubManager, string hubName)
        {
            var descriptor = hubManager.GetHub(hubName);

            if (descriptor == null)
            {
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "'{0}' hub could not be resolved.", hubName));
            }

            return(descriptor);
        }
Esempio n. 3
0
        public static HubDescriptor EnsureHub(this IHubManager hubManager, string hubName, params PerformanceCounter[] counters)
        {
            var descriptor = hubManager.GetHub(hubName);

            if (descriptor == null)
            {
                for (var i = 0; i < counters.Length; i++)
                {
                    counters[i].SafeIncrement();
                }
                throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, "'{0}' hub could not be resolved.", hubName));
            }

            return(descriptor);
        }
        protected override Task OnReceived(HostContext context, string data)
        {
            Trace.WriteLine($"OnReceived : { data }");
            var request = Newtonsoft.Json.JsonConvert.DeserializeObject <Message>(data);

            var setting = new Newtonsoft.Json.JsonSerializerSettings
            {
                TypeNameHandling      = Newtonsoft.Json.TypeNameHandling.All,
                MissingMemberHandling = Newtonsoft.Json.MissingMemberHandling.Error
            };

            var hubDescriptor    = _manager.GetHub(request.Value.Hub);
            var methodDescriptor = _manager.GetHubMethod(hubDescriptor.Name, request.Value.Method, request.Value.Args.ToArray());
            var hub = _activator.Create(hubDescriptor);

            hub.Clients = new HubConnectionContextBase(hubDescriptor.Name, Connection, _pipelineInvoker);
            methodDescriptor.Invoke(hub, request.Value.Args.Select((r, index) =>
            {
                return(JsonSerializer.Deserialize(JToken.FromObject(r), methodDescriptor.Parameters[index].ParameterType));
            }).ToArray());
            hub.Dispose();

            return(base.OnReceived(context, data));
        }