예제 #1
0
        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);
        }
예제 #2
0
        //////////////////////////////////////////////////////////

        public int SetParent(GUTag parent, GUTag child)
        {
            //添加的tag必须是有效节点
            AssertValid(parent);
            AssertValid(child);
            GUTag pTag = id2Gutag[parent.Id] as GUTag;
            GUTag cTag = id2Gutag[child.Id] as GUTag;

            //保护性检查,防止调用无效
            if (pTag != null && cTag != null)
            {
                pTag.AddChild(cTag);
                Save(pTag);
                //Save(child);  parent保存实际上已经保存所有了,这儿就不需要保存了。
            }
            return(ITagDBConst.R_OK);
        }
예제 #3
0
        //////////////////////////////////////////////////////////

        #region 修改Tag:父子关系
        //建立两个Tag之间的父子关系
        public int SetParent(GUTag parent, GUTag child)
        {
            //添加的tag必须是有效节点
            AssertValid(parent);
            AssertValid(child);
            GUTag pTag = QueryTag(parent.Id);
            GUTag cTag = QueryTag(child.Id);

            //保护性检查,防止调用无效
            if (pTag != null && cTag != null)
            {
                pTag.AddChild(cTag);
                System.Diagnostics.Debug.Assert(cTag.PId == pTag.Id);
                AddUptSqlDB(pTag);
                AddUptSqlDB(cTag);
                ChangeNotify();

                //Save(child);  parent保存实际上已经保存所有了,这儿就不需要保存了。
            }
            return(ITagDBConst.R_OK);
        }
예제 #4
0
        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);
        }
예제 #5
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);
        }