Skip to content

Commit

Permalink
Merge pull request dotnet#1297 from sergeybykov/1.1.2
Browse files Browse the repository at this point in the history
Fixes for 1.1.2 release
  • Loading branch information
jdom committed Jan 19, 2016
2 parents 7a6b2c7 + a8a7508 commit d21dab5
Show file tree
Hide file tree
Showing 43 changed files with 1,047 additions and 210 deletions.
6 changes: 3 additions & 3 deletions src/NuGet/BondSerializerInstall.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param($installPath, $toolsPath, $package, $project)

$bondSerializerTypeName = 'Orleans.Serialization.BondSerializer, BondSerializer'
$bondSerializerTypeName = 'Orleans.Serialization.BondSerializer, OrleansBondUtils'

function AddOrGetElement(
[OutputType([System.Xml.XmlElement])]
Expand All @@ -9,7 +9,7 @@ function AddOrGetElement(
[Parameter(Mandatory=$true)]
[string]$name,
[Parameter(Mandatory=$true)]
[System.Xml.XmlNamespaceManager]$namespaceManager
[System.Xml.XmlNamespaceManager]$namespaceManager
)
{
$node = $xml.ChildNodes | where { $_.Name -eq $name }
Expand Down Expand Up @@ -51,7 +51,7 @@ function RegisterSerializer(

$bondTypeProvider = $providersnode.Provider | where { $_.type -eq $type }

if ($bondTypeProvider -eq $null)
if ($bondTypeProvider -eq $null)
{
$provider = AddOrGetElement -xml $providersNode -name "Provider" -namespaceManager $namespaceManager
$typeAttribute = $fileXml.CreateAttribute("type");
Expand Down
2 changes: 1 addition & 1 deletion src/NuGet/BondSerializerUninstall.ps1
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
param($installPath, $toolsPath, $package, $project)

$bondSerializerTypeName = 'Orleans.Serialization.BondSerializer, BondSerializer'
$bondSerializerTypeName = 'Orleans.Serialization.BondSerializer, OrleansBondUtils'

function UnregisterSerializer(
[Parameter(Mandatory=$true)]
Expand Down
3 changes: 1 addition & 2 deletions src/NuGet/Microsoft.Orleans.OrleansAzureUtils.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@
<dependency id="Microsoft.Orleans.OrleansRuntime" version="$version$" />
<dependency id="Microsoft.Orleans.OrleansProviders" version="$version$" />

<dependency id="WindowsAzure.Storage" version="4.2.0.0" />
<dependency id="Microsoft.WindowsAzure.ConfigurationManager" version="2.0.0.0" />
<dependency id="WindowsAzure.Storage" version="5.0.2" />
</dependencies>
</metadata>
<files>
Expand Down
135 changes: 135 additions & 0 deletions src/Orleans/CodeGeneration/TypeFormattingOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
namespace Orleans.Runtime
{
using System;

/// <summary>
/// Options for formatting type names.
/// </summary>
public class TypeFormattingOptions : IEquatable<TypeFormattingOptions>
{
public TypeFormattingOptions(
string nameSuffix = null,
bool includeNamespace = true,
bool includeGenericParameters = true,
bool includeTypeParameters = true,
char nestedClassSeparator = '.',
bool includeGlobal = true)
{

this.NameSuffix = nameSuffix;
this.IncludeNamespace = includeNamespace;
this.IncludeGenericTypeParameters = includeGenericParameters;
this.IncludeTypeParameters = includeTypeParameters;
this.NestedTypeSeparator = nestedClassSeparator;
this.IncludeGlobal = includeGlobal;
}

/// <summary>
/// Gets a value indicating whether or not to include the fully-qualified namespace of the class in the result.
/// </summary>
public bool IncludeNamespace { get; private set; }

/// <summary>
/// Gets a value indicating whether or not to include concrete type parameters in the result.
/// </summary>
public bool IncludeTypeParameters { get; private set; }

/// <summary>
/// Gets a value indicating whether or not to include generic type parameters in the result.
/// </summary>
public bool IncludeGenericTypeParameters { get; private set; }

/// <summary>
/// Gets the separator used between declaring types and their declared types.
/// </summary>
public char NestedTypeSeparator { get; private set; }

/// <summary>
/// Gets the name to append to the formatted name, before any type parameters.
/// </summary>
public string NameSuffix { get; private set; }

/// <summary>
/// Gets a value indicating whether or not to include the global namespace qualifier.
/// </summary>
public bool IncludeGlobal { get; private set; }

/// <summary>
/// Indicates whether the current object is equal to another object of the same type.
/// </summary>
/// <param name="other">An object to compare with this object.</param>
/// <returns>
/// <see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>.
/// </returns>
public bool Equals(TypeFormattingOptions other)
{
if (ReferenceEquals(null, other))
{
return false;
}
if (ReferenceEquals(this, other))
{
return true;
}
return this.IncludeNamespace == other.IncludeNamespace
&& this.IncludeTypeParameters == other.IncludeTypeParameters
&& this.IncludeGenericTypeParameters == other.IncludeGenericTypeParameters
&& this.NestedTypeSeparator == other.NestedTypeSeparator
&& string.Equals(this.NameSuffix, other.NameSuffix) && this.IncludeGlobal == other.IncludeGlobal;
}

/// <summary>
/// Determines whether the specified object is equal to the current object.
/// </summary>
/// <param name="obj">The object to compare with the current object.</param>
/// <returns>
/// <see langword="true"/> if the specified object is equal to the current object; otherwise, <see langword="false"/>.
/// </returns>
public override bool Equals(object obj)
{
if (ReferenceEquals(null, obj))
{
return false;
}
if (ReferenceEquals(this, obj))
{
return true;
}
if (obj.GetType() != this.GetType())
{
return false;
}
return Equals((TypeFormattingOptions)obj);
}

/// <summary>
/// Serves as a hash function for a particular type.
/// </summary>
/// <returns>
/// A hash code for the current object.
/// </returns>
public override int GetHashCode()
{
unchecked
{
var hashCode = this.IncludeNamespace.GetHashCode();
hashCode = (hashCode * 397) ^ this.IncludeTypeParameters.GetHashCode();
hashCode = (hashCode * 397) ^ this.IncludeGenericTypeParameters.GetHashCode();
hashCode = (hashCode * 397) ^ this.NestedTypeSeparator.GetHashCode();
hashCode = (hashCode * 397) ^ (this.NameSuffix != null ? this.NameSuffix.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.IncludeGlobal.GetHashCode();
return hashCode;
}
}

public static bool operator ==(TypeFormattingOptions left, TypeFormattingOptions right)
{
return Equals(left, right);
}

public static bool operator !=(TypeFormattingOptions left, TypeFormattingOptions right)
{
return !Equals(left, right);
}
}
}
104 changes: 56 additions & 48 deletions src/Orleans/CodeGeneration/TypeUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ internal static class TypeUtils
/// </summary>
private static readonly string OrleansCoreAssembly = typeof(IGrain).Assembly.GetName().FullName;

private static readonly ConcurrentDictionary<Tuple<Type, string, bool, bool>, string> ParseableNameCache = new ConcurrentDictionary<Tuple<Type, string, bool, bool>, string>();
private static readonly ConcurrentDictionary<Tuple<Type, TypeFormattingOptions>, string> ParseableNameCache = new ConcurrentDictionary<Tuple<Type, TypeFormattingOptions>, string>();

private static readonly ConcurrentDictionary<Tuple<Type, bool>, List<Type>> ReferencedTypes = new ConcurrentDictionary<Tuple<Type, bool>, List<Type>>();

Expand All @@ -60,8 +60,15 @@ public static string GetSimpleTypeName(Type t, Func<Type, bool> fullName=null, L
if (typeInfo.IsNestedPublic || typeInfo.IsNestedPrivate)
{
if (typeInfo.DeclaringType.IsGenericType)
return GetTemplatedName(GetUntemplatedTypeName(typeInfo.DeclaringType.Name), typeInfo.DeclaringType, typeInfo.GetGenericArguments(), _ => true, language) + "." + GetUntemplatedTypeName(typeInfo.Name);

{
return GetTemplatedName(
GetUntemplatedTypeName(typeInfo.DeclaringType.Name),
typeInfo.DeclaringType,
typeInfo.GetGenericArguments(),
_ => true,
language) + "." + GetUntemplatedTypeName(typeInfo.Name);
}

return GetTemplatedName(typeInfo.DeclaringType, language: language) + "." + GetUntemplatedTypeName(typeInfo.Name);
}

Expand Down Expand Up @@ -618,25 +625,25 @@ public static string GetUnadornedMethodName(this MethodInfo method)
/// <returns>
/// A string representation of the <paramref name="type"/>.
/// </returns>
public static string GetParseableName(this Type type, string nameSuffix = null, bool includeNamespace = true, bool includeGenericParameters = true)
public static string GetParseableName(this Type type, TypeFormattingOptions options = null)
{
return
ParseableNameCache.GetOrAdd(
Tuple.Create(type, nameSuffix, includeNamespace, includeGenericParameters),
_ =>
{
var builder = new StringBuilder();
var typeInfo = type.GetTypeInfo();
GetParseableName(
type,
nameSuffix ?? string.Empty,
builder,
new Queue<Type>(
typeInfo.IsGenericTypeDefinition ? typeInfo.GetGenericArguments() : typeInfo.GenericTypeArguments),
includeNamespace,
includeGenericParameters);
return builder.ToString();
});
options = options ?? new TypeFormattingOptions();
return ParseableNameCache.GetOrAdd(
Tuple.Create(type, options),
_ =>
{
var builder = new StringBuilder();
var typeInfo = type.GetTypeInfo();
GetParseableName(
type,
builder,
new Queue<Type>(
typeInfo.IsGenericTypeDefinition
? typeInfo.GetGenericArguments()
: typeInfo.GenericTypeArguments),
options);
return builder.ToString();
});
}

/// <summary>
Expand All @@ -651,33 +658,28 @@ public static string GetParseableName(this Type type, string nameSuffix = null,
/// <param name="typeArguments">
/// The type arguments of <paramref name="type"/>.
/// </param>
/// <param name="includeNamespace">
/// A value indicating whether or not to include the namespace name.
/// <param name="options">
/// The type formatting options.
/// </param>
private static void GetParseableName(
Type type,
string nameSuffix,
StringBuilder builder,
Queue<Type> typeArguments,
bool includeNamespace = true,
bool includeGenericParameters = true)
TypeFormattingOptions options)
{
var typeInfo = type.GetTypeInfo();
if (typeInfo.IsArray)
{
builder.AppendFormat(
"{0}[{1}]",
typeInfo.GetElementType()
.GetParseableName(
includeNamespace: includeNamespace,
includeGenericParameters: includeGenericParameters),
typeInfo.GetElementType().GetParseableName(options),
string.Concat(Enumerable.Range(0, type.GetArrayRank() - 1).Select(_ => ',')));
return;
}

if (typeInfo.IsGenericParameter)
{
if (includeGenericParameters)
if (options.IncludeGenericTypeParameters)
{
builder.Append(typeInfo.GetUnadornedTypeName());
}
Expand All @@ -688,57 +690,63 @@ private static void GetParseableName(
if (typeInfo.DeclaringType != null)
{
// This is not the root type.
GetParseableName(typeInfo.DeclaringType, string.Empty, builder, typeArguments, includeNamespace, includeGenericParameters);
builder.Append('.');
GetParseableName(typeInfo.DeclaringType, builder, typeArguments, options);
builder.Append(options.NestedTypeSeparator);
}
else if (!string.IsNullOrWhiteSpace(type.Namespace) && includeNamespace)
else if (!string.IsNullOrWhiteSpace(type.Namespace) && options.IncludeNamespace)
{
// This is the root type.
builder.AppendFormat("global::{0}.", type.Namespace);
// This is the root type, so include the namespace.
var namespaceName = type.Namespace;
if (options.NestedTypeSeparator != '.')
{
namespaceName = namespaceName.Replace('.', options.NestedTypeSeparator);
}

if (options.IncludeGlobal)
{
builder.AppendFormat("global::");
}

builder.AppendFormat("{0}{1}", namespaceName, options.NestedTypeSeparator);
}

if (typeInfo.IsConstructedGenericType)
{
// Get the unadorned name, the generic parameters, and add them together.
var unadornedTypeName = typeInfo.GetUnadornedTypeName() + nameSuffix;
var unadornedTypeName = typeInfo.GetUnadornedTypeName() + options.NameSuffix;
builder.Append(EscapeIdentifier(unadornedTypeName));
var generics =
Enumerable.Range(0, Math.Min(typeInfo.GetGenericArguments().Count(), typeArguments.Count))
.Select(_ => typeArguments.Dequeue())
.ToList();
if (generics.Count > 0)
if (generics.Count > 0 && options.IncludeTypeParameters)
{
var genericParameters = string.Join(
",",
generics.Select(
generic =>
GetParseableName(
generic,
includeNamespace: includeNamespace,
includeGenericParameters: includeGenericParameters)));
generics.Select(generic => GetParseableName(generic, options)));
builder.AppendFormat("<{0}>", genericParameters);
}
}
else if (typeInfo.IsGenericTypeDefinition)
{
// Get the unadorned name, the generic parameters, and add them together.
var unadornedTypeName = type.GetUnadornedTypeName() + nameSuffix;
var unadornedTypeName = type.GetUnadornedTypeName() + options.NameSuffix;
builder.Append(EscapeIdentifier(unadornedTypeName));
var generics =
Enumerable.Range(0, Math.Min(type.GetGenericArguments().Count(), typeArguments.Count))
.Select(_ => typeArguments.Dequeue())
.ToList();
if (generics.Count > 0)
if (generics.Count > 0 && options.IncludeTypeParameters)
{
var genericParameters = string.Join(
",",
generics.Select(_ => includeGenericParameters ? _.ToString() : string.Empty));
generics.Select(_ => options.IncludeGenericTypeParameters ? _.ToString() : string.Empty));
builder.AppendFormat("<{0}>", genericParameters);
}
}
else
{
builder.Append(EscapeIdentifier(type.GetUnadornedTypeName() + nameSuffix));
builder.Append(EscapeIdentifier(type.GetUnadornedTypeName() + options.NameSuffix));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Orleans/Configuration/ClusterConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ internal static IPAddress GetLocalIPAddress(AddressFamily family = AddressFamily
if (!string.IsNullOrWhiteSpace(interfaceName) &&
!netInterface.Name.StartsWith(interfaceName, StringComparison.Ordinal)) continue;

bool isLoopbackInterface = (i == NetworkInterface.LoopbackInterfaceIndex);
bool isLoopbackInterface = (netInterface.NetworkInterfaceType == NetworkInterfaceType.Loopback);
// get list of all unicast IPs from current interface
UnicastIPAddressInformationCollection ipAddresses = netInterface.GetIPProperties().UnicastAddresses;

Expand Down
4 changes: 2 additions & 2 deletions src/Orleans/Core/GrainAttributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ public static FactoryTypes CollectFactoryTypesSpecified<T>()
[AttributeUsage(AttributeTargets.Class, AllowMultiple=true)]
public sealed class ImplicitStreamSubscriptionAttribute : Attribute
{
internal string Namespace { get; private set; }

public string Namespace { get; private set; }
// We have not yet come to an agreement whether the provider should be specified as well.
public ImplicitStreamSubscriptionAttribute(string streamNamespace)
{
Expand Down
Loading

0 comments on commit d21dab5

Please sign in to comment.