示例#1
0
        private void FindPlaceHolders([NotNull] StringWriter result, [NotNull] Item item, Dictionary <string, string> parameters)
        {
            var placeholders = item["Place Holders"];

            if (!string.IsNullOrEmpty(placeholders))
            {
                var parts = placeholders.Split(',');
                foreach (var part in parts)
                {
                    var value = part.Trim();

                    foreach (var pair in parameters)
                    {
                        if (string.Compare(pair.Key, "Id", StringComparison.InvariantCultureIgnoreCase) == 0 && string.IsNullOrEmpty(pair.Value))
                        {
                            continue;
                        }

                        value = value.Replace("$" + pair.Key, pair.Value);
                    }

                    result.WriteLine(value);
                }

                return;
            }

            var placeHolders = PlaceHolderAnalyzer.Analyze(item);

            foreach (var placeHolder in placeHolders)
            {
                result.WriteLine(placeHolder);
            }
        }
        public string Execute([NotNull] string databaseName, [NotNull] string itemId)
        {
            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                throw new InvalidOperationException("Database not found");
            }

            var item = database.GetItem(itemId);

            if (item == null)
            {
                throw new InvalidOperationException("Item not found");
            }

            var placeHolders = PlaceHolderAnalyzer.Analyze(item);

            return(string.Join(",", placeHolders.ToArray()));
        }
示例#3
0
        public string Execute([NotNull] string databaseName, [NotNull] string itemId)
        {
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(itemId, nameof(itemId));

            var database = Factory.GetDatabase(databaseName);

            if (database == null)
            {
                throw new ArgumentException("Database not found");
            }

            var item = database.GetItem(itemId);

            if (item == null)
            {
                throw new ArgumentException("Item not found");
            }

            var speakCoreVersion   = string.Empty;
            var speakCoreVersionId = string.Empty;

            var helper      = new SpeakCoreVersionHelper();
            var versionItem = helper.GetSpeakCoreVersionItem(item);

            if (versionItem != null)
            {
                speakCoreVersion   = versionItem.Name;
                speakCoreVersionId = versionItem.ID.ToString();
            }

            var writer = new StringWriter();
            var output = new XmlTextWriter(writer)
            {
                Formatting = Formatting.Indented
            };

            output.WriteStartElement("template");
            output.WriteAttributeString("name", item.Name);
            output.WriteAttributeString("icon", Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id16x16));
            output.WriteAttributeString("parameters", item["Default Parameters"]);
            output.WriteAttributeString("placeholders", string.Join(",", PlaceHolderAnalyzer.Analyze(item).ToArray()));
            output.WriteAttributeString("dsl", item["Datasource Location"]);
            output.WriteAttributeString("dst", item["Datasource Template"]);
            output.WriteAttributeString("path", item["Path"]);
            output.WriteAttributeString("templateid", item["Parameters Template"]);
            output.WriteAttributeString("speakcoreversion", speakCoreVersion);
            output.WriteAttributeString("speakcoreversionid", speakCoreVersionId);

            var template = item["Parameters Template"];

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

            output.WriteEndElement();

            return(writer.ToString());
        }