public DiscontinuousNumberException(BaseDecoratedNumber decoratedNumber, int expectedNumber) : base(decoratedNumber, $"遇到题号 \"{decoratedNumber.RawRepresentation}\" " + $"(={decoratedNumber.Number.IntNumber}), " + $"但此处应为{expectedNumber}") { ExpectedNumber = expectedNumber; }
public string GetDecoratedNumberDifferentiator(BaseDecoratedNumber number) { var numberDifferentiator = GetNumberDifferentiator(number.Number); switch (number) { case BracketDecoratedNumber bracketDecoratedNumber: var left = NormalizeBracket(bracketDecoratedNumber.LeftBracket); var right = NormalizeBracket(bracketDecoratedNumber.RightBracket); return($"{left}{numberDifferentiator}{right}"); case DelimiterDecoratedNumber delimiterDecoratedNumber: var delimiter = NormalizeDelimiter(delimiterDecoratedNumber.Delimiter); if (number.Number is ChineseNumber) { return($"{numberDifferentiator}"); } return($"{numberDifferentiator}{delimiter}".ToUpper()); case UndecoratedNumber undecoratedNumber: return($"{numberDifferentiator}".ToUpper()); default: return(string.Empty); } }
public NumberNode(BaseNumberNode parent, BaseDecoratedNumber number, int paragraphOrder) { DecoratedNumber = number; ParagraphOrder = paragraphOrder; Parent = parent; Level = parent.Level + 1; }
private void AddNew(BaseNumberNode parent, BaseDecoratedNumber child, string differentiator, int paragraphOrder) { var node = new NumberNode(parent, child, paragraphOrder); parent.ChildDifferentiator = differentiator; parent.Children.Add(node); Current = node; _differentiatorSetInCurrentChain.Add(differentiator); _differentiatorLevelPropsMapping[differentiator] = new LevelProps { Level = Current.Level, MaxNumber = child.Number.IntNumber, }; }
private void ContinueLevel(BaseDecoratedNumber currentNumber, string differentiator, int paragraphOrder) { if (Current == null) { throw new ArgumentNullException("Current node cannot be null"); } if (Current.DecoratedNumber.Number.IntNumber + 1 != currentNumber.Number.IntNumber) { throw new DiscontinuousNumberException(currentNumber, Current.DecoratedNumber.Number.IntNumber + 1); } var node = new NumberNode(Current.Parent, currentNumber, paragraphOrder); Current.Parent.Children.Add(node); Current = node; _differentiatorLevelPropsMapping[differentiator] = new LevelProps { Level = Current.Level, MaxNumber = currentNumber.Number.IntNumber, }; }
public StartFromNonFirstNumberException(BaseDecoratedNumber decoratedNumber) : base(decoratedNumber, $"遇到题号 \"{decoratedNumber.RawRepresentation}\" " + $"(={decoratedNumber.Number.IntNumber}), " + $"但该类型({decoratedNumber.GetType().Name}, {decoratedNumber.Number.GetType().Name})第一次出现,应为1") { }
protected InvalidNumberException(BaseDecoratedNumber decoratedNumber, SerializationInfo info, StreamingContext context) : base(info, context) { DecoratedNumber = decoratedNumber; }
public InvalidNumberException(BaseDecoratedNumber decoratedNumber, string message, Exception innerException) : base(message, innerException) { DecoratedNumber = decoratedNumber; }
public InvalidNumberException(BaseDecoratedNumber decoratedNumber) { DecoratedNumber = decoratedNumber; }
protected ReadingParagraphNumberException(BaseDecoratedNumber decoratedNumber, SerializationInfo info, StreamingContext context) : base(info, context) { DecoratedNumber = decoratedNumber; }
public ReadingParagraphNumberException(BaseDecoratedNumber decoratedNumber, string message, Exception innerException) : base(message, innerException) { DecoratedNumber = decoratedNumber; }
public ReadingParagraphNumberException(BaseDecoratedNumber decoratedNumber) { DecoratedNumber = decoratedNumber; }
public NumberNode AddNumber(BaseDecoratedNumber decoratedNumber, int paragraphOrder) { var differentiator = _numberDifferentiator.GetDecoratedNumberDifferentiator(decoratedNumber); var number = decoratedNumber.Number.IntNumber; if (_readingParagraphNumberDifferentiator.Contains(differentiator)) { throw new ReadingParagraphNumberException(decoratedNumber); } if (Current == null) { // Init should start from 1 if (number == 1 || (_allowFirstNumberForDifferentiators.TryGetValue(differentiator, out var maxNumber) && number == maxNumber)) { AddNew(Root, decoratedNumber, differentiator, paragraphOrder); } else { throw new StartFromNonFirstNumberException(decoratedNumber); } } else if (Current.Parent.ChildDifferentiator == differentiator) { // Continue current level ContinueLevel(decoratedNumber, differentiator, paragraphOrder); } else if (_differentiatorSetInCurrentChain.Contains(differentiator)) { // Back to up level of current chain Current = GoUpLevel(Current, differentiator) ?? throw new InvalidOperationException( $"Differentiator \"{differentiator}\" should exist in up level"); // Continue this level ContinueLevel(decoratedNumber, differentiator, paragraphOrder); } else if (_differentiatorLevelPropsMapping.TryGetValue(differentiator, out var levelProps)) // && number == levelProps.MaxNumber + 1) { if (_numberDifferentiator.AllowedDifferentiatorToSpanParents.Contains(differentiator)) { // Continue previous level AddNew(Current, decoratedNumber, differentiator, paragraphOrder); } else if (number == 1 || (_allowFirstNumberForDifferentiators.TryGetValue(differentiator, out var maxNumber) && number == maxNumber)) { // Don't allow to span parents, then check if it's a new level. // If so, add new level AddNew(Current, decoratedNumber, differentiator, paragraphOrder); } else { throw new StartFromNonFirstNumberException(decoratedNumber); } } else { // New Level, should start from 1 if (number == 1 || (_allowFirstNumberForDifferentiators.TryGetValue(differentiator, out var maxNumber) && number == maxNumber)) { AddNew(Current, decoratedNumber, differentiator, paragraphOrder); } else { throw new StartFromNonFirstNumberException(decoratedNumber); } } if (Current == null) { throw new InvalidOperationException("Current node shouldn't be null now"); } return(Current); }