Esempio n. 1
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);
            }
        }
Esempio n. 2
0
        private void AddDictionaryContent(IParsingSourceStream sourceStream, ResourceDictionary wrapped, Windows.UI.Xaml.ResourceDictionary dictionary, List <string> FileNames)
        {
            foreach (object Key in dictionary.Keys)
            {
                if (!wrapped.Contains(Key))
                {
                    wrapped.Add(Key, dictionary[Key]);
                }
                else
                {
                    throw new ParsingException(92, sourceStream, $"Key '{Key}' found multiple times.");
                }
            }

            foreach (Windows.UI.Xaml.ResourceDictionary Item in dictionary.MergedDictionaries)
            {
                if (Item.Source != null)
                {
                    IParsingSourceStream NestedSourceStream = ParsingSourceStream.CreateFromFileName(Item.Source.AbsolutePath, sourceStream.ConditionalDefineTable);

                    ResourceDictionary NestedContent;
                    List <string>      NestedFileNames;
                    LoadResourceFile(NestedSourceStream, out NestedContent, out NestedFileNames);

                    AddDictionaryContent(NestedSourceStream, wrapped, NestedContent);
                    FileNames.AddRange(NestedFileNames);
                }
            }
        }
Esempio 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);
            }
        }
Esempio n. 4
0
        public override ILayout Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            try
            {
                XamlSchemaContext Context = GetContext();
                using (SourceStream.OpenXamlFromFile(Context))
                {
                    if (SourceStream.IsEmpty)
                    {
                        return(null);
                    }

                    return(Parse(fileName, SourceStream));
                }
            }
            catch (ParsingException)
            {
                throw;
            }
            catch (Exception e)
            {
                throw new ParsingException(93, SourceStream, e);
            }
        }
Esempio n. 5
0
        public static IParsingSourceStream CreateFromFileName(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            ParsingSourceStream Result = new ParsingSourceStream();

            Result.FileName = fileName;
            Result.ConditionalDefineTable = conditionalDefineTable;

            return(Result);
        }
Esempio n. 6
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++;
                }
            }
        }
Esempio n. 7
0
        public override IBackground Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            string Name = Path.GetFileNameWithoutExtension(fileName);
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            List <string> Lines;

            LoadResourceFile(SourceStream, out Lines);

            return(new Background(Name, ParserDomain.ToXamlName(SourceStream, Name, "Background"), Lines));
        }
Esempio n. 8
0
        public override IDesign Parse(string fileName, IDictionary <ConditionalDefine, bool> conditionalDefineTable)
        {
            IParsingSourceStream SourceStream = ParsingSourceStream.CreateFromFileName(fileName, conditionalDefineTable);

            ResourceDictionary Content;
            List <string>      FileNames;

            LoadResourceFile(SourceStream, out Content, out FileNames);

            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Button)))
            {
                throw new ParsingException(82, SourceStream, "Missing 'Button' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.TextBox)))
            {
                throw new ParsingException(83, SourceStream, "Missing 'TextBox' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Image)))
            {
                throw new ParsingException(84, SourceStream, "Missing 'Image' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.ListBox)))
            {
                throw new ParsingException(85, SourceStream, "Missing 'ListBox' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.TextBlock)))
            {
                throw new ParsingException(86, SourceStream, "Missing 'TextBlock' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.RadioButton)))
            {
                throw new ParsingException(87, SourceStream, "Missing 'RadioButton' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.CheckBox)))
            {
                throw new ParsingException(88, SourceStream, "Missing 'CheckBox' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.PasswordBox)))
            {
                throw new ParsingException(89, SourceStream, "Missing 'PasswordBox' style.");
            }
            if (!IsTypeStyleFound(Content, typeof(Windows.UI.Xaml.Controls.Primitives.ToggleButton)))
            {
                throw new ParsingException(206, SourceStream, "Missing 'ToggleButton' style.");
            }

            string MainFileName = FileNames[0];
            string Name         = Path.GetFileNameWithoutExtension(MainFileName);

            return(new Design(FileNames, ParserDomain.ToXamlName(SourceStream, Name, "Design"), Content));
        }
Esempio n. 9
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);
            }
        }
Esempio n. 10
0
 public LayoutElement()
 {
     Source = ParsingSourceStream.GetCurrentSource();
 }
Esempio n. 11
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++;
                }
            }
        }