Skip to content
This repository has been archived by the owner on Nov 2, 2021. It is now read-only.

Commit

Permalink
MAJOR BREAKING CHANGE: Removed Static Properties from AppServices, yo…
Browse files Browse the repository at this point in the history
…u now need to call AppServices.Current, to get to the service classes. This will help future extensibility by breaking into packages.
  • Loading branch information
WilliamABradley committed Nov 21, 2017
1 parent b89c57e commit 47c7b9b
Show file tree
Hide file tree
Showing 26 changed files with 78 additions and 76 deletions.
4 changes: 2 additions & 2 deletions Android/Activities/ActivityHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions Android/Common/AndroidHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
16 changes: 8 additions & 8 deletions Core/AppServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,36 +33,36 @@ public AppServices(bool HasUI, Platform Platform)
/// <summary>
/// Functions for Platform Independent UI Functions.
/// </summary>
public static UIBindings UI { get; protected set; }
public UIBindings UI { get; protected set; }

/// <summary>
/// Functions for Platform Independent IO Functions.
/// </summary>
public static IOBindings IO { get; protected set; }
public IOBindings IO { get; protected set; }

/// <summary>
/// Functions for Platform Independent Credential Management.
/// </summary>
public static ICredentialManager Credentials { get; protected set; }
public ICredentialManager Credentials { get; protected set; }

/// <summary>
/// Functions for Authenticating with OAuth.
/// </summary>
public static IOAuthBroker OAuth { get; protected set; }
public IOAuthBroker OAuth { get; protected set; }

/// <summary>
/// Functions for Testing Connection to the Internet and other Sources.
/// </summary>
public static NetworkUtilities NetworkUtilities { get; protected set; }
public NetworkUtilities NetworkUtilities { get; protected set; }

/// <summary>
/// The Current Platform the Framework is running on.
/// </summary>
public static Platform ServicePlatform { get; private set; }
public Platform ServicePlatform { get; private set; }

/// <summary>
/// The Current AppService, this is required for accessing Platform Specific Methods.
/// The Current AppServices Instance.
/// </summary>
public static AppServices Current { get; private set; }
public static AppServices Current { get; protected set; }
}
}
8 changes: 4 additions & 4 deletions Core/Common/ContinueExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static async void ContinueOnUIThread(this Task Task, IUIBindingInfo UIBin
/// <param name="action">An action to run when the <see cref="Task"/> completes. </param>
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);
}

/// <summary>
Expand All @@ -54,7 +54,7 @@ public static async void ContinueOnUIThread(this Task Task, IUIBindingInfo UIBin
/// <param name="action">An Task to run when the <see cref="Task"/> completes. </param>
public static async void ContinueOnUIThread<T>(this Task<T> Task, Action<Task<T>> action)
{
await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, action);
await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, action);
}

/// <summary>
Expand All @@ -77,7 +77,7 @@ public static async void ContinueOnUIThread<T>(this Task<T> Task, IUIBindingInfo
/// <returns>The Continuation Task</returns>
public static async Task ContinueOnUIThreadAsync(this Task Task, Action<Task> action)
{
await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, () => action(Task));
await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, () => action(Task));
}

/// <summary>
Expand All @@ -101,7 +101,7 @@ public static async Task ContinueOnUIThreadAsync(this Task Task, IUIBindingInfo
/// <returns>The Continuation Task</returns>
public static async Task ContinueOnUIThreadAsync<T>(this Task<T> Task, Action<Task<T>> action)
{
await ContinueOnUIThreadAsync(Task, AppServices.UI.DefaultUIBinding, () => action(Task));
await ContinueOnUIThreadAsync(Task, AppServices.Current.UI.DefaultUIBinding, () => action(Task));
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions Core/Common/PlatformBindingHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -106,7 +106,7 @@ public static async void OnUIThread(Action action)
/// <returns>Continuation Task</returns>
public static async Task OnUIThreadAsync(Action action)
{
await AppServices.UI.DefaultUIBinding.ExecuteAsync(action);
await AppServices.Current.UI.DefaultUIBinding.ExecuteAsync(action);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Core/Models/Settings/AppSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Models/Settings/AppSettingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Core/Models/Settings/SerialAppSettingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Core/Models/Settings/SerialisedAppSetting.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 1 addition & 1 deletion Core/ViewModels/ViewModelBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public abstract class ViewModelBase : INotifyPropertyChanged
{
public ViewModelBase()
{
UIBinding = AppServices.UI.DefaultUIBinding;
UIBinding = AppServices.Current.UI.DefaultUIBinding;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion SMB/SMBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion TestApps/Android/Test-Android/Views/BindingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Button>(Resource.Id.TestFilePickerButton)); } }
Expand Down
2 changes: 1 addition & 1 deletion TestApps/NETCore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private static void Main(string[] args)

private static async void Init()
{
var result = await AppServices.UI.PromptUserAsync("Hello", "This is an Example", "Opt1", "Opt2");
var result = await AppServices.Current.UI.PromptUserAsync("Hello", "This is an Example", "Opt1", "Opt2");
ConsoleHelpers.SystemWriteLine("Result: " + result);
}
}
Expand Down
2 changes: 1 addition & 1 deletion TestApps/Tests-Universal/TestGenerator/TestTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class TestTask
public async void RunTest()
{
var result = await Test(AttachedUI);
if (result != null) AppServices.UI.PromptUser("Test Complete", result, "OK");
if (result != null) AppServices.Current.UI.PromptUser("Test Complete", result, "OK");
}

public string Name { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions TestApps/Tests-Universal/Tests/ContextMenuTestPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public ContextMenuTestPage()
{
void Selected(MenuItem Item)
{
AppServices.UI.PromptUser("Selected", $"^B^{Item.Label}^B^ Pressed", "OK", null);
AppServices.Current.UI.PromptUser("Selected", $"^B^{Item.Label}^B^ Pressed", "OK", null);
if (Item is ToggleMenuItem tog)
{
tog.IsToggled = tog.IsToggled != true;
Expand All @@ -33,7 +33,7 @@ void Selected(MenuItem Item)

public void ShowMenu(IMenuBinding Binding)
{
AppServices.UI.ShowMenu(Menu, Binding);
AppServices.Current.UI.ShowMenu(Menu, Binding);
}

public Menu Menu { get; }
Expand Down
36 changes: 18 additions & 18 deletions TestApps/Tests-Universal/Tests/CredentialTestPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Name = "Get Credentials",
Test = ui => Task.Run(() =>
{
var creds = AppServices.Credentials.AllCredentials;
var creds = AppServices.Current.Credentials.AllCredentials;
return string.Join("\n", creds.Select(item => $"Resource: {item.ResourceName} Username: {item.Username} Password: {item.Password}"));
})
});
Expand All @@ -25,15 +25,15 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Test = ui => Task.Run(async () =>
{
var creator = "Create Credential";
var resource = await AppServices.UI.RequestTextFromUserAsync(creator, "Resource", "OK", "Cancel");
var resource = await AppServices.Current.UI.RequestTextFromUserAsync(creator, "Resource", "OK", "Cancel");
if (resource == null) return Cancelled;
var username = await AppServices.UI.RequestTextFromUserAsync(creator, "Username", "OK", "Cancel");
var username = await AppServices.Current.UI.RequestTextFromUserAsync(creator, "Username", "OK", "Cancel");
if (username == null) return Cancelled;
var password = await AppServices.UI.RequestTextFromUserAsync(creator, "Password", "OK", "Cancel");
var password = await AppServices.Current.UI.RequestTextFromUserAsync(creator, "Password", "OK", "Cancel");
if (password == null) return Cancelled;

AppServices.Credentials.Store(new PlatformBindings.Models.CredentialContainer(resource, username, password));
var cred = AppServices.Credentials.Retrieve(resource, username);
AppServices.Current.Credentials.Store(new PlatformBindings.Models.CredentialContainer(resource, username, password));
var cred = AppServices.Current.Credentials.Retrieve(resource, username);
if (cred != null)
{
if (cred.ResourceName == resource && cred.Username == username && cred.Password == password)
Expand All @@ -51,10 +51,10 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Name = "Get all Credentials for Resource",
Test = ui => Task.Run(async () =>
{
var resource = await AppServices.UI.RequestTextFromUserAsync("Get Credentials for Resource", "Resource Name", "OK", "Cancel");
var resource = await AppServices.Current.UI.RequestTextFromUserAsync("Get Credentials for Resource", "Resource Name", "OK", "Cancel");
if (resource == null) return Cancelled;

var creds = AppServices.Credentials.FetchByResource(resource);
var creds = AppServices.Current.Credentials.FetchByResource(resource);
if (creds.Any())
{
return string.Join("\n", creds.Select(item => $"Resource: {item.ResourceName} Username: {item.Username} Password: {item.Password}"));
Expand All @@ -68,13 +68,13 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Name = "Get Credential",
Test = ui => Task.Run(async () =>
{
var resource = await AppServices.UI.RequestTextFromUserAsync("Credential Resource", "Resource", "OK", "Cancel");
var resource = await AppServices.Current.UI.RequestTextFromUserAsync("Credential Resource", "Resource", "OK", "Cancel");
if (resource == null) return Cancelled;

var username = await AppServices.UI.RequestTextFromUserAsync("Credential Username", "Username", "OK", "Cancel");
var username = await AppServices.Current.UI.RequestTextFromUserAsync("Credential Username", "Username", "OK", "Cancel");
if (username == null) return Cancelled;

var cred = AppServices.Credentials.Retrieve(resource, username);
var cred = AppServices.Current.Credentials.Retrieve(resource, username);
if (cred != null)
{
return $"Resource: {cred.ResourceName} Username: {cred.Username} Password: {cred.Password}";
Expand All @@ -88,17 +88,17 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Name = "Remove Credential",
Test = ui => Task.Run(async () =>
{
var resource = await AppServices.UI.RequestTextFromUserAsync("Credential Resource", "Resource", "OK", "Cancel");
var resource = await AppServices.Current.UI.RequestTextFromUserAsync("Credential Resource", "Resource", "OK", "Cancel");
if (resource == null) return Cancelled;

var username = await AppServices.UI.RequestTextFromUserAsync("Credential Username", "Username", "OK", "Cancel");
var username = await AppServices.Current.UI.RequestTextFromUserAsync("Credential Username", "Username", "OK", "Cancel");
if (username == null) return Cancelled;

var cred = AppServices.Credentials.Retrieve(resource, username);
var cred = AppServices.Current.Credentials.Retrieve(resource, username);
if (cred != null)
{
AppServices.Credentials.Remove(cred);
if (AppServices.Credentials.AllCredentials.FirstOrDefault(item => item.ResourceName == resource && item.Username == username) != null)
AppServices.Current.Credentials.Remove(cred);
if (AppServices.Current.Credentials.AllCredentials.FirstOrDefault(item => item.ResourceName == resource && item.Username == username) != null)
{
return "Failed: Credential still exists";
}
Expand All @@ -113,8 +113,8 @@ public CredentialTestPage(ITestPageGenerator PageGenerator) : base(PageGenerator
Name = "Clear Credentials",
Test = ui => Task.Run(() =>
{
AppServices.Credentials.Clear();
if (AppServices.Credentials.AllCredentials.Any())
AppServices.Current.Credentials.Clear();
if (AppServices.Current.Credentials.AllCredentials.Any())
{
return "Failed: Credentials still exist";
}
Expand Down
Loading

0 comments on commit 47c7b9b

Please sign in to comment.