public string DeviceTree() { var inputValue = _ntsPage.Request.Form["Inputs"]; if (string.IsNullOrEmpty(inputValue)) { var cacheTree = NTS.WEB.Common.CacheHelper.GetCache("device-tree"); if (cacheTree != null) { //var treeObject = cacheTree.ToString(); return cacheTree.ToString(); } var res = new BaseTree().GetDeviceTree(); NTS.WEB.Common.CacheHelper.SetCache("device-tree", res.TreeJson); // Framework.Common.BaseWcf.CreateChannel<ServiceInterface.IObjectTree>("ObjectTree").GetDeviceTree(); return res.TreeJson; } else { var query = Newtonsoft.Json.JsonConvert.DeserializeObject<NTS.WEB.DataContact.QueryDevice>(inputValue); var res = new BaseTree().GetDeviceListByArea(query); //Framework.Common.BaseWcf.CreateChannel<ServiceInterface.IObjectTree>("ObjectTree").GetDeviceListByArea(query); return res; // return Newtonsoft.Json.JsonConvert.SerializeObject(res); } //return Newtonsoft.Json.JsonConvert.SerializeObject(res); }
/// <summary> /// A OnClick event. /// </summary> /// <param name="e"></param> protected virtual void OnClick(EventArgs e) { if (BaseTree.UseSameClickEvent) { if (BaseTree.Click != null) { BaseTree.Click(this, e); } } else { if (Click != null) { Click(this, e); } } }
public void AddParentedNodesTest() { IBaseTree tree = new BaseTree(); String root = "world"; String child = "us"; tree.AddWord((string)null, root); tree.AddWord(root, child); Assert.IsTrue(tree.Contains(root)); Assert.IsTrue(tree.Contains(child)); Assert.AreEqual(root, tree.Root.KeyWord); Assert.AreEqual(root, tree.GetNode(root).KeyWord); Assert.AreEqual(child, tree.GetNode(child).KeyWord); Assert.AreEqual(root, tree.GetNode(child).Parent.KeyWord); }
public void DeleteTest() { BaseTree <float> baseTree = new BaseTree <float>(); baseTree.Insert(new List <float>() { 4f, 3f, 10f, 20f, 50f }); Assert.AreEqual(true, baseTree.Contains(10f)); baseTree.Delete(10f); Assert.AreEqual(false, baseTree.Contains(10f)); Assert.AreEqual(true, baseTree.Contains(4f)); baseTree.Delete(4f); Assert.AreEqual(false, baseTree.Contains(4f)); Assert.AreEqual(true, baseTree.Contains(50f)); baseTree.Delete(50f); Assert.AreEqual(false, baseTree.Contains(50f)); }
/// <summary> /// Casts the structure, and calls ConvertTiles /// </summary> /// <param name="structures">The structures that need to be cast</param> void ConvertTiles(List <Structure> structures) { foreach (Structure s in structures) { if (s != null) { if (s is Terrainer) { Terrainer st = (Terrainer)s; st.ConvertTiles(); } else if (s is BaseTree) { BaseTree sb = (BaseTree)s; sb.ConvertTiles(); } } } }
/// <summary> /// 在水分实验中进入植物调用的函数 /// </summary> /// <param name="baseTree">进入的植物</param> /// <returns>是否调用成功</returns> public override bool OnEnterTree(BaseTree baseTree) { EnvironmentParams envir = baseTree.EnvironmentParams; //int index = MaizeParams.WaterContents.IndexOf(envir.WaterContent); //if (index <= 0) // return false; //else //{ // envir.WaterContent = MaizeParams.WaterContents[index - 1]; // ChangeDayUpdate(envir); // return true; //} envir.WaterContent += 0.07; ChangeDayUpdate(envir); return(true); }
/// <summary> /// Used to determine the start node id while taking into account a user's security /// </summary> /// <param name="tree"></param> /// <param name="definedStartNode"></param> /// <param name="userStartNode"></param> /// <returns></returns> internal static int GetStartNodeId(this BaseTree tree, Content definedStartNode, Content userStartNode) { if (userStartNode == null) { throw new ArgumentNullException("userStartNode"); } //the output start node id var determinedStartNodeId = uQuery.RootNodeId; if (definedStartNode == null) { //if the defined (desired) start node is null (could not be found), return NoChildNodesId determinedStartNodeId = NoChildNodesId; } else if (definedStartNode.Id == uQuery.RootNodeId) { //if the id is -1, then the start node is the user's start node determinedStartNodeId = userStartNode.Id; } else if (definedStartNode.Path.Split(',').Contains(userStartNode.Id.ToString())) { //If User's start node id is found in the defined path, then the start node id //can (allowed) be the defined path. //This should always work for administrator (-1) determinedStartNodeId = definedStartNode.Id; } else if (userStartNode.Path.Split(',').Contains(definedStartNode.Id.ToString())) { //if the defined start node id is found in the user's path, then the start node id //can only be the user's, not the actual start determinedStartNodeId = userStartNode.Id; } else if (!definedStartNode.Path.Split(',').Contains(userStartNode.Id.ToString())) { //they should not have any access! determinedStartNodeId = NoAccessId; } return(determinedStartNodeId); }
public void RemoveTieredNodeWithMultipleChildrenTest() { IBaseTree tree = new BaseTree(); String root = "World"; String child = "US"; String child2 = "UK"; String child3 = "France"; String child4 = "Australia"; String childt2 = "Colorado"; String childt22 = "Utah"; String childt23 = "California"; tree.AddWord((string)null, root); tree.AddWord(root, child); tree.AddWord(root, child2); tree.AddWord(root, child3); tree.AddWord(root, child4); tree.AddWord(child, childt2); tree.AddWord(child, childt22); tree.AddWord(child, childt23); Assert.IsTrue(tree.Contains(root)); Assert.IsTrue(tree.Contains(child)); Assert.IsTrue(tree.Contains(child2)); Assert.IsTrue(tree.Contains(child3)); Assert.IsTrue(tree.Contains(child4)); Assert.IsTrue(tree.Contains(childt2)); Assert.IsTrue(tree.Contains(childt22)); Assert.IsTrue(tree.Contains(childt23)); tree.RemoveNode(tree.GetNode(root)); Assert.IsFalse(tree.Contains(root)); Assert.IsFalse(tree.Contains(child)); Assert.IsFalse(tree.Contains(child2)); Assert.IsFalse(tree.Contains(child3)); Assert.IsFalse(tree.Contains(child4)); Assert.IsFalse(tree.Contains(childt2)); Assert.IsFalse(tree.Contains(childt22)); Assert.IsFalse(tree.Contains(childt23)); }
private void AddSon <T>(Node node, List <T> treelist, bool checkbox) { BaseTree fau = (BaseTree)node.Tag; foreach (var au in treelist) { BaseTree baseTree = (BaseTree)(object)au; T t = (T)(object)au; if (baseTree.ParentID == fau.id) { Node snode = new Node(baseTree.TreeName) { Tag = t }; snode.CheckBoxVisible = checkbox; node.Nodes.Add(snode); AddSon(snode, treelist, checkbox); } } }
/// <summary> /// Returns the JSON markup for one node /// </summary> /// <param name="treeAlias"></param> /// <param name="nodeId"></param> /// <returns></returns> /// <remarks> /// This will initialize the control so all TreeService properties need to be set before hand /// </remarks> public string GetJSONNode(string nodeId) { if (!m_IsInit) { Initialize(); } if (string.IsNullOrEmpty(m_TreeService.TreeType)) { throw new ArgumentException("The TreeType is not set on the tree service"); } BaseTree tree = m_ActiveTrees.Find( delegate(BaseTree t) { return(t.TreeAlias == m_TreeService.TreeType); } ); return(tree.GetSerializedNodeData(nodeId)); }
public string objectItemTree() { //string itemcode = "01A00"; //int classid = 1; string itemcode = _ntsPage.Request["ItemCode"].ToString(); int classid = int.Parse(_ntsPage.Request["ClassId"].ToString()); string strCacheName = "object-tree" + itemcode + classid; var cacheTree = NTS.WEB.Common.CacheHelper.GetCache(strCacheName); if (cacheTree != null) { return cacheTree.ToString(); } // var res = Framework.Common.BaseWcf.CreateChannel<ServiceInterface.IObjectTree>("ObjectTree").GetObjectTree(); var res = new BaseTree(itemcode, classid, "").GetObjectTree(); NTS.WEB.Common.CacheHelper.SetCache(strCacheName, res.TreeJson); return res.TreeJson; }
/// <summary> /// Determines if it needs to render a null tree based on the start node id and returns true if it is the case. /// </summary> /// <param name="tree"></param> /// <param name="startNodeId"></param> /// <param name="rootNode"></param> /// <param name="app"></param> /// <returns></returns> internal static bool SetNullTreeRootNode(this BaseTree tree, int startNodeId, ref XmlTreeNode rootNode, string app) { if (startNodeId == NoAccessId) { rootNode = new NullTree(app).RootNode; rootNode.Text = "You do not have permission to view this tree"; rootNode.HasChildren = false; rootNode.Source = string.Empty; return(true); } if (startNodeId == NoChildNodesId) { rootNode = new NullTree(app).RootNode; rootNode.Text = "[No start node found]"; rootNode.HasChildren = false; rootNode.Source = string.Empty; return(true); } return(false); }
public override bool OnEnterTree(BaseTree baseTree) { EnvironmentParams envir = baseTree.EnvironmentParams; switch (SunshineType) { case SunshineType.High: envir.SunshineFactor = 1.5f; break; case SunshineType.Normal: envir.SunshineFactor = 1.0f; break; case SunshineType.Low: envir.SunshineFactor = 0.5f; break; } envir.SunshineType = SunshineType; ChangeDayUpdate(envir); return(true); }
private List <Node> GetNodes <T>(List <T> treelist, bool checkbox, int parentid = 0) { List <Node> treeNodes = new List <Node>(); foreach (var au in treelist) { BaseTree baseTree = (BaseTree)(object)au; T t = (T)(object)au; if (baseTree.ParentID == parentid) { Node node = new Node { Text = baseTree.TreeName, Tag = t }; node.CheckBoxVisible = checkbox; treeNodes.Add(node); AddSon(node, treelist, checkbox); } } return(treeNodes); }
public void RemoveNodeTest() { IBaseTree tree = new BaseTree(); String root = "World"; String child = "US"; tree.AddWord((string)null, root); tree.AddWord(root, child); Assert.IsTrue(tree.Contains(root)); Assert.IsTrue(tree.Contains(child)); tree.RemoveNode(tree.GetNode(child)); Assert.IsTrue(tree.Contains(root)); Assert.IsFalse(tree.Contains(child)); try { tree.GetNode(child); Assert.Fail(); } catch (KeyNotFoundException) { } }
//递归子类 private object GetChild <T>(List <T> treelist, int id, DelTreeAttr delTreeAttr) { List <WebTreeNode> wtnls = new List <WebTreeNode>(); foreach (var au in treelist) { BaseTree bt = (BaseTree)(object)au; if (bt.FatherID != id) { continue; } WebTreeNode wtn = new WebTreeNode { id = bt.Id, iconCls = bt.ImagePath, text = bt.NodeName, state = bt.State, children = GetChild(treelist, bt.Id, delTreeAttr), attributes = delTreeAttr(au) }; wtnls.Add(wtn); } return(wtnls); }
//初始化以easyui树的数据结构 public List <WebTreeNode> InitTreeNode <T>(List <T> treelist, DelTreeAttr delTreeAttr, int fid = 0) { List <WebTreeNode> webTreeNodes = new List <WebTreeNode>(); foreach (var tn in treelist) { BaseTree bt = (BaseTree)(object)tn; if (bt.FatherID != fid) { continue; } WebTreeNode wtn = new WebTreeNode { id = bt.Id, iconCls = bt.ImagePath, text = bt.NodeName, state = bt.State, children = GetChild(treelist, bt.Id, delTreeAttr), attributes = delTreeAttr(tn) }; webTreeNodes.Add(wtn); } return(webTreeNodes); }
public virtual bool OnEnterTreeInOtherExp(BaseTree baseTree) { return(false); }
public void RemoveNonexistentNode() { IBaseTree tree = new BaseTree(); tree.RemoveNode(new Node("hi")); }
/** * @deprecated use #setChildWithTokens(int,LinkedListTree), damnit */ public void setChild(int index, BaseTree child) { base.SetChild(index, child); ((LinkedListTree)child).Parent = this; }
public IBaseTree BuildTreeGoodMatches() { //change the .1? var orderedByIDF = WordDocumentAppearances.Where(x => x.Value.IDF > .2).OrderBy(x => x.Value.IDF).ToList(); //int b = 0; //var orderedByIDF = WordDocumentAppearances.Where(x => !Int32.TryParse(x.Key, out b)).OrderByDescending(x => x.Value.IDF).Take((int)(WordDocumentAppearances.Count * .7)).ToList(); IBaseTree tree = new BaseTree(); tree.AddWord((string)null, "the"); orderedByIDF = orderedByIDF.OrderBy(x => x.Value.IDF).ToList(); //Make the cutoff greater than 0, so not quite all words are added? - taken care of above? while (orderedByIDF.Count > 0) { //decide next word to add string word = orderedByIDF.First().Key; Console.WriteLine("Adding word '" + word + "' to tree"); //find lowest branch in which all significant occurences of the word/document happen int numDif = Int32.MaxValue; Node parent = null; foreach (Node n in tree) //for every branch in the tree //Console.WriteLine("Checking branch"); //first check to make sure it is completely contained { bool contained = true; foreach (var element in WordDocumentAppearances[word].Docs) { //TODO: Make this check to make sure appearances are significant if (!WordDocumentAppearances[n.KeyWord].Docs.Contains(element) && PossibleContent[new KeyValuePair <string, Document>(word, new Document() { Name = element })].Frequency > 1) { contained = false; break; } } //if it is, if (contained) { //Console.WriteLine("Determining fit"); int numDifTemp = 0; foreach (string s2 in WordDocumentAppearances[n.KeyWord].Docs) //for each document the branch's word appears in { if ((!WordDocumentAppearances[word].Docs.Contains(s2) && PossibleContent[new KeyValuePair <string, Document>(n.KeyWord, new Document() { Name = s2 })].Frequency > 1)) // if this word doesn't appear in a document which the other does { numDifTemp++; } } //if the number of different branches is less than the last node's, if (numDifTemp < numDif) { Console.WriteLine("New parent: " + n.KeyWord); //make this the new parent of the new word numDif = numDifTemp; parent = n; } } } if (parent != null) { Console.WriteLine("Adding " + word + " to tree"); //add to that branch tree.AddNode(parent, new Node(word)); } orderedByIDF.Remove(orderedByIDF.First()); Console.WriteLine("Remaining words: " + orderedByIDF.Count); } return(tree); }
public void RemoveNullTest() { IBaseTree tree = new BaseTree(); tree.RemoveNode(null); }
public void GetNonexistentNodeTest() { IBaseTree tree = new BaseTree(); tree.GetNode("Anything"); }
public void AddNodeToNonexistentParentNodeTest() { IBaseTree tree = new BaseTree(); tree.AddWord(new Node("World"), "US"); }
public abstract bool OnEnterTree(BaseTree baseTree);
public string ObjectTree() { var cacheTree = NTS.WEB.Common.CacheHelper.GetCache("object-tree"); if (cacheTree != null) { return cacheTree.ToString(); } // var res = Framework.Common.BaseWcf.CreateChannel<ServiceInterface.IObjectTree>("ObjectTree").GetObjectTree(); var res = new BaseTree().GetObjectTree(); NTS.WEB.Common.CacheHelper.SetCache("object-tree", res.TreeJson); return res.TreeJson; }
internal void FillData() { string sql; RunSQLiteCommandLine(ConnectionInformation.FileName, ".schema", out sql); try { var ast = GetAST(sql); #region TABLES var tableScripts = ast.Children.Where(c => c.Text == "CREATE_TABLE").ToList(); if (tableScripts.Count == 0 && ast.Text == "CREATE_TABLE") { tableScripts.Add(ast); } foreach (var t in tableScripts) { var tableName = ((BaseTree)t).Children[1].Text.Trim('[', ']', '"'); // Get the columns var colDefs = ((BaseTree)((BaseTree)t).Children.Single(c => c.Text == "COLUMNS")).Children; for (int i = 0; i < colDefs.Count; i++) { var c = colDefs[i]; var colName = c.Text.Trim('[', ']'); var ordinalPos = i; var col = (BaseTree)c; var typeNode = (BaseTree)col.Children.Single(x => x.Text == "TYPE"); var colType = typeNode.Children[1].Text; var typeParamNode = typeNode.Children[0]; int charMaxLength = 0; string defaultValue = ""; // TODO if (((BaseTree)typeParamNode).Children != null) { charMaxLength = int.Parse(((BaseTree)typeParamNode).Children[0].Text); } var colConstraints = ((BaseTree)col.Children.Single(x => x.Text == "CONSTRAINTS")).Children; bool isPrimaryKey = false; bool isNullable = true; bool isIdentity = false; int numericPrecision = 0; // TODO int numericScale = 0; // TODO if (colConstraints != null) { foreach (var constraint in colConstraints) { if (((BaseTree)constraint).Children.Count(x => x.Text.ToUpper() == "PRIMARY") == 1) { isPrimaryKey = true; } else if (((BaseTree)constraint).Children.Count(x => x.Text == "NOT_NULL") == 1) { isNullable = false; } else if (((BaseTree)constraint).Children.Count(x => x.Text == "AUTOINCREMENT") == 1) { isIdentity = true; } } } AddColumn(isPrimaryKey, tableName, "", colName, ordinalPos, isNullable, colType, charMaxLength, defaultValue, isIdentity, false, numericPrecision, numericScale); if (isPrimaryKey) { AddIndex(tableName, "", colName, string.Format("PK_{0}", tableName), "PRIMARY KEY", colType, true, true); } } // Get the constraints if (((BaseTree)t).Children.Count(constraint => constraint.Text == "CONSTRAINTS") == 1) { var constraints = ((BaseTree)((BaseTree)t).Children.Single(constraint => constraint.Text == "CONSTRAINTS")).Children; for (int constraintCounter = 0; constraintCounter < constraints.Count; constraintCounter++) { var constraint = (BaseTree)(BaseTree)constraints[constraintCounter]; var constraintType = constraint.Children[0].Text.Trim('[', ']'); var constraintName = constraint.Children[1].Text.Trim('[', ']'); if (constraintType == "PRIMARY") { constraintType = "PRIMARY KEY"; } if (constraintType == "FOREIGN") { constraintType = "FOREIGN KEY"; } if (constraintType != "CHECK") { // Get the columns var con = (BaseTree)constraint.Children[0]; int counter = 0; foreach (var constraintColumn in ((BaseTree)con.Children.Single(constraintCol => constraintCol.Text == "COLUMNS")).Children) { var constraintColumnName = constraintColumn.Text.Trim('[', ']'); bool isUnique = constraintType == "PRIMARY KEY" || constraintType == "UNIQUE"; AddIndex(tableName, "", constraintColumnName, constraintName, constraintType, "", false, isUnique); if (constraintType == "FOREIGN KEY") { AddForeignKeyColumn(constraintName, constraintColumnName, counter, tableName); //AddForeignKeyConstraint() } counter++; } } } } } #endregion #region Indexes foreach (var t in ast.Children.Where(c => c.Text == "CREATE_INDEX")) { BaseTree node = (BaseTree)t; string indexName = node.Children[1].Text.Trim('[', ']'); string tableName = node.Children[2].Text.Trim('[', ']'); string tableSchema = ""; bool isUnique = ((BaseTree)node.Children[0]).Children != null && ((BaseTree)node.Children[0]).Children.Count(x => x.Text == "UNIQUE") == 1; string constraintType = isUnique ? "UNIQUE" : "NONE"; string dataType = ""; bool isClustered = false; // Get the columns var colDefs = ((BaseTree)((BaseTree)t).Children.Single(c => c.Text == "COLUMNS")).Children; for (int i = 0; i < colDefs.Count; i++) { string columnName = colDefs[i].Text.Trim('[', ']'); AddIndex(tableName, tableSchema, columnName, indexName, constraintType, dataType, isClustered, isUnique); } } #endregion #region Foreign Key constraints foreach (var t in ast.Children.Where(c => c.Text == "CREATE_TABLE")) { var tableName = ((BaseTree)t).Children[1].Text.Trim('[', ']'); if (((BaseTree)t).Children.Count(constraint => constraint.Text == "CONSTRAINTS") == 1) { var constraints = ((BaseTree)((BaseTree)t).Children.Single(constraint => constraint.Text == "CONSTRAINTS")).Children; for (int constraintCounter = 0; constraintCounter < constraints.Count; constraintCounter++) { var constraint = (BaseTree)(BaseTree)constraints[constraintCounter]; var constraintType = constraint.Children[0].Text.Trim('[', ']'); var constraintName = constraint.Children[1].Text.Trim('[', ']'); if (constraintType != "FOREIGN") { continue; } constraintType = "FOREIGN KEY"; var con = (BaseTree)constraint.Children[0]; var reference = (BaseTree)con.Children.SingleOrDefault(constraintCol => constraintCol.Text == "REFERENCES"); if (reference != null) { string refTableName = reference.Children[0].Text.Trim('[', ']'); // Get the name of the primary key on the primary table DataRow[] keyRows = Indexes.Select(string.Format("TABLE_NAME = '{0}' AND TABLE_SCHEMA = '{1}' AND CONSTRAINT_TYPE = 'PRIMARY KEY'", refTableName, "")); string primaryKeyName = keyRows[0]["INDEX_NAME"].ToString(); AddForeignKeyConstraint(primaryKeyName, refTableName, "", constraintName, tableName, ""); } } } } #endregion } catch (Exception e) { throw new Exception(e.Message + Environment.NewLine + "STACKTRACE:" + e.StackTrace + Environment.NewLine + "SQL: " + sql, e); } }