Skip to content

Commit

Permalink
Restore PlatformEnlightenmentProvider.Current until a better service …
Browse files Browse the repository at this point in the history
…injection can be introduced
  • Loading branch information
Oren Novotny committed Aug 29, 2016
1 parent c0e4ee4 commit 3604b23
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ internal static class ConcurrencyAbstractionLayer

private static IConcurrencyAbstractionLayer Initialize()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<IConcurrencyAbstractionLayer>() ?? new DefaultConcurrencyAbstractionLayer();
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,9 @@ public static IScheduler TaskPool

private static IScheduler Initialize(string name)
{
#pragma warning disable CS0618 // Type or member is obsolete
var res = PlatformEnlightenmentProvider.Current.GetService<IScheduler>(name);
#pragma warning restore CS0618 // Type or member is obsolete
if (res == null)
throw new NotSupportedException(string.Format(CultureInfo.CurrentCulture, Strings_Core.CANT_OBTAIN_SCHEDULER, name));
return res;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public static void ThrowIfNotNull(this Exception exception)

private static IExceptionServices Initialize()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<IExceptionServices>() ?? new DefaultExceptionServices();
#pragma warning restore CS0618 // Type or member is obsolete
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ private static void OnResuming(object sender, HostResumingEventArgs e)

private static IHostLifecycleNotifications InitializeNotifications()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<IHostLifecycleNotifications>();
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,26 @@ public interface IPlatformEnlightenmentProvider
[EditorBrowsable(EditorBrowsableState.Never)]
public static class PlatformEnlightenmentProvider
{
private static readonly IPlatformEnlightenmentProvider s_current = CreatePlatformProvider();
private static IPlatformEnlightenmentProvider s_current = CreatePlatformProvider();

/// <summary>
/// (Infrastructure) Gets the current enlightenment provider. If none is loaded yet, accessing this property triggers provider resolution.
/// </summary>
/// <remarks>
/// This member is used by the Rx infrastructure and not meant for public consumption or implementation.
/// </remarks>
[Obsolete("This mechanism will be removed in the next major version", false)]
public static IPlatformEnlightenmentProvider Current
{
get
{
return s_current;
}
set
{
if (value == null) throw new ArgumentNullException(nameof(value));
s_current = value;
}

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,16 @@ private static void OnSystemClockChanged(object sender, SystemClockChangedEventA

private static ISystemClock InitializeSystemClock()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<ISystemClock>() ?? new DefaultSystemClock();
#pragma warning restore CS0618 // Type or member is obsolete
}

private static INotifySystemClockChanged InitializeSystemClockChanged()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<INotifySystemClockChanged>() ?? new DefaultSystemClockMonitor();
#pragma warning restore CS0618 // Type or member is obsolete
}

internal static void Register(LocalScheduler scheduler)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ internal static class TaskHelpers

private static ITaskServices Initialize()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<ITaskServices>() ?? new DefaultTaskServices();
#pragma warning restore CS0618 // Type or member is obsolete
}

public static bool TrySetCanceled<T>(this TaskCompletionSource<T> tcs, CancellationToken token)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ public static T GetQueryImpl<T>(T defaultInstance)

private static IQueryServices Initialize()
{
#pragma warning disable CS0618 // Type or member is obsolete
return PlatformEnlightenmentProvider.Current.GetService<IQueryServices>() ?? new DefaultQueryServices();
#pragma warning restore CS0618 // Type or member is obsolete
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static class EnlightenmentProvider
/// </returns>
public static bool EnsureLoaded()
{
#pragma warning disable CS0618
return PlatformEnlightenmentProvider.Current is CurrentPlatformEnlightenmentProvider;
#pragma warning restore CS0618
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

#if NET45
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -57,9 +56,11 @@ public void Schedulers_ArgumentChecks()
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(TimeSpan.Zero, default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.CurrentThread.Schedule(DateTimeOffset.MaxValue, default(Action)));
#if DESKTOPCLR
ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(TimeSpan.Zero, default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => DispatcherScheduler.Instance.Schedule(DateTimeOffset.MaxValue, default(Action)));
#endif
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(TimeSpan.Zero, default(Action)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.Immediate.Schedule(DateTimeOffset.MaxValue, default(Action)));
Expand Down Expand Up @@ -216,6 +217,8 @@ private void Scheduler_Builtins_NoPlib()
#region ISchedulerLongRunning

#if !NO_PERF

#if !WINDOWS && !NO_THREAD
[Fact]
public void Scheduler_LongRunning_ArgumentChecking()
{
Expand All @@ -238,6 +241,7 @@ public void Scheduler_Periodic_ArgumentChecking()
ReactiveAssert.Throws<ArgumentOutOfRangeException>(() => Scheduler.SchedulePeriodic<int>(ThreadPoolScheduler.Instance, 42, TimeSpan.FromSeconds(-1), _ => _));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.SchedulePeriodic<int>(ThreadPoolScheduler.Instance, 42, TimeSpan.FromSeconds(1), default(Func<int, int>)));
}
#endif

[Fact]
public void Scheduler_Stopwatch_Emulation()
Expand Down Expand Up @@ -295,6 +299,8 @@ public void Scheduler_LongRunning2()
#region ISchedulerPeriodic

#if !NO_PERF

#if !WINDOWS && !NO_THREAD
[Fact]
public void Scheduler_Periodic1()
{
Expand Down Expand Up @@ -328,6 +334,7 @@ public void Scheduler_Periodic2()
e.WaitOne();
d.Dispose();
}
#endif

#if DESKTOPCLR
[Fact]
Expand Down Expand Up @@ -427,7 +434,7 @@ public void OnResuming()

#endif

#endregion
#endregion

#region DisableOptimizations

Expand All @@ -437,8 +444,9 @@ public void DisableOptimizations_ArgumentChecking()
{
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(default(IScheduler)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(default(IScheduler), new Type[0]));
#if !WINDOWS && !NO_THREAD
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(ThreadPoolScheduler.Instance, default(Type[])));

#endif
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, default(Func<IScheduler, int, IDisposable>)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, TimeSpan.FromSeconds(1), default(Func<IScheduler, int, IDisposable>)));
ReactiveAssert.Throws<ArgumentNullException>(() => Scheduler.DisableOptimizations(Scheduler.Default).Schedule(42, DateTimeOffset.Now, default(Func<IScheduler, int, IDisposable>)));
Expand Down Expand Up @@ -1517,4 +1525,3 @@ public override void Post(SendOrPostCallback d, object state)
#endif
}
}
#endif

0 comments on commit 3604b23

Please sign in to comment.