Exemple #1
0
        public static Tuple <bool, string, dynamic> add(string s_key, string s_item)
        {
            try
            {
                string json = "";

                var    o = JsonConvert.DeserializeObject <m_node>(s_item);
                m_node m = JsonConvert.DeserializeObject <m_node>(s_item);

                if (dic_node_code.ContainsKey(m.code) == false)
                {
                    long id_new = 0;
                    bool c      = true;
                    while (c == true)
                    {
                        id_new = DateTime.Now.ToString("yyyyMMddHHmmssfff").TryParseToLong() + new Random().Next(10, 99);
                        c      = dic_node.ContainsKey(id_new);
                    }

                    int  phase_type = o.id_group;
                    long id_parent  = o.id_parent;

                    m.type = o.type;

                    m.id        = id_new;
                    m.id_group  = phase_type;
                    m.id_parent = id_parent;

                    m.id_root0 = o.id_root0;
                    m.id_root1 = o.id_root1;

                    m.level = o.level;
                    m.name  = o.name;
                    m.code  = o.code;

                    lock (lock_node)
                    {
                        dic_node_code.Add(m.code, id_new);
                        dic_node.Add(id_new, m);
                        cache_node_id(phase_type);
                    }
                    update_node(id_new, m);

                    lock (lock_ID_node)
                        dic_ID_node.AddDistinct(id_parent, id_new);

                    List <long> ls = new List <long>()
                    {
                    };
                    if (dic_ID_node.TryGetValue(id_parent, out ls) == false)
                    {
                        ls = new List <long>()
                        {
                        }
                    }
                    ;
                    update_ID_node(id_parent, ls);

                    Task.Factory.StartNew(() => { cache_node_set(phase_type, id_parent); });

                    json = JsonConvert.SerializeObject(m);

                    List <long> ls_parent = new List <long>()
                    {
                    };
                    if (dic_ID_parent.TryGetValue(id_parent, out ls_parent) == false)
                    {
                        ls_parent = new List <long>()
                        {
                        }
                    }
                    ;
                    ls_parent.Add(id_parent);
                    lock (lock_ID_parent)
                        dic_ID_parent.AddListDistinct(m.id, ls_parent);
                    update_ID_parent(m.id, ls_parent);
                }
                else
                {
                    json = "trung_ma";
                }

                return(new Tuple <bool, string, dynamic>(true, json, m));
            }
            catch { }

            return(new Tuple <bool, string, dynamic>(false, "", null));
        }