private static GUTag ReadGUTagFromR(SQLiteDataReader r) { GUTag tag = new GUTag(); //0. ID tag.Id = r.GetGuid(0); //1. Title tag.AddAlias(r.GetString(1)); //2. Alias string alias = r.GetString(2); string[] aliasList = alias.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string a in aliasList) { tag.AddAlias(a); } //3. PID tag.PId = r.GetGuid(3); //4. Children string chilrend = r.GetString(4); string[] childList = chilrend.Split(new char[] { '\n' }, StringSplitOptions.RemoveEmptyEntries); foreach (string c in childList) { tag.AddChild(Guid.Parse(c)); } return(tag); }
public static GUTag MergeTag(GUTag iTag, GUTag oTag) { GUTag nTag = new GUTag(); //ID nTag.Id = iTag.Id; //PID nTag.PId = iTag.PId; //Alias nTag.Alias.AddRange(iTag.Alias); foreach (string s in iTag.Alias) { nTag.AddAlias(s); } //Children nTag.Children.AddRange(iTag.Children); foreach (Guid s in iTag.Children) { nTag.AddChild(s); } return(nTag); }
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); }