bool TryGetItem(ChildList children, Func <Item, bool> predicate, out Item result) { result = null; if (children == null || !children.Any()) { return(false); } result = children.FirstOrDefault(predicate); if (result != null) { return(true); } var query = children.Where(n => n.HasChildren); if (!query.Any()) { return(false); } foreach (var child in query.ToArray()) { if (TryGetItem(child.Children, predicate, out result)) { return(true); } } return(false); }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { List <string> selectedList = new List <string>(); if (string.IsNullOrEmpty(SelectionRootItem)) { return; } var master = Factory.GetDatabase("master"); Item root = master.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } List <string> importvalues = importValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (!importvalues.Any()) { return; } foreach (Item value in selectionValues) { foreach (var temp in importvalues) { Field t = value.Fields["Text"]; if (t == null) { continue; } if (!temp.Trim().ToLower().Equals(t.Value.Trim().ToLower())) { continue; } selectedList.Add(value.ID.ToString()); } } Field f = newItem.Fields[NewItemField]; if (f == null || !selectedList.Any()) { return; } f.Value = string.Join("|", selectedList); }
public void AddSecureItem(ISecureItemVM newItem) { if (!ChildList.Any() || !(ChildList.First() is SecureItemsView)) { ChildList.Insert(0, SecureItemsView); } SecureItemsView.SecureList.Add(newItem); RaisePropertyChanged("Count"); }
public override void FillField(IDataMap map, ref Item newItem, string importValue, string id = null) { string selectedValue = string.Empty; if (string.IsNullOrEmpty(SelectionRootItem)) { return; } var master = Factory.GetDatabase("master"); Item root = master.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } if (!importValue.IsNotNull()) { return; } foreach (Item value in selectionValues) { Field t = value.Fields["Text"]; if (t == null) { continue; } if (!importValue.Trim().ToLower().Equals(t.Value.Trim().ToLower())) { continue; } selectedValue = value.ID.ToString(); } Field f = newItem.Fields[NewItemField]; if (f == null || !selectedValue.IsNotNull()) { return; } f.Value = selectedValue; }
public SitecoreDataMap(Database db, Item importItem, LevelLogger logger) : base(db, importItem, logger) { //deal with sitecore properties if any Item Props = GetItemByTemplate(importItem, Utility.Constants.PropertiesFolderID); if (Props.IsNotNull()) { ChildList c = Props.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseProperty bp = null; try { bp = (IBaseProperty)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Logger.AddError("Error", string.Format("the property:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bp != null) { PropertyDefinitions.Add(bp); } else { Logger.AddError("Error", string.Format("the property: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } } else { Logger.AddError("Error", string.Format("the property: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Logger.AddError("Error", string.Format("the property: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Logger.AddError("Warn", "there are no properties to import"); } } }
public override void FillField(IDataMap map, ref Item newItem, string importValue) { Assert.IsNotNull(newItem, "newItem"); List <string> selectedList = new List <string>(); if (string.IsNullOrEmpty(SelectionRootItem)) { return; } var master = Factory.GetDatabase("master"); Item root = master.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } List <string> importvalues = importValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.Trim().ToLowerInvariant()).ToList(); if (!importvalues.Any()) { return; } selectedList.AddRange(selectionValues .Where(v => v.Fields["Text"] != null) .Where(v => importvalues.Contains(v.Fields["Text"].Value.Trim().ToLowerInvariant())) .Select(v => v.ID.ToString())); Field f = newItem.Fields[NewItemField]; if (f == null || !selectedList.Any()) { return; } f.Value = string.Join("|", selectedList); }
public void RemoveSecureItem(ISecureItemVM item) { if (ChildList.Any() && ChildList.First() is SecureItemsView) { if (SecureItemsView.SecureList.FirstOrDefault(x => x.Id == item.Id) != null) { SecureItemsView.SecureList.Remove(SecureItemsView.SecureList.FirstOrDefault(x => x.Id == item.Id)); if (!SecureItemsView.SecureList.Any()) { ChildList.Remove(SecureItemsView); } } } RaisePropertyChanged("ChildList"); RaisePropertyChanged("Count"); }
public override void FillField(IDataMap map, ref Item newItem, object importRow) { Assert.IsNotNull(newItem, "newItem"); List <string> selectedList = new List <string>(); if (string.IsNullOrEmpty(SelectionRootItem)) { return; } Item root = newItem.Database.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); var importValue = string.Join(Delimiter, map.GetFieldValues(ExistingDataNames, importRow)); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } List <string> importvalues = importValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).Select(i => i.Trim().ToLowerInvariant()).ToList(); if (!importvalues.Any()) { return; } selectedList.AddRange(selectionValues .Where(v => importvalues.Contains(v.DisplayName.Trim().ToLowerInvariant())) .Select(v => v.ID.ToString())); Field f = newItem.Fields[ToWhatField]; if (f == null || !selectedList.Any()) { return; } f.Value = string.Join("|", selectedList); }
public override void FillField(IDataMap map, ref Item newItem, string importValue) { Assert.IsNotNull(newItem, "newItem"); string selectedValue = string.Empty; if (string.IsNullOrEmpty(SelectionRootItem)) { return; } var master = Factory.GetDatabase("master"); Item root = master.GetItem(SelectionRootItem); if (root == null) { return; } ChildList selectionValues = new ChildList(root); if (string.IsNullOrEmpty(importValue) || !selectionValues.Any()) { return; } if (!importValue.IsNotNull()) { return; } importValue = importValue.Trim().ToLowerInvariant(); selectedValue = selectionValues.FirstOrDefault(v => v.Fields["Text"] != null && v.Fields["Text"].Value.Trim().ToLowerInvariant() == importValue)?.ID.ToString(); Field f = newItem.Fields[NewItemField]; if (f == null || !selectedValue.IsNotNull()) { return; } f.Value = selectedValue; }
public override void FillField(BaseDataMap map, ref Item newItem, string importValue) { List <string> selectedList = new List <string>(); if (!string.IsNullOrEmpty(SelectionRootItem)) { var master = Factory.GetDatabase("master"); Item root = master.GetItem(selectionRootItem); if (root != null) { ChildList selectionValues = new ChildList(root); if (!string.IsNullOrEmpty(importValue) && selectionValues.Any()) { List <string> importvalues = importValue.Split(new string[] { Delimiter }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (importvalues.Any()) { foreach (Item value in selectionValues) { foreach (var temp in importvalues) { if (value.Fields["Text"] != null) { if (temp.Trim().ToLower().Equals(value.Fields["Text"].ToString().Trim().ToLower())) { selectedList.Add(value.ID.ToString()); } } } } Field f = newItem.Fields[NewItemField]; //store the imported value as is if (f != null && selectedList.Any()) { f.Value = string.Join("|", selectedList); } } } } } }
public override void FillField(BaseDataMap map, ref Item newItem, string importValue) { string selectedValue = string.Empty; if (!string.IsNullOrEmpty(SelectionRootItem)) { var master = Factory.GetDatabase("master"); Item root = master.GetItem(selectionRootItem); if (root != null) { ChildList selectionValues = new ChildList(root); if (!string.IsNullOrEmpty(importValue) && selectionValues.Any()) { if (importValue.IsNotNull()) { foreach (Item value in selectionValues) { if (value.Fields["Text"] != null) { if (importValue.Trim().ToLower().Equals(value.Fields["Text"].ToString().Trim().ToLower())) { selectedValue = value.ID.ToString(); } } } Field f = newItem.Fields[NewItemField]; //store the imported value as is if (f != null && selectedValue.IsNotNull()) { f.Value = selectedValue; } } } } } }
public SitecoreDataMap(Database db, string connectionString, Item importItem) : base(db, connectionString, importItem) { Item fLang = SitecoreDB.GetItem(importItem.Fields["Import From Language"].Value); ImportFromLanguage = LanguageManager.GetLanguage(fLang.Name); CheckboxField cf = importItem.Fields["Recursively Fetch Children"]; RecursivelyFetchChildren = cf.Checked; //deal with sitecore properties if any Item Props = GetItemByTemplate(importItem, PropertiesFolderID); if (Props.IsNotNull()) { ChildList c = Props.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseProperty bp = null; try { bp = (IBaseProperty)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Log("Error", string.Format("the property:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bp != null) { PropertyDefinitions.Add(bp); } else { Log("Error", string.Format("the property: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the property: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the property: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Log("Warn", "there are no properties to import"); } } Item Temps = GetItemByTemplate(importItem, TemplatesFolderID); if (Temps.IsNotNull()) { ChildList c = Temps.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from TemplateMapping tm = new TemplateMapping(child); if (string.IsNullOrEmpty(tm.FromWhatTemplate)) { Log("Error", string.Format("the template mapping field 'FromWhatTemplate' on '{0}' is not defined", child.Name)); break; } if (string.IsNullOrEmpty(tm.ToWhatTemplate)) { Log("Error", string.Format("the template mapping field 'ToWhatTemplate' on '{0}' is not defined", child.Name)); break; } TemplateMappingDefinitions.Add(tm.FromWhatTemplate, tm); } } } }
public ActionResult TeamsListing() { TeamsViewModel lstTeams = new TeamsViewModel(); try { Item datasource = RenderingContext.Current.Rendering.Item; if (datasource != null && datasource.IsDerived(Templates.Team.ID)) { lstTeams.Teams = new List <Team>(); foreach (var teamItem in datasource.Children.Where(x => x.IsDerived(Templates.Team.ID))) { var team = new Team(); team.Members = new List <TeamMember>(); team.item = teamItem; foreach (var member in teamItem.Children.Where(x => x.IsDerived(Templates.TeamMember.ID))) { team.Members.Add(new TeamMember { item = member }); } lstTeams.Teams.Add(team); } } else { ChildList Childs = Context.Item.Children; if (Context.Item != null && Childs != null) { if (Childs.Any(x => x.IsDerived(Templates.Team.ID))) { lstTeams.Teams = new List <Team>(); foreach (var teamItem in Childs.Where(x => x.IsDerived(Templates.Team.ID))) { var team = new Team(); team.item = teamItem; team.Members = new List <TeamMember>(); foreach (var member in teamItem.Children.Where(x => x.IsDerived(Templates.TeamMember.ID))) { team.Members.Add(new TeamMember { item = member }); } lstTeams.Teams.Add(team); } } else if (Childs.Any(x => x.IsDerived(Templates.TeamsListing.ID))) { lstTeams.Teams = new List <Team>(); var teamItem = Childs.Where(x => x.IsDerived(Templates.TeamsListing.ID)).FirstOrDefault(); foreach (var teamObj in teamItem.Children.Where(x => x.IsDerived(Templates.Team.ID))) { var team = new Team(); team.item = teamObj; team.Members = new List <TeamMember>(); foreach (var member in teamObj.Children.Where(x => x.IsDerived(Templates.TeamMember.ID))) { team.Members.Add(new TeamMember { item = member }); } lstTeams.Teams.Add(team); } } } } } catch (Exception ex) { Log.Error(ex.Message, ex, this); } return(View(lstTeams)); }
public BaseDataMap(Database db, string connectionString, Item importItem) { //instantiate log log = new StringBuilder(); //setup import details SitecoreDB = db; DatabaseConnectionString = connectionString; //get query Query = importItem.Fields["Query"].Value; if (string.IsNullOrEmpty(Query)) { Log("Error", "the 'Query' field was not set"); } //get parent and store it string parentID = importItem.Fields["Import To Where"].Value; if (!string.IsNullOrEmpty(parentID)) { Item parent = SitecoreDB.Items[parentID]; if (parent.IsNotNull()) { Parent = parent; } else { Log("Error", "the 'To Where' item is null"); } } else { Log("Error", "the 'To Where' field is not set"); } //get new item template string templateID = importItem.Fields["Import To What Template"].Value; if (!string.IsNullOrEmpty(templateID)) { Item templateItem = SitecoreDB.Items[templateID]; if (templateItem.IsNotNull()) { if ((BranchItem)templateItem != null) { NewItemTemplate = (BranchItem)templateItem; } else { NewItemTemplate = (TemplateItem)templateItem; } } else { Log("Error", "the 'To What Template' item is null"); } } else { Log("Error", "the 'To What Template' field is not set"); } //more properties ItemNameDataField = importItem.Fields["Pull Item Name from What Fields"].Value; ItemNameMaxLength = int.Parse(importItem.Fields["Item Name Max Length"].Value); Item iLang = SitecoreDB.GetItem(importItem.Fields["Import To Language"].Value); ImportToLanguage = LanguageManager.GetLanguage(iLang.Name); if (ImportToLanguage == null) { Log("Error", "The 'Import Language' field is not set"); } //foldering information FolderByDate = ((CheckboxField)importItem.Fields["Folder By Date"]).Checked; FolderByName = ((CheckboxField)importItem.Fields["Folder By Name"]).Checked; DateField = importItem.Fields["Date Field"].Value; if (FolderByName || FolderByDate) { //setup a default type to an ordinary folder Sitecore.Data.Items.TemplateItem FolderItem = SitecoreDB.Templates["{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}"]; //if they specify a type then use that string folderID = importItem.Fields["Folder Template"].Value; if (!string.IsNullOrEmpty(folderID)) { FolderItem = SitecoreDB.Templates[folderID]; } FolderTemplate = FolderItem; } //start handling fields Item Fields = GetItemByTemplate(importItem, FieldsFolderID); if (Fields.IsNotNull()) { ChildList c = Fields.GetChildren(); if (c.Any()) { foreach (Item child in c) { //create an item to get the class / assembly name from BaseMapping bm = new BaseMapping(child); if (!string.IsNullOrEmpty(bm.HandlerAssembly)) { if (!string.IsNullOrEmpty(bm.HandlerClass)) { //create the object from the class and cast as base field to add it to field definitions IBaseField bf = null; try { bf = (IBaseField)Sitecore.Reflection.ReflectionUtil.CreateObject(bm.HandlerAssembly, bm.HandlerClass, new object[] { child }); } catch (FileNotFoundException fnfe) { Log("Error", string.Format("the field:{0} binary {1} specified could not be found", child.Name, bm.HandlerAssembly)); } if (bf != null) { FieldDefinitions.Add(bf); } else { Log("Error", string.Format("the field: '{0}' class type {1} could not be instantiated", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Class {1} is not defined", child.Name, bm.HandlerClass)); } } else { Log("Error", string.Format("the field: '{0}' Handler Assembly {1} is not defined", child.Name, bm.HandlerAssembly)); } } } else { Log("Warn", "there are no fields to import"); } } else { Log("Warn", "there is no 'Fields' folder"); } }
public ActionResult IdeasListing() { IdeaViewModel lstIdeas = new IdeaViewModel(); try { Item datasource = RenderingContext.Current.Rendering.Item; if (datasource != null && datasource.IsDerived(Templates.IdeasListing.ID)) { lstIdeas.Ideas = new List <Idea>(); foreach (var idea in datasource.Children.Where(x => x.IsDerived(Templates.Ideas.ID))) { lstIdeas.Ideas.Add(new Idea { item = idea }); } } else { ChildList Childs = Context.Item.Children; if (Context.Item != null && Childs != null) { if (Childs.Any(x => x.IsDerived(Templates.Ideas.ID))) { lstIdeas.Ideas = new List <Idea>(); foreach (var ideaItem in Childs.Where(x => x.IsDerived(Templates.Ideas.ID))) { lstIdeas.Ideas.Add(new Idea { item = ideaItem }); } } else if (Childs.Any(x => x.IsDerived(Templates.IdeasListing.ID))) { lstIdeas.Ideas = new List <Idea>(); var ideaItem = Childs.Where(x => x.IsDerived(Templates.IdeasListing.ID)).FirstOrDefault(); foreach (var idea in ideaItem.Children.Where(x => x.IsDerived(Templates.Ideas.ID))) { lstIdeas.Ideas.Add(new Idea { item = idea }); } } } } } catch (Exception ex) { Log.Error(ex.Message, ex, this); } return(View(lstIdeas)); }
bool TryGetItem(ChildList children, Func<Item, bool> predicate, out Item result) { result = null; if (children == null || !children.Any()) return false; result = children.FirstOrDefault(predicate); if (result != null) return true; var query = children.Where(n => n.HasChildren); if (!query.Any()) return false; foreach (var child in query.ToArray()) { if (TryGetItem(child.Children, predicate, out result)) return true; } return false; }