public void InitDB(ITagDB tagDB, IUriDB uriDB) { TagDB = tagDB; UriDB = uriDB; MainCanvas.Initial(tagDB, uriDB, LayoutCanvas.MAIN_CANVAS); SubCanvas.Initial(tagDB, uriDB, LayoutCanvas.SUB_CANVAS); }
public void ITagDB_Test_Reopen()//关闭后重新打开 { GUTag p1 = db.NewTag("p1"); GUTag c1 = db.NewTag("c1"); db.SetParent(p1, c1); List <string> alias = db.QueryTagAlias(p1); foreach (string a in alias) { Logger.D(a); } Assert.AreEqual(1, alias.Count); Assert.AreEqual("p1", alias[0]); Logger.D("end test reopen"); IDisposableFactory.DisposeAll(); db = null; db = TagDBFactory.CreateTagDB("sql"); List <GUTag> p1new = db.QueryTags("p1"); alias = db.QueryTagAlias(p1new[0]); Assert.AreEqual(1, alias.Count); Assert.AreEqual("p1", alias[0]); }
private string GetTagInf(GUTag tag, ITagDB db) { StringBuilder sb = new StringBuilder(); sb.Append("当前选中标签:" + tag); List <GUTag> parents = db.QueryTagParent(tag); if (parents.Count > 0) { sb.Append(" Parent::= "); foreach (GUTag s in parents) { sb.Append(" " + s.Title); } } List <GUTag> children = TagDB.QueryTagChildren(tag); if (children.Count > 0) { sb.Append(" Children::= "); foreach (GUTag s in children) { sb.Append(" " + s.Title); } } return(sb.ToString().Trim()); }
public void teardown() { db.Dispose(); db = null; //if (System.IO.Directory.Exists(Cfg.Ins.TagDB)) // System.IO.Directory.Delete(Cfg.Ins.TagDB,true); }
private int CalcMid(List <GUTag> allChild, ITagDB db) { int rootChildrenCount = allChild.Count; int total = 0; //计算所有节点数量 foreach (GUTag c in allChild) { total += Math.Max(1, db.QueryChildrenCount(c));//没有子节点的算作1 } //找到子节点中间分割线 int tmpTotal = 0; double best = 1; int bestMid = 0; for (int i = 0; i < rootChildrenCount; i++) { tmpTotal += Math.Max(1, db.QueryChildrenCount(allChild[i])); double radio = ((double)tmpTotal) / total; if (Math.Abs(radio - 0.5) < best)//离一半最近 { best = Math.Abs(radio - 0.5); bestMid = i + 1; } } return(Math.Max(1, bestMid)); }
private static GTagBoxTree ExpandChildNoCompact(int level, int MaxLevel, ITagDB db, GTagBoxTree root, GTagBoxTree pre, GUTag ctag, int direct, Size size, TreeLayoutEnv env, LayoutMode mode) { GTagBoxTree cur; Logger.D("ChoosePos:pre:{0}-{1}-{2} cur:{0}-{1},", pre?.GTagBox.Tag, pre == null ? 0 : db.QueryTagChildren(pre.GTagBox.Tag).Count, pre == null ? 0 : pre.totalRange.Right, ctag, db.QueryTagChildren(ctag).Count); if (pre == null) { Logger.D("Place {0} after {1}:follow", ctag, root.GTagBox.Tag); cur = ExpandNode(ctag, level + 1, db, direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left, root.totalRange.Top, direct, size, env, mode); } else { Logger.D("Place {0} after {1}:newline", ctag, root.GTagBox.Tag); cur = ExpandNode(ctag, level + 1, db, direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left, root.totalRange.Bottom, direct, size, env, mode); } env.AddLine(root, cur, direct); return(cur); }
private static int GetTagTreeWidth(GUTag tag, ITagDB db, int level, int maxlevel) { int ret = -1; List <GUTag> children = db.QueryTagChildren(tag); if (level > maxlevel) { ret = 1; } else if (level == maxlevel) { ret = children.Count + 1; //所有子节点+自己 } //只有两种情况下不需要换行: //1. 父节点 -- 子, 孙,重孙 //2. 父节点 -- 子,子,子,子 else if (children.Count <= 1) //情况1: { //只有一列子孙节点,所有都是独生子 ret = 1; GUTag tmp = tag; for (int i = level; i < maxlevel; i++) { children = db.QueryTagChildren(tmp); if (children.Count > 1) { ret = -1; break; } else if (children.Count == 0) { ret++; break; } else if (children.Count == 1) { tmp = children[0]; ret++; } } return(ret); } else { //情况2:只有一层子节点,所有子节点都是叶子(显示为子,子,子,子) ret = children.Count; foreach (GUTag ctag in children) { if (db.QueryChildrenCount(ctag) > 0) //有子节点非叶子,并且自己子节点数量>1,表示不能在一行内显示 { ret = -1; } } } Logger.D("GetTagTreeWidth : {0} {1}", tag.ToString(), ret); return(ret); }
public void setup() { //if (!System.IO.Directory.Exists(Cfg.Ins.TagDB)) //{ // System.IO.Directory.CreateDirectory(Cfg.Ins.TagDB); //} db = TagDBFactory.CreateTagDB(); }
public void setup() { UTestCfg.Ins.IsUTest = true; //if (!System.IO.Directory.Exists(Cfg.Ins.TagDB)) //{ // System.IO.Directory.CreateDirectory(Cfg.Ins.TagDB); //} db = TagDBFactory.CreateTagDB("sql"); }
public override void Layout(ITagDB db, GUTag tag, Size size, TreeLayoutEnv env) { oriSize = size; env.Reset(); tags = new List <TagBox>(); this.db = db; root = GTagBoxTree.ExpandNode(tag, 0, db, 0, 0, 1, oriSize, env, myLayoutMode); tags = env.GetAllTagBox(); lines = env.GetAllLines().Cast <UIElement>(); }
private void Window_Closed(object sender, EventArgs e) { IDisposableFactory.Dispose(tagDB); IDisposableFactory.Dispose(uriDB); //tagDB.Dispose(); //uriDB.Dispose(); tagDB = null; uriDB = null; Logger.I(@"Close main window"); }
public static GUTag Parse(string strGutag, ITagDB db) { Guid id = Guid.Empty; if (strGutag.IndexOf(SplitToken) != -1) { string sID = strGutag.Split(SplitToken)[0]; id = Guid.Parse(sID); } return(db.GetTag(id)); }
public void ShowQueryResult(string query, IUriDB uriDB, ITagDB tagsDB) { this.uriDB = uriDB; this.tagsDB = tagsDB; dataList = SearchResultItem.QueryByTag(query, uriDB); SortType = -1; SortBy("访问时间"); TipsCenter.Ins.ListInf = "文件列表统计:" + query + " Found Files:" + dataList.Count; ShowItemList(); AdjustGridColumnWidth(); }
public static ITagDB CreateTagDB(string t) { if (t.Contains("json")) { Ins = IDisposableFactory.New <ITagDB>(JsonTagDB.Load()); } else if (t.Contains("sql")) { Ins = IDisposableFactory.New <ITagDB>(SQLTagDB.Load()); } return(Ins); }
public void teardown() { IDisposableFactory.DisposeAll(); db = null; //为了安全,直接硬编码,防止把真是数据删除 Directory.Delete(@"B:\00TagExplorerBase", true); //Directory.Delete(CfgPath.DocBasePath); //if (System.IO.Directory.Exists(Cfg.Ins.TagDB)) // System.IO.Directory.Delete(Cfg.Ins.TagDB,true); }
//初始化TagDB,该函数必须在空间初始化时就指定 public void Initial(ITagDB db, IUriDB uridb, LayoutCanvas canvasType) { TagDB = db; UriDB = uridb; MyCanvasType = canvasType; if (!NeedShowRootPath()) { //connectCanvas.Visibility = Visibility.Collapsed; connect.Height = new GridLength(0); } //更新上下文菜单的Check选项(选中哪个模式,就在该模式上打一个勾) UpdateMenuItemCheckStatus(); }
public void test() { ITagDB tagdb = TagDBFactory.CreateTagDB(); tagdb.AddTag("parent", "child"); ITagLayout lay = TagLayoutFactory.CreateLayout(); lay.Layout(tagdb, "parent"); Assert.AreEqual(2, lay.Lines.Count()); Assert.AreEqual(2, lay.TagArea.Count()); }
//公有方法/////////////////////////////////////////////// public void ChangeCurrentUri(string uri, IUriDB uriDB, ITagDB tagDB) { string tips = "当前选中文件:" + uri + " "; this.uriDB = uriDB; this.tagDB = tagDB; autoTextBox.SearchDataProvider = tagDB; currentUri = uri; List <string> tags = uriDB.GetTags(uri); parent.Children.Clear(); foreach (string tag in tags) { ShowTagsList(tag); tips += tag + " "; } TipsCenter.Ins.UriInf = tips; }
private void InitialViews() { if (uriDB == null || tagDB == null) { TipsCenter.Ins.StartTime = "Before Init DBS "; //URI DB初始化 Logger.I("InitializeComponent Finished!,init uridb"); uriDB = UriDBFactory.CreateUriDB(); uriDB.UriDBChanged += UriDBChangedCallback; TipsCenter.Ins.StartTime = "UriDB Init"; //TAG DB初始化 Logger.I("InitializeComponent Finished!,init tagdb"); tagDB = TagDBFactory.CreateTagDB(); tagDB.TagDBChanged += TagDBChanged; TipsCenter.Ins.StartTime = "TagDB Init"; //查询输入框初始化 SearchBox.textBox.TextChanged += SearchBoxTextChanged_Callback; SearchBox.SearchDataProvider = tagDB; TipsCenter.Ins.StartTime = "SearchBoxInit"; //Tag视图初始化 tagCanvas.InitDB(tagDB, uriDB); tagCanvas.SelectedTagChanged += SelectedTagChanged_Callback; TipsCenter.Ins.StartTime = "tagCanvasInit"; GUTag mroot = GUTag.Parse(DynamicCfg.Ins.MainCanvasRoot, tagDB); TipsCenter.Ins.StartTime = "mRoot"; GUTag sroot = GUTag.Parse(DynamicCfg.Ins.SubCanvasRoot, tagDB); TipsCenter.Ins.StartTime = "sRoot"; TipsCenter.Ins.StartTime = "MainWindow:64(before showtaggraph)"; ShowTagGraph(mroot, sroot); TipsCenter.Ins.StartTime = "AfterShowTagGraph"; IDisposableFactory.New <MainWindow>(this); richTxt.Focus(); this.Title = "TagExplorer " + CfgPath.RootPath; TipsCenter.Ins.StartTime = "MainWindow:70"; } }
private static GTagBoxTree ExpandChildCompact(int rootLevel, int MaxLevel, ITagDB db, GTagBoxTree root, GTagBoxTree pre, GUTag ctag, int direct, Size size, TreeLayoutEnv env, LayoutMode mode) { GTagBoxTree cur; Logger.D("ChoosePos:pre:{0}-{1}-{2} cur:{0}-{1},", pre?.GTagBox.Tag, pre == null ? 0 : db.QueryTagChildren(pre.GTagBox.Tag).Count, pre == null ? 0 : pre.totalRange.Right, ctag, db.QueryTagChildren(ctag).Count); bool leftOK = true, rightOK = true; TagBoxSizeInf sizeinf = new TagBoxSizeInf(ctag, rootLevel + 1, StaticCfg.Ins.GFontName); int OneLineChild = GetTagTreeWidth(ctag, db, rootLevel + 1, MaxLevel); //右边是否有足够空间(初步预估,用OneLineChild*本节点的宽度预估) if (pre != null && direct == 1) { rightOK = pre.totalRange.Right + sizeinf.OutterBoxSize.Width < size.Width; } //左边是否有足够空间 if (pre != null && direct == -1) { leftOK = sizeinf.OutterBoxSize.Width < pre.totalRange.Left; } //只有满足严格条件的情况下,才放在兄弟节点的后面,否则在父节点后展开 if (pre != null && OneLineChild >= 0 && (db.QueryTagChildren(pre.GTagBox.Tag).Count == 0 || rootLevel + 1 == MaxLevel) && rightOK && leftOK) { Logger.D("Place {0} after {1}:follow", ctag, pre.GTagBox.Tag); cur = ExpandNode(ctag, rootLevel + 1, db, direct == 1 ? pre.totalRange.Right : pre.totalRange.Left, //X pre.totalRange.Top, //Y direct, size, env, mode); } //第一个节点,没有兄弟节点,放在父节点后面 ==== > 放在父节点的同一行 //非叶子节点,也直接放在父节点后面 or ==== > 放在父节点的下一行 //前一个兄弟已经把这一行占完了 ==== > 放在父节点的下一行 else { if (pre == null) { Logger.D("Place {0} after {1}:follow", ctag, root.GTagBox.Tag); cur = ExpandNode(ctag, rootLevel + 1, db, direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left, root.totalRange.Top, direct, size, env, mode); } else { Logger.D("Place {0} after {1}:newline", ctag, root.GTagBox.Tag); cur = ExpandNode(ctag, rootLevel + 1, db, direct == 1 ? root.GTagBox.OutterBox.Right : root.GTagBox.OutterBox.Left, root.totalRange.Bottom, direct, size, env, mode); } env.AddLine(root, cur, direct); } return(cur); }
public TagDBLogger(ITagDB db) { DB = db; }
public override void Layout(ITagDB db, GUTag rootTag, Size size, TreeLayoutEnv env) { //初始化准备工作 GTagBoxTree subTree = null; double y = 0; oriSize = size; this.db = db; env.Reset(); tags = new List <TagBox>(); //计算出Root节点的位置信息 double rootTagBoxX = size.Width / 2; root = new GTagBoxTree(); root.GTagBox = new GTagBox(0, rootTag, rootTagBoxX, 0, 1); root.Move(-1 * root.GTagBox.InnerBox.Width * 3 / 4, 0); env.Add(rootTag, root); //计算左右子节点的开始位置(估算) double l, r; l = root.GTagBox.InnerBoxLeftTop.X - StaticCfg.Ins.LayoutXPadding * 5; r = root.GTagBox.InnerBoxLeftTop.X + root.GTagBox.InnerBox.Width + StaticCfg.Ins.LayoutXPadding * 5; Rect outterbox = Rect.Empty; List <GUTag> allChild = db.QueryTagChildren(rootTag); allChild.Remove(rootTag); int idx = 0; int mid = CalcMid(allChild, db); GTagBoxTree[] children = new GTagBoxTree[allChild.Count]; int direct = 1; //希望现实是按照顺时针方向现实 List <GUTag> Left = new List <GUTag>(); List <GUTag> Right = new List <GUTag>(); for (int i = 0; i < allChild.Count; i++) { if (i < mid) { Right.Add(allChild[i]); } else { Left.Add(allChild[i]); } } List <GUTag> all = new List <GUTag>(); all.AddRange(Right); Left.Reverse(); all.AddRange(Left); foreach (GUTag c in all) { if (c == rootTag) { continue; //临时规避数据上的一个问题,有些节点自己成环了。 } //确定当前子节点时放在左边,还是放在右边:半数放在左边,半数放在右边 if (idx == mid) { y = 0; //显示从左边转到右边,将y重置 direct = -1; } //展开第idx个子节点 subTree = GTagBoxTree.ExpandNode(c, 1, db, direct == 1?r:l, y, direct, size, env, myLayoutMode); children[idx] = subTree; //更新整个显示区的大小。(outterBox) if (idx == 0) { outterbox = subTree.TotalRange; } else { outterbox.Union(subTree.TotalRange); } root.Children.Add(subTree); env.AddLine(root, subTree, direct); y += subTree.TotalRange.Height; idx++; } outterbox.Union(root.GTagBox.OutterBox); root.TotalRange = outterbox; root.CenterRootY(); root.GTagBox.IsRoot = true; LRBanlance(children, mid); //如果有图形在坐标0的左边,将其往右移一些。 if (outterbox.X < 0) { root.Move(-outterbox.X, 0); } //ShowParent(root); tags = env.GetAllTagBox(); lines = env.GetAllLines().Cast <UIElement>(); }
//public static ITagDB CreateTagDB() //{ // Ins = IDisposableFactory.New<ITagDB>(new LuceneTagDB()); // return Ins; //} public static ITagDB CreateTagDB() { Ins = IDisposableFactory.New <ITagDB>(SQLTagDB.Load()); return(Ins); }
public static GTagBoxTree ExpandNode(GUTag tag, int level, ITagDB db, double x, double y, int direct, Size size, TreeLayoutEnv env, LayoutMode mode) { Logger.IN(tag.Title); Logger.D("Expand " + tag + " " + x + " " + y); //已经展开过,直接返回 if (env.Get(tag) != null) { Logger.D("FOUND " + tag); Logger.OUT(); return(env.Get(tag)); } //创建子树的根对象 GTagBoxTree root = new GTagBoxTree(); root.GTagBox = new GTagBox(level, tag, x, y, direct); root.totalRange = root.GTagBox.OutterBox; root.D("计算自身大小(不包括子节点)" + root.GTagBox.Tag); env.Add(tag, root);//这个特别需要注意,在递归展开之前,先要将该节点加入DB,否则可能会出现无限递归 List <GUTag> children = db.QueryTagChildren(tag); List <Size> childrenSize = new List <Size>(); GTagBoxTree pre = null; GTagBoxTree cur = null; double childX = x + direct * root.GTagBox.OutterBox.Width; double childY = y; int MaxLevel = CalcMaxLevel(mode); //double h = 0; //double w = 0; if (level < MaxLevel) { //遍历展开所有子节点 foreach (GUTag ctag in children) { if (env.Get(ctag) != null) { continue; } cur = null; //GTreeObj child = ExpandNode(ctag, level + 1, db, x + root.box.InnerBox.Width, y + h); //h += child.OutBox.Height; //w = Math.Max(w, child.OutBox.Width); switch (mode) { case LayoutMode.TREE_COMPACT_MORE: case LayoutMode.LRTREE_COMPACT_MORE: cur = ExpandChildMoreCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode); break; case LayoutMode.TREE_COMPACT: case LayoutMode.LRTREE_COMPACT: cur = ExpandChildCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode); break; case LayoutMode.TREE_NO_COMPACT: case LayoutMode.LRTREE_NO_COMPACT: cur = ExpandChildNoCompact(level, MaxLevel, db, root, pre, ctag, direct, size, env, mode); break; default: break; } //h += cur.OutBox.Height; //w = Math.Max(w, cur.OutBox.Width); root.totalRange.Union(cur.totalRange); root.Children.Add(cur); pre = cur; } } //根据所有子节点所占区域的大小,计算自己的位置 //root.OutBox.Width = w + root.box.InnerBox.Width; //root.OutBox.Height = Math.Max(h, root.box.InnerBox.Height); //root.GTagBox.InnerBox.Y = (root.TotalRange.Top + root.TotalRange.Bottom) / 2; root.GTagBox.CenterRootY(root.totalRange); root.D(null); Logger.OUT(); return(root); }
public virtual void Layout(ITagDB db, GUTag root, Size size, TreeLayoutEnv env) { throw new NotImplementedException(); }