Exemplo n.º 1
0
        private void LoadResourceFile(IParsingSourceStream sourceStream, out ResourceDictionary content, out List <string> fileNames)
        {
            try
            {
                string FolderName = Path.GetDirectoryName(sourceStream.FileName);
                FolderName = FolderName.Replace("\\", "/");

                using (sourceStream.Open())
                {
                    string ContentString = sourceStream.ReadToEnd();
                    ContentString = ContentString.Replace("Source=\"/", $"Source=\"{FolderName}/");

                    XamlSchemaContext Context = GetContext(sourceStream);

                    using (sourceStream.OpenXamlFromString(ContentString, Context))
                    {
                        fileNames = new List <string>();
                        fileNames.Add(sourceStream.FileName);

                        content = LoadResourceFile(sourceStream, fileNames);
                    }
                }
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException(90, sourceStream, e);
            }
        }
Exemplo n.º 2
0
        public override IPage Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            string Name = Path.GetFileNameWithoutExtension(fileName);
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            try
            {
                using (SourceStream.Open())
                {
                    if (SourceStream.IsEmpty)
                    {
                        return(null);
                    }

                    return(Parse(Name, SourceStream));
                }
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException(108, SourceStream, e);
            }
        }
Exemplo n.º 3
0
        public override IUnitTest Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            try
            {
                using (SourceStream.Open())
                {
                    if (SourceStream.IsEmpty)
                    {
                        return(null);
                    }

                    return(Parse(fileName, SourceStream));
                }
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException(231, SourceStream, e);
            }
        }
Exemplo n.º 4
0
        public void Process(IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            PreprocessorDefineTable = new Dictionary <string, bool>();

            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(PreprocessorDefineFile, conditionalDefineTable);
            int LineNumber = 0;

            using (SourceStream.Open())
            {
                while (!SourceStream.EndOfStream)
                {
                    SourceStream.ReadLine();

                    string   Line     = SourceStream.Line;
                    string[] Splitted = Line.Split('=');

                    if (Splitted.Length != 2)
                    {
                        throw new ParsingException(0, SourceStream, $"Inconsistent format at line {LineNumber + 1}.");
                    }

                    else
                    {
                        string Define = Splitted[0].Trim();
                        if (!IsDefineValid(Define))
                        {
                            throw new ParsingException(0, SourceStream, $"Invalid define '{Define}' at line {LineNumber + 1}.");
                        }

                        if (PreprocessorDefineTable.ContainsKey(Define))
                        {
                            throw new ParsingException(0, SourceStream, $"'{Define}' at line {LineNumber + 1} already exist.");
                        }

                        string Value = Splitted[1].Trim();

                        int  ValueAsInt;
                        bool ValueAsBool;
                        if (int.TryParse(Value, out ValueAsInt) && (ValueAsInt == 0 || ValueAsInt == 1))
                        {
                            ValueAsBool = (ValueAsInt == 1);
                        }
                        else if (bool.TryParse(Value, out ValueAsBool))
                        {
                        }
                        else
                        {
                            throw new ParsingException(0, SourceStream, $"Invalid define value '{Value}' at line {LineNumber + 1}.");
                        }

                        PreprocessorDefineTable.Add(Define, ValueAsBool);
                    }

                    LineNumber++;
                }
            }
        }
Exemplo n.º 5
0
        public override IResource Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            string Name = Path.GetFileNameWithoutExtension(fileName);
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            try
            {
                using (SourceStream.Open())
                {
                    return(new Resource(Name, ParserDomain.ToXamlName(SourceStream, Name, "Resource"), fileName));
                }
            }
            catch (Exception e)
            {
                throw new ParsingException(116, SourceStream, e);
            }
        }
Exemplo n.º 6
0
        private void LoadResourceFile(IParsingSourceStream sourceStream, out List <string> Lines)
        {
            try
            {
                using (sourceStream.Open())
                {
                    Lines = new List <string>();

                    while (!sourceStream.EndOfStream)
                    {
                        sourceStream.ReadLine();
                        Lines.Add(sourceStream.Line);
                    }
                }
            }
            catch (Exception e)
            {
                throw new ParsingException(79, sourceStream, e);
            }
        }
Exemplo n.º 7
0
        public void Process(IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            TranslationTable = new Dictionary <string, IDictionary <string, string> >();
            LanguageList     = new List <string>();
            KeyList          = new List <string>();
            UsedKeyList      = new List <string>();
            int LineNumber = 0;

            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(TranslationFile, conditionalDefineTable);

            using (SourceStream.Open())
            {
                while (!SourceStream.EndOfStream)
                {
                    SourceStream.ReadLine();

                    string   Line     = SourceStream.Line;
                    string[] Splitted = Line.Split(Separator);

                    if (TranslationTable.Count == 0)
                    {
                        if (Splitted.Length < 2)
                        {
                            throw new ParsingException(178, SourceStream, "The translation file is expected to have a header.");
                        }

                        string KeyHeader = Splitted[0].Trim();
                        if (KeyHeader != "Key")
                        {
                            throw new ParsingException(179, SourceStream, "The translation file is expected to have a header starting with 'Key' for the first column.");
                        }

                        for (int i = 1; i < Splitted.Length; i++)
                        {
                            string Language = Splitted[i].Trim();
                            if (Language.Length == 0 || Language.Length >= 100)
                            {
                                throw new ParsingException(180, SourceStream, $"The translation file is expected to have the name of a language at the header of column #{i + 1}.");
                            }

                            if (TranslationTable.ContainsKey(Language))
                            {
                                throw new ParsingException(181, SourceStream, $"Language '{Language}' found more than once in the header.");
                            }

                            LanguageList.Add(Language);
                            TranslationTable.Add(Language, new Dictionary <string, string>());
                        }
                    }

                    else if (Splitted.Length != LanguageList.Count + 1)
                    {
                        throw new ParsingException(182, SourceStream, $"Inconsistent format at line {LineNumber + 1}.");
                    }

                    else
                    {
                        string Key = Splitted[0];
                        if (!IsKeyReserved(Key) && !IsKeyValid(Key))
                        {
                            throw new ParsingException(183, SourceStream, $"Invalid key '{Key}' at line {LineNumber + 1}.");
                        }

                        for (int i = 1; i < Splitted.Length; i++)
                        {
                            string Language = LanguageList[i - 1];
                            IDictionary <string, string> LanguageTable = TranslationTable[Language];

                            if (i == 1 && LanguageTable.ContainsKey(Key))
                            {
                                throw new ParsingException(184, SourceStream, $"Translation for key '{Key}' found at line {LineNumber + 1} but this key already has an entry.");
                            }

                            LanguageTable.Add(Key, Splitted[i].Trim());
                        }

                        KeyList.Add(Key);
                    }

                    LineNumber++;
                }
            }
        }