public HttpStatusCodeResult ReceiveNotification()
        {
            Facebook.FacebookClient fb = new FacebookClient();
            fb.SetJsonSerializers(null, Deserializer);
            // VerifyPostSubscription will throw exception if verification fails.
            // result is a json object that was sent by Facebook
            FacebookNotifyViewModel notification =
                (FacebookNotifyViewModel)fb.VerifyPostSubscription(
                    Request.Headers["X-Hub-Signature"],
                    new StreamReader(Request.InputStream).ReadToEnd(),
                    typeof(FacebookNotifyViewModel),
                    ConfigurationManager.AppSettings["Facebook_AppSecret"]);

            #region Broadcast notification
            GlobalHost.ConnectionManager.GetHubContext <NotificationHub>().
            Clients.All.
            addNewNotificationToPage(
                RenderRazorViewToString("FB_NotificationItem", notification)
                );
            if (notification.Object == "page")
            {
                GlobalHost.ConnectionManager.GetHubContext <NotificationHub>().
                Clients.All.
                FBPageNotification(notification.entry.First().id);
            }

            #endregion

            return(new HttpStatusCodeResult(HttpStatusCode.OK));
        }
예제 #2
0
        public static FacebookNotifyViewModel NewMessage(string title, string message)
        {
            FacebookNotifyViewModel subscriptionNotice = new FacebookNotifyViewModel
            {
                Object = title
            };

            subscriptionNotice.entry = new List <FacebookNotify_Entry>();
            subscriptionNotice.entry.Add(new FacebookNotify_Entry
            {
                id   = "",
                time = Facebook.DateTimeConvertor.ToUnixTime(DateTime.Now)
            });
            if (!string.IsNullOrEmpty(message))
            {
                subscriptionNotice.entry[0].changes = new List <FacebookNotify_Change>();
                subscriptionNotice.entry[0].changes.Add(new FacebookNotify_Change
                {
                    field = message
                });
            }

            return(subscriptionNotice);
        }