コード例 #1
0
        public string Execute([NotNull] string databaseName, [NotNull] string xslt)
        {
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(xslt, nameof(xslt));

            var database = Factory.GetDatabase(databaseName);

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

            var item = database.GetRootItem();

            var fileName = TempFolder.GetFilename("TransformCodeGeneration.xslt");
            var path     = FileUtil.MapPath(fileName);

            File.WriteAllText(path, xslt, Encoding.UTF8);

            var xslFile = new XslFile
            {
                Path = fileName
            };

            xslFile.XslExtensions["http://www.sitecore.net/codegeneration"] = new Helper();

            var result = xslFile.Transform(item);

            File.Delete(path);

            return(result);
        }
コード例 #2
0
        public string Execute([NotNull] string databaseName, [NotNull] string itemId, [NotNull] string contextId)
        {
            Assert.ArgumentNotNull(databaseName, nameof(databaseName));
            Assert.ArgumentNotNull(itemId, nameof(itemId));
            Assert.ArgumentNotNull(contextId, nameof(contextId));

            var database = Factory.GetDatabase(databaseName);

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

            var item = database.GetItem(itemId);

            if (item == null)
            {
                return(string.Empty);
            }

            var contextItem = database.GetItem(contextId);

            if (contextItem == null)
            {
                return("Context item does not exist");
            }

            var path = item["Path"];

            if (string.IsNullOrEmpty(path))
            {
                return(string.Empty);
            }

            var xslFile = new XslFile
            {
                Path = path
            };

            using (new DatabaseSwitcher(contextItem.Database))
            {
                using (new ContextItemSwitcher(contextItem))
                {
                    return(xslFile.Transform(contextItem));
                }
            }
        }