Imported Upstream version 4.0.0~alpha1

Former-commit-id: 806294f5ded97629b74c85c09952f2a74fe182d9
This commit is contained in:
Jo Shields
2015-04-07 09:35:12 +01:00
parent 283343f570
commit 3c1f479b9d
22469 changed files with 2931443 additions and 869343 deletions

View File

@@ -0,0 +1,51 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.XamlIntegration
{
using System;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime;
using System.Windows.Markup;
[SuppressMessage(FxCop.Category.Xaml, "XAML1012",
Justification = "ConvertFrom methods are not required for MarkupExtension converters")]
public class EndpointIdentityConverter : TypeConverter
{
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
if (destinationType == typeof(MarkupExtension))
{
return true;
}
return base.CanConvertTo(context, destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
if (value == null)
{
return null;
}
if (destinationType == typeof(MarkupExtension) && value is EndpointIdentity)
{
if (value is SpnEndpointIdentity)
{
return new SpnEndpointIdentityExtension((SpnEndpointIdentity)value);
}
else if (value is UpnEndpointIdentity)
{
return new UpnEndpointIdentityExtension((UpnEndpointIdentity)value);
}
else
{
return new EndpointIdentityExtension((EndpointIdentity)value);
}
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}

View File

@@ -0,0 +1,49 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Claims;
using System.Runtime;
using System.ServiceModel.Activities;
using System.Windows.Markup;
[MarkupExtensionReturnType(typeof(EndpointIdentity))]
public class EndpointIdentityExtension : MarkupExtension
{
public EndpointIdentityExtension()
{
}
public EndpointIdentityExtension(EndpointIdentity identity)
{
if (identity == null)
{
throw FxTrace.Exception.ArgumentNull("identity");
}
this.ClaimType = identity.IdentityClaim.ClaimType;
this.ClaimRight = identity.IdentityClaim.Right;
this.ClaimResource = identity.IdentityClaim.Resource;
}
public string ClaimType
{ get; set; }
public string ClaimRight
{ get; set; }
public object ClaimResource
{ get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
Claim claim = new Claim(this.ClaimType, this.ClaimResource, this.ClaimRight);
return EndpointIdentity.CreateIdentity(claim);
}
}
}

View File

@@ -0,0 +1,77 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.XamlIntegration
{
using System.ComponentModel;
using System.Globalization;
using System.Runtime;
using System.Xml.Linq;
public class ServiceXNameTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return XNameTypeConverterHelper.CanConvertFrom(sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
string stringValue = value as string;
if (!string.IsNullOrEmpty(stringValue))
{
if (!IsQualifiedName(stringValue))
{
// We want the name to remain unqualified; we don't want XNameTypeConverter to add the default namespace
return XName.Get(stringValue);
}
}
return XNameTypeConverterHelper.ConvertFrom(context, value) ?? base.ConvertFrom(context, culture, value);
}
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
return XNameTypeConverterHelper.CanConvertTo(destinationType);
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
XName name = value as XName;
if (destinationType == typeof(string) && name != null)
{
if (name.Namespace == XNamespace.None)
{
// return unqualified name
return name.LocalName;
}
else
{
string result = (string)(XNameTypeConverterHelper.ConvertTo(context, value, destinationType) ??
base.ConvertTo(context, culture, value, destinationType));
if (IsQualifiedName(result))
{
return result;
}
else
{
// The name is in the default XAML namespace, so we need to fully-qualify it,
// or we'll interpret it as unqualified in ConvertFrom
// Also need to escape the {} so it doesn't get interpreted as MarkupExtension
return name.ToString().Replace("{", "{{").Replace("}", "}}");
}
}
}
else
{
return XNameTypeConverterHelper.ConvertTo(context, value, destinationType) ??
base.ConvertTo(context, culture, value, destinationType);
}
}
bool IsQualifiedName(string name)
{
return (name.IndexOf(':') >= 1) || (name.Length > 0 && name[0] == '{');
}
}
}

View File

@@ -0,0 +1,43 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.XamlIntegration
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
using System.Windows.Markup;
using System.ServiceModel.Activities;
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldBeSpelledCorrectly, Justification = "Spn is an acronym")]
[MarkupExtensionReturnType(typeof(SpnEndpointIdentity))]
public class SpnEndpointIdentityExtension : MarkupExtension
{
public SpnEndpointIdentityExtension()
{
}
public SpnEndpointIdentityExtension(SpnEndpointIdentity identity)
{
if (identity == null)
{
throw FxTrace.Exception.ArgumentNull("identity");
}
Fx.Assert(identity.IdentityClaim.Resource is string, "SpnEndpointIdentity claim resource is not string");
this.SpnName = (string)identity.IdentityClaim.Resource;
}
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldBeSpelledCorrectly, Justification = "Spn is an acronym")]
public string SpnName
{
get;
set;
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
return new SpnEndpointIdentity(this.SpnName);
}
}
}

View File

@@ -0,0 +1,40 @@
//----------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------
namespace System.ServiceModel.XamlIntegration
{
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime;
using System.Windows.Markup;
using System.ServiceModel.Activities;
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldBeSpelledCorrectly, Justification = "Upn is an acronym")]
[MarkupExtensionReturnType(typeof(UpnEndpointIdentity))]
public class UpnEndpointIdentityExtension : MarkupExtension
{
public UpnEndpointIdentityExtension()
{
}
public UpnEndpointIdentityExtension(UpnEndpointIdentity identity)
{
if (identity == null)
{
throw FxTrace.Exception.ArgumentNull("identity");
}
Fx.Assert(identity.IdentityClaim.Resource is string, "UpnEndpointIdentity claim resource is not string");
this.UpnName = (string)identity.IdentityClaim.Resource;
}
[SuppressMessage(FxCop.Category.Naming, FxCop.Rule.IdentifiersShouldBeSpelledCorrectly, Justification = "Upn is an acronym")]
public string UpnName
{ get; set; }
public override object ProvideValue(IServiceProvider serviceProvider)
{
return new UpnEndpointIdentity(this.UpnName);
}
}
}

View File

@@ -0,0 +1,113 @@
//------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------
namespace System.ServiceModel.XamlIntegration
{
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Runtime;
using System.Xaml;
using System.Xml.Linq;
internal static class XNameTypeConverterHelper
{
public static bool CanConvertFrom(Type sourceType)
{
return sourceType == typeof(string);
}
public static object ConvertFrom(ITypeDescriptorContext context, object value)
{
return XNameTypeConverterHelper.ConvertFromHelper(context, value);
}
public static bool CanConvertTo(Type destinationType)
{
return destinationType == typeof(string);
}
public static object ConvertTo(ITypeDescriptorContext context, object value, Type destinationType)
{
return XNameTypeConverterHelper.ConvertToHelper(context, value, destinationType);
}
internal static object ConvertFromHelper(ITypeDescriptorContext context, object value)
{
if (value == null)
{
return null;
}
String stringValue = value as String;
if (stringValue == null)
{
return null;
}
stringValue = stringValue.Trim();
if (stringValue == String.Empty)
{
return null;
}
IXamlNamespaceResolver resolver =
context.GetService(typeof(IXamlNamespaceResolver)) as IXamlNamespaceResolver;
if (resolver == null)
{
return null;
}
if (stringValue[0] == '{')
{
return XName.Get(stringValue);
}
int indexOfColon = stringValue.IndexOf(':');
string prefix, localName;
if (indexOfColon >= 0)
{
prefix = stringValue.Substring(0, indexOfColon);
localName = stringValue.Substring(indexOfColon + 1);
}
else
{
prefix = string.Empty;
localName = stringValue;
}
string ns = resolver.GetNamespace(prefix);
if (ns == null)
{
throw FxTrace.Exception.AsError(new FormatException(SRCore.CouldNotResolveNamespacePrefix(prefix)));
}
return XName.Get(localName, ns);
}
internal static object ConvertToHelper(ITypeDescriptorContext context, object value, Type destinationType)
{
XName name = value as XName;
if (destinationType == typeof(string) && name != null)
{
if (context != null)
{
var lookupPrefix = (INamespacePrefixLookup)context.GetService(typeof(INamespacePrefixLookup));
if (lookupPrefix != null)
{
string prefix = lookupPrefix.LookupPrefix(name.Namespace.NamespaceName);
if (String.IsNullOrEmpty(prefix))
{
// Default namespace is in scope
//
return name.LocalName;
}
else
{
return prefix + ":" + name.LocalName;
}
}
}
}
return null;
}
}
}