当前位置: 首页>>代码示例>>C#>>正文


C# Hubs.HubDescriptor类代码示例

本文整理汇总了C#中Microsoft.AspNet.SignalR.Hubs.HubDescriptor的典型用法代码示例。如果您正苦于以下问题:C# HubDescriptor类的具体用法?C# HubDescriptor怎么用?C# HubDescriptor使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HubDescriptor类属于Microsoft.AspNet.SignalR.Hubs命名空间,在下文中一共展示了HubDescriptor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnBeforeAuthorizeConnect

 protected override bool OnBeforeAuthorizeConnect(HubDescriptor hubDescriptor, Microsoft.AspNet.SignalR.IRequest request)
 {
     _logger.Log("OnBeforeAuthorizeConnect " +
         "RemoteIpAddress:\"" + request.Environment["server.RemoteIpAddress"] + "\" " +
         "User-Agent: \"" + request.Headers["User-Agent"] + "\"");
     return base.OnBeforeAuthorizeConnect(hubDescriptor, request);
 }
开发者ID:Widdershin,项目名称:vox,代码行数:7,代码来源:LoggingHubPipelineModule.cs

示例2: AuthorizeHubConnection

 public bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
 {
     VerifyArgument.IsNotNull("hubDescriptor", hubDescriptor);
     VerifyArgument.IsNotNull("request", request);
     var result = request.User.IsAuthenticated() && Service.IsAuthorized(hubDescriptor.GetAuthorizationRequest(request));
     return result;
 }
开发者ID:Robin--,项目名称:Warewolf,代码行数:7,代码来源:AuthorizeHubAttribute.cs

示例3: TryGetMethod

        /// <summary>
        /// Searches the specified <paramref name="hub">Hub</paramref> for the specified <paramref name="method"/>.
        /// </summary>
        /// <remarks>
        /// In the case that there are multiple overloads of the specified <paramref name="method"/>, the <paramref name="parameters">parameter set</paramref> helps determine exactly which instance of the overload should be resolved. 
        /// If there are multiple overloads found with the same number of matching parameters, none of the methods will be returned because it is not possible to determine which overload of the method was intended to be resolved.
        /// </remarks>
        /// <param name="hub">Hub to search for the specified <paramref name="method"/> on.</param>
        /// <param name="method">The method name to search for.</param>
        /// <param name="descriptor">If successful, the <see cref="MethodDescriptor"/> that was resolved.</param>
        /// <param name="parameters">The set of parameters that will be used to help locate a specific overload of the specified <paramref name="method"/>.</param>
        /// <returns>True if the method matching the name/parameter set is found on the hub, otherwise false.</returns>
        public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, IList<IJsonValue> parameters)
        {
            string hubMethodKey = BuildHubExecutableMethodCacheKey(hub, method, parameters);

            if (!_executableMethods.TryGetValue(hubMethodKey, out descriptor))
            {
                IEnumerable<MethodDescriptor> overloads;

                if (FetchMethodsFor(hub).TryGetValue(method, out overloads))
                {
                    var matches = overloads.Where(o => o.Matches(parameters)).ToList();

                    // If only one match is found, that is the "executable" version, otherwise none of the methods can be returned because we don't know which one was actually being targeted
                    descriptor = matches.Count == 1 ? matches[0] : null;
                }
                else
                {
                    descriptor = null;
                }

                // If an executable method was found, cache it for future lookups (NOTE: we don't cache null instances because it could be a surface area for DoS attack by supplying random method names to flood the cache)
                if (descriptor != null)
                {
                    _executableMethods.TryAdd(hubMethodKey, descriptor);
                }
            }

            return descriptor != null;
        }
开发者ID:eduaglz,项目名称:SignalR-Server,代码行数:41,代码来源:ReflectedMethodDescriptorProvider.cs

示例4: TryGetMethod

        public bool TryGetMethod(HubDescriptor hub, string method, out MethodDescriptor descriptor, params IJsonValue[] parameters)
        {
            descriptor = new MethodDescriptor
            {
                Hub = hub,
                Invoker = (h, args) =>
                {
                    var pkg = ((dynamic)args[0]);

                    //default to broadcast only to others
                    IClientProxy proxy = h.Clients.Others;
                    if (pkg.recipients == "ALL")
                        proxy = h.Clients.All;
                    else if (pkg.recipients == "SELF")
                        proxy = h.Clients.Caller;

                    var _appId = h.Context.ConnectionId;
                    dynamic _op = false;

                    //How to deal with concurrent requests?
                    //This is the derby/racer conflict resolution problem
                    //Like -- what if two users perform an update at the same time?
                    //For now, the broadcast is just sent to all....
                    //but an in-out pub/sub redis store that caches the requests
                    //and only executes the LAST one might be a simple solution

                    if (pkg.appBoxr != null)
                    {
                        var _clientId = pkg.clientId.ToString();
                        var _repo = GlobalHost.DependencyResolver.Resolve<IDataLayer>();
                        var appBoxr = (dynamic)pkg.appBoxr;

                        string process = appBoxr.process.top.ToString();

                        if (process == "GET")
                        {
                            _op = _repo.Get(appBoxr.queries);
                        }
                        else if (process == "SAVE")
                        {
                            _op = _repo.Save(appBoxr.models.ToString());
                        }
                        else if (process == "DELETE")
                        {
                            _op = _repo.Delete(new { ids = appBoxr.ids.ToString(), collection = appBoxr.collection });
                        }
                    }

                    //result is always 2nd param of GET SAVE and DELETE ops
                    return proxy.Invoke(method, pkg, _op);
                },
                Name = method,
                Attributes = new List<AuthAttribute>() { new AuthAttribute() },
                Parameters = Enumerable.Range(0, parameters.Length).Select(i => new Microsoft.AspNet.SignalR.Hubs.ParameterDescriptor { Name = "p_" + i, ParameterType = typeof(object) }).ToArray(),
                ReturnType = typeof(Task)
            };

            return true;
        }
开发者ID:TimHeckel,项目名称:AppBoxr,代码行数:59,代码来源:AppBoxrHub.cs

示例5: BuildMethodCacheFor

 /// <summary>
 /// Builds a dictionary of all possible methods on a given hub.
 /// Single entry contains a collection of available overloads for a given method name (key).
 /// This dictionary is being cached afterwards.
 /// </summary>
 /// <param name="hub">Hub to build cache for</param>
 /// <returns>Dictionary of available methods</returns>
 private static IDictionary<string, IEnumerable<MethodDescriptor>> BuildMethodCacheFor(HubDescriptor hub)
 {
     return ReflectionHelper.GetExportedHubMethods(hub.HubType)
         .GroupBy(GetMethodName, StringComparer.OrdinalIgnoreCase)
         .ToDictionary(group => group.Key,
                       group => group.Select(oload => GetMethodDescriptor(group.Key, hub, oload)),
                       StringComparer.OrdinalIgnoreCase);
 }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:15,代码来源:ReflectedMethodDescriptorProvider.cs

示例6: AuthorizeHubConnection

        public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
        {
            var token = request.Cookies[AuthCookieName()].Value;
            var user = skUserRepository.GetUserByToken(token);

            if (user == null) return false;
            request.Environment["UserName"] = user.Alias.ToUpperInvariant();
            return true;
        }
开发者ID:kamsiuman,项目名称:awdk,代码行数:9,代码来源:NotificationPushHub.cs

示例7: Create

        public IHub Create(HubDescriptor descriptor)
        {
            if(descriptor.Type == null)
            {
                return null;
            }

            object hub = _resolver.Resolve(descriptor.Type) ?? Activator.CreateInstance(descriptor.Type);
            return hub as IHub;
        }
开发者ID:Kazzje,项目名称:SignalR,代码行数:10,代码来源:DefaultHubActivator.cs

示例8: Create

        public IHub Create(HubDescriptor descriptor)
        {
            if (descriptor == null)
                throw new ArgumentNullException("descriptor");

            if (descriptor.HubType == null)
                return null;

            object hub = _container.Resolve(descriptor.HubType) ?? Activator.CreateInstance(descriptor.HubType);
            return hub as IHub;
        }
开发者ID:Primalpat-,项目名称:LycanTally,代码行数:11,代码来源:UnityHubActivator.cs

示例9: AuthorizeHubConnection

 public bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
 {
     switch (Mode)
     {
         case AuthorizeMode.Both:
         case AuthorizeMode.Outgoing:
             return UserAuthorized(request.User);
         default:
             Debug.Assert(Mode == AuthorizeMode.Incoming); // Guard in case new values are added to the enum
             return true;
     }
 }
开发者ID:nonintanon,项目名称:SignalR,代码行数:12,代码来源:AuthorizeAttribute.cs

示例10: Create_Hub_ReturnsHubProxy

        public void Create_Hub_ReturnsHubProxy()
        {                                    
            var container = new ServiceContainer();
            container.EnableSignalR();
            container.Register<SampleHub>(new PerScopeLifetime());
            var activator = new LightInjectHubActivator(container);                     
            var hubDescriptor = new HubDescriptor { HubType = typeof(SampleHub) };
            
            var hub = activator.Create(hubDescriptor);

            Assert.IsInstanceOfType(hub, typeof(IProxy));
        }
开发者ID:vitamink,项目名称:LightInject,代码行数:12,代码来源:HubActivatorTests.cs

示例11: Create_Hub_StartsScope

 public void Create_Hub_StartsScope()
 {
     var container = new ServiceContainer();
     container.EnableSignalR();
     container.Register<SampleHub>();
     var activator = new LightInjectHubActivator(container);
     var hubDescriptor = new HubDescriptor { HubType = typeof(SampleHub) };
     using (activator.Create(hubDescriptor))
     {
         Assert.IsNotNull(container.ScopeManagerProvider.GetScopeManager().CurrentScope);
     }                       
 }
开发者ID:vitamink,项目名称:LightInject,代码行数:12,代码来源:HubActivatorTests.cs

示例12: CorrectQualifiedName

        public void CorrectQualifiedName()
        {
            string hubName = "MyHubDescriptor",
                   unqualifiedName = "MyUnqualifiedName";

            HubDescriptor hubDescriptor = new HubDescriptor()
            {
                Name = hubName
            };

            Assert.Equal(hubDescriptor.CreateQualifiedName(unqualifiedName), hubName + "." + unqualifiedName);
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:12,代码来源:HubDescriptorFacts.cs

示例13: AuthorizeHubConnection

 public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
 {
     try
     {
         return Authorize(request);
     }
     catch (Exception e)
     {
         log.ErrorFormat("AuthorizeHubConnection error: {0}, {1}, {2}", e, e.StackTrace, e.InnerException != null ? e.InnerException.Message : string.Empty);
         return false;
     }
 }
开发者ID:vipwan,项目名称:CommunityServer,代码行数:12,代码来源:AuthorizeHubAttribute.cs

示例14: AuthorizeHubConnection

        public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
        {
            var username = request.Headers[Settings.Default.UsernameHeader]??request.QueryString[Settings.Default.UsernameHeader];
            request.Environment["server.User"] = new GenericPrincipal(new ExcelServiceIdentity(username), new string[] { });
            //request.GetOwinContext().Authentication.User = new GenericPrincipal(new ExcelServiceIdentity(username), new string[] { });
            if (!string.IsNullOrWhiteSpace(username))
            {
                return true;
            }

            return false;
        }
开发者ID:TNOCS,项目名称:csTouch,代码行数:12,代码来源:BasicAuthenticationAttribute.cs

示例15: AuthorizeHubConnection

 public override bool AuthorizeHubConnection(HubDescriptor hubDescriptor, IRequest request)
 {
     try
     {
         var login = request.Headers["login"];
         var token = new Guid(request.Headers["token"]);
         return _authorizeStrategy.Authorize(login, token);
     }
     catch (Exception ex)
     {
         return false;
     }
 }
开发者ID:karczewskip,项目名称:Waiter-Management-2,代码行数:13,代码来源:CustomAuthorizeAttribute.cs


注:本文中的Microsoft.AspNet.SignalR.Hubs.HubDescriptor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。