Beispiel #1
0
        public string GetComponentValue(IGeneratorPage currentPage, IGeneratorObject currentObject, IGeneratorResource resourceValue, IGeneratorObject objectValue, IGeneratorObjectProperty objectPropertyValue, IDeclarationSource key, bool isTwoWays)
        {
            if (resourceValue != null)
            {
                return($"{{StaticResource {resourceValue.XamlName}}}");
            }

            else if (objectValue != null && objectPropertyValue != null)
            {
                string Mode          = isTwoWays ? ", Mode=TwoWay" : "";
                string ObjectBinding = GetObjectBinding(currentObject, objectValue, objectPropertyValue);

                if (key == null)
                {
                    return($"{{Binding {ObjectBinding}{Mode}}}");
                }
                else if (key.Name == GeneratorPage.CurrentPage.Name)
                {
                    return($"{{Binding {ObjectBinding}{Mode}, Converter={{StaticResource convKeyToValue}}, ConverterParameter=page-{ParserDomain.ToKeyName(currentPage.Name)}}}");
                }
                else
                {
                    return($"{{Binding {ObjectBinding}{Mode}, Converter={{StaticResource convKeyToValue}}, ConverterParameter={key.Name}}}");
                }
            }

            else
            {
                throw new InvalidOperationException();
            }
        }
Beispiel #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();
        }