Esempio n. 1
0
        private void WriteDevice([NotNull] XmlTextWriter output, [NotNull] Database database, [NotNull] DeviceDefinition device, [NotNull] XElement deviceElement)
        {
            Assert.ArgumentNotNull(output, nameof(output));
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(device, nameof(device));
            Assert.ArgumentNotNull(deviceElement, nameof(deviceElement));

            var item = database.GetItem(device.ID);

            if (item == null)
            {
                return;
            }

            var icon = Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id16x16);

            output.WriteStartElement("d");
            output.WriteAttributeString("id", device.ID);
            output.WriteAttributeString("ic", icon);
            output.WriteAttributeString("l", device.Layout);

            var deviceItem = database.GetItem(device.ID);

            if (deviceItem != null)
            {
                output.WriteAttributeString("n", deviceItem.Name);
            }

            if (!string.IsNullOrEmpty(device.Layout))
            {
                var layout = database.GetItem(device.Layout);
                if (layout != null)
                {
                    output.WriteAttributeString("ln", layout.Name);
                    output.WriteAttributeString("lp", layout.Paths.Path);

                    var placeHolders = PlaceHolderAnalyzer.Analyze(layout).ToArray();
                    if (placeHolders.Any())
                    {
                        output.WriteAttributeString("ph", string.Join(",", placeHolders));
                    }
                }
            }

            var renderings = device.Renderings;

            if (renderings != null)
            {
                foreach (RenderingDefinition rendering in renderings)
                {
                    var renderingElement = deviceElement.Elements("r").FirstOrDefault(e => e.GetAttributeValue("uid") == rendering.UniqueId);
                    WriteRendering(output, database, rendering, renderingElement);
                }
            }

            var placeholders = device.Placeholders;

            if (placeholders != null)
            {
                foreach (PlaceholderDefinition placeholder in placeholders)
                {
                    WritePlaceholder(output, placeholder);
                }
            }

            output.WriteEndElement();
        }
Esempio n. 2
0
        private void WriteRendering([NotNull] XmlTextWriter output, [NotNull] Database database, [NotNull] RenderingDefinition rendering, [CanBeNull] XElement renderingElement)
        {
            Assert.ArgumentNotNull(output, nameof(output));
            Assert.ArgumentNotNull(database, nameof(database));
            Assert.ArgumentNotNull(rendering, nameof(rendering));

            if (rendering.ItemID == null)
            {
                return;
            }

            var item = database.GetItem(rendering.ItemID);

            output.WriteStartElement("r");

            var itemName           = "<Unknown Rendering>";
            var dataSourceLocation = string.Empty;
            var dataSourceTemplate = string.Empty;
            var path = string.Empty;
            var parametersTemplate = string.Empty;
            var icon               = "Core2/16x16/question_mark.png";
            var placeHolders       = string.Empty;
            var speakCoreVersion   = string.Empty;
            var speakCoreVersionId = string.Empty;

            if (item != null)
            {
                itemName           = item.Name;
                dataSourceLocation = item["Datasource Location"];
                dataSourceTemplate = item["Datasource Template"];
                path = item["Path"];
                parametersTemplate = item["Parameters Template"];
                icon         = item.Appearance.Icon;
                placeHolders = string.Join(",", PlaceHolderAnalyzer.Analyze(item).ToArray());

                var helper      = new SpeakCoreVersionHelper();
                var versionItem = helper.GetSpeakCoreVersionItem(item);
                if (versionItem != null)
                {
                    speakCoreVersion   = versionItem.Name;
                    speakCoreVersionId = versionItem.ID.ToString();
                }
            }

            output.WriteAttributeString("name", itemName);
            output.WriteAttributeString("cac", rendering.Cachable ?? "0");
            output.WriteAttributeString("cnd", rendering.Conditions ?? string.Empty);
            output.WriteAttributeString("ds", rendering.Datasource ?? string.Empty);
            output.WriteAttributeString("id", rendering.ItemID);
            output.WriteAttributeString("mvt", rendering.MultiVariateTest ?? string.Empty);
            output.WriteAttributeString("par", rendering.Parameters ?? string.Empty);
            output.WriteAttributeString("ph", rendering.Placeholder ?? string.Empty);
            output.WriteAttributeString("uid", rendering.UniqueId ?? string.Empty);
            output.WriteAttributeString("vbd", rendering.VaryByData ?? "0");
            output.WriteAttributeString("vbdev", rendering.VaryByDevice ?? "0");
            output.WriteAttributeString("vbl", rendering.VaryByLogin ?? "0");
            output.WriteAttributeString("vbp", rendering.VaryByParameters ?? "0");
            output.WriteAttributeString("vbqs", rendering.VaryByQueryString ?? "0");
            output.WriteAttributeString("vbu", rendering.VaryByUser ?? "0");
            output.WriteAttributeString("ic", Images.GetThemedImageSource(icon, ImageDimension.id16x16));

            output.WriteAttributeString("placeholders", placeHolders);
            output.WriteAttributeString("dsl", dataSourceLocation);
            output.WriteAttributeString("dst", dataSourceTemplate);
            output.WriteAttributeString("path", path);
            output.WriteAttributeString("templateid", parametersTemplate);
            output.WriteAttributeString("speakcoreversion", speakCoreVersion);
            output.WriteAttributeString("speakcoreversionid", speakCoreVersionId);

            if (renderingElement != null)
            {
                if (renderingElement.HasElements)
                {
                    var rlsElement = renderingElement.Element("rls");
                    if (rlsElement != null)
                    {
                        var ruleset = rlsElement.InnerText();
                        output.WriteAttributeString("rls", ruleset);
                    }
                }
            }

            if (item != null && !string.IsNullOrEmpty(parametersTemplate))
            {
                var templateItem = item.Database.GetItem(parametersTemplate);
                if (templateItem != null)
                {
                    WriteParametersTemplate(output, templateItem);
                }
            }

            output.WriteEndElement();
        }