public void Convert_CopyAttribute_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CopyTreeAttributeRegistrations>(); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree() { TreeName = "TreeName", }; var targetTree = new TargetTree() { MasterDataId = Guid.NewGuid(), }; // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert targetTree.TreeName.Should().Be(sourceTree.TreeName); targetTree.TemporalDataOriginId.Should().Be(targetTree.MasterDataId); }
void ddsAuthorityTree_LoadedData(object sender, LoadedDataEventArgs geted) { this.IsBusy = false; if (geted.HasError) { MessageErp.ErrorMessage(geted.Error.Message.GetErrMsg()); geted.MarkErrorAsHandled(); this.SourceTree.Clear(); return; } var items2 = geted.Entities; foreach (V_S_Function y in items2) { foreach (V_S_Function itenm in SourceTree.SelectMany(item => GetItems(item))) { if (itenm.FunCode.ToUpper() == y.FunCode.ToUpper()) { itenm.IsSelected = true; break; } } } }
public void Convert_CreateToMany_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToManyGenericRegistrations>(); container.Bind <IConvertRegistrations <SourceTreeLeaf, TargetTreeLeaf, IForTest> >().To <CopyLeafAttributeRegistrations>(); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree(); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); var targetTree = new TargetTree(); // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert sourceTree.Leafs.Count.Should().Be(targetTree.TargetLeafs.Count); }
public void Convert_RegisterCreateToManyWithRelation_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToManyWithRelationRegistrations>(); container.Bind <IConvertRegistrations <SourceTreeLeaf, TargetTreeLeaf, IForTest> >().To <CopyLeafAttributeRegistrations>(); container.Bind(typeof(ICreateTargetImplConvertTargetHelperFactory <, , ,>)).To(typeof(CreateTargetImplConvertTargetHelperFactory <, , ,>)); container.Bind(typeof(ICreateTargetImplConvertTargetHelper <, , , ,>)).To(typeof(CreateTargetImplConvertTargetHelper <, , , ,>)); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree() { }; sourceTree.Leafs.Add(new SourceTreeLeaf()); var targetTree = new TargetTree() { RelationOnTarget = new MasterData(), }; // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert targetTree.TargetLeafs.Count.Should().Be(1); var targetLeaf = targetTree.TargetLeafs.Single(); targetLeaf.RelationOnTarget.Should().Be(targetTree.RelationOnTarget); }
private void ResetAllCheck(bool isadd) { foreach (V_S_Function itenm in SourceTree.SelectMany(item => GetItems(item))) { itenm.IsSelected = isadd; } }
public void Convert_RegisterCreateToManyWithRelationAndTarget_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToManyWithRelationAndTargetRegistrations>(); container.Bind <IConvertRegistrations <IdDto, TargetTreeLeaf, IForTest> >().To <CopyIdDtoToTargetTreeLeafRegistrations>(); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree() { }; sourceTree.Leafs.Add(new SourceTreeLeaf()); var targetTree = new TargetTree() { RelationOnTarget = new MasterData(), }; // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert targetTree.TargetLeafs.Count.Should().Be(1); var targetLeaf = targetTree.TargetLeafs.Single(); targetLeaf.RelationOnTarget.Should().Be(targetTree.RelationOnTarget); targetLeaf.OriginId.Should().Be(targetTree.Id); }
public void Convert_RegisterCreateToManyWithRelation_ReverseRelation_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToManyWithRelationReverseRelationRegistrations>(); container.Bind <IConvertRegistrations <SourceTreeLeaf, TargetTreeLeaf, IForTest> >().To <CopyLeafAttributeRegistrations>(); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree(); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); var targetTree = new TargetTree(); // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert sourceTree.Leafs.Count.Should().Be(targetTree.TargetLeafs.Count); for (var i = 0; i < sourceTree.Leafs.Count; i++) { targetTree.TargetLeafs[i].TargetTree.Should().Be(targetTree); targetTree.TargetLeafs[i].OriginId.Should().Be(sourceTree.Leafs.ElementAt(i).Id); } }
private static SourceTree CreateSourceTree() { var tree = new SourceTree(); tree.CreateStringForProperty(x => x.TreeName); tree.MasterData = CreateMasterData(); var leaf = CreateSourceLeaf(); tree.Leafs.Add(leaf); var leaf2 = CreateSourceLeaf(); tree.Leafs.Add(leaf2); leaf.Tree = tree; leaf2.Tree = tree; var hist = CreateTreeHist(new DateTime(1993, 10, 4), new DateTime(2019, 10, 29)); tree.Hists.Add(hist); var hist2 = CreateTreeHist(new DateTime(1994, 10, 7), new DateTime(2019, 10, 3)); tree.Hists.Add(hist2); tree.ExpectedFilteredHist = hist; CreateTreeHistLeaf(hist, leaf); CreateTreeHistLeaf(hist2, leaf2); return(tree); }
public static Location GetLocation(this SourceNode node) { // TODO remove this after SourceNode has this method itself //return new SourceLocation(node); // we don't have tree ref here var tree = SourceTree.CreateForRoot(node.AncestorsAndSelf().Last()); return(new SourceLocation(tree, node.GetSpan())); }
/// <summary> /// Creates an instance of a <see cref="Location"/> for a span in a <see cref="SyntaxTree"/>. /// </summary> public static Location Create(SourceTree syntaxTree, TextSpan textSpan) { if (syntaxTree == null) { throw new ArgumentNullException(nameof(syntaxTree)); } return(new SourceLocation(syntaxTree, textSpan)); }
private static void AssertTreeLeafs(SourceTree sourceTree, TargetTree targetTree) { targetTree.TargetLeafs.Count.Should().Be(sourceTree.Leafs.Count); for (var i = 0; i < sourceTree.Leafs.Count; i++) { var targetLeaf = targetTree.TargetLeafs.ElementAt(i); targetLeaf.TargetTree.Should().Be(targetTree); AssertTreeLeaf(sourceTree.Leafs.ElementAt(i), targetLeaf); } }
public override int GetHashCode() { if (SourceTree != null) { return(Hash.Combine(true, SourceTree.GetHashCode())); } else { RoslynDebug.Assert(AdditionalFile != null); return(Hash.Combine(false, AdditionalFile.GetHashCode())); } }
private static void AssertTreeHistLeafs(SourceTree sourceTree, TargetTree targetTree) { var sourceTreeHistLeafs = sourceTree.Leafs.SelectMany(x => x.TreeHistLeafs).ToList(); targetTree.TargetHistLeafs.Count.Should().Be(sourceTreeHistLeafs.Count); for (var i = 0; i < sourceTreeHistLeafs.Count; i++) { var targetHistLeaf = targetTree.TargetHistLeafs.ElementAt(i); targetHistLeaf.TargetTree.Should().Be(targetTree); AssertTreeHistLeaf(sourceTreeHistLeafs.ElementAt(i), targetHistLeaf); } }
private void tbxSourceFile_TextChanged(object sender, EventArgs e) { if (File.Exists(tbxSourceFile.Text)) { SourceTree = App.NewDescisionTree(); IPersistence persistence = new XmlPersistenceImpl(tbxSourceFile.Text); SrcVariables = SourceTree.LoadVariables(persistence); if (SrcVariables != null && SrcVariables.Nodes.Count > 0) { Analyze(); } } }
public void Convert_Processings_Successful() { // Arrange container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToManyGenericRegistrations>(); container.Bind <IConvertRegistrations <SourceTreeLeaf, TargetTreeLeaf, IForTest> >().To <CopyLeafAttributeRegistrations>(); container.Bind(typeof(ICreateTargetImplConvertTargetHelperFactory <, , ,>)).To(typeof(CreateTargetImplConvertTargetHelperFactory <, , ,>)); container.Bind(typeof(ICreateTargetImplConvertTargetHelper <, , ,>)).To(typeof(CreateTargetImplConvertTargetHelper <, , ,>)); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree(); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); sourceTree.Leafs.Add(new SourceTreeLeaf() { Tree = sourceTree }); var targetTree = new TargetTree(); var targetIds = new List <Guid>(); var sourceIds = new List <Guid>(); var preProcHits = 0; // Act var processings = new List <IBaseAdditionalProcessing>(); processings.Add(new GenericConvertPostProcessing <SourceTreeLeaf, TargetTreeLeaf>((x, y) => targetIds.Add(y.Id))); processings.Add(new GenericContinueConvertInterception <SourceTreeLeaf, TargetTreeLeaf>( x => { sourceIds.Add(x.Id); return(true); })); processings.Add(new GenericConvertPreProcessing <SourceTreeLeaf, TargetTreeLeaf>((x, y) => preProcHits++)); converter.Convert(sourceTree, targetTree, processings); // Assert sourceTree.Leafs.Count.Should().Be(targetTree.TargetLeafs.Count); targetIds.Should().BeEquivalentTo(targetTree.TargetLeafs.Select(x => x.Id).ToList()); sourceIds.Should().BeEquivalentTo(sourceTree.Leafs.Select(x => x.Id).ToList()); preProcHits.Should().Be(2); }
public void Convert_CreateToOneHistWithCondition_Successful() { // Arrange container.Bind(typeof(ITemporalDataHandler <>)).To(typeof(TemporalDataHandler <>)); container.Bind <IConvertRegistrations <SourceTree, TargetTree, IForTest> >().To <CreateToOneHistWithConditionRegistrations>(); container.Bind <IConvertRegistrations <SourceTreeHist, TargetTreeHist, IForTest> >().To <CopyHistAttributeRegistrations>(); container.Bind(typeof(ICreateTargetImplConvertTargetHelperFactory <, , ,>)).To(typeof(CreateTargetImplConvertTargetHelperFactory <, , ,>)); container.Bind(typeof(ICreateTargetImplConvertTargetHelper <, , , ,>)).To(typeof(CreateTargetImplConvertTargetHelper <, , , ,>)); var converter = GetConverter <SourceTree, TargetTree>(); var sourceTree = new SourceTree(); var expFilteredHist = CreateTreeHist(new DateTime(2000, 1, 1), new DateTime(2020, 12, 31)); var expEndDate = new DateTime(9999, 12, 31); sourceTree.Hists.Add(expFilteredHist); sourceTree.Hists.Add(CreateTreeHist(new DateTime(2021, 1, 1), new DateTime(2040, 12, 31))); var targetRoot = new TargetRoot() { ReferenceDate = new DateTime(2015, 6, 12), }; var targetTree = new TargetTree() { TargetRoot = targetRoot }; targetRoot.TargetTree = targetTree; // Act var processings = new List <IBaseAdditionalProcessing>(); converter.Convert(sourceTree, targetTree, processings); // Assert targetTree.TargetHists.Count.Should().Be(1); var targetHist = targetTree.TargetHists.Single(); targetHist.OriginId.Should().Be(expFilteredHist.Id); targetHist.From.Should().Be(expFilteredHist.From); targetHist.To.Should().Be(expEndDate); }
public SourceLocation(SourceTree syntaxTree, TextSpan span) { this.syntaxTree = syntaxTree; this.span = span; }
public override WhamCompilation ReplaceSourceTree(SourceTree oldTree, SourceTree?newTree) => Update(newTree is null ? SourceTrees.Remove(oldTree) : SourceTrees.Replace(oldTree, newTree));
public void RefreshScopeTree() { VisibleNodes = new List <TreeNode>(); string[] searchTerms = (SourceSearch.Text == "") ? null : SourceSearch.Text.ToLowerInvariant().Split(' '); SourceNodeToDef = new Dictionary <TreeNode, ScopeDefinition>(); SourceTree.Nodes.Clear(); TreeNode firstNode = null; var nodes = new List <TreeNode>(); foreach (var def in CategorisedScopes[0]) { if (searchTerms == null || def.SearchMatch(searchTerms)) { var node = new TreeNode(def.Name); if (firstNode == null) { firstNode = node; } SourceNodeToDef.Add(node, def); VisibleNodes.Add(node); nodes.Add(node); if (def == SelectedDef) { SourceTree.SelectedNode = node; } } } SourceTree.Nodes.AddRange(nodes.OrderByDescending(node => SourceNodeToDef[node].LastSearchScore).ToArray()); for (int i = 0; i < 4; i++) { var parent = new TreeNode(Categories[i]); nodes = new List <TreeNode>(); foreach (var def in CategorisedScopes[i + 1]) { if (searchTerms == null || def.SearchMatch(searchTerms)) { var node = new TreeNode(def.Name); if (firstNode == null) { firstNode = node; } SourceNodeToDef.Add(node, def); VisibleNodes.Add(node); nodes.Add(node); if (def == SelectedDef) { SourceTree.SelectedNode = node; } } } parent.Nodes.AddRange(nodes.OrderByDescending(node => SourceNodeToDef[node].LastSearchScore).ToArray()); if (parent.Nodes.Count > 0) { SourceTree.Nodes.Add(parent); } } SourceTree.ExpandAll(); if (SourceTree.SelectedNode == null) { SourceTree.SelectedNode = firstNode; } if (SourceTree.Nodes.Count > 0) { SourceTree.Nodes[0].EnsureVisible(); } }
internal static void OnDocumentSaved(uint docCookie) { // The document identified by docCookie has been saved. Now we have to update // our internal data structures and persist them to file. This will ensure we // will display the same data again when the user closes and reopens the document. // If there is currently no clone report available there is nothing to do. if (!IsCloneReportAvailable) { return; } CloneDetectiveResult cloneDetectiveResult = CloneDetectiveResult; // Get the text buffer. We're done if this fails because that means it was not // a text document. IVsTextLines textLines = GetDocumentTextLines(docCookie); if (textLines == null) { return; } // Get the SourceFile of the document in our data structure. We're done if this // fails because that means the document was not included in clone detection. string path = GetDocumentPath(textLines); SourceNode sourceNode = cloneDetectiveResult.SourceTree.FindNode(path); if (sourceNode == null) { return; } SourceFile sourceFile = sourceNode.SourceFile; // And we need to be able to map existing clone markers to their corresponding // clone classes. If that fails we cannot update any clone information. DocumentInfo documentInfo; if (!_textLinesToDocInfos.TryGetValue(textLines, out documentInfo)) { return; } // If the hash of the file didn't match when we opened it, we don't want to save // any changes. if (!documentInfo.HashMatched) { return; } // Store the new line count of the file. Be aware of the fact that the last line // is not taken into account if it is empty. Replace the fingerprint of the file // with the new one such that we get no problems when opening up the file the // next time. int lastLineIndex; int lastLineLength; if (ErrorHandler.Failed(textLines.GetLastLineIndex(out lastLineIndex, out lastLineLength))) { return; } sourceFile.Length = lastLineIndex + ((lastLineLength > 0) ? 1 : 0); sourceFile.Fingerprint = GetHashFromFile(path); // We need to track which source file clone information was modified to be able // to update the rollups afterwards. HashSet <SourceFile> modifiedSourceFiles = new HashSet <SourceFile>(); // Clear old clone information of the saved document as we're going to rebuild // it from scratch. foreach (Clone clone in sourceFile.Clones) { clone.CloneClass.Clones.Remove(clone); } sourceFile.Clones.Clear(); modifiedSourceFiles.Add(sourceFile); // Store information about current position of each marker. foreach (KeyValuePair <IVsTextLineMarker, CloneClass> markerWithCloneClass in documentInfo.MarkersToCloneClasses) { // Retrieve the current text span of the marker we just enumerated. TextSpan[] span = new TextSpan[1]; ErrorHandler.ThrowOnFailure(markerWithCloneClass.Key.GetCurrentSpan(span)); // Create a new clone object and initialize it appropriately. Clone clone = new Clone(); clone.CloneClass = markerWithCloneClass.Value; clone.SourceFile = sourceFile; clone.StartLine = span[0].iStartLine; clone.LineCount = span[0].iEndLine - span[0].iStartLine + 1; // Add the clone to the clone class as well as the source file. clone.CloneClass.Clones.Add(clone); clone.SourceFile.Clones.Add(clone); } // Remove clone classes with less than two clones. List <CloneClass> cloneClasses = cloneDetectiveResult.CloneReport.CloneClasses; for (int i = cloneClasses.Count - 1; i >= 0; i--) { List <Clone> clones = cloneClasses[i].Clones; if (clones.Count < 2) { foreach (Clone clone in clones) { clone.SourceFile.Clones.Remove(clone); modifiedSourceFiles.Add(clone.SourceFile); } cloneClasses.RemoveAt(i); } } // Save the new clone report to disk. string solutionPath = VSPackage.Instance.GetSolutionPath(); string cloneReportPath = PathHelper.GetCloneReportPath(solutionPath); CloneReport.ToFile(cloneReportPath, cloneDetectiveResult.CloneReport); // Rollup changes within the SourceTree. foreach (SourceFile modifiedSourceFile in modifiedSourceFiles) { SourceNode modifiedSourceNode = cloneDetectiveResult.SourceTree.FindNode(modifiedSourceFile.Path); SourceTree.RecalculateRollups(modifiedSourceNode); } // Send notification about changed result to listeners. OnCloneDetectiveResultChanged(); }
public void Should_work() { var source = new SourceTree <string>("value", new SourceTree <string> [0]); Mapper.Map <DestinationTree <string> >(source).Value.ShouldBe("value"); }
public override SemanticModel GetSemanticModel(SourceTree tree) { throw new NotImplementedException(); }
public BinderFactory(WhamCompilation compilation, SourceTree sourceTree) { Compilation = compilation; SourceTree = sourceTree; BuckStopsHereBinder = new(compilation); }
public abstract Compilation ReplaceSourceTree(SourceTree oldTree, SourceTree?newTree);
public abstract SemanticModel GetSemanticModel(SourceTree tree);