Skip to content

Commit

Permalink
update for Shiny Logging update
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel committed Feb 24, 2021
1 parent 3d715e8 commit b77c08c
Show file tree
Hide file tree
Showing 17 changed files with 162 additions and 78 deletions.
2 changes: 1 addition & 1 deletion sample/PrismSample.Android/MainApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MainApplication(IntPtr javaReference, JniHandleOwnership transfer)
public override void OnCreate()
{
base.OnCreate();
AndroidShinyHost.Init(this, new Startup());
this.ShinyOnCreate(new Startup());
}
}
}
2 changes: 1 addition & 1 deletion sample/PrismSample.Android/PrismSample.Android.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<MonoAndroidResourcePrefix>Resources</MonoAndroidResourcePrefix>
<MonoAndroidAssetsPrefix>Assets</MonoAndroidAssetsPrefix>
<AndroidUseLatestPlatformSdk>false</AndroidUseLatestPlatformSdk>
<TargetFrameworkVersion>v9.0</TargetFrameworkVersion>
<TargetFrameworkVersion>v10.0</TargetFrameworkVersion>
<AndroidEnableSGenConcurrent>true</AndroidEnableSGenConcurrent>
<AndroidUseAapt2>true</AndroidUseAapt2>
<AndroidHttpClientHandlerType>Xamarin.Android.Net.AndroidClientHandler</AndroidHttpClientHandlerType>
Expand Down
10 changes: 5 additions & 5 deletions sample/PrismSample.Android/Properties/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.prismlibrary.prismextensions">
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
<application android:label="Prism Extended"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
<uses-sdk android:minSdkVersion="21" android:targetSdkVersion="29" />
<application android:label="Prism Extended"></application>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>
4 changes: 2 additions & 2 deletions sample/PrismSample.Android/Resources/layout/Tabbar.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
<com.google.android.material.tabs.TabLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
Expand All @@ -8,4 +8,4 @@
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:tabIndicatorColor="@android:color/white"
app:tabGravity="fill"
app:tabMode="fixed" />
app:tabMode="fixed" />
4 changes: 2 additions & 2 deletions sample/PrismSample.Android/Resources/layout/Toolbar.xml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<android.support.v7.widget.Toolbar
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

2 changes: 1 addition & 1 deletion sample/PrismSample.Android/SplashActivity.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Android.App;
using Android.OS;
using Android.Support.V7.App;
using Android.Content;
using Android.Util;
using AndroidX.AppCompat.App;

namespace PrismSample.Droid
{
Expand Down
9 changes: 4 additions & 5 deletions sample/PrismSample.UWP/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Shiny;
using PrismSample.Shiny;

namespace PrismSample.UWP
{
Expand All @@ -30,6 +32,7 @@ public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
this.ShinyInit(new Startup());
}

/// <summary>
Expand All @@ -39,13 +42,9 @@ public App()
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{


Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
if (!(Window.Current.Content is Frame rootFrame))
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
Expand Down
16 changes: 16 additions & 0 deletions sample/PrismSample.UWP/PrismSample.UWP.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,22 @@
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform" Version="6.2.12" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\src\Prism.Container.Extensions\Prism.Container.Extensions.csproj">
<Project>{940ca2d8-b9a8-499a-9ed3-ecee9758073f}</Project>
<Name>Prism.Container.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Prism.DryIoc.Extensions\Prism.DryIoc.Extensions.csproj">
<Project>{3a82a96a-f3fc-4244-87c3-28706494f614}</Project>
<Name>Prism.DryIoc.Extensions</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Prism.Forms.Extended\Prism.Forms.Extended.csproj">
<Project>{771a0fd7-7877-4ab7-8528-7fb07054393d}</Project>
<Name>Prism.Forms.Extended</Name>
</ProjectReference>
<ProjectReference Include="..\..\src\Shiny.Prism\Shiny.Prism.csproj">
<Project>{fd30086e-fa39-408e-935f-8921b454d282}</Project>
<Name>Shiny.Prism</Name>
</ProjectReference>
<ProjectReference Include="..\PrismSample\PrismSample.csproj">
<Project>{0C2D6820-FA64-4050-9546-BF034329D363}</Project>
<Name>PrismSample</Name>
Expand Down
2 changes: 1 addition & 1 deletion sample/PrismSample.iOS/AppDelegate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsAppli
//
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
iOSShinyHost.Init(new Startup());
this.ShinyFinishedLaunching(new Startup());
global::Xamarin.Forms.Forms.Init();
LoadApplication(new App());

Expand Down
9 changes: 3 additions & 6 deletions sample/PrismSample/Shiny/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Shiny;
using Shiny.Prism;
using Shiny.Power;

namespace PrismSample.Shiny
{
public class Startup : PrismStartup
{
protected override void ConfigureServices(IServiceCollection services)
protected override void ConfigureServices(IServiceCollection services, IPlatform platform)
{
// Register Stuff
}
Expand Down
38 changes: 12 additions & 26 deletions src/Shiny.Prism/PrismStartup.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Linq;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Prism.Container.Extensions.Internals;
using Prism.Ioc;
using Prism.Modularity;
Expand All @@ -19,26 +20,30 @@ protected PrismStartup(IContainerExtension container)
WithContainer(container);
}

protected virtual void ConfigureApp(IServiceProvider provider) { }
protected virtual void ConfigureLogging(ILoggingBuilder builder, IPlatform platform) { }

protected abstract void ConfigureServices(IServiceCollection services);
protected abstract void ConfigureServices(IServiceCollection services, IPlatform platform);

void IShinyStartup.ConfigureServices(IServiceCollection services)
protected virtual void RegisterServices(IContainerRegistry containerRegistry) { }

void IShinyStartup.ConfigureLogging(ILoggingBuilder builder, IPlatform platform) =>
ConfigureLogging(builder, platform);

void IShinyStartup.ConfigureServices(IServiceCollection services, IPlatform platform)
{
ConfigureServices(services);
ConfigureServices(services, platform);
services.RegisterPrismCoreServices();
services.Remove(services.First(x => x.ServiceType == typeof(IModuleInitializer)));
services.AddSingleton<IModuleInitializer, ShinyPrismModuleInitializer>();
}

void IShinyStartup.ConfigureApp(IServiceProvider provider) => ConfigureApp(provider);

IServiceProvider IShinyStartup.CreateServiceProvider(IServiceCollection services)
{
var container = ContainerLocationHelper.LocateContainer(CreateContainerExtension()) ??
throw new NullReferenceException("Call PrismContainerExtension.Init() prior to initializing PrismApplication");

var sp = container.CreateServiceProvider(services);
RegisterServices(container);

var moduleCatalog = container.Resolve<IModuleCatalog>();
ConfigureModuleCatalog(moduleCatalog);
Expand All @@ -60,29 +65,10 @@ protected virtual IContainerExtension CreateContainerExtension()
public IShinyStartup WithContainer(IContainerExtension container)
{
ContainerLocator.SetContainerExtension(() => container);
var _ = ContainerLocator.Container;
return this;
}

protected virtual void ConfigureModuleCatalog(IModuleCatalog moduleCatalog) { }
}

//public abstract class PrismStartupTask : IShinyStartupTask
//{
// async void IShinyStartupTask.Start()
// {
// try
// {
// Start();
// await StartAsync();
// }
// catch (Exception ex)
// {
// Log.Write(ex);
// }
// }

// protected virtual void Start() { }

// protected virtual Task StartAsync() => Task.CompletedTask;
//}
}
2 changes: 1 addition & 1 deletion src/Shiny.Prism/Shiny.Prism.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Shiny.Core" Version="1.2.0.1755" />
<PackageReference Include="Shiny.Core" Version="2.0.0.2487-preview" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Xunit;
using Prism.Ioc;
using System.Net.Http;
using Microsoft.Extensions.Logging;
#if DRYIOC
using Prism.DryIoc;
#elif UNITY
Expand Down Expand Up @@ -131,6 +132,24 @@ public void ResolvesHttpClientWithHttpClientFactory()
Assert.NotNull(client);
}

[Fact]
public void RegistersOpenGenerics()
{
PrismContainerExtension.Current.RegisterServices(s =>
{
s.AddLogging(b => b.SetMinimumLevel(LogLevel.Warning));
});

ILogger<CommonAspNetServiceTests> logger = null;
var ex = Record.Exception(() =>
{
logger = PrismContainerExtension.Current.Resolve<ILogger<CommonAspNetServiceTests>>();
});

Assert.Null(ex);
Assert.NotNull(logger);
}

private void ConfigureServices()
{
var services = new ServiceCollection();
Expand Down
60 changes: 52 additions & 8 deletions tests/Shiny.Prism.Tests/Mocks/MockStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
using System.Collections.Generic;
using System.Text;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;
using Prism.DryIoc;
using Prism.Ioc;
//using Shiny.Beacons;
using Shiny.BluetoothLE;
using Shiny.Locations;
using Shiny.Prism.Mocks.Delegates;
using Shiny.Logging;
using Xunit.Abstractions;

namespace Shiny.Prism.Mocks
{
public class MockStartup : PrismStartup, ILogger
public class MockStartup : PrismStartup, ILoggerProvider
{
private ITestOutputHelper _testOutputHelper { get; }

Expand All @@ -28,11 +26,15 @@ public MockStartup(ITestOutputHelper testOutputHelper, bool setContainer = true)
}
}

protected override void ConfigureServices(IServiceCollection services)
protected override void ConfigureLogging(ILoggingBuilder builder, IPlatform platform)
{
Log.Loggers.Clear();
Log.AddLogger(this);
base.ConfigureLogging(builder, platform);
builder.ClearProviders();
builder.AddProvider(this);
}

protected override void ConfigureServices(IServiceCollection services, IPlatform platform)
{
//services.UseBeacons<MockBeaconDelegate>();
services.UseGps<MockGpsDelegate>();
services.UseGeofencing<MockGeofenceDelegate>();
Expand Down Expand Up @@ -66,5 +68,47 @@ private void WriteParams((string Key, string Value)[] parameters)
_testOutputHelper.WriteLine($"{Key}: {Value}");
}
}

ILogger ILoggerProvider.CreateLogger(string categoryName)
{
return new Logger(categoryName, _testOutputHelper);
}

void IDisposable.Dispose()
{
}

class Logger : ILogger
{
private string _name { get; }
private ITestOutputHelper _output { get; }

public Logger(string name, ITestOutputHelper output)
{
_name = name;
_output = output;
}

public IDisposable BeginScope<TState>(TState state)
{
return new EmptyDisposable();
}

public bool IsEnabled(LogLevel logLevel)
{
return true;
}

public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func<TState, Exception, string> formatter)
{
var logEntry = new LogEntry<TState>(logLevel, _name, eventId, state, exception, formatter);
_output.WriteLine(logEntry.ToString());
}

class EmptyDisposable : IDisposable
{
public void Dispose() { }
}
}
}
}
Loading

0 comments on commit b77c08c

Please sign in to comment.