Example #1
0
 private IEnumerable <IPublishedContent> ConvertToDocuments(XmlNodeList xmlNodes, bool isPreviewing)
 {
     return(xmlNodes.Cast <XmlNode>()
            .Select(xmlNode => XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache)));
 }
        // internal for some benchmarks
        internal static void InitializeNode(XmlPublishedContent node, XmlNode xmlNode, bool isPreviewing,
                                            out int id, out Guid key, out int template, out int sortOrder, out string name, out string writerName, out string urlName,
                                            out string creatorName, out int creatorId, out int writerId, out string docTypeAlias, out int docTypeId, out string path,
                                            out DateTime createDate, out DateTime updateDate, out int level, out bool isDraft,
                                            out IPublishedContentType contentType, out Dictionary <string, IPublishedProperty> properties,
                                            Func <PublishedItemType, string, IPublishedContentType> getPublishedContentType)
        {
            //initialize the out params with defaults:
            writerName   = null;
            docTypeAlias = null;
            id           = template = sortOrder = template = creatorId = writerId = docTypeId = level = default(int);
            key          = default(Guid);
            name         = writerName = urlName = creatorName = docTypeAlias = path = null;
            createDate   = updateDate = default(DateTime);
            isDraft      = false;
            contentType  = null;
            properties   = null;

            if (xmlNode == null)
            {
                return;
            }

            if (xmlNode.Attributes != null)
            {
                id = int.Parse(xmlNode.Attributes.GetNamedItem("id").Value);
                if (xmlNode.Attributes.GetNamedItem("key") != null) // because, migration
                {
                    key = Guid.Parse(xmlNode.Attributes.GetNamedItem("key").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("template") != null)
                {
                    template = int.Parse(xmlNode.Attributes.GetNamedItem("template").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("sortOrder") != null)
                {
                    sortOrder = int.Parse(xmlNode.Attributes.GetNamedItem("sortOrder").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("nodeName") != null)
                {
                    name = xmlNode.Attributes.GetNamedItem("nodeName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("writerName") != null)
                {
                    writerName = xmlNode.Attributes.GetNamedItem("writerName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("urlName") != null)
                {
                    urlName = xmlNode.Attributes.GetNamedItem("urlName").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("creatorName") != null)
                {
                    creatorName = xmlNode.Attributes.GetNamedItem("creatorName").Value;
                }

                //Added the actual userID, as a user cannot be looked up via full name only...
                if (xmlNode.Attributes.GetNamedItem("creatorID") != null)
                {
                    creatorId = int.Parse(xmlNode.Attributes.GetNamedItem("creatorID").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("writerID") != null)
                {
                    writerId = int.Parse(xmlNode.Attributes.GetNamedItem("writerID").Value);
                }

                docTypeAlias = xmlNode.Name;

                if (xmlNode.Attributes.GetNamedItem("nodeType") != null)
                {
                    docTypeId = int.Parse(xmlNode.Attributes.GetNamedItem("nodeType").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("path") != null)
                {
                    path = xmlNode.Attributes.GetNamedItem("path").Value;
                }
                if (xmlNode.Attributes.GetNamedItem("createDate") != null)
                {
                    createDate = DateTime.Parse(xmlNode.Attributes.GetNamedItem("createDate").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("updateDate") != null)
                {
                    updateDate = DateTime.Parse(xmlNode.Attributes.GetNamedItem("updateDate").Value);
                }
                if (xmlNode.Attributes.GetNamedItem("level") != null)
                {
                    level = int.Parse(xmlNode.Attributes.GetNamedItem("level").Value);
                }

                isDraft = xmlNode.Attributes.GetNamedItem("isDraft") != null;
            }

            //dictionary to store the property node data
            var propertyNodes = new Dictionary <string, XmlNode>();

            foreach (XmlNode n in xmlNode.ChildNodes)
            {
                var e = n as XmlElement;
                if (e == null)
                {
                    continue;
                }
                if (e.HasAttribute("isDoc") == false)
                {
                    PopulatePropertyNodes(propertyNodes, e, false);
                }
                else
                {
                    break;  //we are not longer on property elements
                }
            }

            //lookup the content type and create the properties collection
            try
            {
                contentType = getPublishedContentType(PublishedItemType.Content, docTypeAlias);
            }
            catch (InvalidOperationException e)
            {
                // TODO: enable!
                //content.Instance.RefreshContentFromDatabase();
                throw new InvalidOperationException($"{e.Message}. This usually indicates that the content cache is corrupt; the content cache has been rebuilt in an attempt to self-fix the issue.");
            }

            //fill in the property collection
            properties = new Dictionary <string, IPublishedProperty>(StringComparer.OrdinalIgnoreCase);
            foreach (var propertyType in contentType.PropertyTypes)
            {
                var val = propertyNodes.TryGetValue(propertyType.Alias.ToLowerInvariant(), out XmlNode n)
                    ? new XmlPublishedProperty(propertyType, node, isPreviewing, n)
                    : new XmlPublishedProperty(propertyType, node, isPreviewing);

                properties[propertyType.Alias] = val;
            }
        }
Example #3
0
 private IPublishedContent ConvertToDocument(XmlNode xmlNode, bool isPreviewing)
 {
     return(xmlNode == null ? null : XmlPublishedContent.Get(xmlNode, isPreviewing, _appCache, _contentTypeCache));
 }