Example #1
0
 protected override void Context()
 {
     _searchExpression = "look for";
     _root             = new Container().WithName("test").WithDescription("Nothing to read her");
     _testObject       = new ModelCoreSimulation {
         Model = new Model()
         {
             Root = _root
         }
     };
     _subContainer1 = new Container().WithName(_searchExpression.ToUpper()).WithDescription("TOOL");
     _subContainer2 = new Container().WithName(_searchExpression + "not").WithDescription("TOOL");
     _root.Add(_subContainer1);
     _root.Add(_subContainer2);
     _p1 = new Parameter().WithName("P1").WithDescription(string.Format("What do you {0}?", _searchExpression));
     _p2 = new Parameter().WithName(_searchExpression);
     _subContainer1.Add(_p1);
     _subContainer1.Add(_p2);
     _p3 = new Parameter().WithName("P3").WithDescription("P§");
     _p4 = new Parameter().WithName("p4").WithDescription("_____" + _searchExpression);
     _subContainer2.Add(_p3);
     _subContainer2.Add(_p4);
     sut           = new SearchVisitor();
     sut.SearchFor = _searchExpression;
 }
Example #2
0
        internal override ModelSearchResults SearchModelByDisplayName(string searchCriteria)
        {
            var searchResults = new ModelSearchResults();

            searchResults.Action         = Resources.SearchResultItemsMatching;
            searchResults.SearchCriteria = String.Format(
                CultureInfo.CurrentCulture,
                Resources.SearchResultSearchCriteria, searchCriteria);
            var visitor = new SearchVisitor(searchCriteria, SearchOnDisplayName);

            searchResults.TargetString        = searchCriteria;
            searchResults.ElementTextToSearch = SearchOnDisplayName;
            if (null != ViewModel.EDMRootNode() &&
                null != ViewModel.EDMRootNode().ConceptualModel &&
                null != ViewModel.EDMRootNode().ConceptualModel.ModelItem)
            {
                visitor.Traverse(ViewModel.EDMRootNode().ConceptualModel.ModelItem);
            }
            if (null != ViewModel.EDMRootNode() &&
                null != ViewModel.EDMRootNode().StorageModel &&
                null != ViewModel.EDMRootNode().StorageModel.ModelItem)
            {
                visitor.Traverse(ViewModel.EDMRootNode().StorageModel.ModelItem);
            }
            if (null != ViewModel.EDMRootNode() &&
                null != ViewModel.EDMRootNode().Diagrams &&
                null != ViewModel.EDMRootNode().Diagrams.ModelItem)
            {
                visitor.Traverse(ViewModel.EDMRootNode().Diagrams.ModelItem);
            }

            searchResults.Results = visitor.SearchResults;

            return(searchResults);
        }
Example #3
0
        private bool MatchesTargetString(ExplorerEFElement explorerElement)
        {
            if (null == _targetString)
            {
                Debug.Assert(false, "MatchesTargetString() for explorerElement has null _targetString");
                return(false);
            }

            if (null == _elementTextToSearch)
            {
                Debug.Assert(false, "MatchesTargetString() has null _elementTextToSearch delegate");
                return(false);
            }

            if (null == explorerElement)
            {
                Debug.Assert(false, "MatchesTargetString() was passed null explorerElement");
                return(false);
            }

            if (null == explorerElement.ModelItem)
            {
                Debug.Fail(
                    "MatchesTargetString() was passed explorerElement with null Model item (name = " + explorerElement.Name + ")");
                return(false);
            }

            var stringToMatch = _elementTextToSearch(explorerElement.ModelItem);

            return(SearchVisitor.StringToSearchContainsTargetString(stringToMatch, _targetString));
        }
Example #4
0
        public Parameters GenerateParameters(CodeFileTs input, Settings pluginSettings, IMetadataReader metadataReader, ILogger logger, IFileGroup <CodeFileTs, GroupItemDetails> fileGroup = null)
        {
            var searcher = new SearchVisitor();

            var classDeclarations = searcher.FindNodes <StClassDeclaration>(input.Model, c => true).ToArray();

            return(new Parameters()
            {
                AdditionalProperty = classDeclarations.Any(d => metadataReader.NodeIsGeneratedBy(input.NodePathService.GetNodePath(d), new ActivityFrame(pluginId: "TsTestPlugin"), out _))
            });
        }
Example #5
0
        public static TypeBase MakeGenericInstance(this GenericBaseType genericType, TypeBase genericTemplateType)
        {
            // TODO cache generic instance that are using predefined hlsl types
            var newType = genericTemplateType.DeepClone();

            var genericParameters         = ((IGenerics)newType).GenericParameters;
            var genericArguments          = ((IGenerics)newType).GenericArguments;
            var genericInstanceParameters = genericType.Parameters;

            var genericParameterTypes     = new TypeBase[genericParameters.Count];
            var genericBaseParameterTypes = new TypeBase[genericParameters.Count];

            // Look for parameter instance types
            for (int i = 0; i < genericInstanceParameters.Count; i++)
            {
                var genericInstanceParameter = genericInstanceParameters[i];
                if (genericInstanceParameter is TypeBase)
                {
                    var genericInstanceParameterType = (TypeBase)genericInstanceParameter;
                    genericParameterTypes[i]     = genericInstanceParameterType;
                    genericBaseParameterTypes[i] = TypeBase.GetBaseType(genericInstanceParameterType);
                    genericParameters[i]         = genericParameterTypes[i];
                    genericArguments.Add(genericInstanceParameterType);
                }
            }

            // Replace all references to template arguments to their respective generic instance types
            SearchVisitor.Run(
                newType,
                node =>
            {
                var typeInferencer = node as ITypeInferencer;
                if (typeInferencer != null && typeInferencer.TypeInference.Declaration is GenericDeclaration)
                {
                    var genericDeclaration = (GenericDeclaration)typeInferencer.TypeInference.Declaration;
                    var i         = genericDeclaration.Index;
                    var targeType = genericDeclaration.IsUsingBase ? genericBaseParameterTypes[i] : genericParameterTypes[i];

                    if (node is TypeBase)
                    {
                        return(targeType.ResolveType());
                    }
                }

                return(node);
            });


            return(newType);
        }
Example #6
0
        static void Main(string[] args)
        {
            string testDirPath  = "Test";
            string testFilePath = Path.Combine("Test", "Test.txt");

            if (!System.IO.Directory.Exists(testDirPath))
            {
                System.IO.Directory.CreateDirectory(testDirPath);
            }

            if (!System.IO.File.Exists(testFilePath))
            {
                System.IO.File.Create(testFilePath);
            }

            Node root = new Directory(System.IO.Directory.GetCurrentDirectory());

            root.Add(new File("Composite.exe"));

            Node testDir = new Directory(testDirPath);

            root.Add(testDir);

            testDir.Add(new File(testFilePath));

            VisitorRunner.Run(root, new PrintVisitor());

            SearchVisitor searchVisitor = new SearchVisitor(testFilePath);

            VisitorRunner.Run(root, searchVisitor);

            foreach (Node node in searchVisitor.Results)
            {
                Console.WriteLine("Found node: " + node.Path);
            }

            Console.ReadLine();
        }