Example #1
0
        public IActionResult OnPostGetNewPubSubsTest()
        {
            UserObject = new CurrentUser(this.HttpContext, _configuration);
            if (UserObject.Information == null)
            {
                return(new JsonResult("Error"));
            }

            // This adds a testing alert to the official alert file for alert window
            MyWebsocketHelper.GetPubSubAlertsTest(UserObject.Information.id);

            // This creates a test event for the dashboard from a testfile
            List <TwitchJsonHelper.JsonPubSubRoot> pubSubList = MyWebsocketHelper.GetPubSubEventsTest();

            if (pubSubList == null)
            {
                return(new JsonResult("Error"));
            }
            if (pubSubList.Count < 1)
            {
                return(new JsonResult("Error"));
            }

            List <TwitchJsonHelper.JsonMyPubSub> events = new List <TwitchJsonHelper.JsonMyPubSub>();

            foreach (TwitchJsonHelper.JsonPubSubRoot item in pubSubList)
            {
                TwitchJsonHelper.JsonMyPubSub pubSubObj = new TwitchJsonHelper.JsonMyPubSub();
                pubSubObj.title        = item.data.redemption.reward.title;
                pubSubObj.pubSub_id    = item.data.redemption.id;
                pubSubObj.display_name = item.data.redemption.user.display_name;
                // Time parsing to read it better
                string date = item.data.timestamp.Substring(0, item.data.timestamp.IndexOf('T'));
                string time = item.data.timestamp.Substring(item.data.timestamp.IndexOf('T') + 1, 8);
                pubSubObj.redeemed_at = date + " " + time;
                pubSubObj.cost        = item.data.redemption.reward.cost;
                if (item.data.redemption.reward.image != null)
                {
                    pubSubObj.image = item.data.redemption.reward.image.url_1x;
                }
                if (item.data.redemption.reward.default_image != null)
                {
                    pubSubObj.default_image = item.data.redemption.reward.default_image.url_1x;
                }
                pubSubObj.user_input = item.data.redemption.user_input;
                events.Add(pubSubObj);
            }
            // Return to ajax request
            return(new JsonResult(JsonSerializer.Serialize(events)));
        }
Example #2
0
        // This gets called from the html file every x seconds
        public IActionResult OnPostGetNewPubSubs()
        {
            UserObject = new CurrentUser(this.HttpContext, _configuration);
            if (UserObject.Information == null)
            {
                return(new JsonResult("Error"));
            }

            List <TwitchJsonHelper.JsonPubSubRoot> pubSubList = MyWebsocketHelper.GetPubSubs(UserObject.Information.id, MyWebsocketHelper.WebsocketDataPath);

            if (pubSubList == null)
            {
                return(new JsonResult("Error"));
            }
            if (pubSubList.Count < 1)
            {
                return(new JsonResult("Error"));
            }

            List <TwitchJsonHelper.JsonMyPubSub> events = new List <TwitchJsonHelper.JsonMyPubSub>();

            foreach (TwitchJsonHelper.JsonPubSubRoot item in pubSubList)
            {
                TwitchJsonHelper.JsonMyPubSub pubSubObj = new TwitchJsonHelper.JsonMyPubSub();
                pubSubObj.title        = item.data.redemption.reward.title;
                pubSubObj.pubSub_id    = item.data.redemption.id;
                pubSubObj.display_name = item.data.redemption.user.display_name;
                // Time parsing to read it better
                string date = item.data.timestamp.Substring(0, item.data.timestamp.IndexOf('T'));
                string time = item.data.timestamp.Substring(item.data.timestamp.IndexOf('T') + 1, 8);
                pubSubObj.redeemed_at = date + " " + time;
                pubSubObj.cost        = item.data.redemption.reward.cost;
                if (item.data.redemption.reward.image != null)
                {
                    pubSubObj.image = item.data.redemption.reward.image.url_4x;
                }
                if (item.data.redemption.reward.default_image != null)
                {
                    pubSubObj.default_image = item.data.redemption.reward.default_image.url_4x;
                }
                pubSubObj.user_input = item.data.redemption.user_input;
                events.Add(pubSubObj);
            }
            // Return to ajax request
            MyWebsocketHelper.ClearPubSubFile(UserObject.Information.id, MyWebsocketHelper.WebsocketDataPath);
            return(new JsonResult(JsonSerializer.Serialize(events)));
        }
Example #3
0
        // This gets called from the html file every x seconds
        public IActionResult OnPostGetNewPubSubs()
        {
            // Get all alerts to play from our websocket file
            List <TwitchJsonHelper.JsonPubSubRoot> pubSubList = MyWebsocketHelper.GetPubSubs(HttpContext.Request.Query["id"], MyWebsocketHelper.WebsocketDataPathAlert);

            if (pubSubList == null)
            {
                return(new JsonResult("Error"));
            }
            if (pubSubList.Count < 1)
            {
                return(new JsonResult("Error"));
            }

            List <TwitchJsonHelper.JsonMyPubSub> events = new List <TwitchJsonHelper.JsonMyPubSub>();

            foreach (TwitchJsonHelper.JsonPubSubRoot item in pubSubList)
            {
                TwitchJsonHelper.JsonMyPubSub pubSubObj = new TwitchJsonHelper.JsonMyPubSub();
                pubSubObj.title        = item.data.redemption.reward.title;
                pubSubObj.pubSub_id    = item.data.redemption.id;
                pubSubObj.display_name = item.data.redemption.user.display_name;
                // Time parsing to read it better. This can play the wrong time because of timezones
                string date = item.data.timestamp.Substring(0, item.data.timestamp.IndexOf('T'));
                string time = item.data.timestamp.Substring(item.data.timestamp.IndexOf('T') + 1, 8);
                pubSubObj.redeemed_at = date + " " + time;
                pubSubObj.cost        = item.data.redemption.reward.cost;
                if (item.data.redemption.reward.image != null)
                {
                    pubSubObj.image = item.data.redemption.reward.image.url_4x;
                }
                if (item.data.redemption.reward.default_image != null)
                {
                    pubSubObj.default_image = item.data.redemption.reward.default_image.url_4x;
                }
                pubSubObj.user_input = item.data.redemption.user_input;
                events.Add(pubSubObj);
            }
            // After getting all alerts from our websocket file we clear it. Important: If an alert happens in this function the alert will be destroyed
            MyWebsocketHelper.ClearPubSubFile(HttpContext.Request.Query["id"], MyWebsocketHelper.WebsocketDataPathAlert);
            // We return the json file with all the alerts. It returns a json with a list
            return(new JsonResult(JsonSerializer.Serialize(events)));
        }