예제 #1
0
        public async Task <List <LogHeader> > Monitor(string gameName, string playerName)
        {
            if (String.IsNullOrEmpty(gameName))
            {
                throw new ArgumentException("names can't be null or empty");
            }
            string url  = $"{HostName}/api/catan/monitor/{gameName}/{playerName}";
            string json = await Get <string>(url);

            ServiceLogCollection serviceLogCollection = CatanProxy.Deserialize <ServiceLogCollection>(json);
            List <LogHeader>     records = ParseLogRecords(serviceLogCollection);

            //Debug.WriteLine($"[Game={gameName}] [Player={playerName}] [LogCount={logList.Count}]");
            return(records);
        }
예제 #2
0
        public async Task <List <LogHeader> > GetAllLogs(string gameName, string playerName, int startAt)
        {
            if (String.IsNullOrEmpty(gameName))
            {
                throw new Exception("names can't be null or empty");
            }
            string url  = $"{HostName}/api/catan/monitor/logs/{gameName}/{playerName}/{startAt}";
            string json = await Get <string>(url);

            if (String.IsNullOrEmpty(json))
            {
                return(null);
            }

            ServiceLogCollection serviceLogCollection = CatanProxy.Deserialize <ServiceLogCollection>(json);
            List <LogHeader>     records = ParseLogRecords(serviceLogCollection);

            return(records);
        }
예제 #3
0
        //
        //  this allows us to deal with the polymorphic deserialization of these log records
        //  "json" has the full object graph of the LogHeader, PlayedDevCardModel, and any
        //  derived class
        //
        static public PlayedDevCardModel Deserialize(object unparsedJson)
        {
            string action = ((JsonElement)unparsedJson).GetProperty("devCard").GetString();

            if (String.IsNullOrEmpty(action))
            {
                return(null);
            }
            bool ret = Enum.TryParse(action, true, out DevCardType devCard);

            if (!ret)
            {
                return(null);
            }
            string json = unparsedJson.ToString();

            switch (devCard)
            {
            case DevCardType.Knight:
                KnightPlayedLog pk = CatanProxy.Deserialize <KnightPlayedLog>(json);
                return(pk as PlayedDevCardModel);

            case DevCardType.YearOfPlenty:
                PlayedPlayedYearOfPlentyLog yop = CatanProxy.Deserialize <PlayedPlayedYearOfPlentyLog>(json);
                return(yop as PlayedDevCardModel);

            case DevCardType.RoadBuilding:
                return(CatanProxy.Deserialize <PlayedDevCardModel>(json));

            case DevCardType.Monopoly:
                PlayedMonopoly mono = CatanProxy.Deserialize <PlayedMonopoly>(json);
                return(mono as PlayedMonopoly);

            case DevCardType.Back:
            case DevCardType.Unknown:
            case DevCardType.VictoryPoint:
            default:
                break;
            }

            return(null);
        }
예제 #4
0
 //
 //  because of the way S.T.Json works, we have to Deserialize in two passes.
 //  first pass gets the header, then we switch on the Action and Deserialize
 //  the full object.
 //
 public static LogHeader DeserializeHeader(string json)
 {
     return CatanProxy.Deserialize<LogHeader>(json);
 }