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,117 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xaml.Hosting.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Web;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using System.Runtime;
|
||||
|
||||
public sealed class HandlerElement : ConfigurationElement
|
||||
{
|
||||
static ConfigurationPropertyCollection properties = InitializeProperties();
|
||||
|
||||
Type httpHandlerCLRType;
|
||||
|
||||
Type xamlRootElementClrType;
|
||||
|
||||
static ConfigurationPropertyCollection InitializeProperties()
|
||||
{
|
||||
ConfigurationProperty handler = new ConfigurationProperty(XamlHostingConfiguration.HttpHandlerType, typeof(string), " ", null, new StringValidator(1), ConfigurationPropertyOptions.IsRequired);
|
||||
ConfigurationProperty xamlRoot = new ConfigurationProperty(XamlHostingConfiguration.XamlRootElementType, typeof(string), " ", null, new StringValidator(1), ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired);
|
||||
ConfigurationPropertyCollection tempProperties = new ConfigurationPropertyCollection();
|
||||
tempProperties.Add(xamlRoot);
|
||||
tempProperties.Add(handler);
|
||||
return tempProperties;
|
||||
}
|
||||
|
||||
public HandlerElement()
|
||||
{
|
||||
}
|
||||
|
||||
[SuppressMessage(FxCop.Category.Usage, FxCop.Rule.DoNotCallOverridableMethodsInConstructors,
|
||||
Justification = "This is enforced by configuration classes in framework library")]
|
||||
public HandlerElement(string xamlType, string handlerType)
|
||||
{
|
||||
XamlRootElementType = xamlType;
|
||||
HttpHandlerType = handlerType;
|
||||
}
|
||||
|
||||
[ConfigurationProperty(XamlHostingConfiguration.HttpHandlerType, DefaultValue = " ",
|
||||
Options = ConfigurationPropertyOptions.IsRequired)]
|
||||
[StringValidator(MinLength = 1)]
|
||||
public string HttpHandlerType
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[XamlHostingConfiguration.HttpHandlerType];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
value = string.Empty;
|
||||
}
|
||||
base[XamlHostingConfiguration.HttpHandlerType] = value;
|
||||
}
|
||||
}
|
||||
|
||||
[ConfigurationProperty(XamlHostingConfiguration.XamlRootElementType, DefaultValue = " ",
|
||||
Options = ConfigurationPropertyOptions.IsKey | ConfigurationPropertyOptions.IsRequired)]
|
||||
[StringValidator(MinLength = 1)]
|
||||
public string XamlRootElementType
|
||||
{
|
||||
get
|
||||
{
|
||||
return (string)base[XamlHostingConfiguration.XamlRootElementType];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
{
|
||||
value = string.Empty;
|
||||
}
|
||||
base[XamlHostingConfiguration.XamlRootElementType] = value;
|
||||
}
|
||||
}
|
||||
|
||||
internal string Key
|
||||
{
|
||||
get
|
||||
{
|
||||
return XamlRootElementType;
|
||||
}
|
||||
}
|
||||
|
||||
protected override ConfigurationPropertyCollection Properties
|
||||
{
|
||||
get
|
||||
{
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
|
||||
internal Type LoadHttpHandlerType()
|
||||
{
|
||||
if (this.httpHandlerCLRType == null)
|
||||
{
|
||||
this.httpHandlerCLRType = Type.GetType(HttpHandlerType, true);
|
||||
}
|
||||
return this.httpHandlerCLRType;
|
||||
}
|
||||
|
||||
|
||||
internal Type LoadXamlRootElementType()
|
||||
{
|
||||
if (this.xamlRootElementClrType == null)
|
||||
{
|
||||
this.xamlRootElementClrType = Type.GetType(XamlRootElementType, true);
|
||||
}
|
||||
return this.xamlRootElementClrType;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,131 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xaml.Hosting.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Collections.Generic;
|
||||
using System.Web;
|
||||
using System.Runtime;
|
||||
|
||||
[ConfigurationCollection(typeof(HandlerElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMapAlternate)]
|
||||
public sealed class HandlerElementCollection : ConfigurationElementCollection
|
||||
{
|
||||
public HandlerElementCollection()
|
||||
: base(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
}
|
||||
|
||||
public override ConfigurationElementCollectionType CollectionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return ConfigurationElementCollectionType.AddRemoveClearMapAlternate;
|
||||
}
|
||||
}
|
||||
|
||||
protected override bool ThrowOnDuplicate
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public HandlerElement this[int index]
|
||||
{
|
||||
get
|
||||
{
|
||||
return (HandlerElement)base.BaseGet(index);
|
||||
}
|
||||
set
|
||||
{
|
||||
if (base.BaseGet(index) != null)
|
||||
{
|
||||
base.BaseRemoveAt(index);
|
||||
}
|
||||
this.BaseAdd(index, value);
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(HandlerElement handlerElement)
|
||||
{
|
||||
if (!this.IsReadOnly())
|
||||
{
|
||||
if (handlerElement == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("handlerElement");
|
||||
}
|
||||
}
|
||||
|
||||
this.BaseAdd(handlerElement, false);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
base.BaseClear();
|
||||
}
|
||||
|
||||
public void Remove(HandlerElement handlerElement)
|
||||
{
|
||||
if (!this.IsReadOnly())
|
||||
{
|
||||
if (handlerElement == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("handlerElement");
|
||||
}
|
||||
}
|
||||
|
||||
this.BaseRemove(this.GetElementKey(handlerElement));
|
||||
}
|
||||
|
||||
public void Remove(string xamlRootElementType)
|
||||
{
|
||||
if (!this.IsReadOnly())
|
||||
{
|
||||
if (xamlRootElementType == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("xamlRootElementType");
|
||||
}
|
||||
}
|
||||
|
||||
this.BaseRemove(xamlRootElementType);
|
||||
}
|
||||
|
||||
public void RemoveAt(int index)
|
||||
{
|
||||
base.BaseRemoveAt(index);
|
||||
}
|
||||
|
||||
internal bool TryGetHttpHandlerType(Type hostedXamlType, out Type httpHandlerType)
|
||||
{
|
||||
httpHandlerType = null;
|
||||
foreach (HandlerElement handler in this)
|
||||
{
|
||||
if (handler.LoadXamlRootElementType().IsAssignableFrom(hostedXamlType))
|
||||
{
|
||||
httpHandlerType = handler.LoadHttpHandlerType();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override ConfigurationElement CreateNewElement()
|
||||
{
|
||||
return new HandlerElement();
|
||||
}
|
||||
|
||||
protected override object GetElementKey(ConfigurationElement element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
throw FxTrace.Exception.ArgumentNull("element");
|
||||
}
|
||||
return ((HandlerElement)element).Key;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,39 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xaml.Hosting.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Web.Configuration;
|
||||
using System.Runtime;
|
||||
using System.Security;
|
||||
|
||||
static class XamlHostingConfiguration
|
||||
{
|
||||
internal const string CollectionName = "";
|
||||
internal const string HttpHandlerType = "httpHandlerType";
|
||||
internal const string XamlHostingConfigGroup = @"system.xaml.hosting";
|
||||
internal const string XamlHostingSection = XamlHostingConfigGroup + "/httpHandlers";
|
||||
internal const string XamlRootElementType = "xamlRootElementType";
|
||||
|
||||
internal static bool TryGetHttpHandlerType(string virtualPath, Type hostedXamlType, out Type httpHandlerType)
|
||||
{
|
||||
XamlHostingSection section = LoadXamlHostingSection(virtualPath);
|
||||
if (null == section)
|
||||
{
|
||||
ConfigurationErrorsException configException = new ConfigurationErrorsException(SR.ConfigSectionNotFound);
|
||||
throw FxTrace.Exception.AsError(configException);
|
||||
}
|
||||
return section.Handlers.TryGetHttpHandlerType(hostedXamlType, out httpHandlerType);
|
||||
}
|
||||
|
||||
static XamlHostingSection LoadXamlHostingSection(string virtualPath)
|
||||
{
|
||||
//WebConfigurationManager returns the same section object for a given virtual directory (not virtual path).
|
||||
return (XamlHostingSection)WebConfigurationManager.GetSection(XamlHostingConfiguration.XamlHostingSection, virtualPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,24 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xaml.Hosting.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Runtime;
|
||||
using System.Web;
|
||||
|
||||
public sealed class XamlHostingSection : ConfigurationSection
|
||||
{
|
||||
[ConfigurationProperty(XamlHostingConfiguration.CollectionName, IsDefaultCollection = true)]
|
||||
public HandlerElementCollection Handlers
|
||||
{
|
||||
get
|
||||
{
|
||||
return (HandlerElementCollection)base[XamlHostingConfiguration.CollectionName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,27 @@
|
||||
//------------------------------------------------------------------------------
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace System.Xaml.Hosting.Configuration
|
||||
{
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Runtime;
|
||||
using System.Web;
|
||||
|
||||
public sealed class XamlHostingSectionGroup : ConfigurationSectionGroup
|
||||
{
|
||||
public XamlHostingSectionGroup()
|
||||
{
|
||||
}
|
||||
|
||||
public XamlHostingSection XamlHostingSection
|
||||
{
|
||||
get
|
||||
{
|
||||
return (XamlHostingSection)this.Sections[XamlHostingConfiguration.XamlHostingConfigGroup];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user