Esempio n. 1
0
        private string ReplaceTypeSyntax(string line, string prefix, string replace, bool renameType)
        {
            int TypeIndex = 0;

            while ((TypeIndex = line.IndexOf($"{prefix}{{x:Type ", TypeIndex)) >= 0)
            {
                int SeparatorIndex = line.IndexOf("}", TypeIndex);
                if (SeparatorIndex > TypeIndex + 8 + prefix.Length)
                {
                    string TypeName = line.Substring(TypeIndex + 8 + prefix.Length, SeparatorIndex - TypeIndex - 8 - prefix.Length);

                    if (renameType)
                    {
                        TypeName = ParserDomain.StyleTypeConverter(TypeName);
                    }

                    line = line.Substring(0, TypeIndex) + $"{prefix}{replace}" + TypeName + line.Substring(SeparatorIndex + 1);
                }
                else
                {
                    break;
                }
            }

            return(line);
        }
Esempio n. 2
0
        public void Verify()
        {
            foreach (IPage Page in Pages)
            {
                IFormCollection <IArea> UsedAreas = new FormCollection <IArea>();
                Dictionary <IArea, IDeclarationSource> SpecifiedAreas = new Dictionary <IArea, IDeclarationSource>();
                foreach (KeyValuePair <IArea, ILayout> Entry in Page.AreaLayouts)
                {
                    UsedAreas.Add(Entry.Key);
                }

                ListAreas(Page.Area, Page.AreaSource, UsedAreas, SpecifiedAreas);

                if (UsedAreas.Count > 0)
                {
                    IArea SpecifiedArea = UsedAreas[0];
                    if (Page.AreaLayoutBacktracks.ContainsKey(SpecifiedArea))
                    {
                        throw new ParsingException(9, Page.AreaLayoutBacktracks[SpecifiedArea].Source, $"Layout specified for area '{SpecifiedArea.Name}' but this area isn't used in page '{Page.Name}'.");
                    }
                    else
                    {
                        throw new ParsingException(9, Page.AreaSource.Source, $"Layout specified for area '{SpecifiedArea.Name}' but this area isn't used in page '{Page.Name}'.");
                    }
                }

                foreach (KeyValuePair <IArea, IDeclarationSource> Entry in SpecifiedAreas)
                {
                    IArea SpecifiedArea = Entry.Key;

                    if (!Page.AreaLayouts.ContainsKey(SpecifiedArea))
                    {
                        throw new ParsingException(10, Page.AllAreaLayoutsSource, $"Area '{SpecifiedArea.Name}' has not layout specified.");
                    }

                    if (ComponentProperty.AreaWithCurrentPage.ContainsKey(SpecifiedArea))
                    {
                        IDeclarationSource Declaration = ComponentProperty.AreaWithCurrentPage[SpecifiedArea];

                        string PageKey = ParserDomain.ToKeyName($"page {Page.Name}");
                        if (Translation == null)
                        {
                            throw new ParsingException(11, Declaration.Source, $"Translation key used in area '{SpecifiedArea.Name}' but no translation file provided.");
                        }
                        if (!Translation.KeyList.Contains(PageKey))
                        {
                            throw new ParsingException(12, Declaration.Source, $"Translation key for page '{Page.Name}' used in area '{SpecifiedArea.Name}' not found.");
                        }

                        if (!Translation.UsedKeyList.Contains(PageKey))
                        {
                            Translation.UsedKeyList.Add(PageKey);
                        }
                    }

                    ILayout SpecifiedLayout = Page.AreaLayouts[SpecifiedArea];
                    foreach (IComponent Component in SpecifiedArea.Components)
                    {
                        if (Component is IComponentWithEvent AsComponentWithEvent)
                        {
                            List <IControl> ControlList = new List <IControl>();
                            SpecifiedLayout.Content.ReportControlsUsingComponent(ControlList, AsComponentWithEvent);
                            if (ControlList.Count > 1)
                            {
                                throw new ParsingException(220, Component.Source.Source, $"Component '{Component.Source.Name}' is used more than once in page '{Page.Name}'.");
                            }
                        }
                    }
                }

                List <string> KeyList = new List <string>();
                foreach (KeyValuePair <IArea, ILayout> Entry in Page.AreaLayouts)
                {
                    Entry.Value.ReportResourceKeys(Page.Design, KeyList);
                }

                List <string> DesignKeyList = new List <string>();
                foreach (object Key in Page.Design.Root)
                {
                    if (Key is DictionaryEntry AsEntry)
                    {
                        if (AsEntry.Key is string AsStringKey)
                        {
                            DesignKeyList.Add(AsStringKey);
                        }
                        else if (AsEntry.Key is Type AsTypeKey)
                        {
                            DesignKeyList.Add($"{Page.Design.XamlName}{ParserDomain.StyleTypeConverter(AsTypeKey.Name)}");
                        }
                        else
                        {
                            throw new ParsingException(240, "", $"Unexpected key in design '{Page.Design.Name}'.");
                        }
                    }
                    else
                    {
                        throw new ParsingException(240, "", $"Unexpected key in design '{Page.Design.Name}'.");
                    }
                }

                foreach (string Key in KeyList)
                {
                    if (!DesignKeyList.Contains(Key) && !Key.EndsWith("DesignHtml"))
                    {
                        throw new ParsingException(241, "", $"Resource key '{Key}' not found in design '{Page.Design.Name}'.");
                    }
                }
            }

            VerifyAttachedProperties();
        }