public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; parsingContext.SceneContext.Reset(); if (string.IsNullOrWhiteSpace(parsedText)) { var node = new PauseNode(myContext.When); parentParsingContext.AddNode(node); return; } var value = int.Parse(parsedText); if (value <= 0) { parsingContext.LogError(reader, "O tempo de espera precisa ser maior que zero."); return; } if (value > 5000) { parsingContext.LogError(reader, "O tempo de espera não pode ser maior que 5000."); return; } var timedPauseNode = new TimedPauseNode(TimeSpan.FromMilliseconds(value), myContext.When); parentParsingContext.AddNode(timedPauseNode); }
public async Task Empty() { A.CallTo(() => context.LogError(reader, "Elemento filho era esperado.")).DoesNothing(); A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings)).DoesNothing(); var result = await sut.ParseAsync(reader, context); result.Should().BeEmpty(); A.CallTo(() => context.LogError(reader, "Elemento filho era esperado.")).MustHaveHappenedOnceExactly(); }
public void InvalidPatterns(string expression) { const string message = "Expressão 'Set' inválida."; A.CallTo(() => context.LogError(reader, message)).DoesNothing(); var sut = new VarSetTextParser(); sut.Parse(reader, context, expression); A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly(); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new BalloonChildParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.ParsedText is null) { return; } var textSourceParsingResult = textSourceParser.Parse(myContext.ParsedText); if (textSourceParsingResult.IsError) { parsingContext.LogError(reader, textSourceParsingResult.ErrorMessage); return; } var textSource = textSourceParsingResult.TextSource; if (reader.ReadState != ReadState.EndOfFile) { await elementParser.ParseAsync(reader, parsingContext, myContext, AggregationSettings); } var node = new BalloonTextNode(textSource, BalloonType, myContext.ChoiceNode); parentParsingContext.AddNode(node); parsingContext.SceneContext.Reset(); }
public async Task ContextArgument() { var reader = new StringReader("<storyboard />"); A.CallTo(() => parsingContext.IsSuccess).Returns(false); A.CallTo(() => parsingContext.ToString()).Returns("Erro proposital"); A.CallTo(() => parsingContext.LogError(A<XmlReader>.Ignored, "Erro proposital")).DoesNothing(); A.CallTo(() => rootBlockParser.ParseAsync(A<XmlReader>.Ignored, parsingContext)) .ReturnsLazily(i => { var reader = i.GetArgument<XmlReader>(0); var context = i.GetArgument<IParsingContext>(1); context.LogError(reader, "Erro proposital"); return Task.FromResult(new List<INode>()); }); var ex = await Assert.ThrowsAsync<ParsingException>( () => sut.ParseAsync(reader) ); ex.Message.Should().Be("Erro proposital"); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var context = new BackgroundContext(); await elementParser.ParseAsync(reader, parsingContext, context, Settings); if (!string.IsNullOrWhiteSpace(context.ParsedText)) { var state = new BackgroundState(context.ParsedText, BackgroundType.Image, BackgroundPosition.Left); var block = parsingContext.BlockFactory.Create( new BackgroundNode(state, null), new ScrollNode(null) ); parentParsingContext.AddNode(new BlockNode(block, context.When)); parsingContext.RegisterDismissNode(DismissNode); return; } if (context.Nodes.Count == 0) { parsingContext.LogError(reader, "Nome de imagem ou elemento filho era esperado."); return; } { var block = parsingContext.BlockFactory.Create(context.Nodes); parentParsingContext.AddNode(new BlockNode(block, context.When)); parsingContext.RegisterDismissNode(DismissNode); } }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.ParsedText is null) { return; } var value = int.Parse(myContext.ParsedText); if (value < 1) { return; } if (value > 30000) { parsingContext.LogError(reader, "O limite de tempo não pode ser maior que 30 segundos."); return; } var ctx = (ChoiceParentParsingContext)parentParsingContext; ctx.Choice.TimeLimit = TimeSpan.FromMilliseconds(value); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new BlockParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; if (parsedText is null) { return; } if (parsedText.Length == 0) { parsingContext.LogError(reader, "Era esperado o nome do personagem."); return; } if (reader.ReadState == ReadState.EndOfFile) { return; } await elementParser.ParseAsync(reader, parsingContext, myContext, AggregationSettings); if (myContext.Nodes.Count == 0) { return; } if (parsingContext.SceneContext.HasMood) { parsingContext.LogError(reader, "Foi definido humor mas não foi definida uma fala ou pensamento correspondente."); return; } myContext.Nodes.Insert(0, InitializeMoodNode); myContext.Nodes.Add(DismissMoodNode); var block = parsingContext.BlockFactory.Create(myContext.Nodes); var node = new PersonNode(parsedText, block); parentParsingContext.AddNode(node); }
public IAttribute?Parse(XmlReader reader, IParsingContext parsingContext) { if (ConditionParser.TryParse(reader.Value, out var condition)) { return(new WhenAttribute(condition)); } parsingContext.LogError(reader, "Condição 'when' inválida."); return(null); }
public async Task ShouldLogErrorIfParserReturnsNull() { const string message = "Expressão de atribuição de variável inválida."; const string parsedText = "alpha=1"; A.CallTo(() => context.LogError(reader, message)).DoesNothing(); A.CallTo(() => varSetParser.Parse(parsedText)).Returns(null); A.CallTo(() => elementParser.ParseAsync(reader, context, A <IParentParsingContext> .Ignored, sut.Settings)) .Invokes(i => i.GetArgument <IParentParsingContext>(2).ParsedText = parsedText); await sut.ParseAsync(reader, context, parentContext); parentContext.ShouldBeEmpty(); A.CallTo(() => varSetParser.Parse(parsedText)).MustHaveHappenedOnceExactly(); A.CallTo(() => context.LogError(reader, message)).MustHaveHappenedOnceExactly(); }
public IAttribute?Parse(XmlReader reader, IParsingContext parsingContext) { var result = conditionParser.Parse(reader.Value); if (result.Condition is not null) { return(new WhenAttribute(result.Condition)); } parsingContext.LogError(reader, "Condição 'when' inválida. " + result.Message); return(null); }
public async Task <List <INode> > ParseAsync(XmlReader reader, IParsingContext parsingContext) { var context = new BlockParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, context, Settings); if (context.Nodes.Count == 0) { parsingContext.LogError(reader, "Elemento filho era esperado."); } return(context.Nodes); }
public string?Parse(XmlReader reader, IParsingContext parsingContext, string value) { if (string.IsNullOrWhiteSpace(value)) { return(null); } if (Regex.IsMatch(value, @"[^A-Za-z0-9_\r\n\. ]")) { parsingContext.LogError(reader, $"O texto '{value}' contém caracteres inválidos."); return(null); } var result = value.ReplaceLineEndings(string.Empty).Trim(); if (result.Length <= 64) { return(result); } parsingContext.LogError(reader, $"O texto contém {result.Length} caracteres, o que excede a quantidade máxima de 64."); return(null); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new ChoiceParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.Choice.Options.Count == 0) { parsingContext.LogError(reader, "Nenhuma opção informada."); return; } var ctx = (BalloonChildParsingContext)parentParsingContext; ctx.ChoiceNode = myContext.Choice; }
public string?Parse(XmlReader reader, IParsingContext parsingContext, string value) { if (string.IsNullOrWhiteSpace(value)) { return(string.Empty); } if (!Regex.IsMatch(value, @"^(#[a-f0-9]{6}|black|green|silver|gray|olive|white|yellow|maroon|navy|red|blue|purple|teal|fuchsia|aqua)$", RegexOptions.IgnoreCase)) { parsingContext.LogError(reader, $"O texto '{value}' não representa uma cor válida."); return(null); } return(value.ToLower()); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new BlockParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.Nodes.Count == 0) { parsingContext.LogError(reader, "Elemento filho era esperado."); return; } var block = parsingContext.BlockFactory.Create(myContext.Nodes, myContext.While); var node = new BlockNode(block, myContext.When); parentParsingContext.AddNode(node); }
public async Task <INode?> ParseAsync(XmlReader reader, IParsingContext parsingContext) { var parsed = await elementParser.ParseAsync(reader, parsingContext); if (parsed is null) { return(null); } if (parsed.Block is null || parsed.Block.IsEmpty()) { parsingContext.LogError(reader, "Nenhum comando de storyboard válido encontrado."); return(null); } return(new BlockNode(parsed.Block, null, null)); }
public string?Parse(XmlReader reader, IParsingContext parsingContext, string value) { if (string.IsNullOrWhiteSpace(value)) { return(string.Empty); } value = value.Trim(); if (!Regex.IsMatch(value, @"^\-?\d{1,9}$")) { parsingContext.LogError(reader, $"O texto '{value}' não representa um número inteiro válido."); return(null); } return(value); }
public string?Parse(XmlReader reader, IParsingContext parsingContext, string value) { if (string.IsNullOrWhiteSpace(value)) { return(null); } var result = Format(value); if (result.Length <= 64) { return(result); } parsingContext.LogError(reader, $"O texto contém {result.Length} caracteres, o que excede a quantidade máxima de 64."); return(null); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new ChoiceOptionParentParsingContext(); myContext.Option.Key = reader.LocalName; await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (string.IsNullOrWhiteSpace(myContext.Option.Text)) { parsingContext.LogError(reader, "O texto da opção não foi informado."); return; } var ctx = (ChoiceParentParsingContext)parentParsingContext; ctx.Choice.Options.Add(myContext.Option); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new BlockParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (reader.ReadState != ReadState.EndOfFile) { await elementParser.ParseAsync(reader, parsingContext, myContext, AggregationSettings); } var nonPauseNodes = new Stack <INode>(); for (var n = myContext.Nodes.Count - 1; n >= 0; n--) { var currentNode = myContext.Nodes[n]; if (currentNode is IPauseNode) { break; } nonPauseNodes.Push(currentNode); myContext.Nodes.RemoveAt(n); } if (myContext.Nodes.Count == 0) { parsingContext.LogError(reader, "Era esperado um elemento filho."); return; } var block = parsingContext.BlockFactory.Create(myContext.Nodes); var node = new BalloonNode(childParser.BalloonType, block); parentParsingContext.AddNode(node); while (nonPauseNodes.TryPop(out var nonPauseNode)) { parentParsingContext.AddNode(nonPauseNode); } return; }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.ParsedText is null) { return; } var result = conditionParser.Parse(myContext.ParsedText); if (result.Condition is null) { parsingContext.LogError(reader, "Condição EnabledWhen inválida. " + result.Message); return; } var ctx = (IChoiceOptionParentParsingContext)parentParsingContext; ctx.Option.EnabledWhen = result.Condition; }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); if (myContext.ParsedText is null) { return; } if (myContext.ParsedText.Length == 0) { parsingContext.LogError(reader, "Era esperado o nome da cor."); return; } var state = new BackgroundState(myContext.ParsedText, BackgroundType.Color, BackgroundPosition.Undefined); var node = new BackgroundNode(state, myContext.When); parentParsingContext.AddNode(node); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; if (parsedText is null) { return; } var varSet = varSetParser.Parse(parsedText); if (varSet is null) { parsingContext.LogError(reader, "Expressão de atribuição de variável inválida."); } else { parentParsingContext.AddNode(new VarSetNode(varSet)); } }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; if (parsedText is null) { return; } if (parsingContext.SceneContext.HasMood) { parsingContext.LogError(reader, "Mais de uma definição de humor para a mesma cena."); return; } parsingContext.SceneContext.HasMood = true; var moodType = Enum.Parse <MoodType>(parsedText); parentParsingContext.AddNode(new MoodNode(moodType)); }
public string?Parse(XmlReader reader, IParsingContext parsingContext, string value) { if (!string.IsNullOrWhiteSpace(value)) { if (Regex.IsMatch(value, IntegerSetPattern)) { return(value); } if (Regex.IsMatch(value, IntegerIncrementPattern)) { return(value); } if (Regex.IsMatch(value, StringSetPattern)) { return(value); } } parsingContext.LogError(reader, "Expressão 'Set' inválida."); return(null); }
public async Task ParseAsync(XmlReader reader, IParsingContext parsingContext, IParentParsingContext parentParsingContext) { var myContext = new TextParentParsingContext(); await elementParser.ParseAsync(reader, parsingContext, myContext, Settings); var parsedText = myContext.ParsedText; if (parsedText is null) { return; } if (parsingContext.SceneContext.HasMusic) { parsingContext.LogError(reader, "Mais de uma definição de música para a mesma cena."); return; } parsingContext.SceneContext.HasMusic = true; var node = new MusicNode(parsedText.Length == 0 ? null : parsedText, myContext.When); parentParsingContext.AddNode(node); parsingContext.RegisterDismissNode(DismissNode); }