Nancy.LongPoll.PollService.Wait C# (CSharp) Method

Wait() private method

private Wait ( string clientId, ulong seqCode ) : string
clientId string
seqCode ulong
return string
    internal string Wait(string clientId, ulong seqCode)
    {
      try
      {
        Client client = null;
        lock (_Clients)
        {
          if (_Clients.ContainsKey(clientId))
          {
            client = _Clients[clientId];
            client.LastSeen = DateTime.UtcNow;
          }
        }
        if (client != null)
        {
          Message message = client.Wait(seqCode);
          if (message is Client.ClientMessage)
          {
            return (message as Client.ClientMessage).GetJson();
          }

          return message.GetJson();
        }
        else
        {
          return new Message
          {
            success = false,
            retcode = Message.RetCodes.ClientNotRegistered
          }.GetJson();
        }
      }
      catch (Exception ex)
      {
        _Logger.LogException(ex, "Exception on Poll.Wait");
        return new Message
        {
          success = false,
          retcode = Message.RetCodes.ErrorOnServer
        }.GetJson();
      }
    }
    #endregion

Usage Example

Beispiel #1
0
    public PollModule(TinyIoc.TinyIoCContainer container, IPollService pollService = null, ISessionProvider sessionProvider = null)
    {
      if (container == null) throw new ArgumentNullException("container");
      if (!(sessionProvider is DefaultSessionProvider)) _SessionProvider = sessionProvider;

      if (pollService == null)
      {
        container.Register<IPollService, PollService>().AsSingleton();
        pollService = container.Resolve<IPollService>();
      }
      _PollService = pollService as PollService;
      if (pollService == null) throw new ApplicationException("Support Nany.LongPoll.PollService implementation only");

      Get["/Poll/Register"] = x =>
      {
        var sp = _SessionProvider;
        if (sp == null) sp = new DefaultSessionProvider(Request);

        var response = Response.AsJson(_PollService.Register(Request.UserHostAddress, sp.SessionId));
        if (sp is DefaultSessionProvider)
        {
          response = response.WithCookie(DefaultSessionProvider.SessionIdCookieName, sp.SessionId);
        }

        return response;
      };
      Get["/Poll/Wait"] = x =>
      {
        string clientId = Request.Query.clientId;
        ulong seqCode = Request.Query.seqCode;

        return Response.AsText(JsonConvert.SerializeObject(_PollService.Wait(clientId, seqCode)), "application/json");
      };
    }
All Usage Examples Of Nancy.LongPoll.PollService::Wait