You've already forked linux-packaging-mono
Imported Upstream version 4.6.0.125
Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
parent
a569aebcfd
commit
e79aa3c0ed
@ -0,0 +1,20 @@
|
||||
// <copyright file="CacheSectionGroup.cs" company="Microsoft">
|
||||
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Configuration;
|
||||
|
||||
namespace System.Runtime.Caching.Configuration {
|
||||
public sealed class CachingSectionGroup : ConfigurationSectionGroup {
|
||||
public CachingSectionGroup() {
|
||||
}
|
||||
|
||||
// public properties
|
||||
[ConfigurationProperty("memoryCache")]
|
||||
public MemoryCacheSection MemoryCaches {
|
||||
get {
|
||||
return (MemoryCacheSection)Sections["memoryCache"];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,67 @@
|
||||
// <copyright file="ConfigUtil.cs" company="Microsoft">
|
||||
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
using System;
|
||||
using System.Runtime.Caching.Resources;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
|
||||
namespace System.Runtime.Caching.Configuration {
|
||||
internal static class ConfigUtil {
|
||||
internal const string CacheMemoryLimitMegabytes = "cacheMemoryLimitMegabytes";
|
||||
internal const string PhysicalMemoryLimitPercentage = "physicalMemoryLimitPercentage";
|
||||
internal const string PollingInterval = "pollingInterval";
|
||||
internal const int DefaultPollingTimeMilliseconds = 120000;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -0,0 +1,126 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MemoryCacheSettingsSettingsCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Runtime.Caching.Configuration {
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Configuration;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Security.Permissions;
|
||||
|
||||
public sealed class MemoryCacheElement : ConfigurationElement {
|
||||
private static ConfigurationPropertyCollection _properties;
|
||||
private static readonly ConfigurationProperty _propName;
|
||||
private static readonly ConfigurationProperty _propPhysicalMemoryLimitPercentage;
|
||||
private static readonly ConfigurationProperty _propCacheMemoryLimitMegabytes;
|
||||
private static readonly ConfigurationProperty _propPollingInterval;
|
||||
|
||||
static MemoryCacheElement() {
|
||||
// Property initialization
|
||||
_properties = new ConfigurationPropertyCollection();
|
||||
|
||||
_propName =
|
||||
new ConfigurationProperty("name",
|
||||
typeof(string),
|
||||
null,
|
||||
new WhiteSpaceTrimStringConverter(),
|
||||
new StringValidator(1),
|
||||
ConfigurationPropertyOptions.IsRequired |
|
||||
ConfigurationPropertyOptions.IsKey);
|
||||
|
||||
_propPhysicalMemoryLimitPercentage =
|
||||
new ConfigurationProperty("physicalMemoryLimitPercentage",
|
||||
typeof(int),
|
||||
(int)0,
|
||||
null,
|
||||
new IntegerValidator(0, 100),
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
_propCacheMemoryLimitMegabytes =
|
||||
new ConfigurationProperty("cacheMemoryLimitMegabytes",
|
||||
typeof(int),
|
||||
(int)0,
|
||||
null,
|
||||
new IntegerValidator(0, Int32.MaxValue),
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
_propPollingInterval =
|
||||
new ConfigurationProperty("pollingInterval",
|
||||
typeof(TimeSpan),
|
||||
TimeSpan.FromMilliseconds(ConfigUtil.DefaultPollingTimeMilliseconds),
|
||||
new InfiniteTimeSpanConverter(),
|
||||
new PositiveTimeSpanValidator(),
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
_properties.Add(_propName);
|
||||
_properties.Add(_propPhysicalMemoryLimitPercentage);
|
||||
_properties.Add(_propCacheMemoryLimitMegabytes);
|
||||
_properties.Add(_propPollingInterval);
|
||||
}
|
||||
|
||||
internal MemoryCacheElement() {
|
||||
}
|
||||
|
||||
public MemoryCacheElement(string name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties {
|
||||
get {
|
||||
return _properties;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("name", DefaultValue = "", IsRequired = true, IsKey = true)]
|
||||
[TypeConverter(typeof(WhiteSpaceTrimStringConverter))]
|
||||
[StringValidator(MinLength = 1)]
|
||||
public string Name {
|
||||
get {
|
||||
return (string)base["name"];
|
||||
}
|
||||
set {
|
||||
base["name"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("physicalMemoryLimitPercentage", DefaultValue = (int)0)]
|
||||
[IntegerValidator(MinValue = 0, MaxValue = 100)]
|
||||
public int PhysicalMemoryLimitPercentage {
|
||||
get {
|
||||
return (int)base["physicalMemoryLimitPercentage"];
|
||||
}
|
||||
set {
|
||||
base["physicalMemoryLimitPercentage"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("cacheMemoryLimitMegabytes", DefaultValue = (int)0)]
|
||||
[IntegerValidator(MinValue = 0)]
|
||||
public int CacheMemoryLimitMegabytes {
|
||||
get {
|
||||
return (int)base["cacheMemoryLimitMegabytes"];
|
||||
}
|
||||
set {
|
||||
base["cacheMemoryLimitMegabytes"] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("pollingInterval", DefaultValue = "00:02:00")]
|
||||
[TypeConverter(typeof(InfiniteTimeSpanConverter))]
|
||||
public TimeSpan PollingInterval {
|
||||
get {
|
||||
return (TimeSpan)base["pollingInterval"];
|
||||
}
|
||||
set {
|
||||
base["pollingInterval"] = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
// <copyright file="MemoryCacheSection.cs" company="Microsoft">
|
||||
// Copyright (c) 2009 Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
|
||||
using System;
|
||||
using System.Collections.Specialized;
|
||||
using System.Configuration;
|
||||
using System.Runtime.Caching.Resources;
|
||||
|
||||
namespace System.Runtime.Caching.Configuration {
|
||||
|
||||
/*
|
||||
<system.runtime.caching>
|
||||
<memoryCaches>
|
||||
<namedCaches>
|
||||
<add name="Default" physicalMemoryPercentage="0" pollingInterval="00:02:00"/>
|
||||
<add name="Foo" physicalMemoryPercentage="0" pollingInterval="00:02:00"/>
|
||||
<add name="Bar" physicalMemoryPercentage="0" pollingInterval="00:02:00"/>
|
||||
</namedCaches>
|
||||
</memoryCaches>
|
||||
</system.caching>
|
||||
|
||||
*/
|
||||
|
||||
public sealed class MemoryCacheSection : ConfigurationSection {
|
||||
private static ConfigurationPropertyCollection _properties;
|
||||
private static readonly ConfigurationProperty _propNamedCaches;
|
||||
|
||||
static MemoryCacheSection() {
|
||||
_propNamedCaches = new ConfigurationProperty("namedCaches",
|
||||
typeof(MemoryCacheSettingsCollection),
|
||||
null, // defaultValue
|
||||
ConfigurationPropertyOptions.None);
|
||||
|
||||
_properties = new ConfigurationPropertyCollection();
|
||||
_properties.Add(_propNamedCaches);
|
||||
}
|
||||
|
||||
public MemoryCacheSection() {
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties {
|
||||
get {
|
||||
return _properties;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty("namedCaches")]
|
||||
public MemoryCacheSettingsCollection NamedCaches {
|
||||
get {
|
||||
return (MemoryCacheSettingsCollection)base[_propNamedCaches];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,91 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// <copyright file="MemoryCacheSettingsSettingsCollection.cs" company="Microsoft">
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// </copyright>
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Runtime.Caching.Configuration {
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Specialized;
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Security.Permissions;
|
||||
|
||||
[ConfigurationCollection(typeof(MemoryCacheElement),
|
||||
CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
|
||||
public sealed class MemoryCacheSettingsCollection : ConfigurationElementCollection {
|
||||
private static ConfigurationPropertyCollection _properties;
|
||||
|
||||
static MemoryCacheSettingsCollection() {
|
||||
// Property initialization
|
||||
_properties = new ConfigurationPropertyCollection();
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties {
|
||||
get {
|
||||
return _properties;
|
||||
}
|
||||
}
|
||||
|
||||
public MemoryCacheSettingsCollection() {
|
||||
}
|
||||
|
||||
public MemoryCacheElement this[int index] {
|
||||
get { return (MemoryCacheElement)base.BaseGet(index); }
|
||||
set {
|
||||
if (base.BaseGet(index) != null) {
|
||||
base.BaseRemoveAt(index);
|
||||
}
|
||||
base.BaseAdd(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
public new MemoryCacheElement this[string key] {
|
||||
get {
|
||||
return (MemoryCacheElement)BaseGet(key);
|
||||
}
|
||||
}
|
||||
|
||||
public override ConfigurationElementCollectionType CollectionType {
|
||||
get {
|
||||
return ConfigurationElementCollectionType.AddRemoveClearMapAlternate;
|
||||
}
|
||||
}
|
||||
|
||||
public int IndexOf(MemoryCacheElement cache) {
|
||||
return BaseIndexOf(cache);
|
||||
}
|
||||
|
||||
public void Add(MemoryCacheElement cache) {
|
||||
BaseAdd(cache);
|
||||
}
|
||||
|
||||
public void Remove(MemoryCacheElement cache) {
|
||||
BaseRemove(cache.Name);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index) {
|
||||
BaseRemoveAt(index);
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
BaseClear();
|
||||
}
|
||||
|
||||
protected override ConfigurationElement CreateNewElement() {
|
||||
return new MemoryCacheElement();
|
||||
}
|
||||
|
||||
protected override ConfigurationElement CreateNewElement(string elementName) {
|
||||
return new MemoryCacheElement(elementName);
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element) {
|
||||
return ((MemoryCacheElement)element).Name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user