Пример #1
0
        public static JToken SerializeArray <T>(IEnumerable <T> enumerable, Func <T, string> serializer, bool compressed)
        {
            if (_sArrayBuilder == null)
            {
                _sArrayBuilder = new StringBuilder();
            }
            else
            {
                _sArrayBuilder.Remove(0, _sArrayBuilder.Length);
            }

            _sArrayBuilder.Append("[");
            foreach (var item in enumerable)
            {
                _sArrayBuilder.Append(serializer(item));
                _sArrayBuilder.Append(",");
            }

            if (_sArrayBuilder.Length > 1)
            {
                _sArrayBuilder.Remove(_sArrayBuilder.Length - 1, 1);
            }
            _sArrayBuilder.Append("]");

            return(compressed
                ? (JToken)LZString.compressToBase64(_sArrayBuilder.ToString())
                : JArray.Parse(_sArrayBuilder.ToString()));
        }
Пример #2
0
        public JToken GetModels([Url] string mapName, int index)
        {
            if (CheckNotExpired(mapName))
            {
                return(null);
            }

            var response = new JObject();

            var bsp   = GetBspFile(Request, mapName);
            var model = bsp.Models[index];
            var tree  = SerializeBspNode(bsp, model.HeadNode);

            response.Add("index", index);
            response.Add("min", model.Min.ToJson());
            response.Add("max", model.Max.ToJson());
            response.Add("origin", model.Origin.ToJson());
            response.Add("tree", Compressed ? LZString.compressToBase64(tree.ToString(Formatting.None)) : tree);

            return(response);
        }