public void LoadDataFromRibbon(XDocument docRibbon)
        {
            if (docRibbon == null)
            {
                return;
            }

            this.NextLoadFileDate = DateTime.Now.AddMinutes(_loadPeriodInMinutes);

            {
                var elementsCommandDefinitions = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/CommandDefinitions/CommandDefinition");

                foreach (var command in elementsCommandDefinitions)
                {
                    var id = command.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.CommandDefinitions.ContainsKey(id))
                        {
                            this.CommandDefinitions.Add(id, command);
                        }
                    }
                }
            }

            {
                var elementsEnableRules = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/RuleDefinitions/EnableRules/EnableRule");

                foreach (var enableRule in elementsEnableRules)
                {
                    var id = enableRule.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.EnableRules.ContainsKey(id))
                        {
                            this.EnableRules.Add(id, enableRule);
                        }
                    }
                }
            }

            {
                var elementsDisplayRules = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/RuleDefinitions/DisplayRules/DisplayRule");

                foreach (var displayRule in elementsDisplayRules)
                {
                    var id = displayRule.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.DisplayRules.ContainsKey(id))
                        {
                            this.DisplayRules.Add(id, displayRule);
                        }
                    }
                }
            }

            {
                var elementsLibraries = docRibbon.Descendants().Where(e => e.Attribute("Library") != null && !string.IsNullOrEmpty(e.Attribute("Library").Value));

                foreach (var library in elementsLibraries)
                {
                    var value = library.Attribute("Library")?.Value;

                    if (!string.IsNullOrEmpty(value) &&
                        !value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        this.Libraries.Add(value);
                    }
                }
            }

            {
                var elementsFunctionNames = docRibbon.Descendants().Where(e => e.Attribute("FunctionName") != null && !string.IsNullOrEmpty(e.Attribute("FunctionName").Value));

                foreach (var functionName in elementsFunctionNames)
                {
                    var value = functionName.Attribute("FunctionName")?.Value;

                    if (!string.IsNullOrEmpty(value))
                    {
                        this.FunctionsNames.Add(value);
                    }
                }
            }

            {
                var elementsLables = docRibbon.Descendants().Where(e => e.Attributes().Any(a => XmlCompletionSource.LabelXmlAttributes.Contains(a.Name.LocalName) && !string.IsNullOrEmpty(a.Value)));

                foreach (var label in elementsLables)
                {
                    if (!string.Equals(label.Name.LocalName, "Layout", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        foreach (var attr in label.Attributes().Where(a => !string.IsNullOrEmpty(a.Value)))
                        {
                            if (XmlCompletionSource.LabelXmlAttributes.Contains(attr.Name.LocalName))
                            {
                                this.LabelTexts.Add(attr.Value);
                            }
                        }
                    }
                }
            }

            {
                var elementsImages = docRibbon.Descendants().Where(e => e.Attributes().Any(a => XmlCompletionSource.ImagesXmlAttributes.Contains(a.Name.LocalName) &&
                                                                                           !string.IsNullOrEmpty(a.Value) &&
                                                                                           !a.Value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                                                                                           ));

                foreach (var label in elementsImages)
                {
                    foreach (var attr in label.Attributes().Where(a => !string.IsNullOrEmpty(a.Value)))
                    {
                        if (XmlCompletionSource.ImagesXmlAttributes.Contains(attr.Name.LocalName) &&
                            !attr.Value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                            )
                        {
                            this.Images.Add(attr.Value);
                        }
                    }
                }
            }

            {
                var elementsModernImages = docRibbon.Descendants().Where(e => e.Attribute("ModernImage") != null && !string.IsNullOrEmpty(e.Attribute("ModernImage").Value));

                foreach (var modernImage in elementsModernImages)
                {
                    var value = modernImage.Attribute("ModernImage")?.Value;

                    if (!string.IsNullOrEmpty(value))
                    {
                        this.ModernImages.Add(value);
                    }
                }
            }

            {
                var elementsControls = docRibbon.Descendants("Controls");

                foreach (var controls in elementsControls)
                {
                    var id = controls.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.Locations.ContainsKey(id))
                        {
                            var newItem = new RibbonLocation()
                            {
                                Id = id,
                            };

                            this.Locations.Add(id, newItem);

                            foreach (var item in controls.Elements())
                            {
                                newItem.Controls.Add(new RibbonLocationControl()
                                {
                                    ControlType = item.Name.LocalName,
                                    Id          = item.Attribute("Id")?.Value,
                                    Sequence    = item.Attribute("Sequence")?.Value,
                                    LabelText   = item.Attribute("LabelText")?.Value,
                                    Command     = item.Attribute("Command")?.Value,
                                });
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public void LoadDataFromRibbon(XDocument docRibbon)
        {
            ClearData();

            if (docRibbon == null)
            {
                return;
            }

            {
                var elementsCommandDefinitions = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/CommandDefinitions/CommandDefinition");

                foreach (var command in elementsCommandDefinitions)
                {
                    var id = command.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.CommandDefinitions.ContainsKey(id))
                        {
                            this.CommandDefinitions.TryAdd(id, command);
                        }
                    }
                }
            }

            {
                var elementsEnableRules = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/RuleDefinitions/EnableRules/EnableRule");

                foreach (var enableRule in elementsEnableRules)
                {
                    var id = enableRule.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.EnableRules.ContainsKey(id))
                        {
                            this.EnableRules.TryAdd(id, enableRule);
                        }
                    }
                }
            }

            {
                var elementsDisplayRules = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/RuleDefinitions/DisplayRules/DisplayRule");

                foreach (var displayRule in elementsDisplayRules)
                {
                    var id = displayRule.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id))
                    {
                        if (!this.DisplayRules.ContainsKey(id))
                        {
                            this.DisplayRules.TryAdd(id, displayRule);
                        }
                    }
                }
            }

            {
                var elementsLibraries = docRibbon.Descendants().Where(e => e.Attribute("Library") != null && !string.IsNullOrEmpty(e.Attribute("Library").Value));

                foreach (var library in elementsLibraries)
                {
                    var value = library.Attribute("Library")?.Value;

                    if (!string.IsNullOrEmpty(value) &&
                        !value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        this.Libraries.Add(value);
                    }
                }
            }

            {
                var elementsFunctionNames = docRibbon.Descendants().Where(e => e.Attribute("FunctionName") != null && !string.IsNullOrEmpty(e.Attribute("FunctionName").Value));

                foreach (var functionName in elementsFunctionNames)
                {
                    var value = functionName.Attribute("FunctionName")?.Value;

                    if (!string.IsNullOrEmpty(value))
                    {
                        this.FunctionsNames.Add(value);
                    }
                }
            }

            {
                var elementsLables = docRibbon.Descendants().Where(e => e.Attributes().Any(a => XmlCompletionSource.LabelXmlAttributes.Contains(a.Name.LocalName) && !string.IsNullOrEmpty(a.Value)));

                foreach (var label in elementsLables)
                {
                    if (!string.Equals(label.Name.LocalName, "Layout", StringComparison.InvariantCultureIgnoreCase)
                        )
                    {
                        foreach (var attr in label.Attributes().Where(a => !string.IsNullOrEmpty(a.Value)))
                        {
                            if (XmlCompletionSource.LabelXmlAttributes.Contains(attr.Name.LocalName))
                            {
                                this.LabelTexts.Add(attr.Value);
                            }
                        }
                    }
                }
            }

            {
                var elementsImages = docRibbon.Descendants().Where(e => e.Attributes().Any(a => XmlCompletionSource.ImagesXmlAttributes.Contains(a.Name.LocalName) &&
                                                                                           !string.IsNullOrEmpty(a.Value) &&
                                                                                           !a.Value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                                                                                           ));

                foreach (var label in elementsImages)
                {
                    foreach (var attr in label.Attributes().Where(a => !string.IsNullOrEmpty(a.Value)))
                    {
                        if (XmlCompletionSource.ImagesXmlAttributes.Contains(attr.Name.LocalName) &&
                            !attr.Value.StartsWith("$webresource:", StringComparison.InvariantCultureIgnoreCase)
                            )
                        {
                            this.Images.Add(attr.Value);
                        }
                    }
                }
            }

            {
                var elementsModernImages = docRibbon.Descendants().Where(e => e.Attribute("ModernImage") != null && !string.IsNullOrEmpty(e.Attribute("ModernImage").Value));

                foreach (var modernImage in elementsModernImages)
                {
                    var value = modernImage.Attribute("ModernImage")?.Value;

                    if (!string.IsNullOrEmpty(value))
                    {
                        this.ModernImages.Add(value);
                    }
                }
            }

            {
                var elementsGroupTemplates = docRibbon.XPathSelectElements("RibbonDefinitions/RibbonDefinition/Templates/RibbonTemplates/GroupTemplate");

                foreach (var template in elementsGroupTemplates)
                {
                    var id = template.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id) && !this.Templates.ContainsKey(id))
                    {
                        var newItem = new RibbonGroupTemplate()
                        {
                            Id = id,
                        };

                        this.Templates.TryAdd(id, newItem);

                        foreach (var item in template.Descendants("OverflowSection"))
                        {
                            string alias = item.Attribute("TemplateAlias")?.Value;

                            if (!string.IsNullOrEmpty(alias) && !newItem.TemplateAliases.Contains(alias))
                            {
                                newItem.TemplateAliases.Add(alias);
                            }
                        }
                    }
                }
            }

            {
                var elementsControls = docRibbon.Descendants("Controls");

                foreach (var controls in elementsControls)
                {
                    var id = controls.Attribute("Id")?.Value;

                    if (!string.IsNullOrEmpty(id) && !this.Locations.ContainsKey(id))
                    {
                        var newItem = new RibbonLocation()
                        {
                            Id = id,
                        };

                        var parentTemplateId = controls.AncestorsAndSelf().FirstOrDefault(e => e.Attribute("Template") != null)?.Attribute("Template")?.Value;

                        if (!string.IsNullOrEmpty(parentTemplateId) && this.Templates.ContainsKey(parentTemplateId))
                        {
                            newItem.Template = this.Templates[parentTemplateId];
                        }

                        this.Locations.TryAdd(id, newItem);

                        foreach (var item in controls.Elements())
                        {
                            newItem.Controls.Add(new RibbonLocationControl()
                            {
                                ControlType = item.Name.LocalName,
                                Id          = item.Attribute("Id")?.Value,
                                Sequence    = item.Attribute("Sequence")?.Value,
                                LabelText   = item.Attribute("LabelText")?.Value,
                                Command     = item.Attribute("Command")?.Value,

                                TemplateAlias = item.Attribute("TemplateAlias")?.Value,
                            });
                        }
                    }
                }
            }
        }