private static async Task <string> GetUploadToken()
        {
            if (!string.IsNullOrEmpty(Account.Instance.UploadToken))
            {
                return(Account.Instance.UploadToken);
            }
            string token;

            try
            {
                Log.Info("Requesting new upload token...");
                token = await Client.CreateUploadToken();

                if (string.IsNullOrEmpty(token))
                {
                    throw new Exception("Reponse contained no upload-token.");
                }
            }
            catch (Exception e)
            {
                Log.Error(e);
                throw new Exception("Webrequest to obtain upload-token failed.", e);
            }
            Account.Instance.UploadToken = token;
            Account.Save();
            Log.Info("Received new upload-token.");
            return(token);
        }
Beispiel #2
0
        public void KeyGen_AccountStatus_Upload()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var client = new HsReplayClient("89c8bbc1-474a-4b1b-91b5-2a116d19df7a", "HSReplay-API-Test/1.0", true);

            var token = client.CreateUploadToken().Result;

            Assert.IsFalse(string.IsNullOrEmpty(token), "string.IsNullOrEmpty(key)");

            var account = client.GetAccountStatus(token).Result;

            Assert.AreEqual(token, account.Key, "Key matches sent token");
            Assert.IsTrue(account.TestData, "account.TestData");
            Assert.IsNull(account.User);

            var metaData = new UploadMetaData()
            {
                TestData         = true,
                HearthstoneBuild = 1,
                MatchStart       = DateTime.Now.ToString("o")
            };
            var uploadEvent = client.CreateUploadRequest(metaData, token).Result;

            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.PutUrl));
            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.ShortId));
            Assert.IsFalse(string.IsNullOrEmpty(uploadEvent.ReplayUrl));

            var packUpload = client.UploadPack(
                new PackData
            {
                AccountHi   = 1,
                AccountLo   = 1,
                BoosterType = 1,
                Date        = DateTime.Now.ToString("o"),
                Cards       =
                    new[]
                {
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    },
                    new CardData {
                        CardId = "GAME_005", Premium = true
                    }
                }
            }, token).Result;

            string[] log;
            using (var sr = new StreamReader("TestData/Power.log"))
                log = sr.ReadToEnd().Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
            client.UploadLog(uploadEvent, log).Wait();
        }
Beispiel #3
0
        public void TestDeckWinrate()
        {
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
            var client = new HsReplayClient("89c8bbc1-474a-4b1b-91b5-2a116d19df7a", "HSReplay-API-Test/1.0", true);

            const string wildDeckId = "AslFFZWw1KEskJD94V00fh";

            var token        = client.CreateUploadToken().Result;
            var dataStandard = client.GetDeckWinrates(wildDeckId, false, token).Result;

            Assert.IsNull(dataStandard);

            var dataWild = client.GetDeckWinrates(wildDeckId, true, token).Result;

            Assert.IsNotNull(dataWild);
        }
Beispiel #4
0
        public void ClientConfig_InvalidUrl_Error()
        {
            var webException = false;
            var config       = new ClientConfig()
            {
                TokensUrl = "https://hsreplay.net/api/v0/tokens/"
            };
            var client = new HsReplayClient("89c8bbc1-474a-4b1b-91b5-2a116d19df7a", "HSReplay-API-Test/1.0", true, config);

            try
            {
                var token = client.CreateUploadToken().Result;
            }
            catch (AggregateException aggregateException)
            {
                Assert.IsInstanceOfType(aggregateException.InnerExceptions[0], typeof(WebException));
                webException = true;
            }
            Assert.IsTrue(webException);
        }
Beispiel #5
0
        private static void Main(string[] args)
        {
            Util.DebugLog = new Log();

            //1. Ensure Hearthstone is generating the Power.log file
            var logConfigState = LogConfigHelper.VerifyLogConfig();

            switch (logConfigState.State)
            {
            case LogConfigHelper.LogConfigState.Ok:
                Console.WriteLine("log.config already set up");
                break;

            case LogConfigHelper.LogConfigState.Updated:
                Console.WriteLine("log.config was updated/created. Hearthstone might need to be restarted.");
                break;

            case LogConfigHelper.LogConfigState.Error:
                Console.WriteLine("Was not able to update/create log.config.");
                Console.WriteLine(logConfigState.Exception);
                break;
            }

            //2a. Create new HsReplayClient instance and request/store new user token
            var client = new HsReplayClient(MyApiKey, testData: true);
            var token  = client.CreateUploadToken().Result;
            //MyConfig["HSReplayUserToken"] = token;

            //2b. Create new HsReplayClient, passing the existing user token
            //var client = new HSReplay(MyApiKey, MyConfig[HSReplayUserToken]);

            //3. Claim account process
            var claimUrl = client.GetClaimAccountUrl().Result;

            Console.WriteLine($"Visit [{claimUrl}] to claim the account");

            //4. Create new HearthstoneWatcher instance and hook onto desired events.
            string hearthstoneDir = null;             //MyConfig[HearthstoneInstallDir]
            var    watcher        = new HearthstoneWatcher(client, new[] { BnetGameType.BGT_FRIENDS, BnetGameType.BGT_VS_AI }, hearthstoneDir);

            watcher.OnGameStart += (sender, eventArgs) => Console.WriteLine($"A new game started! GameMode={eventArgs.Mode}, GameHandle={eventArgs.GameHandle}");
            watcher.OnGameEnd   += (sender, eventArgs) => Console.WriteLine($"Game ended! UploadSuccessful={eventArgs.UploadSuccessful}, Exception={eventArgs.Exception}");

            while (true)
            {
                switch (Console.ReadKey().KeyChar)
                {
                case 'r':
                    Console.WriteLine("Starting wacher...");
                    watcher.Start().Wait();
                    Console.WriteLine("Started wacher...");
                    break;

                case 's':
                    Console.WriteLine("Stopping watcher...");
                    watcher.Stop().Wait();
                    Console.WriteLine("Stopped watcher.");
                    break;

                case 'a':
                    Console.WriteLine("Linked account: " + client.GetLinkedBattleTag().Result + " (not claimed if empty)");
                    break;

                case 'q':
                    return;
                }
            }
        }