/// <summary> /// Adds the items. /// </summary> /// <param name="elements">The elements.</param> private void AddItems(FolderElement[] elements) { if (elements == null) { return; } foreach (FolderElement element in elements) { ComboBoxItem item = new ComboBoxItem(BuildFullPath(element) + element.Name); item.Value = element.PrimaryKeyId.ToString(); item["icon"] = Page.ResolveClientUrl(CHelper.GetIcon(element.Name)); AssetItemsFilter.Items.Add(item); } }
/// <summary> /// Gets the data source. /// </summary> /// <param name="totalRecords">The total records.</param> /// <returns></returns> private DataTable GetDataSource(out int totalRecords) { DataTable table = new DataTable(); int grandParentId = -1; char[] delimiters = new char[] { '.' }; table.Columns.Add(new DataColumn("ID", typeof(string))); table.Columns.Add(new DataColumn("Type", typeof(string))); table.Columns.Add(new DataColumn("OutlineNumber", typeof(string))); table.Columns.Add(new DataColumn("CheckboxEnabled", typeof(bool))); table.Columns.Add(new DataColumn("Name", typeof(string))); table.Columns.Add(new DataColumn("Filename", typeof(string))); table.Columns.Add(new DataColumn("Size", typeof(string))); table.Columns.Add(new DataColumn("Url", typeof(string))); table.Columns.Add(new DataColumn("Icon", typeof(string))); table.Columns.Add(new DataColumn("Created", typeof(DateTime))); table.Columns.Add(new DataColumn("GrandParentId", typeof(string))); Mediachase.Ibn.Data.Services.TreeNode[] nodes = TreeManager.GetChildNodes(Folder.GetAssignedMetaClass(), ParentId); FolderElement[] elements = FolderElement.List <FolderElement>(FolderElement.GetAssignedMetaClass(), new FilterElement[] { new FilterElement("ParentId", FilterElementType.Equal, ParentId) }); int nodeIndex = 0; foreach (Mediachase.Ibn.Data.Services.TreeNode node in nodes) { //check to see if the grandParentId has been set yet if (grandParentId == -1) { //get the ID for the folder above the current folder string[] outlineArray = node.OutlineNumber.ToString().Split(delimiters); if (node.OutlineLevel > 2) { int.TryParse(outlineArray[outlineArray.Length - 3].ToString(), out grandParentId); } } //if (nodeIndex >= recordToDisplay) { DataRow newRow = table.NewRow(); newRow["ID"] = node.ObjectId.ToString(); newRow["OutlineNumber"] = node.OutlineNumber; newRow["Type"] = "Folder"; newRow["CheckboxEnabled"] = true; newRow["Name"] = node.Title; newRow["Icon"] = String.Format("~/App_Themes/Default/images/icons/Node.gif"); newRow["FileName"] = node.Title; newRow["Url"] = String.Empty; newRow["Created"] = (DateTime)node.InnerObject.Properties["Created"].Value; table.Rows.Add(newRow); } nodeIndex++; } //check to see if folder outline level was available in folders and that the parent is not the root folder if (grandParentId < 0 && ParentId > 1) { //the grandparent folder id needs to be retrieved through other means BusinessObject _bindObject = MetaObjectActivator.CreateInstance <BusinessObject>("Folder", ParentId); if (_bindObject != null) { //get the ID for the folder above the current folder string[] outlineArray = _bindObject["OutlineNumber"].ToString().Split(delimiters); if (outlineArray.Length > 1) { int.TryParse(outlineArray[outlineArray.Length - 2].ToString(), out grandParentId); } } } //if this row is below the root level, show an up-level folder link. //now that all means have been exhausted, only add the up-level link if there is a valid value //for the grandParentId if (grandParentId >= 0) { //add a 'level up' row at the top // add additional row at the top. Don't add row if parent node is a Catalog DataRow row = table.NewRow(); row["ID"] = ParentId; row["GrandParentId"] = grandParentId; row["CheckboxEnabled"] = false; row["Name"] = "[..]"; row["Type"] = "LevelUp"; table.Rows.InsertAt(row, 0); } foreach (FolderElement element in elements) { //if (nodeIndex >= recordToDisplay) { DataRow newRow = table.NewRow(); newRow["ID"] = element.PrimaryKeyId.ToString(); newRow["OutlineNumber"] = String.Empty; newRow["Type"] = "Node"; newRow["CheckboxEnabled"] = true; newRow["Name"] = element.Name; /* * BlobStorageProvider prov = BlobStorage.Providers[element.BlobStorageProvider]; * BlobInfo info = prov.GetInfo(new Guid(element.BlobUid.ToString())); * */ newRow["Url"] = String.Format("~{0}", element.GetUrl()); /*if (info != null) * { * newRow["FileName"] = info.FileName; * newRow["Icon"] = CHelper.GetIcon(info.FileName); * newRow["Created"] = info.Created; * newRow["Size"] = CommerceHelper.ByteSizeToStr(info.ContentSize); * } * */ //else { newRow["FileName"] = element.Name; newRow["Icon"] = CHelper.GetIcon(element.Name); newRow["Created"] = element.Created; newRow["Size"] = CommerceHelper.ByteSizeToStr((element.ContentSize != null) ? (long)element.ContentSize : 0); } table.Rows.Add(newRow); } nodeIndex++; } // TODO: implement paging totalRecords = nodes.Length + elements.Length; return(table); }