예제 #1
0
        /// <summary>
        /// Gets a single Virtual MTA Group.
        /// </summary>
        /// <param name="id">ID of the Virtual MTA Group to get.</param>
        /// <returns>The Virtual MTA Group or NULL if none exist with ID</returns>
        public static VirtualMtaGroup GetVirtualMtaGroup(int id)
        {
            VirtualMtaGroup grp = VirtualMtaGroupDB.GetVirtualMtaGroup(id);

            grp.VirtualMtaCollection = VirtualMtaDB.GetVirtualMtasInVirtualMtaGroup(grp.ID);
            return(grp);
        }
예제 #2
0
        /// <summary>
        /// Get a collection of all of the Virtual MTA Groups.
        /// </summary>
        /// <returns></returns>
        public static IList <VirtualMtaGroup> GetAllVirtualMtaGroups()
        {
            IList <VirtualMtaGroup> ipGroups = VirtualMtaGroupDB.GetVirtualMtaGroups();

            // Get all the groups Virtual MTAs.
            foreach (VirtualMtaGroup grp in ipGroups)
            {
                grp.VirtualMtaCollection = VirtualMtaDB.GetVirtualMtasInVirtualMtaGroup(grp.ID);
            }

            return(ipGroups);
        }
예제 #3
0
        /// <summary>
        /// Gets the specfied MTA IP Group
        /// </summary>
        /// <param name="id">ID of the group to get.</param>
        /// <returns>The IP Group or NULL if doesn't exist.</returns>
        public static VirtualMtaGroup GetVirtualMtaGroup(int id)
        {
            VirtualMtaGroup group = null;

            // Try and get IPGroup from the in memory collection.
            if (_vmtaGroups.TryGetValue(id, out group))
            {
                // Only cache IP Groups for N minutes.
                if (group.CreatedTimestamp.AddMinutes(MtaParameters.MTA_CACHE_MINUTES) > DateTime.UtcNow)
                {
                    return(group);
                }
            }

            // We need to goto the database to get the group. Lock!
            lock (_MtaVirtualMtaGroupSyncLock)
            {
                // Check that something else didn't already load from the database.
                // If it did then we can just return that.
                _vmtaGroups.TryGetValue(id, out group);
                if (group != null && group.CreatedTimestamp.AddMinutes(MtaParameters.MTA_CACHE_MINUTES) > DateTime.UtcNow)
                {
                    return(group);
                }

                // Get group from the database.
                group = VirtualMtaGroupDB.GetVirtualMtaGroup(id);

                // Group doesn't exist, so don't try and get it's IPs
                if (group == null)
                {
                    return(null);
                }

                // Got the group, go get it's IPs.
                group.VirtualMtaCollection = VirtualMtaDB.GetVirtualMtasInVirtualMtaGroup(id);

                // Add the group to collection, so others can use it.
                _vmtaGroups.AddOrUpdate(id, group, new Func <int, VirtualMtaGroup, VirtualMtaGroup>(delegate(int key, VirtualMtaGroup existing)
                {
                    return(group);
                }));
                return(group);
            }
        }