Пример #1
0
        public void ProcessCommandLineArguments(string[] args)
        {
            try
            {
                if (args.Length != 2)
                {
                    HandleError("Error: Expecting 2 command line arguments");
                    return;
                }

                var filterName = args[0];
                var filepath   = args[1];
                // throws a number of exception that inherit from IOException
                var inputString = File.ReadAllText(filepath);

                // throws filterNotFoundException
                var filter         = filterFactory.CreateFilter(filterName);
                var filteredString = filter.Filter(inputString);

                outputService.OutputMessage($"string filtered by {filterName}:");
                outputService.OutputMessage(filteredString);
            }
            catch (IOException ex)
            {
                HandleError($"Error: Accessing filepath: {args[1]}", ex);
            }
            catch (FilterNotFoundException ex)
            {
                HandleError($"Error: filter \"{args[0]}\" not found", ex);
            }
            catch (Exception ex)
            {
                HandleError("Something went wrong", ex);
            }
        }
Пример #2
0
        void ExecuteFilters(StaticFile staticFile, Site site)
        {
            foreach (var filterName in staticFile.FilterNameQueue)
            {
                IFilter filter = filterFactory.CreateFilter(filterName);

                string source    = staticFile.GetLastSnapShot();
                var    arguments = new Dictionary <string, object> {
                    { "configuration", site.Configuration as IDictionary <string, object> },
                    { "item", staticFile.Item.Meta }
                };

                string result = filter.Execute(source, arguments);

                staticFile.CreateSnapShot(result);
            }
        }
Пример #3
0
        public Bank(IFilterFactory filterFactory)
        {
            if (filterFactory == null)
            {
                throw new ArgumentNullException(nameof(filterFactory));
            }

            Filters = filterFactory.CreateFilter();
        }
Пример #4
0
            public void SetUp()
            {
                site          = LoadFakeSite();
                log           = Substitute.For <ILog>();
                fileSystem    = Substitute.For <IFileSystem>();
                filterFactory = Substitute.For <IFilterFactory>();
                filter        = Substitute.For <IFilter>();
                filterFactory.CreateFilter(Arg.Any <string>()).Returns(filter);

                compiler = new Compiler(log, fileSystem, filterFactory);
            }
Пример #5
0
			public void SetUp()
			{
				site = LoadFakeSite();
				log = Substitute.For<ILog>();
				fileSystem = Substitute.For<IFileSystem>();
				filterFactory = Substitute.For<IFilterFactory>();
				filter = Substitute.For<IFilter>();
				filterFactory.CreateFilter(Arg.Any<string>()).Returns(filter);
				
				compiler = new Compiler(log, fileSystem, filterFactory);
			}
Пример #6
0
        private Filter <T> MatchSimpleFilter(FilterLexer lexer)
        {
            FilterToken nextToken = LookAhead(lexer, 1);

            if (nextToken != null)
            {
                if (nextToken.Type == FilterTokenType.Star)
                {
                    GetNextToken(lexer);
                    return(new AnyFilter <T>());
                }
                if (IsWord(nextToken))
                {
                    string key = MatchKey(lexer);
                    MatchColon(lexer);
                    Filter <string> valueFilter = MatchMatchSequence(lexer);
                    return(factory.CreateFilter(key, valueFilter));
                }
            }

            throw new FilterParseException(Resources.FilterParser_FilterExpressionExpected);
        }
Пример #7
0
            public void should_be_able_to_create_liquid_filter()
            {
                IFilter filter = filterFactory.CreateFilter("liquid");

                filter.ShouldBeTypeOf(typeof(LiquidFilter));
            }