示例#1
0
        public Task <List <PlayerResources> > Trade(string gameName, string fromPlayer, TradeResources from, string toPlayer, TradeResources to)
        {
            if (String.IsNullOrEmpty(fromPlayer) || String.IsNullOrEmpty(toPlayer) || String.IsNullOrEmpty(gameName))
            {
                throw new Exception("names can't be null or empty");
            }
            string url  = $"{HostName}/api/catan/resource/trade/{gameName}/{fromPlayer}/{toPlayer}";
            var    body = CatanProxy.Serialize <TradeResources[]>(new TradeResources[] { from, to });

            return(Post <List <PlayerResources> >(url, body));
        }
示例#2
0
        public Task <T> PostUndoRequest <T>(CatanRequest undoRequest)
        {
            if (undoRequest == null || String.IsNullOrEmpty(undoRequest.Url))
            {
                throw new Exception("names can't be null or empty");
            }
            string url  = $"{HostName}/{undoRequest.Url}";
            string body = CatanProxy.Serialize <object>(undoRequest.Body);

            return(Post <T>(url, body));
        }
示例#3
0
        public Task <PlayerResources> ReturnResource(string gameName, string playerName, TradeResources resources)
        {
            if (String.IsNullOrEmpty(gameName) || String.IsNullOrEmpty(playerName))
            {
                throw new Exception("names can't be null or empty");
            }
            string url  = $"{HostName}/api/catan/resource/return/{gameName}/{playerName}";
            var    body = CatanProxy.Serialize <TradeResources>(resources);

            return(Post <PlayerResources>(url, body));
        }
示例#4
0
        public Task <List <string> > CreateGame(string gameName, GameInfo gameInfo)
        {
            if (String.IsNullOrEmpty(gameName))
            {
                throw new ArgumentException("names can't be null or empty");
            }
            if (gameInfo == null)
            {
                throw new ArgumentException("gameInfo can't be null");
            }
            string url = $"{HostName}/api/catan/game/create/{gameName}";

            return(Post <List <string> >(url, CatanProxy.Serialize <GameInfo>(gameInfo)));
        }
示例#5
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);
        }
示例#6
0
        public Task <PlayerResources> UndoGrantResource(string gameName, ResourceLog lastLogRecord)
        {
            if (lastLogRecord is null)
            {
                throw new Exception("log record can't be null");
            }
            if (String.IsNullOrEmpty(gameName) || String.IsNullOrEmpty(lastLogRecord.PlayerName))
            {
                throw new Exception("names can't be null or empty");
            }

            string url  = $"{HostName}/api/catan/resource/undo/{gameName}";
            var    body = CatanProxy.Serialize <ResourceLog>(lastLogRecord);

            return(Post <PlayerResources>(url, body));
        }
示例#7
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);
        }
示例#8
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);
        }
示例#9
0
        public async Task <CatanMessage> PostLogMessage <T>(string sessionName, LogHeader logHeader)
        {
            if (String.IsNullOrEmpty(sessionName))
            {
                throw new ArgumentException("names can't be null or empty");
            }
            if (logHeader == null)
            {
                throw new ArgumentException("LogHeader cannot be null");
            }

            string       url     = $"{HostName}/api/catan/session/message/{sessionName}";
            CatanMessage message = new CatanMessage()
            {
                TypeName = logHeader.GetType().FullName,
                Data     = logHeader as object
            };

            CatanMessage returnedMessage = await Post <CatanMessage>(url, CatanProxy.Serialize(message));

            returnedMessage.Data = ParseCatanMessage(returnedMessage);
            return(returnedMessage);
        }
示例#10
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);
 }
示例#11
0
 public string Serialize()
 {
     return CatanProxy.Serialize<object>(this);
 }