public string Execute([NotNull] string databaseName, [NotNull] string newItemPath, [NotNull] string fileStream) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(newItemPath, nameof(newItemPath)); Assert.ArgumentNotNull(fileStream, nameof(fileStream)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var parentPath = newItemPath; var n = parentPath.LastIndexOf('/'); if (n > 0) { parentPath = parentPath.Left(n); } var parent = database.GetItem(parentPath); if (parent == null) { throw new Exception("Item not found: " + parentPath); } var stream = new MemoryStream(System.Convert.FromBase64String(fileStream)); var options = new MediaCreatorOptions { AlternateText = Path.GetFileNameWithoutExtension(newItemPath), Database = database, FileBased = false, IncludeExtensionInItemName = false, Language = LanguageManager.DefaultLanguage, Versioned = false }; var item = MediaManager.Creator.CreateFromStream(stream, "/upload/" + Path.GetFileName(newItemPath), options); if (item == null) { throw new Exception("Failed to upload file"); } item.MoveTo(parent); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("upload"); output.WriteItemHeader(item); output.WriteEndElement(); return(writer.ToString()); }
private void ProcessRenderings([NotNull] XmlTextWriter output, List <string> placeHolderNames, [NotNull] Item item) { Debug.ArgumentNotNull(output, nameof(output)); Debug.ArgumentNotNull(item, nameof(item)); foreach (Item child in item.Children) { var template = TemplateManager.GetTemplate(child); if (template.DescendsFrom(GetRenderings.RenderingOptionsId)) { var defaultParameters = child["Default Parameters"]; if (!string.IsNullOrEmpty(defaultParameters)) { var url = new UrlString(defaultParameters); var name = url["Placeholder"]; if (placeHolderNames.Contains(name)) { output.WriteStartElement("add"); output.WriteAttributeString("placeholder", name); output.WriteItemHeader(child); output.WriteEndElement(); } } } ProcessRenderings(output, placeHolderNames, child); } }
public string Execute([NotNull] string id, [NotNull] string databaseName) { Assert.ArgumentNotNull(id, nameof(id)); Assert.ArgumentNotNull(databaseName, nameof(databaseName)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var item = database.GetItem(id); if (item == null) { throw new Exception("Item not found"); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteItemHeader(item, string.Empty); return(writer.ToString()); }
public string Execute([NotNull] string queryText, [NotNull] string databaseName) { Assert.ArgumentNotNull(queryText, nameof(queryText)); Assert.ArgumentNotNull(databaseName, nameof(databaseName)); var database = Factory.GetDatabase(databaseName); if (database == null) { return(string.Empty); } var selectedItems = database.SelectItems(queryText); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("children"); foreach (var child in selectedItems) { output.WriteItemHeader(child, string.Empty); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string id, [NotNull] string databaseName) { Assert.ArgumentNotNull(id, nameof(id)); Assert.ArgumentNotNull(databaseName, nameof(databaseName)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var item = database.GetItem(id); if (item == null) { return(string.Empty); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("descendants"); foreach (var child in item.Axes.GetDescendants()) { output.WriteItemHeader(child, string.Empty); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string databaseName, [NotNull] string placeHolderName, [NotNull] string placeHolderPath) { var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var placeHolderSettingsRoot = database.GetItem(ItemIDs.PlaceholderSettingsRoot); if (placeHolderSettingsRoot == null) { return(string.Empty); } var item = database.GetItem(placeHolderSettingsRoot.Paths.Path + placeHolderPath) ?? database.GetItem(placeHolderSettingsRoot.Paths.Path + "/" + placeHolderName); if (item == null) { return(string.Empty); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteItemHeader(item); return(writer.ToString()); }
public string Execute([NotNull] string items) { var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("items"); foreach (var part in items.Split('|')) { var tuple = part.Split(','); var database = Factory.GetDatabase(tuple[0]); if (database == null) { continue; } var item = database.GetItem(tuple[1]); if (item == null) { continue; } output.WriteItemHeader(item, string.Empty); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string sourceItemIds, [NotNull] string itemId, [NotNull] string databaseName) { Assert.ArgumentNotNull(sourceItemIds, nameof(sourceItemIds)); Assert.ArgumentNotNull(itemId, nameof(itemId)); Assert.ArgumentNotNull(databaseName, nameof(databaseName)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var parent = database.Items[itemId]; Debug.Assert(parent != null, "Parent item \"" + itemId + "\" not found."); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("items"); var list = sourceItemIds.Split(','); foreach (var id in list) { var source = database.GetItem(id); if (source == null) { continue; } if (!source.Access.CanCopyTo(parent)) { continue; } var newName = source.Name; var count = 0; while (parent.Children[newName] != null) { newName = source.Name + " - Copy"; if (count > 0) { newName += " (" + count + ")"; } count++; } var copy = source.CopyTo(parent, newName); output.WriteItemHeader(copy); } output.WriteEndElement(); return(writer.ToString()); }
private void WriteItem([NotNull] XmlTextWriter output, [NotNull] List <Item> items, [NotNull] Item item) { Debug.ArgumentNotNull(output, nameof(output)); Debug.ArgumentNotNull(items, nameof(items)); Debug.ArgumentNotNull(item, nameof(item)); output.WriteItemHeader(item); items.Add(item); }
private void GetFieldRoot([NotNull] XmlTextWriter output, [NotNull] Field field) { Debug.ArgumentNotNull(output, nameof(output)); Debug.ArgumentNotNull(field, nameof(field)); var type = field.Type.ToLowerInvariant(); if (type != "treelist" && type != "treelistex" && type != "tree list") { return; } var database = field.Database; var source = field.Source; string path; if (ID.IsID(source)) { path = source; } else if (source.StartsWith("/")) { path = source; } else { path = StringUtil.ExtractParameter("DataSource", source).Trim().ToLower(); if (string.IsNullOrEmpty(path)) { path = "/sitecore"; } var databaseName = StringUtil.ExtractParameter("database", source).Trim().ToLower(); if (string.IsNullOrEmpty(databaseName)) { databaseName = StringUtil.ExtractParameter("databasename", source).Trim().ToLower(); } if (!string.IsNullOrEmpty(databaseName)) { database = Factory.GetDatabase(databaseName); } } var root = database.GetItem(path); if (root == null) { return; } output.WriteStartElement("root"); output.WriteItemHeader(root, string.Empty); output.WriteEndElement(); }
public string Execute([NotNull] string databaseName, [NotNull] string path) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(path, nameof(path)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var root = database.GetItem(ItemIDs.PlaceholderSettingsRoot); if (root == null) { return(string.Empty); } var folderTemplate = database.GetItem(PlaceHolderSettingsFolderTemplateId); if (folderTemplate == null) { return(string.Empty); } var placeHolderSettingsTemplate = database.GetItem(PlaceHolderSettingsTemplateId); if (placeHolderSettingsTemplate == null) { return(string.Empty); } var p = root.Paths.Path + (path.StartsWith("/") ? string.Empty : "/") + path; var item = database.CreateItemPath(p, new TemplateItem(folderTemplate), new TemplateItem(placeHolderSettingsTemplate)); if (item == null) { return(string.Empty); } item.Editing.BeginEdit(); item["Placeholder Key"] = path; item.Editing.EndEdit(); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteItemHeader(item); return(writer.ToString()); }
public string Execute([NotNull] string databaseName, int pageNumber) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var publishQueue = PublishManager.GetPublishQueue(DateTime.MinValue, DateTime.MaxValue, database); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("items"); var count = 0; var start = pageNumber * 250; foreach (var id in publishQueue) { var item = database.GetItem(id); if (item == null) { continue; } count++; if (count < start) { continue; } if (count >= start + 250) { break; } output.WriteItemHeader(item, string.Empty); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string databaseName, [NotNull] string fromDate, [NotNull] string toDate) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(fromDate, nameof(fromDate)); Assert.ArgumentNotNull(toDate, nameof(toDate)); var items = new List <Item>(); var keys = new List <string>(); if (!string.IsNullOrEmpty(databaseName)) { var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } GetItems(database, fromDate, toDate, items, keys); } else { foreach (var database in Factory.GetDatabases()) { if (database.Name == "web" || database.ReadOnly) { continue; } GetItems(database, fromDate, toDate, items, keys); } } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("items"); foreach (var item in items) { output.WriteItemHeader(item); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string queryText) { Assert.ArgumentNotNull(queryText, nameof(queryText)); var args = new SearchArgs(queryText) { Type = SearchType.ContentEditor, Limit = 30, }; using (new LongRunningOperationWatcher(250, "Search pipeline from instant search for '{0} query", queryText)) { CorePipeline.Run("search", args); } var results = args.Result; if (results.Count == 0) { return(string.Empty); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("hits"); foreach (var category in results.Categories) { foreach (var hit in category) { var item = hit.GetObject <Item>(); if (item == null) { continue; } output.WriteItemHeader(item, category.Name); } } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string databaseName, [NotNull] string placeHolderName, [NotNull] string placeHolderPath) { var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var items = new List <Item>(); foreach (var path in GetRenderings.RootPaths) { var item = database.GetItem(path); if (item != null) { ProcessRenderings(items, placeHolderName, item); } } var placeHolderSettingsRoot = database.GetItem(ItemIDs.PlaceholderSettingsRoot); if (placeHolderSettingsRoot != null) { ProcessPlaceHolderSettings(items, database, placeHolderSettingsRoot.Paths.Path + "/" + placeHolderName); ProcessPlaceHolderSettings(items, database, placeHolderSettingsRoot.Paths.Path + placeHolderPath); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("renderings"); foreach (var item in items) { output.WriteItemHeader(item); } output.WriteEndElement(); return(writer.ToString()); }
public string Execute([NotNull] string databaseName, [NotNull] string id) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(id, nameof(id)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var item = database.GetItem(id); if (item == null) { throw new Exception("Item not found"); } var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("insertoptions"); var insertOptions = Masters.GetMasters(item); foreach (var option in insertOptions) { if (option.TemplateID == TemplateIDs.CommandMaster) { continue; } output.WriteItemHeader(option); } output.WriteEndElement(); return(writer.ToString()); }
private string FormatResults([NotNull] List <SearchResultItem> results) { Debug.ArgumentNotNull(results, nameof(results)); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("hits"); foreach (var result in results) { var item = result.GetItem(); if (item != null) { output.WriteItemHeader(item); } } output.WriteEndElement(); return(writer.ToString()); }
private void ProcessRenderings([NotNull] XmlTextWriter output, [NotNull] Item item) { Assert.ArgumentNotNull(output, nameof(output)); Assert.ArgumentNotNull(item, nameof(item)); foreach (Item child in item.Children) { try { var template = TemplateManager.GetTemplate(child); if (template.DescendsFrom(RenderingOptionsId)) { output.WriteItemHeader(child); } } catch (Exception ex) { Log.Error("Get Renderings", ex, GetType()); } ProcessRenderings(output, child); } }
public string Execute([NotNull] string databaseName, [NotNull] string id) { Assert.ArgumentNotNull(databaseName, nameof(databaseName)); Assert.ArgumentNotNull(id, nameof(id)); var database = Factory.GetDatabase(databaseName); if (database == null) { throw new Exception("Database not found"); } var item = database.GetItem(id); if (item == null) { throw new Exception("Item not found"); } var categorizer = Factory.CreateObject("/sitecore/search/categorizer", true) as CategorizeResults.Categorizer; Assert.IsNotNull(categorizer, "categorizer"); var writer = new StringWriter(); var output = new XmlTextWriter(writer); output.WriteStartElement("links"); output.WriteAttributeString("name", item.Name); output.WriteStartElement("references"); var links = new List <string>(); foreach (var itemLink in Globals.LinkDatabase.GetReferences(item)) { var targetItem = itemLink.GetTargetItem(); if (targetItem == null) { continue; } var key = targetItem.Database.Name + targetItem.ID; if (links.Contains(key)) { continue; } links.Add(key); var category = categorizer.GetCategory(targetItem); output.WriteItemHeader(targetItem, category); } output.WriteEndElement(); output.WriteStartElement("referrers"); links.Clear(); foreach (var itemLink in Globals.LinkDatabase.GetReferrers(item)) { var sourceItem = itemLink.GetSourceItem(); if (sourceItem == null) { continue; } var key = sourceItem.Database.Name + sourceItem.ID; if (links.Contains(key)) { continue; } links.Add(key); var category = categorizer.GetCategory(sourceItem); output.WriteItemHeader(sourceItem, category); } output.WriteEndElement(); output.WriteEndElement(); return(writer.ToString()); }