Ejemplo n.º 1
0
 public void Merge(JTagInf tag)
 {
     foreach (string a in tag.Alias)
     {
         AddAlias(a);
     }
     foreach (string c in tag.Children)
     {
         AddChild(c);
     }
     //foreach (string p in tag.Parents) AddParent(p);
 }
Ejemplo n.º 2
0
        public int Import(string importInf)
        {
            int   ret  = 0;
            GUTag dtag = NewTag(StaticCfg.Ins.DefaultTag);

            Hashtable title2GUtag = new Hashtable();

            title2GUtag.Add(StaticCfg.Ins.DefaultTag, dtag);
            if (File.Exists(importInf))
            {
                string[] lns = File.ReadAllLines(importInf);
                //第一遍,恢复tag本身的信息
                foreach (string ln in lns)
                {
                    JTagInf j = JsonConvert.DeserializeObject <JTagInf>(ln);

                    GUTag tag = title2GUtag[j.Title] as GUTag;
                    if (tag == null)
                    {
                        tag = NewTag(j.Title);
                        if (title2GUtag[j.Title] == null)
                        {
                            title2GUtag.Add(j.Title, tag);
                        }
                    }
                    foreach (string a in j.Alias)
                    {
                        tag.AddAlias(a);
                        if (title2GUtag[a] == null)
                        {
                            title2GUtag.Add(a, tag);
                        }
                    }
                    //把子节点先创建出来
                    foreach (string c in j.Children)
                    {
                        if (title2GUtag[c] == null)
                        {
                            GUTag ctag = NewTag(c);
                            if (title2GUtag[c] == null)
                            {
                                title2GUtag.Add(c, ctag);
                            }
                        }
                    }
                }
                //第二步,恢复child信息
                foreach (string ln in lns)
                {
                    JTagInf j = JsonConvert.DeserializeObject <JTagInf>(ln);

                    GUTag tag = title2GUtag[j.Title] as GUTag;
                    Debug.Assert(tag != null);

                    //把子节点先创建出来
                    foreach (string c in j.Children)
                    {
                        GUTag ctag = title2GUtag[c] as GUTag;
                        Debug.Assert(ctag != null);
                        tag.AddChild(ctag);
                    }
                }
            }
            Save();
            return(ret);
        }