Imported Upstream version 3.6.0

Former-commit-id: da6be194a6b1221998fc28233f2503bd61dd9d14
This commit is contained in:
Jo Shields
2014-08-13 10:39:27 +01:00
commit a575963da9
50588 changed files with 8155799 additions and 0 deletions

View File

@@ -0,0 +1,14 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
// This file is used by Code Analysis to maintain SuppressMessage
// attributes that are applied to this project.
// Project-level suppressions either have no target or are given
// a specific target and scoped to a namespace, type, member, etc.
//
// To add a suppression to this file, right-click the message in the
// Error List, point to "Suppress Message(s)", and click
// "In Project Suppression File".
// You do not need to add suppressions to this file manually.
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA2210:AssembliesShouldHaveValidStrongNames", Justification = "Taken care of by lab build.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1016:MarkAssembliesWithAssemblyVersion", Justification = "Taken care of by lab build.")]

View File

@@ -0,0 +1,37 @@
using System;
using System.Reflection;
using System.Resources;
using System.Runtime.InteropServices;
using System.Security;
[assembly: AssemblyTitle("System.Reactive.Runtime.Remoting")]
// Notice: same description as in the .nuspec files; see Source/Rx/Setup/NuGet
[assembly: AssemblyDescription("Reactive Extensions Remoting Library used to expose observable sequences through .NET Remoting.")]
#if DEBUG
[assembly: AssemblyConfiguration("Debug")]
#else
[assembly: AssemblyConfiguration("Retail")]
#endif
[assembly: AssemblyCompany("Microsoft Open Technologies, Inc.")]
[assembly: AssemblyProduct("Reactive Extensions")]
[assembly: AssemblyCopyright("\x00a9 Microsoft Open Technologies, Inc. All rights reserved.")]
[assembly: NeutralResourcesLanguage("en-US")]
#if !PLIB
[assembly: ComVisible(false)]
#endif
[assembly: CLSCompliant(true)]
#if HAS_APTCA && NO_CODECOVERAGE
[assembly: AllowPartiallyTrustedCallers]
#endif
// ===========================================================================
// DO NOT EDIT OR REMOVE ANYTHING BELOW THIS COMMENT.
// Version numbers are automatically generated in the msbuild files based on regular expressions
// ===========================================================================
[assembly: AssemblyVersion("2.2.0.0")]
[assembly: AssemblyFileVersion("2.2.0.0")]
[assembly: AssemblyInformationalVersion("2.2.0.0")]

View File

@@ -0,0 +1,114 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if !NO_REMOTING
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.Remoting.Lifetime;
namespace System.Reactive.Linq
{
/// <summary>
/// Provides a set of static methods for exposing observable sequences through .NET Remoting.
/// </summary>
public static partial class RemotingObservable
{
#region Remotable
/// <summary>
/// Makes an observable sequence remotable, using an infinite lease for the <see cref="MarshalByRefObject"/> wrapping the source.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">Source sequence.</param>
/// <returns>The observable sequence that supports remote subscriptions.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
public static IObservable<TSource> Remotable<TSource>(this IObservable<TSource> source)
{
if (source == null)
throw new ArgumentNullException("source");
return Remotable_<TSource>(source);
}
/// <summary>
/// Makes an observable sequence remotable, using a controllable lease for the <see cref="MarshalByRefObject"/> wrapping the source.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="lease">Lease object to control lifetime of the remotable sequence. Notice null is a supported value.</param>
/// <returns>The observable sequence that supports remote subscriptions.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
public static IObservable<TSource> Remotable<TSource>(this IObservable<TSource> source, ILease lease)
{
if (source == null)
throw new ArgumentNullException("source");
return Remotable_<TSource>(source, lease);
}
/// <summary>
/// Makes an observable sequence remotable, using an infinite lease for the <see cref="MarshalByRefObject"/> wrapping the source.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">Source sequence.</param>
/// <returns>The observable sequence that supports remote subscriptions.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
public static IQbservable<TSource> Remotable<TSource>(this IQbservable<TSource> source)
{
if (source == null)
throw new ArgumentNullException("source");
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
#if CRIPPLED_REFLECTION
InfoOf(() => RemotingObservable.Remotable<TSource>(default(IQbservable<TSource>))),
#else
((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
#endif
source.Expression
)
);
}
/// <summary>
/// Makes an observable sequence remotable, using a controllable lease for the <see cref="MarshalByRefObject"/> wrapping the source.
/// </summary>
/// <typeparam name="TSource">The type of the elements in the source sequence.</typeparam>
/// <param name="source">Source sequence.</param>
/// <param name="lease">Lease object to control lifetime of the remotable sequence. Notice null is a supported value.</param>
/// <returns>The observable sequence that supports remote subscriptions.</returns>
/// <exception cref="ArgumentNullException"><paramref name="source"/> is null.</exception>
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", MessageId = "Remotable", Justification = "In honor of the .NET Remoting heroes.")]
public static IQbservable<TSource> Remotable<TSource>(this IQbservable<TSource> source, ILease lease)
{
if (source == null)
throw new ArgumentNullException("source");
return source.Provider.CreateQuery<TSource>(
Expression.Call(
null,
#if CRIPPLED_REFLECTION
InfoOf(() => RemotingObservable.Remotable<TSource>(default(IQbservable<TSource>), default(ILease))),
#else
((MethodInfo)MethodInfo.GetCurrentMethod()).MakeGenericMethod(typeof(TSource)),
#endif
source.Expression,
Expression.Constant(lease, typeof(ILease))
)
);
}
#if CRIPPLED_REFLECTION
internal static MethodInfo InfoOf<R>(Expression<Func<R>> f)
{
return ((MethodCallExpression)f.Body).Method;
}
#endif
#endregion
}
}
#endif

View File

@@ -0,0 +1,255 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
#if !NO_REMOTING
using System.Reactive.Disposables;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Lifetime;
using System.Security;
using System.Threading;
//
// DESIGN: The MarshalByRefObject (MBRO) implementations for RemotableObserver and RemotableSubscription act as
// self-sponsoring objects controlling their lease times in order to tie those to the lifetime of the
// underlying observable sequence (ended by OnError or OnCompleted) or the user-controlled subscription
// lifetime. If we were to implement InitializeLifetimeService to return null, we'd end up with leases
// that are infinite, so we need a more fine-grained lease scheme. The default configuration would time
// out after 5 minutes, causing clients to fail while they're still observing the sequence. To solve
// this, those MBROs also implement ISponsor with a Renewal method that continues to renew the lease
// upon every call. When the sequence comes to an end or the subscription is disposed, the sponsor gets
// unregistered, allowing the objects to be reclaimed eventually by the Remoting infrastructure.
//
// SECURITY: Registration and unregistration of sponsors is protected by SecurityCritical annotations. The
// implementation of ISponsor is known (i.e. no foreign implementation can be passed in) at the call
// sites of the Register and Unregister methods. The call to Register happens in the SecurityCritical
// InitializeLifetimeService method and is called by trusted Remoting infrastructure. The Renewal
// method is also marked as SecurityCritical and called by Remoting. The Unregister method is wrapped
// in a ***SecurityTreatAsSafe*** private method which only gets called by the observer's OnError and
// OnCompleted notifications, or the subscription's Dispose method. In the former case, the sequence
// indicates it has reached the end, and hence resources can be reclaimed. Clients will no longer be
// connected to the source due to auto-detach behavior enforced in the SerializableObservable client-
// side implementation. In the latter case of disposing the subscription, the client is in control
// and will cause the underlying remote subscription to be disposed as well, allowing resources to be
// reclaimed. Rogue messages on either the data or the subscription channel can cause a DoS of the
// client-server communication but this is subject to the security of the Remoting channels used. In
// no case an untrusted party can cause _extension_ of the lease time.
//
//
// Notice this assembly is marked as APTCA in official builds, causing methods to be treated as transparent,
// thus requiring the ***SecurityTreatAsSafe*** annotation on the security boundaries described above. When not
// applied, the following exception would occur at runtime:
//
// System.MethodAccessException:
//
// Attempt by security transparent method 'System.Reactive.Linq.QueryLanguage+RemotableObservable`1+
// RemotableSubscription<T>.Unregister()' to access security critical method 'System.Runtime.Remoting.Lifetime.
// ILease.Unregister(System.Runtime.Remoting.Lifetime.ISponsor)' failed.
//
// Assembly 'System.Reactive.Linq, Version=2.0.ymmdd.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35'
// is marked with the AllowPartiallyTrustedCallersAttribute, and uses the level 2 security transparency model.
// Level 2 transparency causes all methods in AllowPartiallyTrustedCallers assemblies to become security
// transparent by default, which may be the cause of this exception.
//
//
// The two CodeAnalysis suppressions below are explained by the Justification property (scroll to the right):
//
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2136:TransparencyAnnotationsShouldNotConflictFxCopRule", Scope = "member", Target = "System.Reactive.Linq.QueryLanguage+RemotableObserver`1.#Unregister()", Justification = "This error only occurs while running FxCop on local builds that don't have NO_CODECOVERAGE set, causing the assembly not to be marked with APTCA (see AssemblyInfo.cs). When APTCA is enabled in official builds, this SecurityTreatAsSafe annotation is required.")]
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Security", "CA2136:TransparencyAnnotationsShouldNotConflictFxCopRule", Scope = "member", Target = "System.Reactive.Linq.QueryLanguage+RemotableObservable`1+RemotableSubscription.#Unregister()", Justification = "This error only occurs while running FxCop on local builds that don't have NO_CODECOVERAGE set, causing the assembly not to be marked with APTCA (see AssemblyInfo.cs). When APTCA is enabled in official builds, this SecurityTreatAsSafe annotation is required.")]
namespace System.Reactive.Linq
{
public static partial class RemotingObservable
{
#region Remotable
private static IObservable<TSource> Remotable_<TSource>(IObservable<TSource> source)
{
return new SerializableObservable<TSource>(new RemotableObservable<TSource>(source, null));
}
private static IObservable<TSource> Remotable_<TSource>(IObservable<TSource> source, ILease lease)
{
return new SerializableObservable<TSource>(new RemotableObservable<TSource>(source, lease));
}
[Serializable]
class SerializableObservable<T> : IObservable<T>
{
readonly RemotableObservable<T> remotableObservable;
public SerializableObservable(RemotableObservable<T> remotableObservable)
{
this.remotableObservable = remotableObservable;
}
public IDisposable Subscribe(IObserver<T> observer)
{
var d = new SingleAssignmentDisposable();
var o = Observer.Create<T>(
observer.OnNext,
ex =>
{
//
// Make call to the remote subscription, causing lease renewal to be stopped.
//
using (d)
{
observer.OnError(ex);
}
},
() =>
{
//
// Make call to the remote subscription, causing lease renewal to be stopped.
//
using (d)
{
observer.OnCompleted();
}
}
);
//
// [OK] Use of unsafe Subscribe: non-pretentious transparent wrapping through remoting; exception coming from the remote object is not re-routed.
//
d.Disposable = remotableObservable.Subscribe/*Unsafe*/(new RemotableObserver<T>(o));
return d;
}
}
class RemotableObserver<T> : MarshalByRefObject, IObserver<T>, ISponsor
{
readonly IObserver<T> underlyingObserver;
public RemotableObserver(IObserver<T> underlyingObserver)
{
this.underlyingObserver = underlyingObserver;
}
public void OnNext(T value)
{
underlyingObserver.OnNext(value);
}
public void OnError(Exception exception)
{
try
{
underlyingObserver.OnError(exception);
}
finally
{
Unregister();
}
}
public void OnCompleted()
{
try
{
underlyingObserver.OnCompleted();
}
finally
{
Unregister();
}
}
[SecuritySafeCritical] // See remarks at the top of the file.
private void Unregister()
{
var lease = (ILease)RemotingServices.GetLifetimeService(this);
if (lease != null)
lease.Unregister(this);
}
[SecurityCritical]
public override object InitializeLifetimeService()
{
var lease = (ILease)base.InitializeLifetimeService();
lease.Register(this);
return lease;
}
[SecurityCritical]
TimeSpan ISponsor.Renewal(ILease lease)
{
return lease.InitialLeaseTime;
}
}
[Serializable]
sealed class RemotableObservable<T> : MarshalByRefObject, IObservable<T>
{
readonly IObservable<T> underlyingObservable;
readonly ILease lease;
public RemotableObservable(IObservable<T> underlyingObservable, ILease lease)
{
this.underlyingObservable = underlyingObservable;
this.lease = lease;
}
public IDisposable Subscribe(IObserver<T> observer)
{
//
// [OK] Use of unsafe Subscribe: non-pretentious transparent wrapping through remoting; throwing across remoting boundaries is fine.
//
return new RemotableSubscription(underlyingObservable.Subscribe/*Unsafe*/(observer));
}
[SecurityCritical]
public override object InitializeLifetimeService()
{
return lease;
}
sealed class RemotableSubscription : MarshalByRefObject, IDisposable, ISponsor
{
private IDisposable underlyingSubscription;
public RemotableSubscription(IDisposable underlyingSubscription)
{
this.underlyingSubscription = underlyingSubscription;
}
public void Dispose()
{
//
// Avoiding double-dispose and dropping the reference upon disposal.
//
using (Interlocked.Exchange(ref underlyingSubscription, Disposable.Empty))
{
Unregister();
}
}
[SecuritySafeCritical] // See remarks at the top of the file.
private void Unregister()
{
var lease = (ILease)RemotingServices.GetLifetimeService(this);
if (lease != null)
lease.Unregister(this);
}
[SecurityCritical]
public override object InitializeLifetimeService()
{
var lease = (ILease)base.InitializeLifetimeService();
lease.Register(this);
return lease;
}
[SecurityCritical]
TimeSpan ISponsor.Renewal(ILease lease)
{
return lease.InitialLeaseTime;
}
}
}
#endregion
}
}
#endif

View File

@@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{7A6EF49E-7946-4101-9C89-407B9C53A173}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>System.Reactive</RootNamespace>
<AssemblyName>System.Reactive.Runtime.Remoting</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProductSignAssembly>true</ProductSignAssembly>
<CodeAnalysisRuleSet>..\Rx.ruleset</CodeAnalysisRuleSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'ReleaseXBLV|AnyCPU'">
<OutputPath>bin\ReleaseXBLV\</OutputPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'DebugXBLV|AnyCPU'">
<OutputPath>bin\DebugXBLV\</OutputPath>
</PropertyGroup>
<Import Project="..\Common.targets" />
<PropertyGroup>
<DocumentationFile>$(OutputPath)\$(AssemblyName).XML</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
</ItemGroup>
<ItemGroup>
<Compile Include="GlobalSuppressions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Reactive\Linq\Observable.Remoting.cs" />
<Compile Include="Reactive\Linq\QueryLanguage.Remoting.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\System.Reactive.Core\System.Reactive.Core.csproj">
<Project>{4E516F10-DA7A-4D43-963E-A93865ABEA5B}</Project>
<Name>System.Reactive.Core</Name>
</ProjectReference>
<ProjectReference Include="..\System.Reactive.Interfaces\System.Reactive.Interfaces.csproj">
<Project>{9E9B9C60-98B0-40FA-9C2B-1218D417CAA4}</Project>
<Name>System.Reactive.Interfaces</Name>
</ProjectReference>
</ItemGroup>
<Import Project="..\Import.targets" />
</Project>