コード例 #1
0
        public async Task <IHttpActionResult> ReconnectAndInvoke(string connectionId, string hubName, string methodName, [FromBody] HubNamesAndArguments hubNamesAndArguments)
        {
            Session session;
            bool    sessionRetrieved;

            sessionManagementLock.EnterReadLock();
            try
            {
                sessionRetrieved = sessions.TryGetValue(connectionId, out session);
            }
            finally
            {
                sessionManagementLock.ExitReadLock();
            }
            var hubMethodInvocation = new HubMethodInvocation
            {
                Arguments = hubNamesAndArguments.Arguments,
                Hub       = hubName,
                Method    = methodName
            };

            if (!sessionRetrieved)
            {
                try
                {
                    session = await PerformConnect(hubNamesAndArguments.HubNames, connectionId);
                }
                catch (ArgumentOutOfRangeException)
                {
                    return(NotFound());
                }
                return(Ok(new
                {
                    ConnectionId = session.ConnectionId,
                    ReturnValue = await ExecuteHubMethodInvocation(session, Request, hubMethodInvocation)
                }));
            }
            if (!session.Hubs.Keys.OrderBy(n => n).SequenceEqual(hubNamesAndArguments.HubNames.OrderBy(n => n), StringComparer.OrdinalIgnoreCase))
            {
                return(Conflict());
            }
            return(Ok(new
            {
                Events = GetEvents(session),
                ReturnValue = await ExecuteHubMethodInvocation(session, Request, hubMethodInvocation)
            }));
        }
コード例 #2
0
        public async Task <IHttpActionResult> ConnectAndInvoke(string hubName, string methodName, [FromBody] HubNamesAndArguments hubNamesAndArguments)
        {
            Session session;

            try
            {
                session = await PerformConnect(hubNamesAndArguments.HubNames);
            }
            catch (ArgumentOutOfRangeException)
            {
                return(NotFound());
            }

            return(Ok(new
            {
                ConnectionId = session.ConnectionId,
                ReturnValue = await ExecuteHubMethodInvocation(session, Request, new HubMethodInvocation
                {
                    Arguments = hubNamesAndArguments.Arguments,
                    Hub = hubName,
                    Method = methodName
                })
            }));
        }