internal void Process(StringBuilder log, Dictionary<string, DocumentType> documentTypeLookup) { bool requiresSave = false; var oldHash = GetHash(_documentType.AllowedChildContentTypeIDs); var paths = _element.SelectNodes("allowedChildren/add").Cast<XmlElement>().Select(n => n.InnerText).ToArray(); var invalidKeys = paths.Where(p => !documentTypeLookup.ContainsKey(p)).ToArray(); if (invalidKeys.Any()) throw new ApplicationException("Invalid child structure keys: " + invalidKeys.ToSeparatedString(", ")); var newElements = paths.Select(p => documentTypeLookup[p].Id).ToArray(); var newHash = GetHash(newElements); if (newHash != oldHash) { _documentType.AllowedChildContentTypeIDs = newElements; requiresSave = true; log.AppendLine("SET DT Structure: " + _documentType.Text + " -> " + oldHash + " => " + newHash); } if (requiresSave) { _documentType.Save(); ContentType.RemoveFromDataTypeCache(_documentType.Alias); } }
/// <summary> /// Gets all wiki files for all nodes /// </summary> /// <returns></returns> public static Dictionary<int, IEnumerable<WikiFile>> CurrentFiles(IEnumerable<int> nodeIds) { var wikiFiles = new Dictionary<int, List<WikiFile>>(); //we can only have 2000 (actually 2100) SQL parameters used at once, so we need to group them var nodeBatches = nodeIds.InGroupsOf(2000); foreach (var nodeBatch in nodeBatches) { foreach (var result in ApplicationContext.Current.DatabaseContext.Database.Query<dynamic>("SELECT * FROM wikiFiles WHERE nodeId IN (@nodeIds)", new { nodeIds = nodeBatch })) { var file = new WikiFile { Id = result.id, Path = result.path, Name = result.name, FileType = result.type, RemovedBy = result.removedBy, CreatedBy = result.createdBy, NodeVersion = result.version, NodeId = result.nodeId, CreateDate = result.createDate, DotNetVersion = result.dotNetVersion, Downloads = result.downloads, Archived = result.archived, Verified = result.verified, Versions = GetVersionsFromString(result.umbracoVersion) }; file.Version = file.Versions.Any() ? GetVersionsFromString(result.umbracoVersion)[0] : UmbracoVersion.DefaultVersion(); if (wikiFiles.ContainsKey(result.nodeId)) { var list = wikiFiles[result.nodeId]; list.Add(file); } else { wikiFiles.Add(result.nodeId, new List<WikiFile>(new[] { file })); } } } return wikiFiles.ToDictionary(x => x.Key, x => (IEnumerable<WikiFile>)x.Value); }
internal IPublishedContent ConvertFromXPathNavigator(XPathNavigator xpath) { if (xpath == null) throw new ArgumentNullException("xpath"); var values = new Dictionary<string, string> {{"nodeName", xpath.GetAttribute("nodeName", "")}}; if (!UmbracoSettings.UseLegacyXmlSchema) { values.Add("nodeTypeAlias", xpath.Name); } var result = xpath.SelectChildren(XPathNodeType.Element); //add the attributes e.g. id, parentId etc if (result.Current != null && result.Current.HasAttributes) { if (result.Current.MoveToFirstAttribute()) { //checking for duplicate keys because of the 'nodeTypeAlias' might already be added above. if (!values.ContainsKey(result.Current.Name)) { values.Add(result.Current.Name, result.Current.Value); } while (result.Current.MoveToNextAttribute()) { if (!values.ContainsKey(result.Current.Name)) { values.Add(result.Current.Name, result.Current.Value); } } result.Current.MoveToParent(); } } //add the user props while (result.MoveNext()) { if (result.Current != null && !result.Current.HasAttributes) { string value = result.Current.Value; if (string.IsNullOrEmpty(value)) { if (result.Current.HasAttributes || result.Current.SelectChildren(XPathNodeType.Element).Count > 0) { value = result.Current.OuterXml; } } values.Add(result.Current.Name, value); } } return new DictionaryPublishedContent(values, d => d.ParentId != -1 //parent should be null if -1 ? GetUmbracoMedia(d.ParentId) : null, //callback to return the children of the current node based on the xml structure already found d => GetChildrenMedia(d.ParentId, xpath), GetProperty); }
private static IEnumerable<KeyValuePair<PropertyInfo, DocumentTypePropertyAttribute>> GetPropertiesWithAttributes(IReflect type) { var privateOrPublicInstanceProperties = type.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); var propertiesWithPropertyAttributes = privateOrPublicInstanceProperties.Where(propertyInfo => HasAttribute(propertyInfo, typeof(DocumentTypePropertyAttribute))); var propertyAttributeMapping = new Dictionary<PropertyInfo, DocumentTypePropertyAttribute>(); foreach (var property in propertiesWithPropertyAttributes) { var propertyAttribute = (DocumentTypePropertyAttribute)property.GetCustomAttributes(true).SingleOrDefault(attribute => attribute is DocumentTypePropertyAttribute); if (propertyAttribute != null && !propertyAttributeMapping.ContainsKey(property)) { propertyAttributeMapping.Add(property, propertyAttribute); } } return propertyAttributeMapping; }