Exemple #1
0
 /// <summary>
 /// Fires the before a publish action updates the content cache
 /// </summary>
 /// <param name="node">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.ContentCacheLoadNodeEventArgs"/> instance containing the event data.</param>
 public static void FireBeforePublishNodeToContentCache(XmlNode node, ContentCacheLoadNodeEventArgs e)
 {
     if (BeforePublishNodeToContentCache != null)
     {
         BeforePublishNodeToContentCache(node, e);
     }
 }
Exemple #2
0
 /// <summary>
 /// Fires the after loading document cache xml node from database
 /// </summary>
 /// <param name="node">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.ContentCacheLoadNodeEventArgs"/> instance containing the event data.</param>
 internal static void FireAfterContentCacheLoadNodeFromDatabase(XmlNode node, ContentCacheLoadNodeEventArgs e)
 {
     if (AfterContentCacheLoadNodeFromDatabase != null)
     {
         AfterContentCacheLoadNodeFromDatabase(node, e);
     }
 }
Exemple #3
0
 /// <summary>
 /// Fires the before when creating the document cache from database
 /// </summary>
 /// <param name="node">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.ContentCacheLoadNodeEventArgs"/> instance containing the event data.</param>
 internal static void FireAfterContentCacheDatabaseLoadXmlString(ref string xml, ContentCacheLoadNodeEventArgs e)
 {
     if (AfterContentCacheDatabaseLoadXmlString != null)
     {
         AfterContentCacheDatabaseLoadXmlString(ref xml, e);
     }
 }
Exemple #4
0
 /// <summary>
 /// Fires the before when creating the document cache from database
 /// </summary>
 /// <param name="node">The sender.</param>
 /// <param name="e">The <see cref="umbraco.cms.businesslogic.ContentCacheLoadNodeEventArgs"/> instance containing the event data.</param>
 internal static void FireBeforeContentCacheLoadNode(XmlNode node, ContentCacheLoadNodeEventArgs e)
 {
     if (BeforeContentCacheLoadNode != null)
     {
         BeforeContentCacheLoadNode(node, e);
     }
 }
Exemple #5
0
        /// <summary>
        /// Load content from database
        /// </summary>
        private XmlDocument LoadContentFromDatabase()
        {
            // Alex N - 2010 06 - Very generic try-catch simply because at the moment, unfortunately, this method gets called inside a ThreadPool thread
            // and we need to guarantee it won't tear down the app pool by throwing an unhandled exception
            try
            {
                // Moved User to a local variable - why are we causing user 0 to load from the DB though?
                // Alex N 20100212
                User staticUser = null;
                try
                {
                    staticUser = User.GetCurrent(); //User.GetUser(0);
                }
                catch
                {
                    /* We don't care later if the staticUser is null */
                }

                // Try to log to the DB
                Log.Add(LogTypes.System, staticUser, -1, "Loading content from database...");

                var hierarchy = new Dictionary<int, List<int>>();
                var nodeIndex = new Dictionary<int, XmlNode>();

                try
                {
                    Log.Add(LogTypes.Debug, staticUser, -1, "Republishing starting");

                    // Lets cache the DTD to save on the DB hit on the subsequent use
                    string dtd = DocumentType.GenerateDtd();

                    // Prepare an XmlDocument with an appropriate inline DTD to match
                    // the expected content
                    var xmlDoc = new XmlDocument();
                    InitContentDocument(xmlDoc, dtd);

                    // Esben Carlsen: At some point we really need to put all data access into to a tier of its own.
                    string sql =
                        @"select umbracoNode.id, umbracoNode.parentId, umbracoNode.sortOrder, cmsContentXml.xml from umbracoNode 
inner join cmsContentXml on cmsContentXml.nodeId = umbracoNode.id and umbracoNode.nodeObjectType = @type
order by umbracoNode.level, umbracoNode.sortOrder";

                    lock (_dbReadSyncLock)
                    {
                        using (
                            IRecordsReader dr = SqlHelper.ExecuteReader(sql,
                                                                        SqlHelper.CreateParameter("@type",
                                                                                                  new Guid(
                                                                                                      "C66BA18E-EAF3-4CFF-8A22-41B16D66A972")))
                            )
                        {
                            while (dr.Read())
                            {
                                int currentId = dr.GetInt("id");
                                int parentId = dr.GetInt("parentId");
                                string xml = dr.GetString("xml");

                                // Call the eventhandler to allow modification of the string
                                var e1 = new ContentCacheLoadNodeEventArgs();
                                FireAfterContentCacheDatabaseLoadXmlString(ref xml, e1);
                                // check if a listener has canceled the event
                                if (!e1.Cancel)
                                {
                                    // and parse it into a DOM node
                                    xmlDoc.LoadXml(xml);
                                    XmlNode node = xmlDoc.FirstChild;
                                    // same event handler loader form the xml node
                                    var e2 = new ContentCacheLoadNodeEventArgs();
                                    FireAfterContentCacheLoadNodeFromDatabase(node, e2);
                                    // and checking if it was canceled again
                                    if (!e1.Cancel)
                                    {
                                        nodeIndex.Add(currentId, node);

                                        // verify if either of the handlers canceled the children to load
                                        if (!e1.CancelChildren && !e2.CancelChildren)
                                        {
                                            // Build the content hierarchy
                                            List<int> children;
                                            if (!hierarchy.TryGetValue(parentId, out children))
                                            {
                                                // No children for this parent, so add one
                                                children = new List<int>();
                                                hierarchy.Add(parentId, children);
                                            }
                                            children.Add(currentId);
                                        }
                                    }
                                }
                            }
                        }
                    }

                    Log.Add(LogTypes.Debug, staticUser, -1, "Xml Pages loaded");

                    try
                    {
                        // If we got to here we must have successfully retrieved the content from the DB so
                        // we can safely initialise and compose the final content DOM. 
                        // Note: We are reusing the XmlDocument used to create the xml nodes above so 
                        // we don't have to import them into a new XmlDocument

                        // Initialise the document ready for the final composition of content
                        InitContentDocument(xmlDoc, dtd);

                        // Start building the content tree recursively from the root (-1) node
                        GenerateXmlDocument(hierarchy, nodeIndex, -1, xmlDoc.DocumentElement);

                        Log.Add(LogTypes.Debug, staticUser, -1, "Done republishing Xml Index");

                        return xmlDoc;
                    }
                    catch (Exception ee)
                    {
                        Log.Add(LogTypes.Error, staticUser, -1,
                                string.Format("Error while generating XmlDocument from database: {0}", ee));
                    }
                }
                catch (OutOfMemoryException)
                {
                    Log.Add(LogTypes.Error, staticUser, -1,
                            string.Format("Error Republishing: Out Of Memory. Parents: {0}, Nodes: {1}",
                                          hierarchy.Count, nodeIndex.Count));
                }
                catch (Exception ee)
                {
                    Log.Add(LogTypes.Error, staticUser, -1, string.Format("Error Republishing: {0}", ee));
                }
            }
            catch (Exception ee)
            {
                Log.Add(LogTypes.Error, -1, string.Format("Error Republishing: {0}", ee));
            }

            // An error of some sort must have stopped us from successfully generating
            // the content tree, so lets return null signifying there is no content available
            return null;
        }