Beispiel #1
0
        private void parseJSONResult(String result, String oppName)
        {
            // convert the html data to ApiResultMessage
            JsonReader reader  = new JsonReader();
            Message    message = reader.Read(result, System.Type.GetType("ApiResultMessage")) as ApiResultMessage;

            ApiResultMessage armsg = (ApiResultMessage)message;

            String chatMsg = "";

            if (armsg.msg.Equals("success"))             // api call succeeded
            {
                chatMsg += "Player info: " + armsg.data.name + "\n";
                chatMsg += "Rank: " + armsg.data.rank + "\n";
                chatMsg += "Rating: " + armsg.data.rating + "\n";
                chatMsg += "Games played: " + armsg.data.played + "\n";
                chatMsg += "Games won: " + armsg.data.won + " (" + Math.Round(((float)armsg.data.won / (float)armsg.data.played) * 100) + "%)\n";
            }
            else
            {
                chatMsg = "Couldn't get data for " + oppName + ".";
            }
            MethodInfo mi = typeof(BattleMode).GetMethod("updateChat", BindingFlags.NonPublic | BindingFlags.Instance);

            if (mi != null)             // send chat message
            {
                mi.Invoke(bm, new String[] { chatMsg });
            }
            else             // can't invoke updateChat
            {
            }
        }
        public static OkObjectResult Result(Object data, string userMessage, string userMessageCode = null, int?errorCode = null, string message = null, Exception exception = null)
        {
            var result = new ApiResultMessage
            {
                Data            = data,
                UserMessage     = userMessage,
                UserMessageCode = userMessageCode,
                ErrorCode       = errorCode ?? 0,
                Message         = message,
                Exception       = exception?.ToString()
            };

            if (errorCode.HasValue || !string.IsNullOrEmpty(message) || exception != null)
            {
                result.IsSuccessful = false;
            }
            else
            {
                result.IsSuccessful = true;
            }
            return(new OkObjectResult(result));
        }