AcManager.Tools.Helpers.Api.Kunos.ServerInformation.Deserialize C# (CSharp) Method

Deserialize() public static method

public static Deserialize ( Stream stream ) : AcManager.Tools.Helpers.Api.Kunos.ServerInformation[]
stream Stream
return AcManager.Tools.Helpers.Api.Kunos.ServerInformation[]
        public static ServerInformation[] Deserialize(Stream stream) {
            var reader = new JsonTextReader(new StreamReader(stream));

            var response = new List<ServerInformation>(1200);
            var currentProperty = string.Empty;

            reader.MatchNext(JsonToken.StartArray);
            while (reader.IsMatchNext(JsonToken.StartObject)) {
                var entry = new ServerInformation();

                while (reader.Until(JsonToken.EndObject)) {
                    switch (reader.TokenType) {
                        case JsonToken.PropertyName:
                            currentProperty = reader.Value.ToString();
                            break;

                        case JsonToken.String:
                            switch (currentProperty) {
                                case "ip":
                                    entry.Ip = reader.Value.ToString();
                                    break;
                                case "name":
                                    entry.Name = reader.Value.ToString();
                                    break;
                                case "track":
                                    entry.TrackId = reader.Value.ToString();
                                    break;
                            }
                            break;

                        case JsonToken.Integer:
                            switch (currentProperty) {
                                case "port":
                                    entry.Port = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "cport":
                                    entry.PortC = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "tport":
                                    entry.PortT = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "clients":
                                    entry.Clients = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "maxclients":
                                    entry.Capacity = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timeofday":
                                    entry.Time = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "session":
                                    entry.Session = int.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timeleft":
                                    entry.TimeLeft = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "timestamp":
                                    entry.Timestamp = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                                case "lastupdate":
                                    entry.LastUpdate = long.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture);
                                    break;
                            }
                            break;

                        case JsonToken.Boolean:
                            switch (currentProperty) {
                                case "pass":
                                    entry.Password = bool.Parse(reader.Value.ToString());
                                    break;
                                case "pickup":
                                    entry.PickUp = bool.Parse(reader.Value.ToString());
                                    break;
                                case "l":
                                    entry.L = bool.Parse(reader.Value.ToString());
                                    break;
                            }
                            break;

                        case JsonToken.StartArray:
                            switch (currentProperty) {
                                case "cars":
                                    entry.CarIds = reader.ReadStringArray(1);
                                    break;
                                case "sessiontypes":
                                    entry.SessionTypes = reader.ReadIntArray(1);
                                    break;
                                case "durations":
                                    entry.Durations = reader.ReadLongArray(1);
                                    break;
                                case "country":
                                    entry.Country = reader.ReadStringArray(2);
                                    break;
                                default:
                                    while (reader.Until(JsonToken.EndArray)) { }
                                    break;
                            }
                            break;

                        default:
                            throw new Exception("Unexpected token: " + reader.TokenType);
                    }
                }

                response.Add(entry);
            }

            return response.ToArray();
        }
    }