From 47c7b9b04fdceab8716f3bed1fed5d57b8ed716b Mon Sep 17 00:00:00 2001 From: William Bradley Date: Tue, 21 Nov 2017 22:12:07 +1300 Subject: [PATCH] MAJOR BREAKING CHANGE: Removed Static Properties from AppServices, you now need to call AppServices.Current, to get to the service classes. This will help future extensibility by breaking into packages. --- Android/Activities/ActivityHandler.cs | 4 +-- Android/Common/AndroidHelpers.cs | 4 +-- Core/AppServices.cs | 16 ++++----- Core/Common/ContinueExtensions.cs | 8 ++--- Core/Common/PlatformBindingHelpers.cs | 4 +-- Core/Models/Settings/AppSetting.cs | 2 +- Core/Models/Settings/AppSettingList.cs | 2 +- Core/Models/Settings/SerialAppSettingList.cs | 2 +- Core/Models/Settings/SerialisedAppSetting.cs | 2 +- Core/ViewModels/ViewModelBase.cs | 2 +- README.md | 2 +- SMB/SMBService.cs | 2 +- .../Test-Android/Views/BindingTests.cs | 2 +- TestApps/NETCore/Program.cs | 2 +- .../Tests-Universal/TestGenerator/TestTask.cs | 2 +- .../Tests/ContextMenuTestPage.cs | 4 +-- .../Tests/CredentialTestPage.cs | 36 +++++++++---------- .../Tests/FileFolderTestPage.cs | 8 ++--- .../Tests-Universal/Tests/PickerTestPage.cs | 18 +++++----- .../Tests-Universal/Tests/SettingTestPage.cs | 16 ++++----- TestApps/UWP/Test-UWP/MainPage.xaml.cs | 2 +- .../UWP/Test-UWP/Views/BindingTests.xaml.cs | 2 +- XamarinForms/Services/XamarinUIBindings.cs | 2 +- _docs/GettingStarted.md | 2 +- _docs/Platform/NETCore/NETCoreRemarks.md | 2 +- _docs/Platform/UWP/UWPRemarks.md | 6 ++-- 26 files changed, 78 insertions(+), 76 deletions(-) diff --git a/Android/Activities/ActivityHandler.cs b/Android/Activities/ActivityHandler.cs index 8aca1e7..6846953 100644 --- a/Android/Activities/ActivityHandler.cs +++ b/Android/Activities/ActivityHandler.cs @@ -27,12 +27,12 @@ public static ActivityHandler GetActivityHandler(Activity Activity) public void UpdateCurrentActivity() { - if (AppServices.UI == null) + if (AppServices.Current.UI == null) { throw new Exception("Please Initialise a new AndroidAppServices Instance for PlatformBindings to work."); } - var uibinding = AppServices.UI.DefaultUIBinding as AndroidUIBindingInfo; + var uibinding = AppServices.Current.UI.DefaultUIBinding as AndroidUIBindingInfo; uibinding.Activity = Activity; if (AndroidAppServices.UseAppCompatUI) uibinding.CompatActivity = (Android.Support.V7.App.AppCompatActivity)Activity; } diff --git a/Android/Common/AndroidHelpers.cs b/Android/Common/AndroidHelpers.cs index 2d61cc5..e1a2c13 100644 --- a/Android/Common/AndroidHelpers.cs +++ b/Android/Common/AndroidHelpers.cs @@ -13,13 +13,13 @@ public static Activity GetCurrentActivity() public static Activity GetCurrentActivity(this IUIBindingInfo UIBinding) { - var uibinding = (UIBinding ?? AppServices.UI.DefaultUIBinding) as AndroidUIBindingInfo; + var uibinding = (UIBinding ?? AppServices.Current.UI.DefaultUIBinding) as AndroidUIBindingInfo; return uibinding.Activity; } public static ActivityHandler GetCurrentActivityHandler(this IUIBindingInfo UIBinding) { - var uibinding = (UIBinding ?? AppServices.UI.DefaultUIBinding) as AndroidUIBindingInfo; + var uibinding = (UIBinding ?? AppServices.Current.UI.DefaultUIBinding) as AndroidUIBindingInfo; return ActivityHandler.GetActivityHandler(uibinding.Activity); } diff --git a/Core/AppServices.cs b/Core/AppServices.cs index 31106da..4ffe3b0 100644 --- a/Core/AppServices.cs +++ b/Core/AppServices.cs @@ -33,36 +33,36 @@ public AppServices(bool HasUI, Platform Platform) /// /// Functions for Platform Independent UI Functions. /// - public static UIBindings UI { get; protected set; } + public UIBindings UI { get; protected set; } /// /// Functions for Platform Independent IO Functions. /// - public static IOBindings IO { get; protected set; } + public IOBindings IO { get; protected set; } /// /// Functions for Platform Independent Credential Management. /// - public static ICredentialManager Credentials { get; protected set; } + public ICredentialManager Credentials { get; protected set; } /// /// Functions for Authenticating with OAuth. /// - public static IOAuthBroker OAuth { get; protected set; } + public IOAuthBroker OAuth { get; protected set; } /// /// Functions for Testing Connection to the Internet and other Sources. /// - public static NetworkUtilities NetworkUtilities { get; protected set; } + public NetworkUtilities NetworkUtilities { get; protected set; } /// /// The Current Platform the Framework is running on. /// - public static Platform ServicePlatform { get; private set; } + public Platform ServicePlatform { get; private set; } /// - /// The Current AppService, this is required for accessing Platform Specific Methods. + /// The Current AppServices Instance. /// - public static AppServices Current { get; private set; } + public static AppServices Current { get; protected set; } } } \ No newline at end of file diff --git a/Core/Common/ContinueExtensions.cs b/Core/Common/ContinueExtensions.cs index 4b4266e..2887ae2 100644 --- a/Core/Common/ContinueExtensions.cs +++ b/Core/Common/ContinueExtensions.cs @@ -34,7 +34,7 @@ public static async void ContinueOnUIThread(this Task Task, IUIBindingInfo UIBin /// An action to run when the completes. public static async void ContinueOnUIThread(this Task Task, Action action) { - await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, action); + await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, action); } /// @@ -54,7 +54,7 @@ public static async void ContinueOnUIThread(this Task Task, IUIBindingInfo UIBin /// An Task to run when the completes. public static async void ContinueOnUIThread(this Task Task, Action> action) { - await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, action); + await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, action); } /// @@ -77,7 +77,7 @@ public static async void ContinueOnUIThread(this Task Task, IUIBindingInfo /// The Continuation Task public static async Task ContinueOnUIThreadAsync(this Task Task, Action action) { - await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, () => action(Task)); + await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, () => action(Task)); } /// @@ -101,7 +101,7 @@ public static async Task ContinueOnUIThreadAsync(this Task Task, IUIBindingInfo /// The Continuation Task public static async Task ContinueOnUIThreadAsync(this Task Task, Action> action) { - await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, () => action(Task)); + await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, () => action(Task)); } /// diff --git a/Core/Common/PlatformBindingHelpers.cs b/Core/Common/PlatformBindingHelpers.cs index 480d38e..35243d8 100644 --- a/Core/Common/PlatformBindingHelpers.cs +++ b/Core/Common/PlatformBindingHelpers.cs @@ -21,7 +21,7 @@ public static string ResolvePath(FolderPath Path) { char separator = System.IO.Path.DirectorySeparatorChar; - var path = AppServices.IO.GetBaseFolder(Path.Root).Path; + var path = AppServices.Current.IO.GetBaseFolder(Path.Root).Path; foreach (var piece in GetPathPieces(Path.Path)) { @@ -106,7 +106,7 @@ public static async void OnUIThread(Action action) /// Continuation Task public static async Task OnUIThreadAsync(Action action) { - await AppServices.UI.DefaultUIBinding.ExecuteAsync(action); + await AppServices.Current.UI.DefaultUIBinding.ExecuteAsync(action); } /// diff --git a/Core/Models/Settings/AppSetting.cs b/Core/Models/Settings/AppSetting.cs index 9582685..f8a5baf 100644 --- a/Core/Models/Settings/AppSetting.cs +++ b/Core/Models/Settings/AppSetting.cs @@ -20,7 +20,7 @@ public AppSetting(T Default, [CallerMemberName] string SettingName = "") : this( public AppSetting(T Default, bool Roam, [CallerMemberName] string SettingName = "") : base(SettingName, Default) { this.Roam = Roam; - Attach(Roam ? AppServices.IO.RoamingSettings : AppServices.IO.LocalSettings); + Attach(Roam ? AppServices.Current.IO.RoamingSettings : AppServices.Current.IO.LocalSettings); } public bool Roam { get; private set; } diff --git a/Core/Models/Settings/AppSettingList.cs b/Core/Models/Settings/AppSettingList.cs index 6df6447..a49caf6 100644 --- a/Core/Models/Settings/AppSettingList.cs +++ b/Core/Models/Settings/AppSettingList.cs @@ -12,7 +12,7 @@ public AppSettingList([CallerMemberName] string SettingName = "") : this(false, public AppSettingList(bool Roam, [CallerMemberName] string SettingName = "") : base(SettingName) { this.Roam = Roam; - Attach(Roam ? AppServices.IO.RoamingSettings : AppServices.IO.LocalSettings); + Attach(Roam ? AppServices.Current.IO.RoamingSettings : AppServices.Current.IO.LocalSettings); } public bool Roam { get; private set; } diff --git a/Core/Models/Settings/SerialAppSettingList.cs b/Core/Models/Settings/SerialAppSettingList.cs index da89b08..4a5971d 100644 --- a/Core/Models/Settings/SerialAppSettingList.cs +++ b/Core/Models/Settings/SerialAppSettingList.cs @@ -12,7 +12,7 @@ public SerialAppSettingList([CallerMemberName] string SettingName = "") : this(f public SerialAppSettingList(bool Roam, [CallerMemberName] string SettingName = "") : base(SettingName) { this.Roam = Roam; - Attach(Roam ? AppServices.IO.RoamingSettings : AppServices.IO.LocalSettings); + Attach(Roam ? AppServices.Current.IO.RoamingSettings : AppServices.Current.IO.LocalSettings); } public bool Roam { get; private set; } = false; diff --git a/Core/Models/Settings/SerialisedAppSetting.cs b/Core/Models/Settings/SerialisedAppSetting.cs index 13bf372..5a6025e 100644 --- a/Core/Models/Settings/SerialisedAppSetting.cs +++ b/Core/Models/Settings/SerialisedAppSetting.cs @@ -20,7 +20,7 @@ public SerialisedAppSetting(T Default, [CallerMemberName] string SettingName = " public SerialisedAppSetting(T Default, bool Roam, [CallerMemberName] string SettingName = "") : base(SettingName, Default) { this.Roam = Roam; - Attach(Roam ? AppServices.IO.RoamingSettings : AppServices.IO.LocalSettings); + Attach(Roam ? AppServices.Current.IO.RoamingSettings : AppServices.Current.IO.LocalSettings); } public bool Roam { get; private set; } diff --git a/Core/ViewModels/ViewModelBase.cs b/Core/ViewModels/ViewModelBase.cs index 406684f..a6b1f61 100644 --- a/Core/ViewModels/ViewModelBase.cs +++ b/Core/ViewModels/ViewModelBase.cs @@ -11,7 +11,7 @@ public abstract class ViewModelBase : INotifyPropertyChanged { public ViewModelBase() { - UIBinding = AppServices.UI.DefaultUIBinding; + UIBinding = AppServices.Current.UI.DefaultUIBinding; } /// diff --git a/README.md b/README.md index e8114c7..cf71ec0 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ A Framework for creating code that performs Platform Dependent Tasks in a Generi Since this Framework is still in Early Alpha/Planning stages, the Documentation and API surface is subject to change, with breaking changes on new Releases until it is Production ready. -Be sure to perform null checks when interacting with the Framework, such as `AppServices.UI?.NavigationManager?.CanGoBack`, as well as check if a Platform Supports a certain feature, such as UI Access in Background Tasks, using the File/FolderPicker or File/Folder Open Functions. +Be sure to perform null checks when interacting with the Framework, such as `AppServices.Current.UI?.NavigationManager?.CanGoBack`, as well as check if a Platform Supports a certain feature, such as UI Access in Background Tasks, using the File/FolderPicker or File/Folder Open Functions. Not all Platforms have the same level of implementation, UWP is currently fully implemented, and a lot of the APIs are based off of UWP APIs. Android is somewhat implemented, while Xamarin.Forms is mostly unimplemented. diff --git a/SMB/SMBService.cs b/SMB/SMBService.cs index 5e04da8..a9b5079 100644 --- a/SMB/SMBService.cs +++ b/SMB/SMBService.cs @@ -7,7 +7,7 @@ public static class SMBService { public static void Register() { - var address = AppServices.NetworkUtilities.LocalIPAddress; + var address = AppServices.Current.NetworkUtilities.LocalIPAddress; if (address != null) { SMBSettings.LocalIPAddress = address; diff --git a/TestApps/Android/Test-Android/Views/BindingTests.cs b/TestApps/Android/Test-Android/Views/BindingTests.cs index 564c41e..aca42bd 100644 --- a/TestApps/Android/Test-Android/Views/BindingTests.cs +++ b/TestApps/Android/Test-Android/Views/BindingTests.cs @@ -29,7 +29,7 @@ protected override void OnCreate(Bundle savedInstanceState) private async void TestAsyncActivity_Click(object sender, EventArgs e) { var result = await this.StartActivityForResultAsync(typeof(ReturnActivity)); - AppServices.UI.PromptUser("Activity Returned", $"RequestCode: {result.RequestCode}\nResponse: {result.ResultCode}", "OK"); + AppServices.Current.UI.PromptUser("Activity Returned", $"RequestCode: {result.RequestCode}\nResponse: {result.ResultCode}", "OK"); } public Button Pickers { get { return _Pickers ?? (_Pickers = FindViewById