public String SerializeData(NotificationData notificationData)
        {
            if (notificationData == null)
            {
                return("");
            }
            var settings = new JsonSerializerSettings {
                DateFormatString = "yyyy-MM-ddTHH:mm:ss",
            };

            return(JsonConvert.SerializeObject(notificationData));
        }
        public NotificationData DeserializeData(string json)
        {
            NotificationData notificationData = new NotificationData();

            var settings = new JsonSerializerSettings {
                DateFormatString     = "yyyy-MM-ddTHH:mm:ssK",
                DateTimeZoneHandling = DateTimeZoneHandling.Local
            };

            /*"offline_at":"2018-08-23T19:21:34+00:00" */
            notificationData = JsonConvert.DeserializeObject <NotificationData>(json, settings);

            return(notificationData);
        }
Example #3
0
        private void HandleMessage(string jsonMessage)
        {
            FileCache cache = new FileCache();

            Console.WriteLine(jsonMessage);

            NotificationHelper helper = new NotificationHelper();
            NotificationData   data   = helper.DeserializeData(jsonMessage);
            bool noOneOnline          = true;

            if (data.Type != "status")
            {
                return;
            }
            FileCache.WriteToLogFile("MessageReceived: " + jsonMessage);

            FileCache.WriteToLogFile("Checking streamers");
            foreach (var item in data.Data.Stream.Services)
            {
                if (item.Status == true)
                {
                    if (cache.GetValue <string>(LAST_ONLINE_STREAMER_ID, "") == "" && !cache.GetValue <string>(LAST_ONLINE_STREAMER_ID, "-1").Equals(item.ID))
                    {
                        cache.SetValue <string>(LAST_ONLINE_STREAMER_ID, item.ID);
                        string streamerName = data.Data.Streamers.First((streamer) => streamer.ID == item.StreamerID).Name;
                        SendPostRequestToFirebase(String.Format("Strumień trwa od {1}, {0} zaprasza!", streamerName, data.Data.Stream.OnlineAt.ToShortTimeString()), "Strumień się zaczął!", streamerName);
                    }
                    noOneOnline = false;
                }
            }

            if (noOneOnline)
            {
                cache.SetValue <string>(LAST_ONLINE_STREAMER_ID, "");
            }

            FileCache.WriteToLogFile("Checking topic");
            if (cache.GetValue <long>(LAST_TOPIC_ID, 0) != data.Data.Topic.ID)
            {
                SendPostRequestToFirebase("Powiadamiacz", data.Data.Topic.Text, "topic");
                cache.SetValue <long>(LAST_TOPIC_ID, data.Data.Topic.ID);
            }

            FileCache.WriteToLogFile("Checking test topic");
            if (cache.GetValue <long>(TEST_TOPIC_ID, 0) == 0)
            {
                SendPostRequestToFirebase("Offline, kalendarz na ten tydzień został zaktualizowany. A dzisiaj zaczniemy tak do 18:00. Offline, kalendarz na ten tydzień został zaktualizowany. A dzisiaj zaczniemy tak do 18:00", "Test title", "topicTest");
                cache.SetValue <long>(TEST_TOPIC_ID, 1);
            }
        }