public void Parser_Received_Recipe_With_No_Instructions()
        {
            // Arrange
            var inputString = @"
Puppies
Kittens
Bunnies

";
            var recipeParserConfiguration = new ParserConfiguration {
                ReportExceptions = true
            };
            var recipeParser = new RecipeParser(recipeParserConfiguration);
            var parseError   = new ParseError
            {
                Character    = -1,
                Line         = -1,
                Description  = "Could Not find any instructions",
                ErrorCode    = ParseErrorCode.NoInstructions,
                ErrorType    = ErrorType.MissingSection,
                UnparsedLine = ""
            };

            // Act
            var output = recipeParser.Parse(inputString);

            // Assert
            Assert.NotNull(output);
            Assert.Equal(ParseStatus.ParsedWithErrors, output.Status);
            Assert.NotEmpty(output.Errors);
            Assert.Matches(parseError.ToString(),
                           output.Errors.Single(c => c.ErrorCode == ParseErrorCode.NoInstructions).ToString());
        }
示例#2
0
        public MainWindow(
            CefBrowserHandler browser,
            IDatabaseItemDao databaseItemDao,
            IDatabaseItemStatDao databaseItemStatDao,
            IPlayerItemDao playerItemDao,
            IDatabaseSettingDao databaseSettingDao,
            IBuddyItemDao buddyItemDao,
            IBuddySubscriptionDao buddySubscriptionDao,
            ArzParser arzParser,
            IRecipeItemDao recipeItemDao,
            IItemSkillDao itemSkillDao
            )
        {
            _cefBrowserHandler = browser;
            InitializeComponent();
            FormClosing += MainWindow_FormClosing;
            Instance     = this;

            _reportUsageStatistics = new Stopwatch();
            _reportUsageStatistics.Start();

            _dynamicPacker        = new DynamicPacker(databaseItemStatDao);
            _databaseItemDao      = databaseItemDao;
            _databaseItemStatDao  = databaseItemStatDao;
            _playerItemDao        = playerItemDao;
            _databaseSettingDao   = databaseSettingDao;
            _buddyItemDao         = buddyItemDao;
            _buddySubscriptionDao = buddySubscriptionDao;
            _arzParser            = arzParser;
            _recipeParser         = new RecipeParser(recipeItemDao);
            _itemSkillDao         = itemSkillDao;
        }
示例#3
0
 private static int Main(string[] args)
 {
     Console.WriteLine(ProgramInfo.Greeting);
     if (args.NeedsHelp())
     {
         PrintUsage();
         return(ErrorCodes.MissingUserInput);
     }
     try
     {
         var arguments = args.To <MergeArgs>();
         Logger.Level = arguments.L;
         var source  = RecipeSource.FromFileOrInput(arguments.Recipe);
         var recipe  = new RecipeParser(source).Recipe;
         var options = TransformOptionsProvider.GetTransformOptions();
         recipe.Compile()(new ConfigTransformer(source.BasePath, options));
         return(ErrorCodes.Ok);
     }
     catch (RecipeCompilerException ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine(ex.Message);
         Console.ResetColor();
         return(ErrorCodes.RecipeError);
     }
     catch (Exception ex)
     {
         Console.ForegroundColor = ConsoleColor.Red;
         Console.WriteLine($"{ProgramInfo.Name}: error: {ex.Message}");
         Console.WriteLine(ex.StackTrace);
         Console.ResetColor();
         return(ErrorCodes.Unhandled);
     }
 }
        public void Parser_Received_Recipe_With_Proper_Sections()
        {
            // Arrange
            var inputString = @"
description

my description

ingredients

my ingredients

instructions

my instructions

";
            var recipeParserConfiguration = new ParserConfiguration {
                ReportExceptions = true
            };
            var recipeParser = new RecipeParser(recipeParserConfiguration);

            // Act
            var output = recipeParser.Parse(inputString);

            // Assert
            Assert.NotNull(output);
            Assert.Equal(ParseStatus.Succeeded, output.Status);
            Assert.Empty(output.Errors);
        }
示例#5
0
        public void EmptyScript_ReturnsVoidExpression()
        {
            var expression = new RecipeParser(Enumerable.Empty <Token>()).Recipe;

            expression.Compile()(_transformer);
            A.CallTo(() => _transformer.Transform(A <string> ._, A <IEnumerable <string> > ._)).MustNotHaveHappened();
        }
        public void Parser_Received_Empty_String()
        {
            // Arrange
            var inputString = "";
            var recipeParserConfiguration = new ParserConfiguration {
                ReportExceptions = true
            };
            var recipeParser = new RecipeParser(recipeParserConfiguration);
            var parseError   = new ParseError
            {
                Character    = -1,
                Line         = -1,
                Description  = "Empty String was provided.  No Content to Parse",
                ErrorCode    = ParseErrorCode.NoInput,
                ErrorType    = ErrorType.Fatal,
                UnparsedLine = ""
            };

            // Act
            var output = recipeParser.Parse(inputString);

            // Assert
            Assert.NotNull(output);
            Assert.Equal(ParseStatus.Failed, output.Status);
            Assert.NotEmpty(output.Errors);
            Assert.Single(output.Errors);
            Assert.Matches(parseError.ToString(), output.Errors.FirstOrDefault().ToString());
        }
示例#7
0
        public static void Merge(string recipe, LogLevel logLevel = LogLevel.Normal)
        {
            Logger.Level = logLevel;
            var source        = RecipeSource.FromFileOrInput(recipe);
            var recipeExpress = new RecipeParser(source).Recipe;
            var options       = TransformOptionsProvider.GetTransformOptions();

            recipeExpress.Compile()(new ConfigTransformer(source.BasePath, options));
        }
示例#8
0
        public void Simple()
        {
            RecipeString source     = "App.config = [App.root.config, App.dev.local.config];";
            var          expression = new RecipeParser(source).Recipe;

            expression.Compile()(_transformer);
            A.CallTo(() => _transformer.Transform("App.config", A <IEnumerable <string> > .That.IsSameSequenceAs(new [] { "App.root.config", "App.dev.local.config" })))
            .MustHaveHappened();
        }
        public ParserProgram(string pattern)
        {
            Pattern      = pattern;
            Parser       = new FolderParser();
            RecipeParser = new RecipeParser();
            BasicParser  = new BasicParser();

            Provider = new ServiceProvider();
        }
示例#10
0
        public Recipe GetRecipe(string pickName)
        {
            var    startTime = TimetrackingStart();
            string content   = GetRecipeContent(pickName);
            Recipe opskrift  = RecipeParser.Parse(content);

            Logger.Debug(string.Format("Hentede opskrift [{0}] på {1}", pickName, TimetrackingEnd(startTime)));

            return(opskrift);
        }
示例#11
0
        public RecipeService(IRecipeRepository recipeRepository, IRecipeIngredientRepository recipeIngredientRepository,
                             IStepRepository stepRepository, IRecipeHistoryRepository recipeHistoryRepository,
                             ISecurityService securityService)
        {
            RecipeRepository           = recipeRepository;
            RecipeIngredientRepository = recipeIngredientRepository;
            StepRepository             = stepRepository;
            RecipeHistoryRepository    = recipeHistoryRepository;
            RecipeParser = new RecipeParser(new ParserConfiguration());

            SecurityService = securityService;
        }
示例#12
0
        public static void ImportRecipes(string headerPath, string materialPath)
        {
            string header;

            using (var sr = new StreamReader(headerPath))
                header = sr.ReadToEnd();


            string materials;

            using (var sr = new StreamReader(materialPath))
                materials = sr.ReadToEnd();


            using (var itemrepo = new ItemRepository())
            {
                var parser = new RecipeParser(itemrepo, new RecipeParserSettings(), header, string.Empty, materials);

                using (var reciperepo = new RecipeRepository())
                {
                    reciperepo.Begin();
                    foreach (var recipe in parser.Recipes)
                    {
                        var  existing = reciperepo.GetByPrimaryResult(recipe.Result);
                        bool skip     = false;
                        foreach (var e in existing)
                        {
                            var match = true;
                            foreach (var kvp in recipe.Materials)
                            {
                                if (!e.Materials.ContainsKey(kvp.Key) || e.Materials[kvp.Key] != kvp.Value)
                                {
                                    match = false;
                                }
                            }
                            if (match)
                            {
                                skip = true;
                            }
                        }

                        if (skip)
                        {
                            Console.WriteLine($"Skipping duplicate recipe for {recipe.Result.Name}");
                            continue;
                        }

                        reciperepo.Save(recipe);
                    }
                    reciperepo.End();
                }
            }
        }
示例#13
0
        public void ArrayManipulations()
        {
            RecipeString source = new[]
            {
                "App.config = App. + [root, dev.local] + .config;"
            };

            var expression = new RecipeParser(source).Recipe;

            expression.Compile()(_transformer);
            A.CallTo(() => _transformer.Transform("App.config", A <IEnumerable <string> > .That.IsSameSequenceAs(new[] { "App.root.config", "App.dev.local.config" })))
            .MustHaveHappened();
        }
示例#14
0
        public RecipeWebDao()
        {
            RecipeParser         = new RecipeParser();
            HopParser            = new HopParser();
            MaltParser           = new MaltParser();
            YeastParser          = new YeastParser();
            BeerstyleGroupParser = new BeerstyleGroupParser();

            /*
             * List<Hop> hopList = hopParser.Parse(content);
             * List<Malt> maltList = maltParser.Parse(content);
             * List<Yeast> yeastList = yeastParser.Parse(content);
             * */
        }
示例#15
0
        public void CrazyArrayManiuplations()
        {
            RecipeString source = new[]
            {
                "var i = \"input/\";",
                "App.config = i + (App. + [root, dev.local] + .config) + [another.file];"
            };

            var expression = new RecipeParser(source).Recipe;

            expression.Compile()(_transformer);
            A.CallTo(() => _transformer.Transform("App.config", A <IEnumerable <string> > .That.IsSameSequenceAs(new[] { "input/App.root.config", "input/App.dev.local.config", "input/another.file" })))
            .MustHaveHappened();
        }
示例#16
0
        public void ExpressionInMerge()
        {
            RecipeString source = new[]
            {
                "",
                "var c = \"config/\";",
                "",
                "App.config = [c + App.root.config, c + App.dev.local.config];",
                ""
            };

            var expression = new RecipeParser(source).Recipe;

            expression.Compile()(_transformer);
            A.CallTo(() => _transformer.Transform("App.config", A <IEnumerable <string> > .That.IsSameSequenceAs(new[] { "config/App.root.config", "config/App.dev.local.config" })))
            .MustHaveHappened();
        }
示例#17
0
        public void TestUpdateRecipes()
        {
            var parser = new RecipeParser(this.dao);

            var dbItemDao = new DatabaseItemDaoImpl(factory);

            dbItemDao.Save(new DatabaseItem {
                Record = "records/items/crafting/blueprints/armor/craft_armor_decoratedpauldrons.dbr",
                Name   = "Whatever",
                Id     = 123,
                Stats  = new List <DatabaseItemStat> {
                    new DatabaseItemStat {
                        TextValue = "Whatever",
                        Stat      = "artifactName"
                    }
                }
            });

            dbItemDao.Save(new DatabaseItem {
                Record = "records/items/crafting/blueprints/armor/craft_armorc02_unholyvisageofthecovenant.dbr",
                Name   = "Whatever 2",
                Id     = 1234,
                Stats  = new List <DatabaseItemStat> {
                    new DatabaseItemStat {
                        TextValue = "Whatever 2",
                        Stat      = "artifactName"
                    }
                }
            });

            using (ISession session = factory.OpenSession()) {
                var tmp = dbItemDao.ListAll();
                var sss = tmp[0].Stats;
                dbItemDao.ListAll().Count.Should().Be.EqualTo(2);
                // insert stat with name artifactName
            }

            parser.UpdateFormulas(Path.Combine("Dao", "TestData", "formulas.gst"), false);
            dao.ListAll().Count.Should().Be.GreaterThan(0);
            var numSoftcore = dao.ListAll().Count;

            parser.UpdateFormulas(Path.Combine("Dao", "TestData", "formulas.gsh"), true);
            dao.ListAll().Count.Should().Be.GreaterThan(numSoftcore);
        }
示例#18
0
        public async Task <ParserResult> ParseFull(string input)
        {
            var output        = RecipeParser.Parse(input);
            var recipeHistory = new RecipeHistory
            {
                FullText   = input,
                CreatedBy  = await SecurityService.GetCurrentUserName(),
                ModifiedBy = await SecurityService.GetCurrentUserName(),
                Version    = 1
            };

            var history = RecipeHistoryRepository.Create(recipeHistory);

            await RecipeHistoryRepository.UpdateSearchIndex(history.ID);

            output.Output.FullTextReference = history.ID;

            return(output);
        }
示例#19
0
 public MainWindow(
     CefBrowserHandler browser,
     IDatabaseItemDao databaseItemDao,
     IDatabaseItemStatDao databaseItemStatDao,
     IPlayerItemDao playerItemDao,
     IAzurePartitionDao azurePartitionDao,
     IDatabaseSettingDao databaseSettingDao,
     IBuddyItemDao buddyItemDao,
     IBuddySubscriptionDao buddySubscriptionDao,
     IRecipeItemDao recipeItemDao,
     IItemSkillDao itemSkillDao,
     IItemTagDao itemTagDao,
     ParsingService parsingService,
     AugmentationItemRepo augmentationItemRepo,
     SettingsService settingsService,
     GrimDawnDetector grimDawnDetector,
     IItemCollectionDao itemCollectionRepo
     )
 {
     _cefBrowserHandler = browser;
     InitializeComponent();
     FormClosing            += MainWindow_FormClosing;
     _automaticUpdateChecker = new AutomaticUpdateChecker(settingsService);
     _settingsController     = new SettingsController(settingsService);
     _dynamicPacker          = new DynamicPacker(databaseItemStatDao);
     _databaseItemDao        = databaseItemDao;
     _databaseItemStatDao    = databaseItemStatDao;
     _playerItemDao          = playerItemDao;
     _azurePartitionDao      = azurePartitionDao;
     _databaseSettingDao     = databaseSettingDao;
     _buddyItemDao           = buddyItemDao;
     _buddySubscriptionDao   = buddySubscriptionDao;
     _recipeParser           = new RecipeParser(recipeItemDao);
     _itemSkillDao           = itemSkillDao;
     _itemTagDao             = itemTagDao;
     _parsingService         = parsingService;
     _augmentationItemRepo   = augmentationItemRepo;
     _userFeedbackService    = new UserFeedbackService(_cefBrowserHandler);
     _settingsService        = settingsService;
     _grimDawnDetector       = grimDawnDetector;
     _itemCollectionRepo     = itemCollectionRepo;
 }
示例#20
0
        public MainWindow(
            CefBrowserHandler browser,
            IDatabaseItemDao databaseItemDao,
            IDatabaseItemStatDao databaseItemStatDao,
            IPlayerItemDao playerItemDao,
            IAzurePartitionDao azurePartitionDao,
            IDatabaseSettingDao databaseSettingDao,
            IBuddyItemDao buddyItemDao,
            IBuddySubscriptionDao buddySubscriptionDao,
            ArzParser arzParser,
            IRecipeItemDao recipeItemDao,
            IItemSkillDao itemSkillDao,
            IItemTagDao itemTagDao,
            ParsingService parsingService,
            bool requestedDevtools,
            AugmentationItemRepo augmentationItemRepo
            )
        {
            _cefBrowserHandler = browser;
            InitializeComponent();
            FormClosing += MainWindow_FormClosing;

            _reportUsageStatistics = new Stopwatch();
            _reportUsageStatistics.Start();

            _dynamicPacker          = new DynamicPacker(databaseItemStatDao);
            _databaseItemDao        = databaseItemDao;
            _databaseItemStatDao    = databaseItemStatDao;
            _playerItemDao          = playerItemDao;
            _azurePartitionDao      = azurePartitionDao;
            _databaseSettingDao     = databaseSettingDao;
            _buddyItemDao           = buddyItemDao;
            _buddySubscriptionDao   = buddySubscriptionDao;
            _arzParser              = arzParser;
            _recipeParser           = new RecipeParser(recipeItemDao);
            _itemSkillDao           = itemSkillDao;
            _itemTagDao             = itemTagDao;
            _parsingService         = parsingService;
            this._requestedDevtools = requestedDevtools;
            _augmentationItemRepo   = augmentationItemRepo;
        }
示例#21
0
        public MainWindow(
            ServiceProvider serviceProvider,
            CefBrowserHandler browser,
            ParsingService parsingService
            )
        {
            this._serviceProvider = serviceProvider;
            _cefBrowserHandler    = browser;
            InitializeComponent();
            FormClosing += MainWindow_FormClosing;

            _minimizeToTrayHandler = new MinimizeToTrayHandler(this, notifyIcon1, serviceProvider.Get <SettingsService>());

            var settingsService = _serviceProvider.Get <SettingsService>();

            _automaticUpdateChecker = new AutomaticUpdateChecker(settingsService);
            _settingsController     = new SettingsController(settingsService);
            _dynamicPacker          = new DynamicPacker(serviceProvider.Get <IDatabaseItemStatDao>());
            _recipeParser           = new RecipeParser(serviceProvider.Get <IRecipeItemDao>());
            _parsingService         = parsingService;
            _userFeedbackService    = new UserFeedbackService(_cefBrowserHandler);
        }
        public void Parser_Received_Full_Recipe()
        {
            // Arrange
            var inputString = @"
description

a great recipe for chicken wings

ingredients

1 cup franks red hot
1 cup butter
1 cup bbq sauce
1 cup v8
1 lb chicken wings

instructions

1) mix redhot, butter, bbq sauce, and v8 together stirring frequently
2) bake, grill or deep fry chicken wings
3) coat chicken wings in sauce 
4) put wings on grill for a minute or two (optional)

";
            var recipeParserConfiguration = new ParserConfiguration {
                ReportExceptions = true
            };
            var recipeParser = new RecipeParser(recipeParserConfiguration);
            var recipe       = new Recipe
            {
                Description = "a great recipe for chicken wings",
                Steps       = new List <Step>
                {
                    new Step
                    {
                        Ordinal      = 1,
                        Instructions = "mix redhot, butter, bbq sauce, and v8 together stirring frequently"
                    },
                    new Step {
                        Ordinal = 2, Instructions = "bake, grill or deep fry chicken wings"
                    },
                    new Step {
                        Ordinal = 3, Instructions = "coat chicken wings in sauce"
                    },
                    new Step {
                        Ordinal = 4, Instructions = "put wings on grill for a minute or two (optional)"
                    }
                }
            };

            // Act
            var output = recipeParser.Parse(inputString);

            // Assert
            Assert.NotNull(output);
            Assert.Equal(ParseStatus.Succeeded, output.Status);
            Assert.Empty(output.Errors);
            Assert.NotEmpty(output.Output.Ingredients);
            Assert.NotEmpty(output.Output.Steps);
            Assert.Matches(recipe.Description, output.Output.Description);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 1).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 1).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 2).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 2).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 3).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 3).Instructions);
            Assert.Equal(recipe.Steps.Single(s => s.Ordinal == 4).Instructions,
                         output.Output.Steps.Single(s => s.Ordinal == 4).Instructions);
        }
示例#23
0
 public RecipeParserFacts()
 {
     Parser = new RecipeParser();
 }