private void VerifyCloningEquivalence(ILazinator lazinator, IncludeChildrenMode includeChildrenMode) { var clonedWithBuffer = lazinator.CloneLazinator(includeChildrenMode, CloneBufferOptions.IndependentBuffers); var clonedNoBuffer = lazinator.CloneLazinator(includeChildrenMode, CloneBufferOptions.NoBuffer); string clonedWithBufferString = new HierarchyTree(clonedWithBuffer).ToString(); string clonedNoBufferString = new HierarchyTree(clonedNoBuffer).ToString(); try { LazinatorUtilities.ConfirmHierarchiesEqual(clonedWithBuffer, clonedNoBuffer); } catch (Exception ex) { int i = 0; if (clonedNoBuffer.IsStruct) { clonedNoBuffer = clonedNoBuffer.CloneLazinator(); } for (; i < Math.Min(clonedWithBuffer.LazinatorMemoryStorage.Length, clonedNoBuffer.LazinatorMemoryStorage.Length); i++) { if (clonedWithBuffer.LazinatorMemoryStorage.OnlyMemory.Span[i] != clonedNoBuffer.LazinatorMemoryStorage.OnlyMemory.Span[i]) { break; } } throw new Exception("Verify cloning failed at position " + i + ". See inner exception.", ex); } }
/// <summary>Initializes a new instance of the <see cref="MarkdownReport"/> class.</summary> /// <param name="assemblyPropertiesInfo">The assembly properties information.</param> /// <param name="hierarchy">The assembly hierarchy.</param> /// <param name="reportSettings">The report settings.</param> public MarkdownReport(AssemblyPropertiesInfo assemblyPropertiesInfo, HierarchyTree hierarchy, ReportSettings reportSettings) : base(Path.GetFileNameWithoutExtension(assemblyPropertiesInfo.Location), assemblyPropertiesInfo.AssemblyDirectory.FullName) { // Initialize variables AssemblyPropertiesInfo = assemblyPropertiesInfo; HierarchyTree = hierarchy; ReportSettings = reportSettings; }
private async void buttonHistory_ClickAsync(object sender, EventArgs e) { HttpResponseMessage response; if (_history.Count > 0) { response = await _client.PostAsJsonAsync("api/tree/getpath", _history.Pop().ToString()); } else { response = await _client.GetAsync("api/tree/getroot"); } if (response.IsSuccessStatusCode) { _tree = await response.Content.ReadAsAsync <HierarchyTree>(); } if (_tree != null) { treeView.Nodes.Clear(); treeView.Nodes.AddRange(_tree.Directories .Select(x => new TreeNode() { Text = x }) .ToArray()); treeView.Nodes.AddRange(_tree.Files .Select(x => new TreeNode() { Text = x }) .ToArray()); labelPath.Text = _path; } }
private async void treeView_NodeMouseDoubleClickAsync(object sender, TreeNodeMouseClickEventArgs e) { var response = await _client.PostAsJsonAsync("api/tree/getpath", e.Node.Text); if (response.IsSuccessStatusCode) { _tree = await response.Content.ReadAsAsync <HierarchyTree>(); } if (_tree != null) { treeView.Nodes.Clear(); treeView.Nodes.AddRange(_tree.Directories .Select(x => new TreeNode() { Text = x }) .ToArray()); treeView.Nodes.AddRange(_tree.Files .Select(x => new TreeNode() { Text = x }) .ToArray()); if (_path != null) { _history.Push(_path); } _path = e.Node.Text; labelPath.Text = _path; } }
public void CreateTest() { HierarchyTree tree = new HierarchyTree(); tree.GetOrCreateNode(new string[] { "数学" }); tree.GetOrCreateNode(new string[] { "数学", "一年级" }); HierarchyTreeNode node = tree.GetOrCreateNode(new string[] { "数学", "一年级", "上册" }); tree.GetOrCreateNode(new string[] { "物理", "一年级" }); Assert.IsTrue(tree.root.children.Count == 2); HierarchyTreeNode[] arr = tree.root.GetAllChild(); Assert.IsTrue(arr.Length == 5); Assert.IsNotNull(tree.GetNode(new string[] { "数学", "一年级", "上册" })); HierarchyTreeNode node1 = tree.GetNode(new string[] { "数学", "一年级", "上册" }); Assert.IsTrue(node1.IsValid()); Assert.IsTrue(node1.Path.Length == 3); Assert.IsNotNull(tree.GetNode(new string[] { "数学", "一年级" })); tree.GetNode(new string[] { "数学", "一年级" }).IsValid(); Assert.IsNull(tree.GetNode(new string[] { "数学123", "一年级" })); //移除一个节点 tree.RemoveNode(new string[] { "数学", "一年级", "上册" }); Assert.IsNull(tree.GetNode(new string[] { "数学", "一年级", "上册" })); Assert.IsFalse(node1.IsValid()); }
/// <summary>Initializes a new instance of the <see cref="AssemblyAnalyzer"/> class.</summary> /// <param name="assemblyPath">The assembly file path.</param> public AssemblyAnalyzer(string assemblyPath) : this() { // Validate the assembly path if (string.IsNullOrEmpty(assemblyPath)) { throw new ArgumentNullException(nameof(assemblyPath), @"The file name cannot be null or empty."); } if (!File.Exists(assemblyPath)) { throw new FileNotFoundException(@"The assembly file name cannot be found!", assemblyPath); } if (!AsmUtil.IsAssembly(assemblyPath)) { throw new ArgumentNullException(nameof(assemblyPath), @"The file name is not an assembly file (*.DLL;*.EXE)."); } // Initialize Location = assemblyPath; AssemblyPropertiesInfo = new AssemblyPropertiesInfo(assemblyPath); HierarchyTree = new HierarchyTree(assemblyPath); AssemblyReport = new MarkdownReport(AssemblyPropertiesInfo, HierarchyTree, Settings); Settings = new ReportSettings(AssemblyPropertiesInfo, HierarchyTree); }
/// <summary>Initializes a new instance of the <see cref="AssemblyAnalyzer"/> class.</summary> public AssemblyAnalyzer() { AssemblyPropertiesInfo = new AssemblyPropertiesInfo(); HierarchyTree = new HierarchyTree(); Location = string.Empty; Settings = new ReportSettings(); }
public App() { InitializeComponent(); AlignHorizontalSplits(); SetColors(); HierarchyTree = new HierarchyTree(trvHierarchy, cmsHierarchy); }
public void HierarchyTreeWorks_TwoLevel() { var hierarchy = GetTypicalExample(); HierarchyTree tree = new HierarchyTree(hierarchy); string result = tree.ToString(); result.Should().Be(twoLevelExpected); }
public async ValueTask HierarchyTreeWorksAsync_TwoLevel() { var hierarchy = GetTypicalExample(); HierarchyTree tree = await HierarchyTree.ConstructAsync(hierarchy); string result = tree.ToString(); result.Should().Be(twoLevelExpected); }
public HierarchyTree GetTree() { DirectoryInfo directoryInfo = new DirectoryInfo(root); var tree = new HierarchyTree(); tree.Files.AddRange(directoryInfo.GetFiles().Select(x => x.FullName)); tree.Directories.AddRange(directoryInfo.GetDirectories().Select(x => x.FullName)); return(tree); }
protected void bindtreeviewMaping() { try { this.TreeView2.Nodes.Clear(); HierarchyTree hierarchy = new HierarchyTree(); HierarchyTree.HGroup objhtree = null; string selgroup = "select distinct ITGroupPK,GroupName,ParentCode from IT_GroupMaster where CollegeCode='" + ddlcolload.SelectedItem.Value + "'"; ds.Clear(); ds = d2.select_method_wo_parameter(selgroup, "Text"); this.TreeView2.Nodes.Clear(); hierarchy.Clear(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { objhtree = new HierarchyTree.HGroup(); objhtree.group_code = int.Parse(ds.Tables[0].Rows[i]["ITGroupPK"].ToString()); objhtree.parent_code = int.Parse(ds.Tables[0].Rows[i]["ParentCode"].ToString()); objhtree.group_name = ds.Tables[0].Rows[i]["GroupName"].ToString(); hierarchy.Add(objhtree); } foreach (HierarchyTree.HGroup hTree in hierarchy) { HierarchyTree.HGroup parentNode = hierarchy.Find(delegate(HierarchyTree.HGroup emp) { return(emp.group_code == hTree.parent_code); }); if (parentNode != null) { foreach (TreeNode tn in TreeView2.Nodes) { if (tn.Value == parentNode.group_code.ToString()) { tn.ChildNodes.Add(new TreeNode(hTree.group_name.ToString(), hTree.group_code.ToString())); } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { RecursiveChild(ctn, parentNode.group_code.ToString(), hTree); } } } } else { TreeView2.Nodes.Add(new TreeNode(hTree.group_name, hTree.group_code.ToString())); } TreeView2.ExpandAll(); //TreeView2.ExpandAll(); } } catch { } }
public void HierarchyTreeWorks_Larger() { var hierarchy = GetHierarchy(0, 1, 2, 0, 0); hierarchy.MyChild1.MyWrapperContainer = new WrapperContainer() { WrappedInt = 17 }; HierarchyTree tree = new HierarchyTree(hierarchy); string result = tree.ToString(); string expected = $@"LazinatorTests.Examples.Example MyNullableDouble: 3.5 MyBool: True MyChar: b MyDateTime: 1/1/2000 12:00:00 AM MyNewString: NULL MyNullableDecimal: -2341.5212352 MyNullableTimeSpan: 03:00:00 MyOldString: NULL MyString: this is a very long way of saying hello, world MyStringUncompressed: this is a very long way of saying hello, world MyTestEnum: MyTestValue2 MyTestEnumByteNullable: NULL MyUInt: 2342343242 MyNonLazinatorChild: NULL IncludableChild: NULL MyChild1: LazinatorTests.Examples.ExampleChild MyLong: 123123 MyShort: 543 ByteSpan: System.ReadOnlyMemory<Byte>[0] MyExampleGrandchild: LazinatorTests.Examples.ExampleGrandchild AString: hello MyInt: 123 MyWrapperContainer: LazinatorTests.Examples.Structs.WrapperContainer WrappedInt: 17 WrappedValue: 17 MyChild2: LazinatorTests.Examples.ExampleChild MyLong: 999888 MyShort: -23 ByteSpan: System.ReadOnlyMemory<Byte>[0] MyExampleGrandchild: LazinatorTests.Examples.ExampleGrandchild AString: x MyInt: 3456345 MyWrapperContainer: NULL MyChild2Previous: NULL MyInterfaceImplementer: NULL WrappedInt: 5 WrappedValue: 5 ExcludableChild: NULL "; result.Should().Be(expected); }
public Boolean OnlyUnCheckHierarchyNode(string[] hierarchyNames) { try { HierarchyTree.ExpandNodePath(hierarchyNames); HierarchyTree.UncheckNode(hierarchyNames.Last()); return(true); } catch (Exception) { return(false); } }
public HierarchyTree GetTree(string path) { DirectoryInfo directoryInfo = new DirectoryInfo(path); var tree = new HierarchyTree(); if (string.IsNullOrEmpty(directoryInfo.Extension)) { tree.Files.AddRange(directoryInfo.GetFiles().Select(x => x.FullName)); tree.Directories.AddRange(directoryInfo.GetDirectories().Select(x => x.FullName)); return(tree); } return(null); }
public Boolean UnCheckHierarchyNode(string[] hierarchyNames) { try { SelectHierarchyButton.Click(); TimeManager.ShortPause(); HierarchyTree.ExpandNodePath(hierarchyNames); HierarchyTree.CheckNode(hierarchyNames.Last()); return(true); } catch (Exception) { return(false); } }
public async Task <IActionResult> Update([FromBody] HierarchyTree item, int id) { if (item == null) { return(this.BadRequest()); } var updated = await this.hierarchyServices.UpdateHierarchyTreeAsync(item, id); if (!updated) { return(this.NotFound()); } return(new NoContentResult()); }
private void SetParentNodes( HierarchyTree newStructure, HierarchyTree originalStructure, IReadOnlyCollection <HierarchyTreeNode> originalNodes) { if (newStructure.ChildNodes == null) { return; } foreach (var newNode in newStructure.ChildNodes) { newNode.ParentNode = null; newNode.ParentTree = originalStructure; this.SetParentNodeForNode(newNode, originalNodes); } }
/// <summary>Analyze the Assembly.</summary> /// <param name="assemblyPath">The assembly to analyze.</param> public void Analyze(string assemblyPath) { try { // Update the assembly path to analyze start scanning Location = assemblyPath; AssemblyPropertiesInfo = new AssemblyPropertiesInfo(assemblyPath); HierarchyTree = new HierarchyTree(assemblyPath); AssemblyReport = new MarkdownReport(AssemblyPropertiesInfo, HierarchyTree, Settings); Settings = new ReportSettings(AssemblyPropertiesInfo, HierarchyTree); // Generate a new assembly report. AssemblyReport.GenerateReport(AssemblyPropertiesInfo, HierarchyTree, Settings); } catch (Exception e) { Console.WriteLine(e); } }
public async Task <IActionResult> Create([FromBody] HierarchyTree item) { if (item == null) { return(this.BadRequest()); } if (item.ChildNodes != null) { foreach (var node in item.ChildNodes) { this.SetNodeRecursively(node); } } await this.unitOfWork.HierarchyTreeRepository.AddAsync(item); await this.unitOfWork.SaveAsync(); return(this.CreatedAtRoute("GetStructure", new { id = item.Id }, item)); }
private async void InitAsync() { var response = await _client.GetAsync("api/tree/getroot"); if (response.IsSuccessStatusCode) { _tree = await response.Content.ReadAsAsync <HierarchyTree>(); } treeView.Nodes.AddRange(_tree.Directories .Select(x => new TreeNode() { Text = x }) .ToArray()); treeView.Nodes.AddRange(_tree.Files .Select(x => new TreeNode() { Text = x }) .ToArray()); }
public void OnlyCheckHierarchyNode(string[] hierarchyNames) { HierarchyTree.ExpandNodePath(hierarchyNames); TimeManager.ShortPause(); HierarchyTree.CheckNode(hierarchyNames.Last()); }
public Hierarchy(ExtendedForm parentForm) : base(parentForm) { InitializeComponent(); HierarchyTree.DoubleBuffered(true); StartSearch(); }
/* * public void SelectCommodityCarbon(string commodityName) * { * CommodityRank.CheckRowCheckbox(2, commodityName, false); * JazzMessageBox.LoadingMask.WaitSubMaskLoading(); * } * * public void SelectCommodityCost(string commodityName) * { * CommodityRankCost.CheckRowCheckbox(2, commodityName, false); * JazzMessageBox.LoadingMask.WaitSubMaskLoading(); * } */ #endregion #region ranking panel public Boolean IsHierarchyNodeChecked(string hierarchyNode) { return(HierarchyTree.IsNodeChecked(hierarchyNode)); }
/// <summary>Generates the report.</summary> /// <param name="assemblyPropertiesInfo">The assembly properties information.</param> /// <param name="hierarchy">The hierarchy.</param> /// <param name="reportSettings">The report settings.</param> public void GenerateReport(AssemblyPropertiesInfo assemblyPropertiesInfo, HierarchyTree hierarchy, ReportSettings reportSettings) { AssemblyPropertiesInfo = assemblyPropertiesInfo; HierarchyTree = hierarchy; ReportSettings = reportSettings; // Begin the generation process for the report. StringBuilder reportBuilder = new StringBuilder(); // Header reportBuilder.AppendLine(MarkdownElement.CreateComment(@"Initialize Document Variables")); reportBuilder.AppendLine(); // Generate Top link reportBuilder.AppendLine(HtmlUtil.GenerateBackToTop()[0]); reportBuilder.AppendLine(); // Loop thru each member info type and register the commonly used variables for the markdown document. //foreach (MarkdownTypeId reference in GetCategoryTypes(ReportSettings)) //{ // Create a comment to separate the categories. //reportBuilder.AppendLine(MarkdownElement.CreateComment($@"ID: {reference.ID} Variables")); // Create the image source reference variables. //string imageTypeSource = reference.ImageTypeSource; //reportBuilder.AppendLine(imageTypeSource); //} // Create visual document content reportBuilder.AppendLine(HtmlUtil.GenerateHTMLTextCode(HorizontalAlign.Center, @"Assembly Report", "h2")); // Render assembly report information string italicAssemblyLocation = MarkdownEmphasis.CreateEmphasis(AssemblyPropertiesInfo.FileName, MarkdownEmphasis.EmphasisType.Italic); reportBuilder.AppendLine(MarkdownHeader.CreateHeader(@"Assembly: " + italicAssemblyLocation, 6)); string italicAssemblyExportedTypes = MarkdownEmphasis.CreateEmphasis(Convert.ToString(ReportSettings.ExportedTypes), MarkdownEmphasis.EmphasisType.Italic); reportBuilder.AppendLine(MarkdownHeader.CreateHeader(@"Exported Types: " + italicAssemblyExportedTypes, 6)); string italicAssemblyMissingDocumentation = MarkdownEmphasis.CreateEmphasis(Convert.ToString(ReportSettings.MissingDocumentation.Count), MarkdownEmphasis.EmphasisType.Italic); reportBuilder.AppendLine(MarkdownHeader.CreateHeader(@"Missing Documentation: " + italicAssemblyMissingDocumentation, 6)); string italicTimestampGenerated = MarkdownEmphasis.CreateEmphasis(DateTime.Now.ToLongDateString() + " - " + DateTime.Now.ToLongTimeString(), MarkdownEmphasis.EmphasisType.Italic); reportBuilder.AppendLine(MarkdownHeader.CreateHeader(@"Generated: " + italicTimestampGenerated, 6)); // Draw splitter reportBuilder.AppendLine(); reportBuilder.AppendLine(DocumentSeparator); reportBuilder.AppendLine(); // Generate architecture sections and their images. if (HierarchyTree.Classes.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Class, "Classes", "Class", reportSettings, HierarchyTree.Classes)); } if (HierarchyTree.Delegates.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Delegate, "Delegates", "Delegate", reportSettings, HierarchyTree.Delegates)); } if (HierarchyTree.Enumerators.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Enumerator, "Enumerators", "Enumerator", reportSettings, HierarchyTree.Enumerators)); } if (HierarchyTree.Events.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Event, "Events", "Event", reportSettings, HierarchyTree.Events)); } if (HierarchyTree.Interfaces.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Interface, "Interfaces", "Interface", reportSettings, HierarchyTree.Interfaces)); } if (HierarchyTree.Structures.Count > 0) { reportBuilder.AppendLine(GenerateSection(MemberInfoTypes.Structure, "Structures", "Structure", reportSettings, HierarchyTree.Structures)); } reportBuilder.AppendLine(DocumentSeparator); reportBuilder.AppendLine(); reportBuilder.Append(HtmlUtil.GenerateBackToTop()[1]); Contents = reportBuilder.ToString(); }
protected void bindtreeview() { try { string dt_groupcode = ""; string dt_parentcode = ""; if (collegecode != "") { this.TreeView1.Nodes.Clear(); HierarchyTree hierarchy = new HierarchyTree(); HierarchyTree.HGroup objhtree = null; string selgroup = "select distinct FinGroupPK,GroupName,ParentCode from FM_FinGroupMaster where CollegeCode='" + ddlcolload.SelectedItem.Value + "'"; ds.Clear(); ds = d2.select_method_wo_parameter(selgroup, "Text"); this.TreeView1.Nodes.Clear(); hierarchy.Clear(); for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { objhtree = new HierarchyTree.HGroup(); objhtree.group_code = int.Parse(ds.Tables[0].Rows[i]["FinGroupPK"].ToString()); objhtree.parent_code = int.Parse(ds.Tables[0].Rows[i]["ParentCode"].ToString()); objhtree.group_name = ds.Tables[0].Rows[i]["GroupName"].ToString(); hierarchy.Add(objhtree); } if (ds.Tables[0].Rows.Count > 0) { string get_topic_no = ""; string get_topic_no1 = ""; string get_topic_no2 = ""; for (int dt_row_cnt = 0; dt_row_cnt < ds.Tables[0].Rows.Count; dt_row_cnt++) { dt_groupcode = ds.Tables[0].Rows[dt_row_cnt][0].ToString(); string[] split_topics2 = dt_groupcode.Split('/'); for (int i = 0; split_topics2.GetUpperBound(0) >= i; i++) { if (get_topic_no == "") { get_topic_no = "'" + split_topics2[i] + "'"; } else { get_topic_no = get_topic_no + ',' + "'" + split_topics2[i] + "'"; } } } if (ds.Tables[0].Rows.Count > 0) { for (int dt_dailyentdet1_row_cnt = 0; dt_dailyentdet1_row_cnt < ds.Tables[0].Rows.Count; dt_dailyentdet1_row_cnt++) { dt_parentcode = ds.Tables[0].Rows[dt_dailyentdet1_row_cnt][1].ToString(); string[] split_topics3 = dt_parentcode.Split('/'); for (int i = 0; split_topics3.GetUpperBound(0) >= i; i++) { if (get_topic_no1 == "") { get_topic_no1 = "'" + split_topics3[i] + "'"; } else { get_topic_no1 = get_topic_no1 + ',' + "'" + split_topics3[i] + "'"; } } } } if (get_topic_no1 != "") { get_topic_no2 = get_topic_no + "," + get_topic_no1; } else { get_topic_no2 = get_topic_no; } selgroup = "select FinGroupPK,ParentCode,GroupName from FM_FinGroupMaster where convert(varchar,FinGroupPK) in(" + get_topic_no2 + ") and CollegeCode='" + ddlcolload.SelectedItem.Value + "' order by ParentCode,FinGroupPK"; DataSet dsloadtopic = d2.select_method_wo_parameter(selgroup, "Text"); if (dsloadtopic.Tables[0].Rows.Count > 0) { hierarchy.Clear(); for (int at = 0; at < dsloadtopic.Tables[0].Rows.Count; at++) { string sqlquery = "select isnull(count(*),0) as ischild from FM_FinGroupMaster where ParentCode=" + dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString() + " and CollegeCode='" + ddlcolload.SelectedItem.Value + "'"; string ischild = d2.GetFunction(sqlquery); string sqlquery1 = "select isnull(count(*),0) as isavailable from FM_FinGroupMaster where convert(varchar,FinGroupPK) in(" + get_topic_no2 + ") and ParentCode=" + dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString() + " and CollegeCode='" + ddlcolload.SelectedItem.Value + "'"; string isavailable = d2.GetFunction(sqlquery1); if (Convert.ToInt16(ischild) == 0) { objhtree = new HierarchyTree.HGroup(); objhtree.group_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString()); objhtree.parent_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["ParentCode"].ToString()); objhtree.group_name = dsloadtopic.Tables[0].Rows[at]["GroupName"].ToString(); hierarchy.Add(objhtree); } else if (Convert.ToInt16(ischild) > 0 && Convert.ToInt16(isavailable) > 0) { objhtree = new HierarchyTree.HGroup(); objhtree.group_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["FinGroupPK"].ToString()); objhtree.parent_code = int.Parse(dsloadtopic.Tables[0].Rows[at]["ParentCode"].ToString()); objhtree.group_name = dsloadtopic.Tables[0].Rows[at]["GroupName"].ToString(); hierarchy.Add(objhtree); } } } panel3.Visible = true; } foreach (HierarchyTree.HGroup hTree in hierarchy) { HierarchyTree.HGroup parentNode = hierarchy.Find(delegate(HierarchyTree.HGroup emp) { return(emp.group_code == hTree.parent_code); }); if (parentNode != null) { foreach (TreeNode tn in TreeView1.Nodes) { if (tn.Value == parentNode.group_code.ToString()) { tn.ChildNodes.Add(new TreeNode(hTree.group_name.ToString(), hTree.group_code.ToString())); } if (tn.ChildNodes.Count > 0) { foreach (TreeNode ctn in tn.ChildNodes) { RecursiveChild(ctn, parentNode.group_code.ToString(), hTree); } } } } else { TreeView1.Nodes.Add(new TreeNode(hTree.group_name, hTree.group_code.ToString())); } TreeView1.ExpandAll(); } //if (TreeView1.Nodes.Count < 1) //{ // //BtnNewTree.Enabled = false; //} //else //{ // //BtnNewTree.Enabled = true; //} } } catch { } }
public async Task <bool> UpdateHierarchyTreeAsync(HierarchyTree item, int id) { var hierarchy = await this.unitOfWork.HierarchyTreeRepository.GetSingleAsync(id, s => s.ChildNodes); if (hierarchy == null) { return(false); } foreach (var hierarchyStructureNode in hierarchy.ChildNodes) { await this.LoadRecursively(hierarchyStructureNode); } hierarchy.Name = item.Name; hierarchy.Description = item.Description; hierarchy.TimeId = item.TimeId; hierarchy.StartDate = item.StartDate; hierarchy.FinalDate = item.FinalDate; hierarchy.ActiveStatus = item.ActiveStatus; var originalNodes = this.GetPlainNodeList(hierarchy.ChildNodes); this.SetParentNodes(item, hierarchy, originalNodes); var modifiedNodes = this.GetPlainNodeList(item.ChildNodes); var deleted = originalNodes.Where(p => modifiedNodes.All(p2 => p2.Id != p.Id)); var newNodes = modifiedNodes.Where(n => n.Id <= 0); foreach (var newNode in newNodes) { newNode.ChildNodes = null; await this.unitOfWork.HierarchyTreeNodeRepository.AddAsync(newNode); } foreach (var originalNode in originalNodes) { var updated = modifiedNodes.FirstOrDefault(n => n.Id == originalNode.Id); if (updated != null && !updated.Equals(originalNode)) { originalNode.Name = updated.Name; if (updated.ParentNodeId == 0) { originalNode.ParentNode = updated.ParentNode; originalNode.ParentNodeId = null; } else if (originalNode.ParentNodeId != updated.ParentNodeId) { originalNode.ParentNode = null; originalNode.ParentNodeId = updated.ParentNodeId; } originalNode.Revisor = updated.Revisor; originalNode.ParentTree = updated.ParentTree != null ? hierarchy : null; this.unitOfWork.HierarchyTreeNodeRepository.Edit(originalNode); } } foreach (var deletedNode in deleted) { this.unitOfWork.HierarchyTreeNodeRepository.Delete(deletedNode); } this.unitOfWork.HierarchyTreeRepository.Edit(hierarchy); await this.unitOfWork.SaveAsync(); return(true); }