/// <summary>
        /// Creates a new MX Pattern and it's default rules.
        /// </summary>
        /// <param name="name">Name of the pattern.</param>
        /// <param name="description">Description of the pattern.</param>
        /// <param name="type">The Type of the pattern.</param>
        /// <param name="pattern">The pattern value.</param>
        /// <param name="ipAddress">IP Address to limit the outbound rule to, or null if applies to all IP's.</param>
        /// <returns>ID of the MX Pattern.</returns>
        public static int CreatePattern(string name, string description, OutboundMxPatternType type, string pattern, int?ipAddress)
        {
            OutboundMxPattern mxPattern = new OutboundMxPattern
            {
                Description = description,
                Name        = name,
                Type        = type,
                Value       = pattern,
                LimitedToOutboundIpAddressID = ipAddress
            };

            mxPattern.ID = Save(mxPattern);

            // Create the three types of rule.
            Save(new OutboundRule(mxPattern.ID, OutboundRuleType.MaxConnections, "-1"));
            Save(new OutboundRule(mxPattern.ID, OutboundRuleType.MaxMessagesConnection, "-1"));
            Save(new OutboundRule(mxPattern.ID, OutboundRuleType.MaxMessagesPerHour, "-1"));

            return(mxPattern.ID);
        }
示例#2
0
        public bool Update(int patternID, string name, string description, int?virtualMTA, OutboundMxPatternType type, string patternValue, int maxConnections, int maxMessagesConn, int maxMessagesHour)
        {
            if (virtualMTA == -1)
            {
                virtualMTA = null;
            }

            OutboundMxPattern pattern = null;

            if (patternID == WebInterfaceLib.WebInterfaceParameters.OUTBOUND_RULES_NEW_PATTERN_ID)
            {
                pattern = new OutboundMxPattern();
            }
            else
            {
                pattern = MantaMTA.Core.DAL.OutboundRuleDB.GetOutboundRulePatterns().SingleOrDefault(p => p.ID == patternID);
            }
            if (pattern == null)
            {
                return(false);
            }

            pattern.Description = description.Trim();
            pattern.LimitedToOutboundIpAddressID = virtualMTA;
            pattern.Name  = name.Trim();
            pattern.Type  = type;
            pattern.Value = patternValue;
            pattern.ID    = OutboundRuleWebManager.Save(pattern);

            OutboundRuleWebManager.Save(new OutboundRule(pattern.ID, OutboundRuleType.MaxConnections, maxConnections.ToString()));
            OutboundRuleWebManager.Save(new OutboundRule(pattern.ID, OutboundRuleType.MaxMessagesConnection, maxMessagesConn.ToString()));
            OutboundRuleWebManager.Save(new OutboundRule(pattern.ID, OutboundRuleType.MaxMessagesPerHour, maxMessagesHour.ToString()));

            return(true);
        }