예제 #1
0
        public string Execute([NotNull] string id, [NotNull] string language, [NotNull] string version, bool allFields, [NotNull] string databaseName)
        {
            Assert.ArgumentNotNull(id, nameof(id));
            Assert.ArgumentNotNull(language, nameof(language));
            Assert.ArgumentNotNull(version, nameof(version));
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));

            var database = Factory.GetDatabase(databaseName);

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

            var item = database.GetItem(id, Language.Parse(language), Data.Version.Parse(version));

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

            var writer = new StringWriter();
            var output = new XmlTextWriter(writer);

            output.WriteStartElement("item");
            try
            {
                WriteCloneInfo(output, item);
            }
            catch (MissingMethodException)
            {
                output.WriteAttributeString("clone", "0");
            }

            WriteItemHeaderPipeline.Run().WithParameters(output, item);

            GetFields(output, item, allFields);
            GetItemVersions(output, item);
            GetItemLanguages(output, item);
            GetItemPath(output, item);
            GetItemTemplate(output, item);
            GetStandardValues(output, item);
            GetItemBaseTemplates(output, item);
            GetItemIcon(output, item);
            GetContentEditorWarnings(output, item);
            GetBreadcrumb(output, item);

            output.WriteEndElement();

            return(writer.ToString());
        }
예제 #2
0
        public static void WriteItemHeader([NotNull] this XmlTextWriter output, [NotNull] Item item, [NotNull] string categoryName)
        {
            Assert.ArgumentNotNull(output, nameof(output));
            Assert.ArgumentNotNull(item, nameof(item));
            Assert.ArgumentNotNull(categoryName, nameof(categoryName));

            var standardValuesId = item[FieldIDs.StandardValues];

            if (string.IsNullOrEmpty(standardValuesId))
            {
                var template = item.Template;
                if (template != null)
                {
                    standardValuesId = template.InnerItem[FieldIDs.StandardValues];
                }
            }

            if (!string.IsNullOrEmpty(standardValuesId))
            {
                if (item.Database.GetItem(standardValuesId) == null)
                {
                    standardValuesId = string.Empty;
                }
            }

            var parent = item.Parent;

            var icon = Images.GetThemedImageSource(item.Appearance.Icon, ImageDimension.id16x16);
            var n    = icon.IndexOf("~", StringComparison.Ordinal);

            if (n > 0)
            {
                icon = icon.Mid(n);
            }

            output.WriteStartElement("item");

            output.WriteAttributeString("id", item.ID.ToString());
            output.WriteAttributeString("database", item.Database.Name);
            output.WriteAttributeString("icon", icon);
            output.WriteAttributeString("haschildren", item.HasChildren ? "1" : "0");
            output.WriteAttributeString("templateid", item.TemplateID.ToString());
            output.WriteAttributeString("category", categoryName);
            output.WriteAttributeString("templatename", item.TemplateName);
            output.WriteAttributeString("path", item.Paths.Path);
            output.WriteAttributeString("standardvaluesfield", item[FieldIDs.StandardValues]);
            output.WriteAttributeString("standardvaluesid", standardValuesId);
            output.WriteAttributeString("sortorder", item.Appearance.Sortorder.ToString());
            output.WriteAttributeString("updatedby", item.Statistics.UpdatedBy);
            output.WriteAttributeString("updated", DateUtil.ToIsoDate(item.Statistics.Updated));
            output.WriteAttributeString("locked", item.Locking.GetOwner());
            output.WriteAttributeString("owner", item.Security.GetOwner());
            output.WriteAttributeString("parentname", parent != null ? parent.Name : string.Empty);

            try
            {
                WriteCloneInfo(output, item);
            }
            catch (MissingMethodException)
            {
                output.WriteAttributeString("clone", "0");
            }

            WriteItemHeaderPipeline.Run().WithParameters(output, item);

            output.WriteValue(item.Name);

            output.WriteEndElement();
        }