Example #1
0
        private static IFilter ReadSmallerThanFilter(XmlReader xml, AttributeParser attributes)
        {
            attributes.AssertNotEmpty();

            var b  = attributes.GetOptional("bytes").AsLong(0);
            var kb = attributes.GetOptional("kb").AsLong(0);
            var mb = attributes.GetOptional("mb").AsLong(0);
            var tb = attributes.GetOptional("tb").AsLong(0);

            return(new SmallerThanFilter {
                Size = b + (kb << 10) + (mb << 20) + (tb << 30)
            });
        }
Example #2
0
        private static IFilter ReadWildcardsFilter(XmlReader xml, AttributeParser attributes)
        {
            var pattern = attributes.GetOptional("pattern").AsString();

            if (string.IsNullOrEmpty(pattern))
            {
                pattern = xml.ReadElementContentAsString();
            }

            return(new WildcardsFilter(pattern));
        }
Example #3
0
        private static IFilter ReadOlderThanFilter(XmlReader xml, AttributeParser attributes)
        {
            attributes.AssertNotEmpty();

            var years   = attributes.GetOptional("years").AsInt(0);
            var months  = attributes.GetOptional("months").AsInt(0);
            var weeks   = attributes.GetOptional("weeks").AsInt(0);
            var days    = attributes.GetOptional("days").AsInt(0);
            var hours   = attributes.GetOptional("hours").AsInt(0);
            var minutes = attributes.GetOptional("minutes").AsInt(0);
            var seconds = attributes.GetOptional("seconds").AsInt(0);

            return(new OlderThanFilter(years, months, days + 7 * weeks, hours, minutes, seconds));
        }
        private static IFilter ReadWildcardsFilter(XmlReader xml, AttributeParser attributes)
        {
            var pattern = attributes.GetOptional("pattern").AsString();

            if (string.IsNullOrEmpty(pattern))
                pattern = xml.ReadElementContentAsString();

            return new WildcardsFilter(pattern);
        }
        private static IFilter ReadSmallerThanFilter(XmlReader xml, AttributeParser attributes)
        {
            attributes.AssertNotEmpty();

            var b  = attributes.GetOptional("bytes").AsLong(0);
            var kb = attributes.GetOptional("kb").AsLong(0);
            var mb = attributes.GetOptional("mb").AsLong(0);
            var tb = attributes.GetOptional("tb").AsLong(0);

            return new SmallerThanFilter { Size = b + (kb << 10) + (mb << 20) + (tb << 30) };
        }
        private static IFilter ReadOlderThanFilter(XmlReader xml, AttributeParser attributes)
        {
            attributes.AssertNotEmpty();

            var years   = attributes.GetOptional("years").AsInt(0);
            var months  = attributes.GetOptional("months").AsInt(0);
            var weeks   = attributes.GetOptional("weeks").AsInt(0);
            var days    = attributes.GetOptional("days").AsInt(0);
            var hours   = attributes.GetOptional("hours").AsInt(0);
            var minutes = attributes.GetOptional("minutes").AsInt(0);
            var seconds = attributes.GetOptional("seconds").AsInt(0);

            return new OlderThanFilter(years, months, days+7*weeks, hours, minutes, seconds);
        }
        internal static IRule ReadRule(XmlReader xml, bool includeFilter=true)
        {
            IRule rule;

            var elementName = xml.Name;

            switch (elementName.ToLower())
            {
                case "recycle":
                    rule = new RecycleRule();
                    break;
                case "delete":
                    rule = new DeleteRule();
                    break;
                case "ignore":
                    rule = new IgnoreRule();
                    break;
                case "move":
                    rule = new MoveRule();
                    break;
                case "rename":
                    rule = new RenameRule();
                    break;
                default:
                    xml.Skip();
                    throw new IgnoredElementException(elementName);
            }

            var attributes = new AttributeParser(xml);

            rule.Target              = attributes.GetOptional("Target").AsEnum(RuleTarget.FilesAndFolders);
            rule.AppliesToSubfolders = attributes.GetOptional("ApplyToSubfolders").AsBool(true);

            if (rule is MoveRuleBase)
            {
                ((MoveRuleBase)rule).IfExists =
                    attributes.GetOptional("ifexists").AsEnum(MoveRuleBase.IfExistsMode.Cancel);
            }

            if( rule is MoveRule)
            {
                ((MoveRule)rule).Destination = attributes.GetMandatory("destination").AsString();
                ((MoveRule)rule).CreateFolder = attributes.GetOptional("createfolder").AsBool(true);
            }

            if (rule is RenameRule)
            {
                ((RenameRule)rule).Name = attributes.GetMandatory("name").AsString();
            }

            attributes.AssertNoUnused();

            if (includeFilter)
            {
                var filters = ReadFilters(xml).ToArray();

                if (filters.Length == 0)
                    throw new Exception("You must specificy a filter for this rule");

                if (filters.Length > 1)
                    throw new Exception("You can only specify one filter at rule's root. Please use <MatchingAll>, <MatchingAny> or <MatchingNone>.");

                rule.Filter = filters.First();
            }

            return rule;
        }
Example #8
0
        internal static IRule ReadRule(XmlReader xml, bool includeFilter = true)
        {
            IRule rule;

            var elementName = xml.Name;

            switch (elementName.ToLower())
            {
            case "recycle":
                rule = new RecycleRule();
                break;

            case "delete":
                rule = new DeleteRule();
                break;

            case "ignore":
                rule = new IgnoreRule();
                break;

            case "move":
                rule = new MoveRule();
                break;

            case "rename":
                rule = new RenameRule();
                break;

            default:
                xml.Skip();
                throw new IgnoredElementException(elementName);
            }

            var attributes = new AttributeParser(xml);

            rule.Target = attributes.GetOptional("Target").AsEnum(RuleTarget.FilesAndFolders);
            rule.AppliesToSubfolders = attributes.GetOptional("ApplyToSubfolders").AsBool(true);

            if (rule is MoveRuleBase)
            {
                ((MoveRuleBase)rule).IfExists =
                    attributes.GetOptional("ifexists").AsEnum(MoveRuleBase.IfExistsMode.Cancel);
            }

            if (rule is MoveRule)
            {
                ((MoveRule)rule).Destination  = attributes.GetMandatory("destination").AsString();
                ((MoveRule)rule).CreateFolder = attributes.GetOptional("createfolder").AsBool(true);
            }

            if (rule is RenameRule)
            {
                ((RenameRule)rule).Name = attributes.GetMandatory("name").AsString();
            }

            attributes.AssertNoUnused();

            if (includeFilter)
            {
                var filters = ReadFilters(xml).ToArray();

                if (filters.Length == 0)
                {
                    throw new Exception("You must specificy a filter for this rule");
                }

                if (filters.Length > 1)
                {
                    throw new Exception("You can only specify one filter at rule's root. Please use <MatchingAll>, <MatchingAny> or <MatchingNone>.");
                }

                rule.Filter = filters.First();
            }

            return(rule);
        }