Ejemplo n.º 1
0
 protected virtual void OnVerify(PushVerifyEventArgs args)
 {
     if (PushVerify != null)
     {
         PushVerify(this, args);
     }
 }
Ejemplo n.º 2
0
        protected virtual int VerifySubscribeRequest(HttpListenerRequest request, out string responseMessage)
        {
            var qs = request.QueryString;
            PushSubscriberMode mode;
            int    leaseSeconds;
            string msg = null;
            Func <string, bool> verifyParam = (paramName) =>
            {
                if (string.IsNullOrEmpty(qs[paramName]))
                {
                    msg = "Expected " + paramName;
                    return(false);
                }
                return(true);
            };

            if (!(verifyParam("hub.mode") && verifyParam("hub.topic") && verifyParam("hub.challenge")))
            {
                responseMessage = msg;
                return((int)HttpStatusCode.BadRequest);
            }
            try
            {
                mode = (PushSubscriberMode)Enum.Parse(typeof(PushSubscriberMode), qs["hub.mode"], true);
            }
            catch (Exception)
            {
                // Not a valid mode.
                responseMessage = "Unknown mode: " + qs["hub.mode"] ?? "";
                return((int)HttpStatusCode.BadRequest);
            }

            if (!int.TryParse(qs["hub.lease_seconds"], out leaseSeconds))
            {
                leaseSeconds = 0;
                if (mode == PushSubscriberMode.Subscribe)
                {
                    responseMessage = "Expected hub.lease_seconds";
                    return((int)HttpStatusCode.BadRequest);
                }
            }
            var args = new PushVerifyEventArgs(mode, qs["hub.topic"],
                                               qs["hub.challenge"], leaseSeconds, qs["hub.verify_token"]);

            args.Response = args.Challenge;
            args.Allow    = true;
            OnVerify(args);
            responseMessage = args.Response;
            return(args.Allow ? (int)HttpStatusCode.OK : (int)HttpStatusCode.NotFound);
        }
        protected virtual int VerifySubscribeRequest(HttpListenerRequest request, out string responseMessage)
        {
            var qs = request.QueryString;
            PushSubscriberMode mode;
            int leaseSeconds;
            string msg = null;
            Func<string, bool> verifyParam = (paramName) =>
            {
                if (string.IsNullOrEmpty(qs[paramName]))
                {
                    msg = "Expected " + paramName;
                    return false;
                }
                return true;
            };
            if (!(verifyParam("hub.mode") && verifyParam("hub.topic") && verifyParam("hub.challenge")))
            {
                responseMessage = msg;
                return (int)HttpStatusCode.BadRequest;
            }
            try
            {
                mode = (PushSubscriberMode)Enum.Parse(typeof(PushSubscriberMode), qs["hub.mode"], true);
            }
            catch (Exception)
            {
                // Not a valid mode.
                responseMessage = "Unknown mode: " + qs["hub.mode"] ?? "";
                return (int)HttpStatusCode.BadRequest;
            }

            if (!int.TryParse(qs["hub.lease_seconds"], out leaseSeconds))
            {
                leaseSeconds = 0;
                if (mode == PushSubscriberMode.Subscribe)
                {
                    responseMessage = "Expected hub.lease_seconds";
                    return (int)HttpStatusCode.BadRequest;
                }
            }
            var args = new PushVerifyEventArgs(mode, qs["hub.topic"],
                qs["hub.challenge"], leaseSeconds, qs["hub.verify_token"]);
            args.Response = args.Challenge;
            args.Allow = true;
            OnVerify(args);
            responseMessage = args.Response;
            return args.Allow ? (int)HttpStatusCode.OK : (int)HttpStatusCode.NotFound;
        }
 protected virtual void OnVerify(PushVerifyEventArgs args)
 {
     if (PushVerify != null)
     {
         PushVerify(this, args);
     }
 }
 static void callback_PushVerify(object sender, PushVerifyEventArgs args)
 {
     Console.WriteLine("{0} - Received verify message from hub.", DateTime.Now);
     // Verify all requests.
     args.Allow = true;
 }