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 ReplayData GetData(ReplayMeta meta)
 {
     return(datas
            .Child(meta.DataId)
            .OnceSingleAsync <ReplayData>()
            .ConfigureAwait(false).GetAwaiter()
            .GetResult());
 }
        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);
        }
Exemplo n.º 5
0
        private static ReplayMeta CreateReplayMeta()
        {
            var meta = new ReplayMeta(
                DateTime.UtcNow,
                "player",
                "0.1",
                "aabbcc",
                0,
                1,
                new[]
            {
                new Score
                {
                    punter = 0,
                    score  = 42
                }
            }
                );

            return(meta);
        }