protected Dictionary <string, Component> GetActiveModules() { Schema moduleConfigSchema = GetSchema(ModuleConfigurationSchemaRootElementName); Session session = moduleConfigSchema.Session; UsingItemsFilter moduleConfigComponentsFilter = new UsingItemsFilter(session) { ItemTypes = new[] { ItemType.Component }, BaseColumns = ListBaseColumns.Id }; Dictionary <string, Component> results = new Dictionary <string, Component>(); foreach (Component comp in moduleConfigSchema.GetUsingItems(moduleConfigComponentsFilter).Cast <Component>()) { // GetUsingItems returns the items in their Owning Publication, which could be lower in the BluePrint than were we are (so don't exist in our context Repository). Component moduleConfigComponent = (Component)Publication.GetObject(comp.Id); if (!session.IsExistingObject(moduleConfigComponent.Id)) { continue; } ItemFields fields = new ItemFields(moduleConfigComponent.Content, moduleConfigComponent.Schema); string moduleName = fields.GetTextValue("name").Trim().ToLower(); if (fields.GetTextValue("isActive").ToLower() == "yes" && !results.ContainsKey(moduleName)) { results.Add(moduleName, moduleConfigComponent); } } return(results); }
private IEnumerable <SiteLocalizationData> GetChildPublicationDetails(Publication master, string siteId, bool masterAdded) { List <SiteLocalizationData> pubs = new List <SiteLocalizationData>(); UsingItemsFilter filter = new UsingItemsFilter(Session) { ItemTypes = new List <ItemType> { ItemType.Publication } }; foreach (XmlElement item in master.GetListUsingItems(filter).ChildNodes) { string id = item.GetAttribute("ID"); Publication child = (Publication)Engine.GetObject(id); string childSiteId = GetSiteIdFromPublication(child); if (childSiteId == siteId) { Logger.Debug(String.Format("Found valid descendent {0} with site ID {1} ", child.Title, childSiteId)); bool isMaster = !masterAdded && IsMasterWebPublication(child); pubs.Add(GetPublicationDetails(child, isMaster)); masterAdded = masterAdded || isMaster; } else { Logger.Debug(String.Format("Descendent {0} has invalid site ID {1} - ignoring ", child.Title, childSiteId)); } } return(pubs); }
private string DetermineLocale() { // TODO: use a less complicated (and more explicit) way to store locale/language. What about Publication metadata? Schema generalConfigSchema = GetSchema("GeneralConfiguration"); UsingItemsFilter configComponentsFilter = new UsingItemsFilter(Session) { ItemTypes = new[] { ItemType.Component }, BaseColumns = ListBaseColumns.IdAndTitle }; IEnumerable <Component> configComponents = generalConfigSchema.GetUsingItems(configComponentsFilter).Cast <Component>(); Component localizationConfigComponent = configComponents.FirstOrDefault(c => c.Title == "Localization Configuration"); if (localizationConfigComponent == null) { Logger.Warning("No Localization Configuration Component found."); return(null); } // Ensure we load the Component in the current context Publication localizationConfigComponent = (Component)Publication.GetObject(localizationConfigComponent.Id); Dictionary <string, string> settings = ExtractKeyValuePairs(localizationConfigComponent); string result; const string cultureSetting = "culture"; if (!settings.TryGetValue(cultureSetting, out result)) { Logger.Warning($"No '{cultureSetting}' setting found in Localization Configuration {localizationConfigComponent.FormatIdentifier()}."); } return(result); }
public static List <TcmUri> GetLinkedComponentTemplates(this Schema schema) { UsingItemsFilter filter = new UsingItemsFilter(schema.Session) { ItemTypes = new List <ItemType> { ItemType.ComponentTemplate } }; return((from XmlNode ctNode in schema.GetListUsingItems(filter) select new TcmUri(ctNode.Attributes["ID"].Value)).ToList()); }
protected List <KeyValuePair <TcmUri, string> > GetUsingItems(RepositoryLocalObject subject, ItemType itemType) { UsingItemsFilter filter = new UsingItemsFilter(Engine.GetSession()) { ItemTypes = new List <ItemType> { itemType }, BaseColumns = ListBaseColumns.IdAndTitle }; return(XmlElementToTcmUriList(subject.GetListUsingItems(filter))); }
/// <summary> /// Clears the where used items of this template. /// </summary> /// <param name="template"></param> public void ClearWhereUsed(TemplateBuildingBlock template) { UsingItemsFilter filter = new UsingItemsFilter(template.Session); filter.BaseColumns = ListBaseColumns.Id; filter.ItemTypes = new ItemType[] { ItemType.TemplateBuildingBlock }; XmlElement items = template.GetListUsingItems(filter); foreach (XmlElement item in items) { RemoveTemplate(item.Attributes["ID"].Value); } }
protected List <TcmUri> GetSchemaComponentTemplatesIds(Schema schema) { //Filter filter = new Filter(); //filter.Conditions.Add("ItemType", ItemType.ComponentTemplate); UsingItemsFilter filter = new UsingItemsFilter(schema.Session) { ItemTypes = new List <ItemType> { ItemType.ComponentTemplate } }; List <TcmUri> cts = new List <TcmUri>(); foreach (XmlNode ctNode in schema.GetListUsingItems(filter)) { string id = ctNode.Attributes["ID"].Value; cts.Add(new TcmUri(id)); } return(cts); }
public void Transform(Engine engine, Package package) { Page page = (Page)engine.GetObject(package.GetByName(Package.PageName)); TcmUri articleSchemaUri = new TcmUri(Constants.SchemaArticleId, ItemType.Schema, page.Id.PublicationId); UsingItemsFilter filter = new UsingItemsFilter(engine.GetSession()) { ItemTypes = new[] { ItemType.Component } }; Schema schema = (Schema)engine.GetObject(articleSchemaUri); TagCloud tagCloud = new TagCloud { Tags = new List<Tag>(), PublicationId = page.Id.PublicationId, TcmId = page.Id.ItemId, PageTitle = page.Title }; SortedList<string, int> tags = new SortedList<string, int>(StringComparer.CurrentCultureIgnoreCase); foreach (Component c in schema.GetUsingItems(filter)) { Article a = new Article(c, engine); string tag = a.Author.Name; if (tags.ContainsKey(tag)) { tags[tag] = tags[tag] + 1; } else { tags.Add(tag, 1); } } foreach (var tag in tags) { tagCloud.Tags.Add(new Tag { TagName = tag.Key.ToAscii(), TagValue = tag.Value }); } string content = JsonConvert.SerializeObject(tagCloud); //content += tagCloud.ToBsonDocument().ToJson(new JsonWriterSettings { OutputMode = JsonOutputMode.Strict }); package.PushItem(Package.OutputName, package.CreateStringItem(ContentType.Text, content)); }
private IEnumerable<PublicationDetails> GetChildPublicationDetails(Publication master, string siteId, bool masterAdded) { List<PublicationDetails> pubs = new List<PublicationDetails>(); UsingItemsFilter filter = new UsingItemsFilter(Engine.GetSession()) { ItemTypes = new List<ItemType> { ItemType.Publication } }; foreach (XmlElement item in master.GetListUsingItems(filter).ChildNodes) { string id = item.GetAttribute("ID"); Publication child = (Publication)Engine.GetObject(id); string childSiteId = GetSiteIdFromPublication(child); if (childSiteId == siteId) { Logger.Debug(String.Format("Found valid descendent {0} with site ID {1} ", child.Title, childSiteId)); bool isMaster = !masterAdded && IsMasterWebPublication(child); pubs.Add(GetPublicationDetails(child, isMaster)); masterAdded = masterAdded || isMaster; } else { Logger.Debug(String.Format("Descendent {0} has invalid site ID {1} - ignoring ",child.Title,childSiteId)); } } return pubs; }
/// <summary> /// On (Save, and) Check-in of a Component, create a Page for that Component and update an index Page with the Component and publish both to a staging target. /// </summary> /// <remarks> /// The metadata of the Folder the Component resides in, will be used as the configuration for the actions. /// </remarks> /// <param name="subject">checked in Component</param> /// <param name="args">check in event arguments</param> /// <param name="phase">event phase</param> private static void ComponentCheckInAction(Component subject, CheckInEventArgs args, EventPhases phase) { // get Folder from Component for configuration metadata Folder folder = (Folder)subject.OrganizationalItem; // proceed when Folder has metadata if (folder.Metadata == null) { return; } ItemFields metadata = new ItemFields(folder.Metadata, folder.MetadataSchema); ReiConfig config = new ReiConfig(metadata); // proceed when metadata contains valid URIs, and Schema of Component is recognised if (!config.IsValid || subject.Schema.Id.ItemId != config.SchemaUri.ItemId) { return; } // create list of items to publish List <IdentifiableObject> items = new List <IdentifiableObject>(); // if Component is already used on any Page then no need to create new Page and update index, just publish Component UsingItemsFilter pageFilter = new UsingItemsFilter(subject.Session) { ItemTypes = new List <ItemType> { ItemType.Page } }; if (subject.HasUsingItems(pageFilter)) { items.Add(subject); } else { // create Page and add Component Presentation (using Context Publication of Structure Group) TcmUri localUri = ReiConfig.TransformTcmUri(subject.Id, config.StructureGroupUri); Component localComponent = new Component(localUri, subject.Session); ComponentTemplate componentTemplate = new ComponentTemplate(config.ComponentTemplateUri, subject.Session); Page page = new Page(subject.Session, config.StructureGroupUri); try { page.Title = subject.Title; page.FileName = GetSafeFileName(subject.Title); page.PageTemplate = new PageTemplate(config.PageTemplateUri, subject.Session); page.ComponentPresentations.Add(new ComponentPresentation(localComponent, componentTemplate)); page.Save(true); // add Page to publish items list items.Add(page); } catch (Exception ex) { Logger.Write(ex, ReiConfig.Name, LoggingCategory.General, TraceEventType.Error); } // add Component to index Page (using Context Publication of index Page) localUri = ReiConfig.TransformTcmUri(subject.Id, config.IndexPageUri); localComponent = new Component(localUri, subject.Session); componentTemplate = new ComponentTemplate(config.IndexComponentTemplateUri, subject.Session); Page indexPage = new Page(config.IndexPageUri, subject.Session); try { indexPage.CheckOut(); indexPage.ComponentPresentations.Add(new ComponentPresentation(localComponent, componentTemplate)); indexPage.Save(true); // add index Page to publish items list items.Add(indexPage); } catch (Exception ex) { Logger.Write(ex, ReiConfig.Name, LoggingCategory.General, TraceEventType.Error); } } // publish items if (items.Count > 0) { List <TargetType> targets = new List <TargetType> { new TargetType(config.TargetTypeUri, subject.Session) }; PublishInstruction publishInstruction = new PublishInstruction(subject.Session); PublishEngine.Publish(items, publishInstruction, targets, ReiConfig.Priority); } else { Logger.Write("No items were published.", ReiConfig.Name, LoggingCategory.General, TraceEventType.Information); } }
protected List<KeyValuePair<TcmUri, string>> GetUsingItems(RepositoryLocalObject subject, ItemType itemType) { UsingItemsFilter filter = new UsingItemsFilter(Engine.GetSession()) { ItemTypes = new List<ItemType> { itemType }, BaseColumns = ListBaseColumns.IdAndTitle }; return XmlElementToTcmUriList(subject.GetListUsingItems(filter)); }
protected Dictionary<string, Component> GetActiveModules() { Schema moduleConfigSchema = GetModuleConfigSchema(); Session session = moduleConfigSchema.Session; UsingItemsFilter moduleConfigComponentsFilter = new UsingItemsFilter(session) { ItemTypes = new[] {ItemType.Component}, BaseColumns = ListBaseColumns.Id }; Dictionary<string, Component> results = new Dictionary<string, Component>(); foreach (Component comp in moduleConfigSchema.GetUsingItems(moduleConfigComponentsFilter).Cast<Component>()) { // GetUsingItems returns the items in their Owning Publication, which could be lower in the BluePrint than were we are (so don't exist in our context Repository). Component moduleConfigComponent = (Component) Publication.GetObject(comp.Id); if (!session.IsExistingObject(moduleConfigComponent.Id)) { continue; } ItemFields fields = new ItemFields(moduleConfigComponent.Content, moduleConfigComponent.Schema); string moduleName = fields.GetTextValue("name").Trim().ToLower(); if (fields.GetTextValue("isActive").ToLower() == "yes" && !results.ContainsKey(moduleName)) { results.Add(moduleName, moduleConfigComponent); } } return results; }