/// <summary>
        /// Rebuilds the Routes for the given Node, optionally allows for settings to be passed
        /// </summary>
        /// <param name="NodeID">The NodeID</param>
        /// <param name="Settings">The Node Item Build Settings, if null will create settings based on the Node itself.</param>
        private static void RebuildRoutesByNode(int NodeID, NodeItemBuilderSettings Settings = null)
        {
            // If settings are not set, then get settings based on the given Node
            if (Settings == null)
            {
                // Get Site from Node
                TreeNode Page = DocumentHelper.GetDocuments()
                                .WhereEquals("NodeID", NodeID)
                                .Columns("NodeSiteID")
                                .FirstOrDefault();

                // Get Settings based on the Page itself
                Settings = GetNodeItemBuilderSettings(Page.NodeAliasPath, GetSite(Page.NodeSiteID).SiteName, true, false);
            }

            // Build and save
            NodeItem GivenNodeItem = new NodeItem(NodeID, Settings);

            if (ErrorOnConflict())
            {
                // If error on conflict, everything MUST be done syncly.
                GivenNodeItem.BuildChildren();
                if (GivenNodeItem.ConflictsExist())
                {
                    throw new UrlSlugCollisionException("Conflict Exists, aborting save");
                }
                // Save changes
                GivenNodeItem.SaveChanges();
            }
            else
            {
                // Do rest asyncly.
                QueueUpUrlSlugGeneration(GivenNodeItem);
            }
        }
        /// <summary>
        /// Rebuilds all URL Routes on the given Site
        /// </summary>
        /// <param name="SiteName">The Site name</param>
        public static void RebuildRoutesBySite(string SiteName)
        {
            //EventLogProvider.LogInformation("DynamicRouteTesting", "SyncBuildStart", eventDescription: DateTime.Now.ToString() + " " + DateTime.Now.Millisecond.ToString());
            // Get NodeItemBuilderSettings
            NodeItemBuilderSettings BuilderSettings = GetNodeItemBuilderSettings(SiteName, true, true, true, true, true);

            // Get root NodeID
            TreeNode RootNode = DocumentHelper.GetDocument(new NodeSelectionParameters()
            {
                AliasPath = "/",
                SiteName  = SiteName
            }, new TreeProvider());

            // Rebuild NodeItem tree structure, this will only affect the initial node syncly.
            NodeItem RootNodeItem = new NodeItem(RootNode.NodeID, BuilderSettings);

            if (ErrorOnConflict())
            {
                // If error on conflict, everything MUST be done syncly.
                RootNodeItem.BuildChildren();
                if (RootNodeItem.ConflictsExist())
                {
                    throw new UrlSlugCollisionException("Conflict Exists, aborting save");
                }
                // Save changes
                RootNodeItem.SaveChanges();
            }
            else
            {
                // Do rest asyncly.
                QueueUpUrlSlugGeneration(RootNodeItem);
            }
            //EventLogProvider.LogInformation("DynamicRouteTesting", "SyncBuildEnd", eventDescription: DateTime.Now.ToString() + " " + DateTime.Now.Millisecond.ToString());
        }
        /// <summary>
        /// Adds the NodeItem to the Url Slug Generation Queue so it can be handled asyncly in the order it's added.
        /// </summary>
        /// <param name="NodeItem">The Node Item</param>
        private static void QueueUpUrlSlugGeneration(NodeItem NodeItem)
        {
            // Add item to the Slug Generation Queue
            SlugGenerationQueueInfo NewQueue = new SlugGenerationQueueInfo()
            {
                SlugGenerationQueueNodeItem = SerializeObject <NodeItem>(NodeItem)
            };

            SlugGenerationQueueInfoProvider.SetSlugGenerationQueueInfo(NewQueue);

            // Run Queue checker
            CheckUrlSlugGenerationQueue();
        }
        /// <summary>
        /// Rebuilds the Routes for the given Node, optionally allows for settings to be passed
        /// </summary>
        /// <param name="NodeID">The NodeID</param>
        /// <param name="Settings">The Node Item Build Settings, if null will create settings based on the Node itself.</param>
        private static void RebuildRoutesByNode(int NodeID, NodeItemBuilderSettings Settings = null, bool CheckConflictOnly = false)
        {
            // If settings are not set, then get settings based on the given Node
            string NodeAliasPath = "";

            if (Settings == null)
            {
                // Get Site from Node
                TreeNode Page = DocumentHelper.GetDocuments()
                                .WhereEquals("NodeID", NodeID)
                                .Columns("NodeSiteID, NodeAliasPath")
                                .CombineWithAnyCulture()
                                .FirstOrDefault();
                NodeAliasPath = Page.NodeAliasPath;
                // Get Settings based on the Page itself
                Settings = GetNodeItemBuilderSettings(Page.NodeAliasPath, GetSite(Page.NodeSiteID).SiteName, true, false);
            }

            // Build and save
            NodeItem GivenNodeItem = new NodeItem(NodeID, Settings, CheckConflictOnly);

            if (ErrorOnConflict() || CheckConflictOnly)
            {
                // If error on conflict, everything MUST be done syncly.
                GivenNodeItem.BuildChildren();
                if (GivenNodeItem.ConflictsExist())
                {
                    string Error = $"Could not save document at {NodeAliasPath} due to a conflict in the generated route:\n\r {string.Join("\n\r", GivenNodeItem.GetConflictItems())}";
                    EventLogProvider.LogEvent("E", "DynamicRouting", "Conflict Exists", eventDescription: Error);
                    throw new UrlSlugCollisionException($"{Error} aborting save");
                }
                // Save changes if not only checking conflict
                if (CheckConflictOnly)
                {
                    return;
                }
                GivenNodeItem.SaveChanges();
            }
            else
            {
                // Save main one
                GivenNodeItem.SaveChanges(false);

                // Do rest asyncly.
                QueueUpUrlSlugGeneration(GivenNodeItem, Settings.CheckQueueImmediately);
            }
        }
Exemplo n.º 5
0
        public NodeItem(NodeItem parent, TreeNode Node, NodeItemBuilderSettings Settings, bool BuildChildren = false)
        {
            NodeID        = Node.NodeID;
            Parent        = parent;
            UrlSlugs      = new List <NodeUrlSlug>();
            Children      = new List <NodeItem>();
            IsContainer   = Node.IsCoupled;
            ClassName     = Node.ClassName;
            this.Settings = Settings;

            // Build it's slugs
            BuildUrlSlugs();

            // If build children, or settings to build descendents, or if an update was found, build children
            if (BuildChildren || Settings.BuildDescendents || HasUpdates)
            {
                this.BuildChildren();
            }
        }
        /// <summary>
        /// Rebuilds all URL Routes on the given Site
        /// </summary>
        /// <param name="SiteName">The Site name</param>
        public static void RebuildRoutesBySite(string SiteName)
        {
            //EventLogProvider.LogInformation("DynamicRouteTesting", "SyncBuildStart", eventDescription: DateTime.Now.ToString() + " " + DateTime.Now.Millisecond.ToString());
            // Get NodeItemBuilderSettings
            NodeItemBuilderSettings BuilderSettings = GetNodeItemBuilderSettings(SiteName, true, true, true, true, true);

            // Get root NodeID
            TreeNode RootNode = DocumentHelper.GetDocuments()
                                .Path("/", PathTypeEnum.Single)
                                .OnSite(SiteName)
                                .CombineWithAnyCulture()
                                .FirstOrDefault();

            // Rebuild NodeItem tree structure, this will only affect the initial node syncly.
            NodeItem RootNodeItem = new NodeItem(RootNode.NodeID, BuilderSettings);

            if (ErrorOnConflict())
            {
                // If error on conflict, everything MUST be done syncly.
                RootNodeItem.BuildChildren();
                if (RootNodeItem.ConflictsExist())
                {
                    EventLogProvider.LogEvent("E", "DynamicRouting", "Conflict Exists", eventDescription: $"Could not rebuild the site {SiteName}'s routes due to a conflict in the generated routes.");
                    throw new UrlSlugCollisionException("Conflict Exists, aborting save");
                }
                // Save changes
                RootNodeItem.SaveChanges();
            }
            else
            {
                // Save itself and then queue up rest
                RootNodeItem.SaveChanges(false);
                // Do rest asyncly.
                QueueUpUrlSlugGeneration(RootNodeItem, BuilderSettings.CheckQueueImmediately);
            }
            //EventLogProvider.LogInformation("DynamicRouteTesting", "SyncBuildEnd", eventDescription: DateTime.Now.ToString() + " " + DateTime.Now.Millisecond.ToString());
        }