Beispiel #1
0
 public void Dispose()
 {
     _dataContext = null;
     _entity      = null;
     _reader      = null;
     _fastObject  = null;
 }
Beispiel #2
0
 void MapValue(FastObject fastObject, string key, string expression)
 {
     if (string.IsNullOrEmpty(expression))
     {
         return;
     }
     if (expression[0] != '$')
     {
         return;
     }
     if (expression.StartsWith("$this.", StringComparison.OrdinalIgnoreCase))
     {
         string path = expression.Substring("$this.".Length);
         fastObject[key] = FastObject.Path(_entity, path);
     }
     if (expression.StartsWith("$reader.", StringComparison.OrdinalIgnoreCase))
     {
         string p10 = expression.Substring("$reader.".Length);
         if (p10.IndexOf('.') > -1)
         {
             string name = p10.Split('.')[0];
             string path = p10.Substring(name.Length + 1);
             fastObject[key] = FastObject.Path(_reader.GetValue(name, null), path);
         }
         else
         {
             fastObject[key] = _reader.GetValue(p10, null);
         }
     }
 }
Beispiel #3
0
            void MapArray(System.Collections.IList list)
            {
                FastObject fastObject = new FastObject(list);

                for (int i = 0; i < list.Count; i++)
                {
                    object value = list[i];
                    if (value == null)
                    {
                        continue;
                    }
                    if (value is string text)
                    {
                        MapValue(fastObject, $"[{i}]", text);
                        continue;
                    }
                    if (value is System.Collections.IList list2)
                    {
                        MapArray(list2);
                        continue;
                    }
                    if (value is System.Collections.Generic.IDictionary <string, object> dictionary)
                    {
                        MapObject(dictionary);
                    }
                }
            }
Beispiel #4
0
            void MapObject(System.Collections.Generic.IDictionary <string, object> map)
            {
                var fastObject = new FastObject(map);

                foreach (var item in LinqHelper.ToArray(map))
                {
                    if (item.Value == null)
                    {
                        continue;
                    }
                    if (item.Value is string text)
                    {
                        MapValue(fastObject, item.Key, text);
                        continue;
                    }
                    if (item.Value is System.Collections.IList list)
                    {
                        MapArray(list);
                        continue;
                    }
                    if (item.Value is System.Collections.Generic.IDictionary <string, object> dictionary)
                    {
                        MapObject(dictionary);
                    }
                }
            }
Beispiel #5
0
 public ObjectMapper(string expression, IDataContext dataContext, object entity, IDataQueryReader reader)
 {
     _fastObject  = expression;
     _dataContext = dataContext;
     _entity      = entity;
     _reader      = reader;
 }
Beispiel #6
0
        bool Load(System.IO.Stream stream)
        {
            Clear();

            System.Collections.Generic.IDictionary <string, object> items;
            using (System.IO.Stream compresStream = new System.IO.Compression.GZipStream(stream, System.IO.Compression.CompressionMode.Decompress, true)) {
                {
                    ushort length;
                    byte[] buffer = new byte[2];
                    if (compresStream.Read(buffer, 0, buffer.Length) != buffer.Length)
                    {
                        return(false);
                    }
                    length = BitConverter.ToUInt16(buffer, 0);
                    buffer = new byte[length];
                    if (compresStream.Read(buffer, 0, buffer.Length) != buffer.Length)
                    {
                        return(false);
                    }
                    string json = System.Text.Encoding.UTF8.GetString(buffer);
                    object root = JSON.Parse(json);
                    _version = TypeExtensions.Convert(FastObject.Path(root, "version"), -1);
                    if (_version < 1)
                    {
                        _version = 1;
                    }
                    items = FastObject.Path(root, "items") as System.Collections.Generic.IDictionary <string, object>;
                }
                if (items == null)
                {
                    return(false);
                }
                foreach (System.Collections.Generic.KeyValuePair <string, object> item in items)
                {
                    Resource o = new Resource()
                    {
                        Name   = item.Key,
                        Offset = TypeExtensions.Convert(FastObject.Path(item.Value, "[0]"), -1),
                        Length = TypeExtensions.Convert(FastObject.Path(item.Value, "[1]"), -1),
                    };
                    if (string.IsNullOrEmpty(o.Name) || o.Offset < 0 || o.Length < 0)
                    {
                        continue;
                    }
                    o.Data = new byte[o.Length];
                    if (compresStream.Read(o.Data, 0, o.Length) != o.Length)
                    {
                        return(false);
                    }
                    Append(o);
                }
            }
            return(true);
        }
Beispiel #7
0
        public override object Invoke(object[] args)
        {
            string path = args[1] as string;

            if (string.IsNullOrEmpty(path) || string.IsNullOrEmpty(path))
            {
                return(null);
            }
            object json = JSON.Parse(args[0] as string);

            return(FastObject.Path(json, path));
        }
        public bool login(string account, string password)
        {
            LastMoneyResult result = invoke("/user/login/base", new {
                info = new {
                    account,
                    password,
                    userAgent = GetUserAgent()
                }
            });

            _token = result.success? FastObject.Path(result.data, "token") as string: "";
            return(result.success);
        }
Beispiel #9
0
        //_list_condition_func
        PreSelectBuilderFunc GetPreSelectBuilderFunc(System.Type type, string value)
        {
            PreSelectBuilderFunc func;
            string key = type.AssemblyQualifiedName + "|" + value;

            if (!_list_condition_func.TryGetValue(key, out func))
            {
                ThreadHelper.Block(_list_condition_func, () => {
                    if (!_list_condition_func.TryGetValue(value, out func))
                    {
                        if (value.StartsWith("$this.", StringComparison.OrdinalIgnoreCase))
                        {
                            string path = value.Substring("$this.".Length);
                            func        = (dataContext, dataReader, entity) => {
                                return(FastObject.Path(entity, path));
                            };
                        }
                        if (value.StartsWith("$reader.", StringComparison.OrdinalIgnoreCase))
                        {
                            string p10 = value.Substring("$reader.".Length);
                            if (p10.IndexOf('.') > -1)
                            {
                                string name = p10.Split('.')[0];
                                string path = p10.Substring(name.Length + 1);
                                func        = (dataContext, dataReader, entity) => {
                                    return(FastObject.Path(DataReaderHelper.Current(dataReader, name), path));
                                };
                            }
                            else
                            {
                                func = (dataContext, dataReader, entity) => {
                                    return(DataReaderHelper.Current(dataReader, p10));
                                };
                            }
                        }
                        _list_condition_func.TryAdd(key, func);
                    }
                });
            }
            return(func);
        }
Beispiel #10
0
 public static bool Path(object instance, string path, object value)
 {
     return(FastObject.Path(instance, path, value));
 }
Beispiel #11
0
 public static object Path(object instance, string path)
 {
     return(FastObject.Path(instance, path));
 }
Beispiel #12
0
 /// <summary>
 /// 获取指定索引的节点值。
 /// </summary>
 /// <param name="index">索引值</param>
 /// <returns></returns>
 public NodeValue this[int index] {
     get {
         return(new NodeValue(FastObject.Path(_value, "[" + index + "]")));
     }
 }
Beispiel #13
0
 /// <summary>
 /// 获取指定path的节点值。
 /// </summary>
 /// <param name="path">path规则。</param>
 /// <returns></returns>
 public NodeValue this[string path] {
     get {
         return(new NodeValue(FastObject.Path(_value, path)));
     }
 }
Beispiel #14
0
 /// <summary>
 /// ctor(config)
 /// </summary>
 /// <param name="config">config object, FastObject instance</param>
 public DomainIPSyncService(FastObject config)
     : this(JSON.ToObject <Config>(config.ToJson()))
 {
 }