Ejemplo n.º 1
0
        private static void SearchDirectory(ConsoleUI consoleUI)
        {
            while (true)
            {
                var benchMark = new DirectoryScannerBenchMark();
                var implementationProvider = new BenchmarkBasedImplementationProvider(benchMark);
                consoleUI.DisplayImplementationMenu(implementationProvider);
                var index = consoleUI.GetMenuChoice();
                if (index == 0)
                {
                    return;
                }

                var typeName       = implementationProvider.GetImplementations().Keys.OrderBy(k => k).ToArray()[index - 1];
                var implementation = ImplementationFactory.CreateInstance(typeName);
                var rootFolder     = consoleUI.GetInput("Please specify root folder", "c:\\program files");
                var searchPattern  = consoleUI.GetInput("Please specify searchPattern", "*.exe");

                Console.WriteLine($"\r\nImplementation:\t{typeName}");
                Console.WriteLine($"Root folder:\t{rootFolder}");
                Console.WriteLine($"Search pattern:\t{searchPattern}");

                var w = new Stopwatch();
                w.Start();
                var count = implementation.EnumerateFiles(rootFolder, searchPattern).Count();
                //Thread.Sleep(1000);
                w.Stop();
                Console.WriteLine($"\r\nFound {count} file(s). Operation took {w.ElapsedMilliseconds} msecs.");
                Console.WriteLine(@"Press any key to continue");
                Console.ReadKey();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Static constructor to setup dynamic implementation
        /// </summary>
        static GraceDynamicMethod()
        {
            DynamicImplementation = DefaultImplementation.Clone();

            DynamicImplementation.ExportSingleton <IDynamicMethodTargetCreator>(f => new DynamicMethodTargetCreator());
            DynamicImplementation.ExportSingleton <INewExpressionGenerator>(f => new NewExpressionGenerator());
            DynamicImplementation.ExportSingleton <IConstantExpressionCollector>(f => new ConstantExpressionCollector());
            DynamicImplementation.ExportSingleton <IConstantExpressionGenerator>(f => new ConstantExpressionGenerator());
            DynamicImplementation.ExportSingleton <IMemeberInitExpressionGenerator>(f => new MemeberInitExpressionGenerator());
            DynamicImplementation.ExportSingleton <IArrayInitExpressionGenerator>(f => new ArrayInitExpressionGenerator());
            DynamicImplementation.ExportSingleton <IParameterExpressionGenerator>(f => new ParameterExpressionGenerator());
            DynamicImplementation.ExportSingleton <ICallExpressionGenerator>(f => new CallExpressionGenerator());
            DynamicImplementation.ExportSingleton <IAssignExpressionGenerator>(f => new AssignExpressionGenerator());

            DynamicImplementation.ExportInstance <ILinqToDynamicMethodConverter>(f => new LinqToDynamicMethodConverter(f));

            DynamicImplementation.ExportInstance <IActivationStrategyCompiler>(
                f => new DynamicMethodStrategyCompiler(f.InjectionScope.ScopeConfiguration,
                                                       f.Locate <IActivationExpressionBuilder>(),
                                                       f.Locate <IAttributeDiscoveryService>(),
                                                       f.Locate <IDefaultStrategyExpressionBuilder>(),
                                                       f.Locate <IInjectionContextCreator>(),
                                                       f.Locate <IExpressionConstants>(),
                                                       f.Locate <IInjectionStrategyDelegateCreator>(),
                                                       f.Locate <ILinqToDynamicMethodConverter>()));
        }
Ejemplo n.º 3
0
        private IDeclarationList Declarations()
        {
            IDeclarationList declarations = ImplementationFactory.CreateDeclarationList();
            PqlToken         declarationType;

            while (currentToken.Type != PqlTokenType.SELECT)
            {
                switch (currentToken.Type)
                {
                case PqlTokenType.PROCEDURE:
                case PqlTokenType.STMTLST:
                case PqlTokenType.STMT:
                case PqlTokenType.ASSIGN:
                case PqlTokenType.CALL:
                case PqlTokenType.WHILE:
                case PqlTokenType.IF:
                case PqlTokenType.VARIABLE:
                case PqlTokenType.CONSTANT:
                case PqlTokenType.PROG_LINE:
                    declarationType = currentToken;
                    Eat(currentToken.Type);
                    while (currentToken.Type != PqlTokenType.SEMI)
                    {
                        declarations.AddDeclaration(Declaration(declarationType));
                    }
                    Eat(PqlTokenType.SEMI);
                    break;

                default:
                    throw new Exception();
                }
            }

            return(declarations);
        }
Ejemplo n.º 4
0
        public void EnumerateFiles(
            [Values(
                 //nameof(FastDirectoryEnumeratorScanner), // causes stackoverflow
                 nameof(FastFileInfoScanner),
                 //nameof(DirectoryEnumerationAsyncScanner), // Had a hardcoded SearchOption.TopDirectoryOnly. but after the fix still has errors
                 nameof(DirectoryTreeWalkerScanner)
                 )]
            string implementation,
            [Values(
                 @"c:\program files",
                 @"c:\program files (x86)"
                 )]
            string path,
            [Values(
                 @"*.*",
                 @"*.exe",
                 @"*.notexisting"
                 )]
            string searchPattern
            )
        {
            // Arrange
            var sut = ImplementationFactory.CreateInstance(implementation);
            var referenceImplementation = new BuiltInDirectoryScanner();

            // Act
            var actual = sut.EnumerateFiles(path, searchPattern).ToList();

            // Assert
            var expected = referenceImplementation.EnumerateFiles(path, searchPattern).ToList();

            Assert.AreEqual(expected.Count, actual.Count);
            // TODO: Check filenames, filesizes for equality
        }
        public IActionResult ReadText(TextDto dto)
        {
            var service       = ImplementationFactory.Create(_services, dto.Implementation);
            var numberOfWords = service.Read(dto.Text);

            return(Ok("There are " + numberOfWords + " words in the text"));
        }
Ejemplo n.º 6
0
        protected override IEntityList LoadSingleRightArg(IProgramKnowledgeBase pkb)
        {
            IEntity     entity = pkb.Statements.GetEntityByAttribute((RightRef as PqlInteger).Value);
            IEntityList result = ImplementationFactory.CreateEntityList();

            result.AddEntity(entity);
            return(result);
        }
Ejemplo n.º 7
0
 public Assign(Variable left, Token operation, Factor right, int programLine) : base(programLine)
 {
     Left       = left;
     Operation  = operation;
     Right      = right;
     AffectedBy = ImplementationFactory.CreateStatementList();
     Affecting  = ImplementationFactory.CreateStatementList();
 }
Ejemplo n.º 8
0
        protected override IEntityList LoadSingleLeftArg(IProgramKnowledgeBase pkb)
        {
            IEntity     entity = pkb.Procedures.GetEntityByAttribute((LeftRef as PqlString).Value);
            IEntityList result = ImplementationFactory.CreateEntityList();

            result.AddEntity(entity);
            return(result);
        }
Ejemplo n.º 9
0
        public List <IStatementList> GetPathsFrom(Statement statement)
        {
            List <IStatementList> paths   = new List <IStatementList>();
            IStatementList        newPath = ImplementationFactory.CreateStatementList();

            BuildPath(paths, newPath, statement);
            return(paths);
        }
Ejemplo n.º 10
0
        protected override IEntityList ProcessRightSide(IProgramKnowledgeBase pkb, IEntity arg)
        {
            Statement      statement = arg as Statement;
            Statement      followed  = pkb.FollowsTable.GetFollowedBy(statement);
            IStatementList result    = ImplementationFactory.CreateStatementList();

            result.AddStatement(followed);
            return(result);
        }
Ejemplo n.º 11
0
        protected override IEntityList ProcessRightSide(IProgramKnowledgeBase pkb, IEntity arg)
        {
            Statement      statement = arg as Statement;
            Statement      parent    = pkb.ParentTable.GetParent(statement);
            IStatementList result    = ImplementationFactory.CreateStatementList();

            result.AddStatement(parent);
            return(result);
        }
Ejemplo n.º 12
0
 public Variable(Token token)
 {
     Name                 = token.Value.ToString();
     Attribute            = new Attribute("varName", Name);
     ModifiedByProcedures = ImplementationFactory.CreateProcedureList();
     ModifiedByStatements = ImplementationFactory.CreateStatementList();
     UsedByProcedures     = ImplementationFactory.CreateProcedureList();
     UsedByStatements     = ImplementationFactory.CreateStatementList();
 }
Ejemplo n.º 13
0
 public Variable(string name)
 {
     Name                 = name;
     Attribute            = new Attribute("varName", Name);
     ModifiedByProcedures = ImplementationFactory.CreateProcedureList();
     ModifiedByStatements = ImplementationFactory.CreateStatementList();
     UsedByProcedures     = ImplementationFactory.CreateProcedureList();
     UsedByStatements     = ImplementationFactory.CreateStatementList();
 }
Ejemplo n.º 14
0
 public Procedure(string name, IStatementList body)
 {
     Name      = name;
     Body      = body;
     Attribute = new Attribute("procName", Name);
     Modifying = ImplementationFactory.CreateVariableList();
     Using     = ImplementationFactory.CreateVariableList();
     CalledBy  = ImplementationFactory.CreateProcedureList();
     Calling   = ImplementationFactory.CreateProcedureList();
 }
Ejemplo n.º 15
0
 public Statement(int programLine)
 {
     ProgramLine = programLine;
     Attribute   = new Attribute("progLine", ProgramLine.ToString());
     Modifying   = ImplementationFactory.CreateVariableList();
     Using       = ImplementationFactory.CreateVariableList();
     NextedBy    = ImplementationFactory.CreateStatementList();
     Nexting     = ImplementationFactory.CreateStatementList();
     Children    = ImplementationFactory.CreateStatementList();
 }
Ejemplo n.º 16
0
 public IStatementList GetUsesStatements(Variable variable)
 {
     if (variable != null)
     {
         return(variable.UsedByStatements);
     }
     else
     {
         return(ImplementationFactory.CreateStatementList());
     }
 }
Ejemplo n.º 17
0
 public IProcedureList GetUsesProcedures(Variable variable)
 {
     if (variable != null)
     {
         return(variable.UsedByProcedures);
     }
     else
     {
         return(ImplementationFactory.CreateProcedureList());
     }
 }
Ejemplo n.º 18
0
 public IVariableList GetUsedBy(Statement statement)
 {
     if (statement != null)
     {
         return(statement.Using.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateVariableList());
     }
 }
Ejemplo n.º 19
0
 public IStatementList GetNextedBy(Statement statement)
 {
     if (statement != null)
     {
         return(statement.Nexting.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateStatementList());
     }
 }
Ejemplo n.º 20
0
 public IStatementList GetParentedBy(Statement statement)
 {
     if (statement != null)
     {
         return(statement.Children.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateStatementList());
     }
 }
Ejemplo n.º 21
0
 public IVariableList GetUsedBy(Procedure procedure)
 {
     if (procedure != null)
     {
         return(procedure.Using.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateVariableList());
     }
 }
Ejemplo n.º 22
0
 public IStatementList GetAffects(Assign assignment)
 {
     if (assignment != null)
     {
         return(assignment.AffectedBy.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateStatementList());
     }
 }
Ejemplo n.º 23
0
 public IProcedureList GetCalledBy(Procedure procedure)
 {
     if (procedure != null)
     {
         return(procedure.Calling.Copy());
     }
     else
     {
         return(ImplementationFactory.CreateProcedureList());
     }
 }
Ejemplo n.º 24
0
        public IStatementList GetFollowsT(Statement statement)
        {
            IStatementList following          = ImplementationFactory.CreateStatementList();
            Statement      followingStatement = GetFollows(statement);

            following.AddStatement(followingStatement);
            for (int i = 0; i < following.GetSize(); i++)
            {
                following.AddStatement(GetFollows(following[i]));
            }
            return(following);
        }
Ejemplo n.º 25
0
        public IStatementList GetFollowedByT(Statement statement)
        {
            IStatementList followed          = ImplementationFactory.CreateStatementList();
            Statement      followedStatement = GetFollowedBy(statement);

            followed.AddStatement(followedStatement);
            for (int i = 0; i < followed.GetSize(); i++)
            {
                followed.AddStatement(GetFollowedBy(followed[i]));
            }
            return(followed);
        }
Ejemplo n.º 26
0
        public IStatementList GetParentT(Statement statement)
        {
            IStatementList parents         = ImplementationFactory.CreateStatementList();
            Statement      parentStatement = GetParent(statement);

            parents.AddStatement(parentStatement);
            for (int i = 0; i < parents.GetSize(); i++)
            {
                parents.AddEntity(GetParent(parents[i]));
            }
            return(parents);
        }
Ejemplo n.º 27
0
        private IProcedureList Procedures()
        {
            Procedure      procedure  = Procedure();
            IProcedureList procedures = ImplementationFactory.CreateProcedureList();

            procedures.AddProcedure(procedure);

            while (currentToken.Type == TokenType.PROCEDURE)
            {
                procedures.AddProcedure(Procedure());
            }
            return(procedures);
        }
Ejemplo n.º 28
0
        private IStatementList Statements()
        {
            Statement      statement  = SingleStatement();
            IStatementList statements = ImplementationFactory.CreateStatementList();

            statements.AddStatement(statement);

            while (currentToken.Type != TokenType.RBRACE)
            {
                statements.AddStatement(SingleStatement());
            }
            return(statements);
        }
Ejemplo n.º 29
0
        /// <summary>
        /// default constructor
        /// </summary>
        public InjectionScopeConfiguration(ImplementationFactory implementationFactory = null)
        {
            Implementation = implementationFactory ?? DefaultImplementation.Clone();
            Behaviors      = new ExportCompilationBehavior();

            CacheArraySize            = 64;
            ExportStrategyArraySize   = 16;
            AutoRegisterUnknown       = true;
            ExportAsBase              = false;
            TrackDisposableTransients = true;
            SupportFuncType           = true;

            ExportByInterfaceFilter = DefaultInterfaceFilter;
        }
Ejemplo n.º 30
0
        public DesignExtractor()
        {
            Statements    = ImplementationFactory.CreateStatementList();
            Variables     = ImplementationFactory.CreateVariableList();
            Procedures    = ImplementationFactory.CreateProcedureList();
            Constants     = ImplementationFactory.CreateConstantList();
            FollowsTable  = ImplementationFactory.CreateFollowsTable();
            ModifiesTable = ImplementationFactory.CreateModifiesTable();
            ParentTable   = ImplementationFactory.CreateParentTable();
            UsesTable     = ImplementationFactory.CreateUsesTable();
            CallsTable    = ImplementationFactory.CreateCallsTable();
            NextTable     = ImplementationFactory.CreateNextTable();
            AffectsTable  = ImplementationFactory.CreateAffectsTable();

            calls = new Dictionary <Procedure, List <Call> >();
        }