예제 #1
0
        /// <summary>
        ///  Should we save this value to disk?
        /// </summary>
        /// <remarks>
        ///  In general we save everything to disk, even if we are not going to remimport it later
        ///  but you can stop this with RulesOnExport = true in the settings
        /// </remarks>

        protected override bool ShouldExport(XElement node, HandlerSettings config)
        {
            // We export trashed items by default, (but we don't import them by default)
            var trashed = node.Element("Info")?.Element("Trashed").ValueOrDefault(false);

            if (trashed.GetValueOrDefault(false) && !config.GetSetting <bool>("ExportTrashed", true))
            {
                return(false);
            }

            if (config.GetSetting("RulesOnExport", false))
            {
                // we run the import rules (but not the base rules as that would confuse.)
                if (!ImportTrashedItem(node, config))
                {
                    return(false);
                }
                if (!ImportPaths(node, config))
                {
                    return(false);
                }
            }

            return(true);
        }
예제 #2
0
        private bool ImportPaths(XElement node, HandlerSettings config)
        {
            var include = config.GetSetting("Include", "")
                          .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (include.Length > 0)
            {
                var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
                if (!string.IsNullOrWhiteSpace(path) && !include.Any(x => path.InvariantStartsWith(x)))
                {
                    logger.LogDebug("Not processing item, {0} path {1} not in include path", node.Attribute("Alias").ValueOrDefault("unknown"), path);
                    return(false);
                }
            }

            var exclude = config.GetSetting("Exclude", "")
                          .Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

            if (exclude.Length > 0)
            {
                var path = node.Element("Info")?.Element("Path").ValueOrDefault(string.Empty);
                if (!string.IsNullOrWhiteSpace(path) && exclude.Any(x => path.InvariantStartsWith(x)))
                {
                    logger.LogDebug("Not processing item, {0} path {1} is excluded", node.Attribute("Alias").ValueOrDefault("unknown"), path);
                    return(false);
                }
            }

            return(true);
        }
예제 #3
0
        /// <summary>
        ///  Workout if we are excluding this relationType from export/import
        /// </summary>
        protected override bool ShouldExport(XElement node, HandlerSettings config)
        {
            var exclude = config.GetSetting <string>("Exclude", defaultRelations);

            if (!string.IsNullOrWhiteSpace(exclude) && exclude.Contains(node.GetAlias()))
            {
                return(false);
            }

            return(true);
        }
예제 #4
0
        /// <summary>
        /// Import an item that is inthe trached state in the XML file.
        /// </summary>
        /// <remarks>
        /// Trashed items are only imported when the "ImportTrashed" setting is true on the handler
        /// </remarks>
        private bool ImportTrashedItem(XElement node, HandlerSettings config)
        {
            // unless the setting is explicit we don't import trashed items.
            var trashed = node.Element("Info")?.Element("Trashed").ValueOrDefault(false);

            if (trashed.GetValueOrDefault(false) && !config.GetSetting("ImportTrashed", true))
            {
                return(false);
            }

            return(true);
        }
예제 #5
0
        protected override void TerminateEvents(HandlerSettings settings)
        {
            RelationService.SavedRelationType   -= EventSavedItem;
            RelationService.DeletedRelationType -= EventDeletedItem;

            if (settings.GetSetting <bool>("IncludeRelations", false))
            {
                // relation saving is noisy, for example if you copy a load of
                // pages the save event fires a lot.
                RelationService.SavedRelation   -= RelationService_SavedRelation;
                RelationService.DeletedRelation -= RelationService_DeletedRelation;
            }
        }
예제 #6
0
        protected override void InitializeEvents(HandlerSettings settings)
        {
            RelationService.SavedRelationType   += EventSavedItem;
            RelationService.DeletedRelationType += EventDeletedItem;

            if (settings.GetSetting <bool>("IncludeRelations", false))
            {
                // relation saving is noisy, for example if you copy a load of
                // pages the save event fires a lot.
                RelationService.SavedRelation   += RelationService_SavedRelation;
                RelationService.DeletedRelation += RelationService_DeletedRelation;

                // the lock and timer are used so we don't do multiple saves
                // instead we queue things and when nothing has changed
                // for about 4 seconds, then we save everything in the queue.
                saveTimer          = new Timer(4064);
                saveTimer.Elapsed += SaveTimer_Elapsed;

                pendingSaveIds = new List <int>();
                saveLock       = new object();
            }
        }