Example #1
0
    /// <summary>
    /// Gets all IP bans cached in the cache.
    /// </summary>
    /// <returns>Dictionary with per range (key) a dictionary with all IP addresses as keys, with the segments falling into the range concatenated
    /// to eachother with a '.'</returns>
    public static Dictionary <int, Dictionary <string, IPBanEntity> > GetAllIPBans()
    {
        Cache activeCache = HttpRuntime.Cache;
        Dictionary <int, Dictionary <string, IPBanEntity> > toReturn = (Dictionary <int, Dictionary <string, IPBanEntity> >)activeCache[CacheKeys.AllIPBans];

        if (toReturn == null)
        {
            // not there, store it.
            IPBanCollection allIPBans = SecurityGuiHelper.GetAllIPBans(0, 0, false);
            toReturn = new Dictionary <int, Dictionary <string, IPBanEntity> >();
            foreach (IPBanEntity currentIPBan in allIPBans)
            {
                Dictionary <string, IPBanEntity> ipAddresses = null;
                if (!toReturn.TryGetValue(currentIPBan.Range, out ipAddresses))
                {
                    // not there yet, add
                    ipAddresses = new Dictionary <string, IPBanEntity>();
                    toReturn.Add(currentIPBan.Range, ipAddresses);
                }

                // add ip address with segments in range to ipAddresses' key list.
                string key = string.Empty;
                switch (currentIPBan.Range)
                {
                case 8:
                    key = currentIPBan.IPSegment1.ToString();
                    break;

                case 16:
                    key = String.Format("{0}.{1}", currentIPBan.IPSegment1, currentIPBan.IPSegment2);
                    break;

                case 24:
                    key = String.Format("{0}.{1}.{2}", currentIPBan.IPSegment1, currentIPBan.IPSegment2, currentIPBan.IPSegment3);
                    break;

                case 32:
                    key = String.Format("{0}.{1}.{2}.{3}", currentIPBan.IPSegment1, currentIPBan.IPSegment2, currentIPBan.IPSegment3, currentIPBan.IPSegment4);
                    break;

                default:
                    // illegal range, ignore
                    continue;
                }

                if (!ipAddresses.ContainsKey(key))
                {
                    ipAddresses.Add(key, currentIPBan);
                }
            }

            // just store it in the cache without any dependency
            activeCache.Insert(CacheKeys.AllIPBans, toReturn);
        }

        return(toReturn);
    }
Example #2
0
 /// <summary>
 /// Handles the PerformSelect event of the _ipBanDS control.
 /// </summary>
 /// <param name="sender">The source of the event.</param>
 /// <param name="e">The <see cref="SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs"/> instance containing the event data.</param>
 protected void _ipBanDS_PerformSelect(object sender, SD.LLBLGen.Pro.ORMSupportClasses.PerformSelectEventArgs e)
 {
     // fetch the page requested, using a BL method. We'll receive a collection from the BL method and will set the collection of the control to the
     // collection we'll receive. Specify that the user entity is prefetched into the IPBan entity.
     _ipBanDS.EntityCollection = SecurityGuiHelper.GetAllIPBans(e.PageNumber, e.PageSize, true);
 }