Exemplo n.º 1
0
        //---------------------------------------------------------------------
        public IProp getProp(string prop_name)
        {
            IProp prop = null;

            mMapProp.TryGetValue(prop_name, out prop);
            return(prop);
        }
Exemplo n.º 2
0
 //---------------------------------------------------------------------
 internal void _tryAddDirtyProp(IProp prop)
 {
     if (!mMapPropDirty.ContainsKey(prop.getKey()))
     {
         mMapPropDirty.Add(prop.getKey(), prop);
     }
 }
Exemplo n.º 3
0
        //-----------------------------------------------------------------------------
        public static void setProp <T>(Dictionary <string, IProp> map_prop, string key, T value, bool collect_dirty = true)
        {
            IProp p = null;

            map_prop.TryGetValue(key, out p);
            if (p == null)
            {
                PropDef  prop_def = new PropDef(key, typeof(T), collect_dirty);
                Prop <T> prop     = new Prop <T>(null, prop_def, value);
                map_prop[prop.getKey()] = prop;
            }
            else
            {
                p.setValue(value);
            }
        }
Exemplo n.º 4
0
        //---------------------------------------------------------------------
        public void applyMapPropDirty(Dictionary <string, string> map_prop_dirty)
        {
            if (map_prop_dirty == null)
            {
                return;
            }

            foreach (var j in map_prop_dirty)
            {
                if (!mMapProp.ContainsKey(j.Key))
                {
                    continue;
                }
                IProp prop = mMapProp[j.Key];
                prop.fromJsonString(j.Value);
            }
        }
Exemplo n.º 5
0
        //---------------------------------------------------------------------
        public Dictionary <string, string> getMapProp4NetSync(byte current_nodetype, byte to_nodetype)
        {
            if (mMapProp.Count == 0)
            {
                return(null);
            }

            Dictionary <string, string> map_ret = new Dictionary <string, string>();

            FieldInfo[] list_fieldinfo = GetType().GetFields(BindingFlags.Public | BindingFlags.Instance);
            foreach (var fi in list_fieldinfo)
            {
                if (!fi.FieldType.BaseType.Equals(typeof(IProp)))
                {
                    continue;
                }

                Attribute[] attrs = System.Attribute.GetCustomAttributes(fi);
                foreach (Attribute attr in attrs)
                {
                    if (!(attr is PropAttrDistribution))
                    {
                        continue;
                    }

                    PropAttrDistribution a = (PropAttrDistribution)attr;
                    if (a.NodePrimary == current_nodetype && a.NodeDistribution != null)
                    {
                        foreach (var i in a.NodeDistribution)
                        {
                            if (i == to_nodetype)
                            {
                                IProp p = (IProp)fi.GetValue(this);
                                map_ret[p.getKey()] = EbTool.jsonSerialize(p.getValue());
                                break;
                            }
                        }
                    }
                    break;
                }
            }

            return(map_ret);
        }
Exemplo n.º 6
0
        //---------------------------------------------------------------------
        void _loadTable(string table_name)
        {
            string str_query_select = string.Format("SELECT * FROM {0};", table_name);
            Dictionary <int, List <DataInfo> > map_data = Sqlite.getTableData(str_query_select);

            if (map_data.Count <= 0)
            {
                return;
            }

            EbTable table = new EbTable();

            table.Name = table_name;

            foreach (var i in map_data)
            {
                EbPropSet       prop_set       = new EbPropSet();
                int             data_id        = i.Key;
                List <DataInfo> list_data_info = i.Value;
                foreach (var data_info in list_data_info)
                {
                    object data_value = data_info.data_value;
                    string data_name  = data_info.data_name;

                    switch (data_info.data_type)
                    {
                    case 1:
                    {
                        PropDef prop_def = table.getPropDef(data_name);
                        if (prop_def == null)
                        {
                            PropDef d = new PropDef(data_name, typeof(int), false);
                            table._addPropDef(d);
                        }
                        Prop <int> prop = new Prop <int>(null, prop_def, 0);
                        prop.set((int)data_value);
                        prop_set._addProp(data_name, prop);
                    }
                    break;

                    case 2:
                    {
                        PropDef prop_def = table.getPropDef(data_name);
                        if (prop_def == null)
                        {
                            PropDef d = new PropDef(data_name, typeof(float), false);
                            table._addPropDef(d);
                        }
                        Prop <float> prop = new Prop <float>(null, prop_def, 0f);
                        prop.set(((float)(double)data_value));
                        prop_set._addProp(data_name, prop);
                    }
                    break;

                    case 3:
                    {
                        PropDef prop_def = table.getPropDef(data_name);
                        if (prop_def == null)
                        {
                            PropDef d = new PropDef(data_name, typeof(string), false);
                            table._addPropDef(d);
                        }
                        Prop <string> prop = new Prop <string>(null, prop_def, "");
                        prop.set((string)data_value);
                        prop_set._addProp(data_name, prop);
                    }
                    break;
                    }
                }

                IProp prop_id = prop_set.getProp("Id");
                if (prop_id == null)
                {
                    EbLog.Error("EbDataMgr._loadTable() Error! Key=Id not exist, TableName=" + table_name);
                    continue;
                }
                Prop <int> p = (Prop <int>)prop_id;
                prop_set.Id = data_id;
                table._addPropSet(prop_set);
            }

            Db._addTable(table);
        }
Exemplo n.º 7
0
 //-----------------------------------------------------------------------------
 public abstract void copyValueFrom(IProp other_prop);
Exemplo n.º 8
0
        //-----------------------------------------------------------------------------
        public override void copyValueFrom(IProp other_prop)
        {
            T value = (T)other_prop.getValue();

            set(value);
        }
Exemplo n.º 9
0
 //---------------------------------------------------------------------
 internal void _addProp(string key, IProp prop)
 {
     mMapProp[key] = prop;
 }