Exemple #1
0
 private void GetGameList()
 {
     Task.Factory.StartNew(() =>
     {
         jsonGames = JsonUtil.DeserializeUrl <GamingLiveGameList>(@"http://api.gaminglive.tv/games");
         if (jsonGames == null)
         {
             return;
         }
     });
 }
Exemple #2
0
        public bool SetTopic()
        {
            if (!Status.IsLoggedIn)
            {
                return(false);
            }

            if (jsonGames == null || jsonGames.games.Count <= 0)
            {
                jsonGames = JsonUtil.DeserializeUrl <GamingLiveGameList>(@"http://api.gaminglive.tv/games");
            }

            var userName  = Config.GetParameterValue("Username") as string;
            var authToken = Config.GetParameterValue("AuthToken") as string;
            var gameId    = this.With(x => jsonGames.games.FirstOrDefault(game => game != null && game.name != null && game.name.Equals(Info.CurrentGame.Name, StringComparison.InvariantCultureIgnoreCase)))
                            .With(x => x.id);

            var jsonInfo = new GamingLiveChannelUpdate
            {
                slug      = userName.ToLower(),
                owner     = userName.ToLower(),
                name      = Info.Topic,
                authToken = authToken,
                gameId    = gameId,
            };



            JsonUtil.SerializeToStream <GamingLiveChannelUpdate>(jsonInfo, (stream) =>
            {
                var putUrl = @"https://api.gaminglive.tv/channels/";
                if (null == loginWebClient.PatchStream(putUrl, stream))
                {
                    //Authentication data expired ? Let's login again
                    LoginWithUsername();
                    jsonInfo.authToken = Config.GetParameterValue("AuthToken") as string;

                    JsonUtil.SerializeToStream <GamingLiveChannelUpdate>(jsonInfo, (streamRetry) =>
                    {
                        loginWebClient.PatchStream(putUrl, streamRetry);
                    });
                }
            });

            //Check if succeed
            var currentInfo = GetLiveStreamInfo();

            if (currentInfo == null)
            {
                return(false);
            }

            if (Info.Topic.Equals(currentInfo["name"].ToObject <string>()) &&
                currentInfo["game"] != null &&
                Info.CurrentGame.Name.Equals(currentInfo["game"]["name"].ToObject <string>()))
            {
                return(true);
            }

            return(false);
        }