Example #1
0
        public override object Insert(
            DataManager dataManager,
            IDynamicMetaObjectProvider data,
            string tableName = null,
            Query query      = null,
            int position     = 0)
        {
            IEnumerable enumerable = (IEnumerable)(this.DataManager.Json ?? (IEnumerable <object>)Enumerable.Empty <object>().ToList <object>());
            IDictionary <string, Type> columnType = DataUtil.GetColumnType(enumerable, false);
            bool flag = typeof(DynamicObject).IsAssignableFrom(enumerable.Cast <object>().ToList <object>().FirstOrDefault <object>()?.GetType());

            if ((enumerable as IEnumerable <object>).Count <object>() != 0)
            {
                if (flag)
                {
                    foreach (string name in (data as DynamicObject).GetDynamicMemberNames().ToArray <string>())
                    {
                        object obj           = enumerable.Cast <object>().ToList <object>().FirstOrDefault <object>();
                        object dynamicValue1 = DataUtil.GetDynamicValue(data as DynamicObject, name);
                        object dynamicValue2 = DataUtil.GetDynamicValue(obj as DynamicObject, name);
                        if (dynamicValue1 != null && dynamicValue2 != null)
                        {
                            (data as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), SfBaseUtils.ChangeType(dynamicValue1, dynamicValue2.GetType()));
                        }
                        else
                        {
                            (data as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), dynamicValue1);
                        }
                    }
                }
                else
                {
                    IDictionary <string, object> dictionary = (IDictionary <string, object>)data;
                    foreach (string key in dictionary.Keys.ToList <string>())
                    {
                        Type conversionType = columnType[key];
                        if (dictionary[key] != null)
                        {
                            ((IDictionary <string, object>)data)[key] = SfBaseUtils.ChangeType(dictionary[key], conversionType);
                        }
                        else
                        {
                            ((IDictionary <string, object>)data)[key] = dictionary[key];
                        }
                    }
                }
            }
            ((IList)enumerable).Insert(position, (object)data);
            return((object)data.ToString());
        }
Example #2
0
        public IEnumerable CollectChildRecords(IEnumerable datasource, DataManagerRequest dm)
        {
            IEnumerable enumerable1 = (IEnumerable)SfBaseUtils.ChangeType((object)datasource, datasource.GetType());
            string      idMapping   = dm.IdMapping;

            object[] objArray = new object[0];
            if (enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject))
            {
                foreach (IDictionary <string, object> dictionary in datasource.Cast <ExpandoObject>().ToList <ExpandoObject>())
                {
                    object obj = dictionary[idMapping];
                    objArray = ((IEnumerable <object>)objArray).Concat <object>((IEnumerable <object>) new object[1]
                    {
                        obj
                    }).ToArray <object>();
                }
            }
            else
            {
                foreach (object obj1 in datasource)
                {
                    object obj2 = obj1.GetType().GetProperty(idMapping).GetValue(obj1);
                    objArray = ((IEnumerable <object>)objArray).Concat <object>((IEnumerable <object>) new object[1]
                    {
                        obj2
                    }).ToArray <object>();
                }
            }
            IEnumerable enumerable2 = (IEnumerable)null;

            foreach (object obj in objArray)
            {
                dm.Where[0].value = obj;
                IEnumerable enumerable3 = enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject) ? (IEnumerable)DynamicObjectOperation.PerformFiltering(enumerable1, dm.Where, dm.Where[0].Operator) : DataOperations.PerformFiltering(enumerable1, dm.Where, dm.Where[0].Operator);
                enumerable2 = enumerable2 == null || enumerable2.AsQueryable().Count() == 0 ? enumerable3 : (IEnumerable)((IEnumerable <object>)enumerable2).Concat <object>((IEnumerable <object>)enumerable3);
            }
            if (enumerable2 != null)
            {
                IEnumerable enumerable3 = this.CollectChildRecords(enumerable2, dm);
                if (dm.Sorted != null && dm.Sorted.Count > 0)
                {
                    enumerable3 = enumerable1.GetType() == typeof(List <ExpandoObject>) || enumerable1.GetElementType() == typeof(ExpandoObject) ? (IEnumerable)DynamicObjectOperation.PerformSorting(enumerable3.AsQueryable(), dm.Sorted) : DataOperations.PerformSorting(enumerable3, dm.Sorted);
                }
                datasource = (IEnumerable)((IEnumerable <object>)datasource).Concat <object>((IEnumerable <object>)enumerable3);
            }
            return(datasource);
        }
Example #3
0
        public override object BatchUpdate(
            DataManager dataManager,
            List <IDynamicMetaObjectProvider> changed,
            List <IDynamicMetaObjectProvider> added,
            List <IDynamicMetaObjectProvider> deleted,
            Utils e,
            string keyField,
            int?dropIndex,
            Query query     = null,
            object original = null)
        {
            IEnumerable <object> source           = this.DataManager.Json ?? (IEnumerable <object>)Enumerable.Empty <object>().ToList <object>();
            object        obj1                    = (object)null;
            object        obj2                    = (object)null;
            object        obj3                    = (object)null;
            List <object> objectList              = new List <object>();
            string        str1                    = (string)null;
            IDictionary <string, Type> columnType = DataUtil.GetColumnType((IEnumerable)source, false);
            bool flag = typeof(DynamicObject).IsAssignableFrom(source.Cast <object>().ToList <object>().FirstOrDefault <object>()?.GetType());

            if (changed != null)
            {
                foreach (object obj4 in (IEnumerable)changed)
                {
                    foreach (object obj5 in (IEnumerable)source)
                    {
                        string str2 = (string)null;
                        if (flag)
                        {
                            string str3 = DataUtil.GetDynamicValue(obj4 as DynamicObject, keyField)?.ToString();
                            str1 = DataUtil.GetDynamicValue(obj5 as DynamicObject, keyField)?.ToString();
                            string[] array = (obj5 as DynamicObject).GetDynamicMemberNames().ToArray <string>();
                            if (str1 == str3)
                            {
                                foreach (string name in array)
                                {
                                    if (name != keyField && name != "BlazId")
                                    {
                                        object dynamicValue1 = DataUtil.GetDynamicValue(obj4 as DynamicObject, name);
                                        object dynamicValue2 = DataUtil.GetDynamicValue(obj5 as DynamicObject, name);
                                        if (dynamicValue1 != null && dynamicValue2 != null)
                                        {
                                            (obj5 as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), SfBaseUtils.ChangeType(dynamicValue1, dynamicValue2.GetType()));
                                        }
                                        else
                                        {
                                            (obj5 as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), dynamicValue1);
                                        }
                                    }
                                }
                                objectList.Add(obj5);
                            }
                        }
                        else
                        {
                            IDictionary <string, object> dictionary1 = (IDictionary <string, object>)obj4;
                            if (dictionary1[keyField] != null)
                            {
                                str2 = dictionary1[keyField].ToString();
                            }
                            IDictionary <string, object> dictionary2 = (IDictionary <string, object>)obj5;
                            if (dictionary2[keyField] != null)
                            {
                                str1 = dictionary2[keyField].ToString();
                            }
                            if (str1 == str2)
                            {
                                foreach (string key in (IEnumerable <string>)dictionary1.Keys)
                                {
                                    if (((IDictionary <string, object>)obj5).ContainsKey(key))
                                    {
                                        if (dictionary1[key] != null)
                                        {
                                            Type conversionType = ((IDictionary <string, object>)obj5)[key] != null ? ((IDictionary <string, object>)obj5)[key].GetType() : columnType[key];
                                            if (conversionType == dictionary1[key].GetType())
                                            {
                                                ((IDictionary <string, object>)obj5)[key] = dictionary1[key];
                                            }
                                            else
                                            {
                                                ((IDictionary <string, object>)obj5)[key] = SfBaseUtils.ChangeType(dictionary1[key], conversionType);
                                            }
                                        }
                                        else
                                        {
                                            ((IDictionary <string, object>)obj5)[key] = dictionary1[key];
                                        }
                                    }
                                }
                                objectList.Add(obj5);
                            }
                        }
                    }
                }
                obj1 = (object)objectList;
            }
            if (added != null)
            {
                obj2 = (object)added;
                foreach (object obj4 in (IEnumerable)obj2)
                {
                    if (flag)
                    {
                        foreach (string name in (obj4 as DynamicObject).GetDynamicMemberNames().ToArray <string>())
                        {
                            object obj5          = source.Cast <object>().ToList <object>().FirstOrDefault <object>();
                            object dynamicValue1 = DataUtil.GetDynamicValue(obj4 as DynamicObject, name);
                            object dynamicValue2 = DataUtil.GetDynamicValue(obj5 as DynamicObject, name);
                            if (dynamicValue1 != null && dynamicValue2 != null)
                            {
                                (obj4 as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), SfBaseUtils.ChangeType(dynamicValue1, dynamicValue2.GetType()));
                            }
                            else
                            {
                                (obj4 as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), dynamicValue1);
                            }
                        }
                    }
                    else
                    {
                        IDictionary <string, object> dictionary = (IDictionary <string, object>)obj4;
                        foreach (string key in dictionary.Keys.ToList <string>())
                        {
                            if (columnType != null && columnType.ContainsKey(key))
                            {
                                Type conversionType = columnType[key];
                                if (dictionary[key] != null)
                                {
                                    ((IDictionary <string, object>)obj4)[key] = SfBaseUtils.ChangeType(dictionary[key], conversionType);
                                }
                                else
                                {
                                    ((IDictionary <string, object>)obj4)[key] = dictionary[key];
                                }
                            }
                        }
                    }
                    if (!dropIndex.HasValue)
                    {
                        ((IList)source).Add(obj4);
                    }
                    else
                    {
                        ((IList)source).Insert(dropIndex.Value, obj4);
                        int?nullable = dropIndex;
                        dropIndex = nullable.HasValue ? new int?(nullable.GetValueOrDefault() + 1) : new int?();
                    }
                }
            }
            if (deleted != null)
            {
                obj3 = (object)deleted;
                List <IDynamicMetaObjectProvider> list = source.Cast <IDynamicMetaObjectProvider>().ToList <IDynamicMetaObjectProvider>();
                foreach (object obj4 in (IEnumerable)obj3)
                {
                    foreach (IDynamicMetaObjectProvider metaObjectProvider in list)
                    {
                        string str2;
                        string str3;
                        if (flag)
                        {
                            str2 = DataUtil.GetDynamicValue(metaObjectProvider as DynamicObject, keyField)?.ToString();
                            str3 = DataUtil.GetDynamicValue(obj4 as DynamicObject, keyField)?.ToString();
                        }
                        else
                        {
                            str2 = ((IDictionary <string, object>)metaObjectProvider)[keyField].ToString();
                            str3 = ((IDictionary <string, object>)obj4)[keyField].ToString();
                        }
                        if (str2 == str3)
                        {
                            (source as IList).Remove((object)metaObjectProvider);
                        }
                    }
                }
            }
            return((object)new
            {
                changedRecords = obj1,
                addedRecords = obj2,
                deletedRecords = obj3
            });
        }
Example #4
0
        public override object Update(
            DataManager dataManager,
            string keyField,
            IDynamicMetaObjectProvider data,
            string tableName = null,
            Query query      = null,
            object original  = null)
        {
            IEnumerable <object> json = this.DataManager.Json;
            string str1 = (string)null;
            IDictionary <string, Type> columnType = DataUtil.GetColumnType((IEnumerable)json, false);
            Type type = data.GetType();
            bool flag = ((object)type != null ? type.BaseType : (Type)null) == typeof(DynamicObject);

            if (flag)
            {
                str1 = DataUtil.GetDynamicValue(data as DynamicObject, keyField).ToString();
            }
            else
            {
                IDictionary <string, object> dictionary = (IDictionary <string, object>)data;
                if (dictionary[keyField] != null)
                {
                    str1 = dictionary[keyField].ToString();
                }
            }
            foreach (object obj in (IEnumerable)json)
            {
                string str2 = (string)null;
                if (flag)
                {
                    str2 = DataUtil.GetDynamicValue(obj as DynamicObject, keyField).ToString();
                }
                else
                {
                    IDictionary <string, object> dictionary = (IDictionary <string, object>)obj;
                    if (dictionary[keyField] != null)
                    {
                        str2 = dictionary[keyField].ToString();
                    }
                }
                if (str2 == str1)
                {
                    if (flag)
                    {
                        foreach (string name in (data as DynamicObject).GetDynamicMemberNames().ToArray <string>())
                        {
                            if (name != keyField)
                            {
                                object dynamicValue1 = DataUtil.GetDynamicValue(data as DynamicObject, name);
                                object dynamicValue2 = DataUtil.GetDynamicValue(obj as DynamicObject, name);
                                if (dynamicValue1 != null && dynamicValue2 != null)
                                {
                                    (obj as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), SfBaseUtils.ChangeType(dynamicValue1, dynamicValue2.GetType()));
                                }
                                else
                                {
                                    (obj as DynamicObject).TrySetMember((SetMemberBinder) new DataSetMemberBinder(name, false), dynamicValue1);
                                }
                            }
                        }
                    }
                    else
                    {
                        IDictionary <string, object> dictionary = (IDictionary <string, object>)data;
                        int           count = dictionary.Keys.Count;
                        List <string> list  = dictionary.Keys.ToList <string>();
                        for (int index = 0; index < count; ++index)
                        {
                            string key = list[index];
                            if (((IDictionary <string, object>)obj).ContainsKey(key))
                            {
                                if (dictionary[key] != null)
                                {
                                    Type conversionType = ((IDictionary <string, object>)obj)[key] != null ? ((IDictionary <string, object>)obj)[key].GetType() : columnType[key];
                                    if (conversionType == dictionary[key].GetType())
                                    {
                                        ((IDictionary <string, object>)obj)[key] = dictionary[key];
                                    }
                                    else
                                    {
                                        ((IDictionary <string, object>)obj)[key] = SfBaseUtils.ChangeType(dictionary[key], conversionType);
                                    }
                                }
                                else
                                {
                                    ((IDictionary <string, object>)obj)[key] = dictionary[key];
                                }
                            }
                            else
                            {
                                ((IDictionary <string, object>)obj).Add(key, dictionary[key]);
                            }
                        }
                    }
                    data = (IDynamicMetaObjectProvider)obj;
                }
            }
            return((object)data);
        }