private void ConnectSize(IParsingSource source, BinaryReader br) { byte[] Signature = br.ReadBytes(8); if (Signature[1] != 0x50 || Signature[2] != 0x4E || Signature[3] != 0x47) { throw new ParsingException(185, source, "Invalid PNG file."); } byte[] Chunk = br.ReadBytes(8); int ChunkLength = BitConverter.ToInt32(Chunk, 0); if (ChunkLength < 13) { throw new ParsingException(185, source, "Invalid PNG file."); } byte[] ChunkData = br.ReadBytes(13); Width = (((((ChunkData[0] << 8) + ChunkData[1]) << 8) + ChunkData[2]) << 8) + ChunkData[3]; Height = (((((ChunkData[4] << 8) + ChunkData[5]) << 8) + ChunkData[6]) << 8) + ChunkData[7]; if (Width <= 0 || Height <= 0) { throw new ParsingException(185, source, "Invalid PNG file."); } }
public static string ToXamlName(IParsingSource source, string name, string suffix) { if (string.IsNullOrEmpty(name)) { throw new ParsingException(17, source, "Empty name not valid."); } string Result = ""; for (int i = 0; i < name.Length; i++) { if (IsValidIdentifierSymbol(name[i], i)) { Result += name[i]; } else { Result += '_'; } } if (!IsIdentifierValid(Result)) { throw new ParsingException(18, source, $"'{name}' only contains invalid characters."); } return(Result + suffix); }
private IPage Parse(string name, IParsingSourceStream sourceStream) { IComponentEvent QueryEvent = null; IDeclarationSource AreaSource = null; IParsingSource AllAreaLayoutsSource = null; Dictionary <IDeclarationSource, string> AreaLayoutsPairs = null; IDeclarationSource DesignSource = null; IDeclarationSource WidthSource = null; IDeclarationSource HeightSource = null; bool IsScrollable = false; IDeclarationSource BackgroundSource = null; IDeclarationSource BackgroundColorSource = null; string Tag = null; while (!sourceStream.EndOfStream) { sourceStream.ReadLine(); string Line = sourceStream.Line; if (!string.IsNullOrWhiteSpace(Line)) { ParseComponent(sourceStream, ref QueryEvent, ref AreaSource, ref AllAreaLayoutsSource, ref AreaLayoutsPairs, ref DesignSource, ref WidthSource, ref HeightSource, ref IsScrollable, ref BackgroundSource, ref BackgroundColorSource, ref Tag); } } if (AreaSource == null || string.IsNullOrEmpty(AreaSource.Name)) { throw new ParsingException(109, sourceStream, "Missing area name."); } if (AreaLayoutsPairs == null) { throw new ParsingException(110, sourceStream, "Missing default area layout."); } if (DesignSource == null || string.IsNullOrEmpty(DesignSource.Name)) { throw new ParsingException(111, sourceStream, "Missing design name."); } if (WidthSource == null || string.IsNullOrEmpty(WidthSource.Name)) { throw new ParsingException(112, sourceStream, "Missing width."); } if (HeightSource == null || string.IsNullOrEmpty(HeightSource.Name)) { throw new ParsingException(113, sourceStream, "Missing height."); } if (BackgroundColorSource == null || string.IsNullOrEmpty(BackgroundColorSource.Name)) { throw new ParsingException(114, sourceStream, "Missing background color."); } return(new Page(name, ParserDomain.ToCSharpName(sourceStream, name + "Page"), ParserDomain.ToXamlName(sourceStream, name, "Page"), QueryEvent, AreaSource, AllAreaLayoutsSource, AreaLayoutsPairs, DesignSource, WidthSource, HeightSource, IsScrollable, BackgroundSource, BackgroundColorSource, Tag)); }
public ParsingException(int code, IParsingSource parsingSource, string message, [CallerLineNumber] int lineNumber = 0, [CallerFilePath] string filePath = null, [CallerMemberName] string caller = null) : base(message) { Code = code; Directory = null; ParsingSource = parsingSource; LineNumber = lineNumber; FilePath = ShortFilePath(filePath); Caller = caller; }
public Page(string name, string fileName, string xamlName, IComponentEvent queryEvent, IDeclarationSource areaSource, IParsingSource allAreaLayoutsSource, Dictionary <IDeclarationSource, string> areaLayoutPairs, IDeclarationSource designSource, IDeclarationSource widthSource, IDeclarationSource heightSource, bool isScrollable, IDeclarationSource backgroundSource, IDeclarationSource backgroundColorSource, string tag) { Name = name; FileName = fileName; XamlName = xamlName; QueryEvent = queryEvent; AreaSource = areaSource; AllAreaLayoutsSource = allAreaLayoutsSource; AreaLayoutPairs = areaLayoutPairs; DesignSource = designSource; WidthSource = widthSource; HeightSource = heightSource; IsScrollable = isScrollable; BackgroundSource = backgroundSource; BackgroundColorSource = backgroundColorSource; Tag = tag; }
public static string ToCSharpName(IParsingSource source, string name) { if (string.IsNullOrEmpty(name)) { throw new ParsingException(17, source, "Empty name not valid."); } string Result = ""; bool SetUpper = true; for (int i = 0; i < name.Length; i++) { if (IsValidIdentifierSymbol(name[i], i)) { if (SetUpper && name[i] != '_') { SetUpper = false; Result += name[i].ToString().ToUpper(); } else { Result += name[i]; } } else if (name[i] == ' ') { SetUpper = true; } else { Result += '_'; } } if (!IsIdentifierValid(Result)) { throw new ParsingException(18, source, $"'{name}' only contains invalid characters."); } return(Result); }
private void ParseComponent(IParsingSourceStream sourceStream, ref IComponentEvent queryEvent, ref IDeclarationSource areaSource, ref IParsingSource allAreaLayoutsSource, ref Dictionary <IDeclarationSource, string> areaLayoutsPairs, ref IDeclarationSource designSource, ref IDeclarationSource widthSource, ref IDeclarationSource heightSource, ref bool isScrollable, ref IDeclarationSource backgroundSource, ref IDeclarationSource backgroundColorSource, ref string tag) { string Line = sourceStream.Line; if (Line.Trim() == "scrollable") { isScrollable = true; return; } IDeclarationSource ComponentSource; string ComponentValue; ParserDomain.ParseStringPair(sourceStream, ':', out ComponentSource, out ComponentValue); //ComponentValue = ComponentValue.ToLower(); if (ComponentSource.Name == "open on query") { if (queryEvent == null) { queryEvent = ParseQueryEvent(sourceStream, ComponentValue); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "area") { if (areaSource == null) { areaSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "default area layout") { if (areaLayoutsPairs == null) { allAreaLayoutsSource = sourceStream.FreezedPosition(); areaLayoutsPairs = ParseAreaLayoutsPairs(sourceStream, ComponentValue); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "design") { if (designSource == null) { designSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "width") { if (widthSource == null) { widthSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "height") { if (heightSource == null) { heightSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "background") { if (backgroundSource == null) { backgroundSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "background color") { if (backgroundColorSource == null) { backgroundColorSource = new DeclarationSource(ComponentValue, sourceStream); } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else if (ComponentSource.Name == "tag") { if (tag == null) { tag = ComponentValue; } else { throw new ParsingException(125, sourceStream, $"Specifier '{ComponentSource.Name}' found more than once."); } } else { throw new ParsingException(115, sourceStream, $"Specifier '{ComponentSource.Name}' was unexpected."); } }