/// <summary> /// Оптимизирует входное дерево компиляции. /// </summary> /// <param name="input">Входное дерево компиляции.</param> /// <returns>Оптимизированное дерево компиляции.</returns> public ReportParser Optimize(ReportParser compiledCode) { if (!compiledCode.IsSuccess) { throw new OptimizingException("Входное дерево компиляции построено не верно!"); } if (compiledCode.Compile == null) { throw new OptimizingException("Вызовите compiledCode.Compile() перед началом."); } ITreeNode <object> outputCompile = compiledCode.Compile.CloneCompileTree(); var stmts = from a in outputCompile where a.Current is ParserToken rpc && (rpc.Source == Parser.ExampleLang.stmt || rpc.Source == Parser.ExampleLang.assign_expr) select a; Dictionary <string, double> varsValues = new Dictionary <string, double>(); foreach (var stmt in stmts) { string stmtResult = TryCalculate(stmt, varsValues); if (stmtResult != null) { ParserToken current = (ParserToken)stmt.Current; if (current.Source == Parser.ExampleLang.stmt && double.TryParse(stmtResult, out _)) { stmt[0].Current = new Token(Lexer.ExampleLang.DIGIT, stmtResult, ran.NextULong()); } } } return(new ReportParser(outputCompile)); }
public void ParseReportWithPolicy() { var stubReportService = new Mock <ReportService>(); stubReportService.Setup(s => s.Create(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <bool>(), It.IsAny <IDictionary <string, string> >(), It.IsAny <IDictionary <string, string> >())).Verifiable(); var reportService = stubReportService.Object; var mockPolicyParser = new Mock <PolicyParser>(); mockPolicyParser.Setup(p => p.Execute(It.IsAny <XmlNode>())).Verifiable(); var policyParser = mockPolicyParser.Object; var parser = new ReportParser(reportService, new[] { policyParser }); var xmlDoc = new XmlDocument(); using (Stream stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("RsPackage.Testing.Resources.MultiLevelSample.xml")) using (StreamReader reader = new StreamReader(stream)) xmlDoc.Load(reader); var root = xmlDoc.FirstChild.NextSibling.SelectSingleNode("./Folder[@Name='Analysis']"); parser.Execute(root); Mock.Get(policyParser).Verify(p => p.Execute(It.IsAny <XmlNode>()), Times.Once); }
/// <summary> /// Быстрое проведение тестирования <see cref="Parser.ParserLang"/>. /// Удаляет жетоны с CH_. /// </summary> /// <param name="resource">Текст тестирования.</param> /// <param name="isSuccess">True, если ожидается успех парсирования.</param> /// <param name="tokens">Количество ожидаемых жетонов. Установите -1 для игнорирования.</param> /// <param name="parser">Особые правила парсера. Оставьте null, если нужен язык <see cref="parserLang"/>.</param> /// <param name="lexer">Особые правила лексера. Оставьте null, если нужен язык <see cref="lexerLang"/>.</param> public ReportParser CheckTest(string resource, bool isSuccess = true, int tokens = -1, ParserLang parser = null, LexerLang lexer = null) { if (parser == null) { parser = parserLang; } if (lexer == null) { lexer = lexerLang; } List <Token> listT = lexer.SearchTokens(StringToStream(resource)); Assert.IsNotNull(listT); Console.WriteLine("Count tokens: " + listT.Count); foreach (Token token in listT) { Console.WriteLine(token); } Console.WriteLine("\n ---- Without CH_:"); listT.RemoveAll((Token t) => t.Type.Name.Contains("CH_")); Console.WriteLine("Count tokens: " + listT.Count); foreach (Token token in listT) { Console.WriteLine(token); } ReportParser report = parser.Check(listT); Console.WriteLine(report); if (tokens != -1) { Assert.AreEqual(tokens, listT.Count); } Assert.AreEqual(isSuccess, report.IsSuccess); return(report); }
/// <summary> /// Handles the parsing of the document /// </summary> /// <param name="document">The document Html</param> /// <param name="serverTime">Time the page was generated</param> public bool Handle(string document, DateTime serverTime) { int index = document.IndexOf(string.Format("<th width=\"140\">{0}</th>", TWWords.ReportSubject)); if (index == -1) { return(false); } document = document.Substring(index); var matches = new Dictionary <string, Group>(); if (HandleReportCore(matches, document)) { bool testEspionage = HandleReportEspionage(matches, document); bool testRest = HandleReportRest(matches, document); var options = new ReportOutputOptions(); Report report = ReportParser.ParseHtmlMatch(matches, options); VillageReportCollection.Save(report); return(true); } return(false); }
public ProjectParser GetXmlParser(Options options) { var serviceBuilder = new ServiceBuilder(); serviceBuilder.Setup(options); serviceBuilder.Build(); var rootPath = GetRootPath(options); var parentFolder = GetParentFolder(options); var namingConvention = GetNamingConvention(options); var parser = new ProjectParser() { ParentFolder = parentFolder, RootPath = rootPath, NamingConvention = namingConvention }; var policyParser = new PolicyParser(serviceBuilder.GetPolicyService()); var dataSourceParser = new DataSourceParser(serviceBuilder.GetDataSourceService()); var reportParser = new ReportParser(serviceBuilder.GetReportService(), new[] { policyParser }); var folderParser = new FolderParser(serviceBuilder.GetFolderService(), new IParser[] { policyParser, dataSourceParser, reportParser }); parser.ChildParsers.Add(dataSourceParser); parser.ChildParsers.Add(reportParser); parser.ChildParsers.Add(folderParser); return(parser); }
public ReportParser Optimize(ReportParser compiledCode) { foreach (var o in optimizations) { compiledCode = o.Optimize(compiledCode); } return(compiledCode); }
public void should_parse_scenario_as_null_when_scenario_is_not_ended() { Reporter.ScenarioStarted(_feature.Title, _scenarioTitle); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestScenario(report).Duration).IsNull(); }
private void SetBodySection(Assembly callingAssembly) { string bodySection = XmlHelper.GetNodeText(this.reportPath, "/MixERPReport/Body/Content"); bodySection = ReportParser.ParseExpression(bodySection, this.dataTableCollection, callingAssembly); bodySection = ReportParser.ParseDataSource(bodySection, this.dataTableCollection); this.bodyContentsLiteral.Text = bodySection; }
public void should_parse_steps() { Reporter.StepStarted(_feature.Title, _scenarioTitle, _step); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestStep(report).Text).IsEqualTo(_step); }
private void SetBottomSection() { string bottomSection = XmlHelper.GetNodeText(this.reportPath, "/MixERPReport/BottomSection"); bottomSection = ReportParser.ParseExpression(bottomSection); bottomSection = ReportParser.ParseDataSource(bottomSection, this.dataTableCollection); this.bottomSectionLiteral.Text = bottomSection; }
private void SetTopSection() { string topSection = XmlHelper.GetNodeText(this.reportPath, "/MixERPReport/TopSection"); topSection = ReportParser.ParseExpression(topSection); topSection = ReportParser.ParseDataSource(topSection, this.dataTableCollection); this.topSectionLiteral.Text = topSection; }
public ActionResult Index(string path) { string query = this.Request?.Url?.Query.Or(""); string sourcePath = "/dashboard/reports/source/" + path + query; var locator = new ReportLocator(); path = locator.GetPathToDisk(this.Tenant, path); var parameters = ParameterHelper.GetParameters(this.Request?.QueryString); var parser = new ReportParser(path, this.Tenant, parameters); var report = parser.Get(); var dbParams = new List <DataSourceParameter>(); if (report.DataSources != null) { foreach (var dataSource in report.DataSources) { foreach (var parameter in dataSource.Parameters) { if (dbParams.Any(x => x.Name.ToLower() == parameter.Name.Replace("@", "").ToLower())) { continue; } if (parameter.HasMetaValue) { continue; } parameter.Name = parameter.Name.Replace("@", ""); var fromQueryString = report.Parameters.FirstOrDefault(x => x.Name.ToLower().Equals(parameter.Name.ToLower())); if (fromQueryString != null) { parameter.DefaultValue = DataSourceParameterHelper.CastValue(fromQueryString.Value, parameter.Type); } if (string.IsNullOrWhiteSpace(parameter.FieldLabel)) { parameter.FieldLabel = parameter.Name; } dbParams.Add(parameter); } } } var model = new ParameterMeta { ReportSourcePath = sourcePath, Parameters = dbParams, ReportTitle = report.Title }; return(this.View("~/Areas/Frapid.Reports/Views/Index.cshtml", model)); }
public void TestFixesDoNothing() { var goodText = File.ReadAllText(@"TestData\Normal.app", Encoding.UTF8); var goodReport = ReportParser.Parse(new StringReader(goodText), ReportParser.BySchemaIndex); /* Bug fixes recognize good data and return the same report. */ Assert.AreSame(goodReport, goodReport.FixCompanyRows()); Assert.AreSame(goodReport, goodReport.FixRowOrder()); }
public void should_parse_empty_report() { var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(report.Features).IsEmpty(); Check.That(report.Start).IsNull(); Check.That(report.End).IsNull(); Check.That(report.Duration).IsNull(); }
public void should_parse_scenario_status_when_scenario_is_failed() { Reporter.ScenarioStarted(_feature.Title, _scenarioTitle); Reporter.MarkScenarioAsFailed(_feature.Title, _scenarioTitle); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestScenario(report).Status).IsEqualTo(ScenarioStatus.Failed); }
public void should_parse_scenario() { Reporter.ScenarioStarted(_feature.Title, _scenarioTitle); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(report.Features.First().Scenarios).CountIs(1); Check.That(LatestScenario(report).Title).IsEqualTo(_scenarioTitle); }
public void TestReadWrite() { var originalBytes = File.ReadAllBytes(@"TestData\Normal.app"); var reader = new StreamReader(new MemoryStream(originalBytes)); var report = ReportParser.Parse(reader, ReportParser.BySchemaIndex); var outputBytes = Encoding.UTF8.GetBytes(report.ToString()); CollectionAssert.AreEqual(originalBytes, outputBytes); }
public static ParameterMeta GetDefinition(string path, string query, string tenant, HttpRequestBase request) { string sourcePath = "/dashboard/reports/source/" + path + query; var locator = new ReportLocator(); path = locator.GetPathToDisk(tenant, path); var parameters = ParameterHelper.GetParameters(request?.QueryString); var parser = new ReportParser(path, tenant, parameters); var report = parser.Get(); var dbParams = new List <DataSourceParameter>(); if (report.DataSources != null) { foreach (var dataSource in report.DataSources) { foreach (var parameter in dataSource.Parameters) { if (dbParams.Any(x => x.Name.ToLower() == parameter.Name.Replace("@", "").ToLower())) { continue; } if (parameter.HasMetaValue) { continue; } parameter.Name = parameter.Name.Replace("@", ""); var fromQueryString = report.Parameters.FirstOrDefault(x => x.Name.ToLower().Equals(parameter.Name.ToLower())); if (fromQueryString != null) { parameter.DefaultValue = DataSourceParameterHelper.CastValue(fromQueryString.Value, parameter.Type); } if (string.IsNullOrWhiteSpace(parameter.FieldLabel)) { parameter.FieldLabel = parameter.Name; } dbParams.Add(parameter); } } } var model = new ParameterMeta { ReportSourcePath = sourcePath, Parameters = dbParams, ReportTitle = report.Title }; return(model); }
public void TestFixMissingRows() { var buggyText = File.ReadAllText(@"TestData\MissingCompanyRows.app", Encoding.UTF8); var buggyReport = ReportParser.Parse(new StringReader(buggyText), ReportParser.BySchemaIndex); Assert.IsFalse(buggyReport.Documents.All(o => o.GetRows().First().Type == "Company")); var fixedReport = buggyReport.FixCompanyRows(); Assert.IsTrue(fixedReport.Documents.All(o => o.GetRows().First().Type == "Company")); }
public void should_parse_report_start_time() { var start = DateTime.Parse("2010/02/03 15:30:20"); GotoTimeAndStartTestSuite(start); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(report.Start.Value).IsEqualTo(start); }
public void should_parse_report_end_time() { var end = DateTime.Parse("2010/02/03 17:30:20"); GotoTimeAndEndTestSuite(end); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(report.End.Value).IsEqualTo(end); }
public void should_parse_features() { Reporter.FeatureStarted(_feature.Title, _feature.Description); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(report.Features).CountIs(1); Check.That(report.Features.First().Title).IsEqualTo(_feature.Title); Check.That(report.Features.First().Description).IsEqualTo(_feature.Description); }
public void should_parse_events_in_steps() { const string eventText = SampleEvents.AdminAttemptsToDefineUsers; Reporter.StepStarted(_feature.Title, _scenarioTitle, _step); Reporter.EventPublished(_feature.Title, _scenarioTitle, eventText); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestStep(report).Events).ContainsExactly(eventText); }
public void should_parse_scenario_start_time() { var start = DateTime.Parse("2010/01/02 15:00:00"); TimeTravelTo(start); Reporter.ScenarioStarted(_feature.Title, _scenarioTitle); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestScenario(report).Start).IsEqualTo(start); }
public void TestRemap() { var normalBytes = File.ReadAllBytes(@"TestData\Normal.app"); var reader = new StreamReader(new MemoryStream(normalBytes)); var normalReport = ReportParser.Parse(reader, ReportParser.BySchemaIndex); var changedText = File.ReadAllText(@"TestData\ColumnOrderChanged.app"); var changedReport = ReportParser.Parse(new StringReader(changedText), ReportParser.BySchemaIndex); var remappedReport = normalReport.Schema.Remap(changedReport.Documents); var remappedBytes = Encoding.UTF8.GetBytes(remappedReport.ToString()); CollectionAssert.AreEqual(normalBytes, remappedBytes); }
public void should_parse_scenario_end_time() { Reporter.ScenarioStarted(_feature.Title, _scenarioTitle); var end = DateTime.Parse("2010/01/02 16:00:00"); TimeTravelTo(end); Reporter.MarkScenarioAsPassed(_feature.Title, _scenarioTitle); var report = ReportParser.Parse(Reporter.ExportXml()); Check.That(LatestScenario(report).End).IsEqualTo(end); }
private void SetTitle() { string title = XmlHelper.GetNodeText(this.reportPath, "/MixERPReport/Title"); this.reportTitleLiteral.Text = ReportParser.ParseExpression(title); this.reportTitleHidden.Value = this.reportTitleLiteral.Text; if (!string.IsNullOrWhiteSpace(this.reportTitleLiteral.Text)) { this.Page.Title = this.reportTitleLiteral.Text; } }
public ActionResult Report(long id, [FromForm] string data) { var bot = bots.Get(id); var reporter = new ReportParser(); var result = reporter.ParseReport(bot, data); bot.ApplyTools(); bots.Update(bot); return(Ok(result)); }
private void SetTitle(Assembly callingAssembly) { string title = XmlHelper.GetNodeText(this.reportPath, "/MixERPReport/Title"); string reportTitle = ReportParser.ParseExpression(title, this.dataTableCollection, callingAssembly); this.reportTitleLiteral.Text = @"<h2>" + reportTitle + @"</h2>"; this.reportTitleHidden.Value = reportTitle; if (!string.IsNullOrWhiteSpace(reportTitle)) { this.Page.Title = reportTitle; } }
public void ParserTest() { StreamReader input = StringToStream(Resources.LangExample); List <Token> tokens = Lexer.ExampleLang.Lang.SearchTokens(input); tokens.RemoveAll((Token t) => t.Type.Name.Contains("CH_")); Console.WriteLine(string.Join("\n", tokens)); input.Close(); ReportParser report = Parser.ExampleLang.Lang.Check(tokens); Console.WriteLine(string.Join("\n", report.Info)); Assert.IsTrue(report.IsSuccess); }