public void SaveReplay(ReplayMeta meta, ReplayData data)
        {
            logger.Info($"Checking for saved maps");
            string encodedMap = Encode(data.Map);
            string mapHash    = encodedMap.CalculateMd5();

            if (maps.Child("keys").Child(mapHash).OnceSingleAsync <EncodedData>().ConfigureAwait(false).GetAwaiter().GetResult()?.D != "1")
            {
                maps.Child("data").Child(mapHash).PutAsync(new EncodedData(encodedMap)).ConfigureAwait(false).GetAwaiter().GetResult();
                maps.Child("keys").Child(mapHash).PutAsync(new EncodedData("1")).ConfigureAwait(false).GetAwaiter().GetResult();
            }

            logger.Info($"Saving data for AI {meta.AiName} to Firebase");
            var resultData = datas
                             .PostAsync(new EncodedData(data.Encode()))
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult();

            logger.Info($"Data for AI {meta.AiName} saved, result is {resultData.Key}");

            meta.DataId  = resultData.Key;
            meta.MapHash = mapHash;

            logger.Info($"Saving meta for AI {meta.AiName} to Firebase");
            var resultMeta = metas.PostAsync(meta)
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult();

            logger.Info($"Meta for AI {meta.AiName} saved, result is {resultMeta.Key}");
        }
        public void SaveReplay(ReplayMeta meta, ReplayData data)
        {
            var result = datas
                         .PostAsync(data)
                         .ConfigureAwait(false).GetAwaiter()
                         .GetResult();

            meta.DataId = result.Key;

            metas
            .PostAsync(meta)
            .ConfigureAwait(false).GetAwaiter()
            .GetResult();
        }
        public ReplayData GetData(ReplayMeta meta)
        {
            string data = datas
                          .Child(meta.DataId)
                          .OnceSingleAsync <EncodedData>()
                          .ConfigureAwait(false).GetAwaiter()
                          .GetResult().D;
            string mapData = maps.Child("data")
                             .Child(meta.MapHash)
                             .OnceSingleAsync <EncodedData>()
                             .ConfigureAwait(false).GetAwaiter()
                             .GetResult().D;
            var replayData = ReplayData.Decode(data);

            replayData.Map = Decode <Map>(mapData);
            return(replayData);
        }
예제 #4
0
        public void SaveReplay_ShouldSave()
        {
            var repo = new ReplayRepo(true);
            var meta = CreateReplayMeta();
            var map  = MapLoader.LoadMap(Path.Combine(TestContext.CurrentContext.TestDirectory, @"..\..\..\..\maps\oxford2.json")).Map;

            JsonConvert.SerializeObject(map).CalculateMd5();
            var data = new ReplayData(map, Enumerable.Range(0, map.Rivers.Length).Select(i => Move.Claim(0, i, i + 1)).ToArray(), new Future[0]);
            var sw   = Stopwatch.StartNew();

            repo.SaveReplay(meta, data);
            Console.WriteLine(sw.Elapsed);
            sw.Restart();
            var savedData = repo.GetData(meta);

            Console.WriteLine(sw.Elapsed);
            Assert.NotNull(savedData);
        }