示例#1
0
        public override IDictionary <string, object> GetValues(IEnumerable <string> keys, string regionName = null)
        {
            if (regionName != null)
            {
                throw new NotSupportedException(SR.RegionName_not_supported);
            }
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            Dictionary <string, object> values = null;

            if (!IsDisposed)
            {
                foreach (string key in keys)
                {
                    if (key == null)
                    {
                        throw new ArgumentException(RH.Format(SR.Collection_contains_null_element, nameof(keys)));
                    }
                    object value = GetInternal(key, null);
                    if (value != null)
                    {
                        if (values == null)
                        {
                            values = new Dictionary <string, object>();
                        }
                        values[key] = value;
                    }
                }
            }
            return(values);
        }
示例#2
0
        internal static int GetIntValueFromTimeSpan(NameValueCollection config, string valueName, int defaultValue)
        {
            string sValue = config[valueName];

            if (sValue == null)
            {
                return(defaultValue);
            }

            if (sValue == "Infinite")
            {
                return(Int32.MaxValue);
            }

            TimeSpan tValue;

            if (!TimeSpan.TryParse(sValue, out tValue) || tValue <= TimeSpan.Zero)
            {
                throw new ArgumentException(RH.Format(R.TimeSpan_invalid_format, valueName, sValue), "config");
            }

            double milliseconds = tValue.TotalMilliseconds;
            int    iValue       = (milliseconds < (double)Int32.MaxValue) ? (int)milliseconds : Int32.MaxValue;

            return(iValue);
        }
示例#3
0
        public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable <string> keys, string regionName = null)
        {
            if (regionName != null)
            {
                throw new NotSupportedException(SR.RegionName_not_supported);
            }
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            List <string> keysClone = new List <string>(keys);

            if (keysClone.Count == 0)
            {
                throw new ArgumentException(RH.Format(SR.Empty_collection, nameof(keys)));
            }

            foreach (string key in keysClone)
            {
                if (key == null)
                {
                    throw new ArgumentException(RH.Format(SR.Collection_contains_null_element, nameof(keys)));
                }
            }

            return(new MemoryCacheEntryChangeMonitor(keysClone.AsReadOnly(), regionName, this));
        }
示例#4
0
        public HostFileChangeMonitor(IList <string> filePaths)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }
            if (filePaths.Count == 0)
            {
                throw new ArgumentException(RH.Format(R.Empty_collection, new object[] { "filePaths" }));
            }
            foreach (string str in filePaths)
            {
                if (string.IsNullOrEmpty(str))
                {
                    throw new ArgumentException(RH.Format(R.Collection_contains_null_or_empty_string, new object[] { "filePaths" }));
                }
                new FileIOPermission(FileIOPermissionAccess.PathDiscovery, str).Demand();
            }
            List <string> list = new List <string>(filePaths.Count);

            list.AddRange(filePaths);
            this._filePaths = list.AsReadOnly();
            InitFCN();
            this.InitDisposableMembers();
        }
示例#5
0
        internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed)
        {
            string sValue = config[valueName];

            if (sValue == null)
            {
                return(defaultValue);
            }

            int iValue;

            if (!Int32.TryParse(sValue, out iValue) ||
                iValue < 0 ||
                (!zeroAllowed && iValue == 0))
            {
                if (zeroAllowed)
                {
                    throw new ArgumentException(RH.Format(R.Value_must_be_non_negative_integer, valueName, sValue), "config");
                }

                throw new ArgumentException(RH.Format(R.Value_must_be_positive_integer, valueName, sValue), "config");
            }

            if (maxValueAllowed > 0 && iValue > maxValueAllowed)
            {
                throw new ArgumentException(RH.Format(R.Value_too_big,
                                                      valueName,
                                                      sValue,
                                                      maxValueAllowed.ToString(CultureInfo.InvariantCulture)), "config");
            }

            return(iValue);
        }
        public override IDictionary <string, object> GetValues(IEnumerable <string> keys, string regionName = null)
        {
            if (regionName != null)
            {
                throw new NotSupportedException(R.RegionName_not_supported);
            }
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }
            Dictionary <string, object> dictionary = null;

            if (!this.IsDisposed)
            {
                foreach (string str in keys)
                {
                    if (str == null)
                    {
                        throw new ArgumentException(RH.Format(R.Collection_contains_null_element, new object[] { "keys" }));
                    }
                    object obj2 = this.GetInternal(str, null);
                    if (obj2 != null)
                    {
                        if (dictionary == null)
                        {
                            dictionary = new Dictionary <string, object>();
                        }
                        dictionary[str] = obj2;
                    }
                }
            }
            return(dictionary);
        }
        public override CacheEntryChangeMonitor CreateCacheEntryChangeMonitor(IEnumerable <string> keys, string regionName = null)
        {
            if (regionName != null)
            {
                throw new NotSupportedException(R.RegionName_not_supported);
            }
            if (keys == null)
            {
                throw new ArgumentNullException("keys");
            }
            List <string> list = new List <string>(keys);

            if (list.Count == 0)
            {
                throw new ArgumentException(RH.Format(R.Empty_collection, new object[] { "keys" }));
            }
            using (List <string> .Enumerator enumerator = list.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    if (enumerator.Current == null)
                    {
                        throw new ArgumentException(RH.Format(R.Collection_contains_null_element, new object[] { "keys" }));
                    }
                }
            }
            return(new MemoryCacheEntryChangeMonitor(list.AsReadOnly(), regionName, this));
        }
示例#8
0
        public HostFileChangeMonitor(IList <String> filePaths)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }
            if (filePaths.Count == 0)
            {
                throw new ArgumentException(RH.Format(SR.Empty_collection, "filePaths"));
            }

            _filePaths = SanitizeFilePathsList(filePaths);

            InitFCN();
            InitDisposableMembers();
        }
示例#9
0
        public HostFileChangeMonitor(IList <String> filePaths)
        {
            if (filePaths == null)
            {
                throw new ArgumentNullException("filePaths");
            }
            if (filePaths.Count == 0)
            {
                throw new ArgumentException(RH.Format(R.Empty_collection, "filePaths"));
            }

            // *SECURITY* - filePaths is untrusted and should not be consumed outside of the sanitization method.
            _filePaths = SanitizeFilePathsList(filePaths);

            InitFCN();
            InitDisposableMembers();
        }
示例#10
0
        internal static bool GetBooleanValue(NameValueCollection config, string valueName, bool defaultValue)
        {
            string sValue = config[valueName];

            if (sValue == null)
            {
                return(defaultValue);
            }

            bool bValue;

            if (!Boolean.TryParse(sValue, out bValue))
            {
                throw new ArgumentException(RH.Format(R.Value_must_be_boolean, valueName, sValue), "config");
            }

            return(bValue);
        }
示例#11
0
        private static ReadOnlyCollection <string> SanitizeFilePathsList(IList <string> filePaths)
        {
            List <string> newList = new List <string>(filePaths.Count);

            foreach (string path in filePaths)
            {
                if (String.IsNullOrEmpty(path))
                {
                    throw new ArgumentException(RH.Format(SR.Collection_contains_null_or_empty_string, "filePaths"));
                }
                else
                {
                    newList.Add(path);
                }
            }

            return(newList.AsReadOnly());
        }
 private void ValidatePolicy(CacheItemPolicy policy)
 {
     if ((policy.AbsoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration) && (policy.SlidingExpiration != ObjectCache.NoSlidingExpiration))
     {
         throw new ArgumentException(R.Invalid_expiration_combination, "policy");
     }
     if ((policy.SlidingExpiration < ObjectCache.NoSlidingExpiration) || (OneYear < policy.SlidingExpiration))
     {
         throw new ArgumentOutOfRangeException("policy", RH.Format(R.Argument_out_of_range, new object[] { "SlidingExpiration", ObjectCache.NoSlidingExpiration, OneYear }));
     }
     if ((policy.RemovedCallback != null) && (policy.UpdateCallback != null))
     {
         throw new ArgumentException(R.Invalid_callback_combination, "policy");
     }
     if ((policy.Priority != CacheItemPriority.Default) && (policy.Priority != CacheItemPriority.NotRemovable))
     {
         throw new ArgumentOutOfRangeException("policy", RH.Format(R.Argument_out_of_range, new object[] { "Priority", CacheItemPriority.Default, CacheItemPriority.NotRemovable }));
     }
 }
示例#13
0
 private void ValidatePolicy(CacheItemPolicy policy)
 {
     if (policy.AbsoluteExpiration != ObjectCache.InfiniteAbsoluteExpiration &&
         policy.SlidingExpiration != ObjectCache.NoSlidingExpiration)
     {
         throw new ArgumentException(SR.Invalid_expiration_combination, nameof(policy));
     }
     if (policy.SlidingExpiration < ObjectCache.NoSlidingExpiration || s_oneYear < policy.SlidingExpiration)
     {
         throw new ArgumentOutOfRangeException(nameof(policy), RH.Format(SR.Argument_out_of_range, "SlidingExpiration", ObjectCache.NoSlidingExpiration, s_oneYear));
     }
     if (policy.RemovedCallback != null &&
         policy.UpdateCallback != null)
     {
         throw new ArgumentException(SR.Invalid_callback_combination, nameof(policy));
     }
     if (policy.Priority != CacheItemPriority.Default && policy.Priority != CacheItemPriority.NotRemovable)
     {
         throw new ArgumentOutOfRangeException(nameof(policy), RH.Format(SR.Argument_out_of_range, "Priority", CacheItemPriority.Default, CacheItemPriority.NotRemovable));
     }
 }
        internal static int GetIntValueFromTimeSpan(NameValueCollection config, string valueName, int defaultValue)
        {
            TimeSpan span;
            string   s = config[valueName];

            switch (s)
            {
            case null:
                return(defaultValue);

            case "Infinite":
                return(0x7fffffff);
            }
            if (!TimeSpan.TryParse(s, out span) || (span <= TimeSpan.Zero))
            {
                throw new ArgumentException(RH.Format(R.TimeSpan_invalid_format, new object[] { valueName, s }), "config");
            }
            double totalMilliseconds = span.TotalMilliseconds;

            return((totalMilliseconds < 2147483647.0) ? ((int)totalMilliseconds) : 0x7fffffff);
        }
示例#15
0
        private static ReadOnlyCollection <string> SanitizeFilePathsList(IList <string> filePaths)
        {
            List <string> newList = new List <string>(filePaths.Count);

            foreach (string path in filePaths)
            {
                if (String.IsNullOrEmpty(path))
                {
                    throw new ArgumentException(RH.Format(R.Collection_contains_null_or_empty_string, "filePaths"));
                }
                else
                {
                    // DevDiv #269534: When we use a user-provided string in the constructor to this FileIOPermission and demand the permission,
                    // we need to be certain that we're adding *exactly that string* to the new list we're generating. The original code tried to
                    // optimize by checking all of the permissions upfront then doing a List<T>.AddRange at the end, but this opened the method
                    // to a TOCTOU attack since a malicious user could have modified the original IList<T> between the two calls.
                    new FileIOPermission(FileIOPermissionAccess.PathDiscovery, path).Demand();
                    newList.Add(path);
                }
            }

            return(newList.AsReadOnly());
        }
        internal static int GetIntValue(NameValueCollection config, string valueName, int defaultValue, bool zeroAllowed, int maxValueAllowed)
        {
            int    num;
            string s = config[valueName];

            if (s == null)
            {
                return(defaultValue);
            }
            if ((!int.TryParse(s, out num) || (num < 0)) || (!zeroAllowed && (num == 0)))
            {
                if (zeroAllowed)
                {
                    throw new ArgumentException(RH.Format(R.Value_must_be_non_negative_integer, new object[] { valueName, s }), "config");
                }
                throw new ArgumentException(RH.Format(R.Value_must_be_positive_integer, new object[] { valueName, s }), "config");
            }
            if ((maxValueAllowed > 0) && (num > maxValueAllowed))
            {
                throw new ArgumentException(RH.Format(R.Value_too_big, new object[] { valueName, s, maxValueAllowed.ToString(CultureInfo.InvariantCulture) }), "config");
            }
            return(num);
        }