diff --git a/Andro2UWP.sln b/Andro2UWP.sln index a122648..eb8e090 100644 --- a/Andro2UWP.sln +++ b/Andro2UWP.sln @@ -7,17 +7,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "Andro2UWP.Shared", "Andro2U EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Andro2UWP.Droid", "Andro2UWP\Andro2UWP.Droid\Andro2UWP.Droid.csproj", "{275B3515-3BBF-4541-A575-8674D2ECE676}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Andro2UWP.iOS", "Andro2UWP\Andro2UWP.iOS\Andro2UWP.iOS.csproj", "{26B683D4-3464-4DD6-8EBE-135CC7F76C2E}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Andro2UWP.UWP", "Andro2UWP\Andro2UWP.UWP\Andro2UWP.UWP.csproj", "{E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Andro2UWP.Wasm", "Andro2UWP\Andro2UWP.Wasm\Andro2UWP.Wasm.csproj", "{BF4E7441-36FD-425C-96B9-B8CB0AB138C2}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneDrive.Sdk.Authentication.Xamarin.Android", "Andro2UWP\OneDrive.Sdk.Authentication.Xamarin.Android\OneDrive.Sdk.Authentication.Xamarin.Android.csproj", "{B68F871E-A9E1-40CB-92A7-0F602504895B}" -EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution - Andro2UWP\Andro2UWP.Shared\Andro2UWP.Shared.projitems*{275b3515-3bbf-4541-a575-8674d2ece676}*SharedItemsImports = 4 Andro2UWP\Andro2UWP.Shared\Andro2UWP.Shared.projitems*{6279c845-92f8-4333-ab99-3d213163593c}*SharedItemsImports = 13 Andro2UWP\Andro2UWP.Shared\Andro2UWP.Shared.projitems*{e92e8f8f-6bbb-4e5b-8d76-0cda640e84f3}*SharedItemsImports = 4 EndGlobalSection @@ -120,38 +113,6 @@ Global {275B3515-3BBF-4541-A575-8674D2ECE676}.Release|x86.ActiveCfg = Release|Any CPU {275B3515-3BBF-4541-A575-8674D2ECE676}.Release|x86.Build.0 = Release|Any CPU {275B3515-3BBF-4541-A575-8674D2ECE676}.Release|x86.Deploy.0 = Release|Any CPU - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|Any CPU.ActiveCfg = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|ARM.ActiveCfg = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|iPhone.ActiveCfg = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|iPhone.Build.0 = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Ad-Hoc|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|iPhoneSimulator.Build.0 = Ad-Hoc|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|x64.ActiveCfg = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Ad-Hoc|x86.ActiveCfg = Ad-Hoc|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|Any CPU.ActiveCfg = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|ARM.ActiveCfg = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|iPhone.ActiveCfg = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|iPhone.Build.0 = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|iPhoneSimulator.ActiveCfg = AppStore|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|iPhoneSimulator.Build.0 = AppStore|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|x64.ActiveCfg = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.AppStore|x86.ActiveCfg = AppStore|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|Any CPU.ActiveCfg = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|ARM.ActiveCfg = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|iPhone.ActiveCfg = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|iPhone.Build.0 = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|x64.ActiveCfg = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Debug|x86.ActiveCfg = Debug|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|Any CPU.ActiveCfg = Release|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|ARM.ActiveCfg = Release|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|iPhone.ActiveCfg = Release|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|iPhone.Build.0 = Release|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|x64.ActiveCfg = Release|iPhone - {26B683D4-3464-4DD6-8EBE-135CC7F76C2E}.Release|x86.ActiveCfg = Release|iPhone {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Ad-Hoc|Any CPU.ActiveCfg = Release|x64 {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Ad-Hoc|Any CPU.Build.0 = Release|x64 {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Ad-Hoc|Any CPU.Deploy.0 = Release|x64 @@ -214,102 +175,6 @@ Global {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Release|x86.ActiveCfg = Release|x86 {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Release|x86.Build.0 = Release|x86 {E92E8F8F-6BBB-4E5B-8D76-0CDA640E84F3}.Release|x86.Deploy.0 = Release|x86 - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|x64.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Ad-Hoc|x86.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|Any CPU.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|ARM.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|ARM.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|iPhone.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|iPhone.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|x64.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|x64.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|x86.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.AppStore|x86.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|Any CPU.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|ARM.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|ARM.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|iPhone.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|x64.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|x64.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|x86.ActiveCfg = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Debug|x86.Build.0 = Debug|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|Any CPU.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|Any CPU.Build.0 = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|ARM.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|ARM.Build.0 = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|iPhone.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|iPhone.Build.0 = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|x64.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|x64.Build.0 = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|x86.ActiveCfg = Release|Any CPU - {BF4E7441-36FD-425C-96B9-B8CB0AB138C2}.Release|x86.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|Any CPU.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|Any CPU.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|ARM.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|ARM.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|iPhone.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|iPhone.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|iPhoneSimulator.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|x64.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|x64.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|x86.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Ad-Hoc|x86.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|Any CPU.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|Any CPU.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|ARM.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|ARM.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|iPhone.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|iPhone.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|iPhoneSimulator.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|x64.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|x64.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|x86.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.AppStore|x86.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|ARM.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|ARM.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|iPhone.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|iPhone.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|iPhoneSimulator.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|iPhoneSimulator.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|x64.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|x64.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|x86.ActiveCfg = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Debug|x86.Build.0 = Debug|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|Any CPU.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|ARM.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|ARM.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|iPhone.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|iPhone.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|iPhoneSimulator.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|x64.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|x64.Build.0 = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|x86.ActiveCfg = Release|Any CPU - {B68F871E-A9E1-40CB-92A7-0F602504895B}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Andro2UWP/Andro2UWP.Droid/Andro2UWP.Droid.csproj b/Andro2UWP/Andro2UWP.Droid/Andro2UWP.Droid.csproj index a689966..990ac30 100644 --- a/Andro2UWP/Andro2UWP.Droid/Andro2UWP.Droid.csproj +++ b/Andro2UWP/Andro2UWP.Droid/Andro2UWP.Droid.csproj @@ -69,20 +69,23 @@ - - 1.24.0 + + + 2.0.7 - - 4.34.0 + + 1.0.10 - - 2.0.4 + + 13.0.1 3.0.1 - - + + @@ -98,7 +101,6 @@ - @@ -129,12 +131,6 @@ - - - {b68f871e-a9e1-40cb-92a7-0f602504895b} - OneDrive.Sdk.Authentication.Xamarin.Android - - diff --git a/Andro2UWP/Andro2UWP.Droid/Main.cs b/Andro2UWP/Andro2UWP.Droid/Main.cs index 70cfc23..7e3e320 100644 --- a/Andro2UWP/Andro2UWP.Droid/Main.cs +++ b/Andro2UWP/Andro2UWP.Droid/Main.cs @@ -23,7 +23,8 @@ namespace Andro2UWP.Droid public class Application : Windows.UI.Xaml.NativeApplication { public Application(IntPtr javaReference, JniHandleOwnership transfer) - : base(() => new App(), javaReference, transfer) // linia dla nowszej wersji + // : base(new App(), javaReference, transfer) // linia dla starszej wersji + : base(() => new App(), javaReference, transfer) // linia dla nowszej wersji { ConfigureUniversalImageLoader(); } diff --git a/Andro2UWP/Andro2UWP.Droid/MainActivity.cs b/Andro2UWP/Andro2UWP.Droid/MainActivity.cs index b628b46..f78c584 100644 --- a/Andro2UWP/Andro2UWP.Droid/MainActivity.cs +++ b/Andro2UWP/Andro2UWP.Droid/MainActivity.cs @@ -18,7 +18,7 @@ public class MainActivity : Windows.UI.Xaml.ApplicationActivity protected override void OnActivityResult(int requestCode, Result resultCode, Android.Content.Intent data) { base.OnActivityResult(requestCode, resultCode, data); - Uno.OneDrive.Connector.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data); + //Uno.OneDrive.Connector.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data); } } } diff --git a/Andro2UWP/Andro2UWP.Droid/OnedriveDroid.cs b/Andro2UWP/Andro2UWP.Droid/OnedriveDroid.cs deleted file mode 100644 index 7dd20d8..0000000 --- a/Andro2UWP/Andro2UWP.Droid/OnedriveDroid.cs +++ /dev/null @@ -1,973 +0,0 @@ -// LeversonCarlos -// Xamarin.OneDrive.Connector - -// https://github.com/LeversonCarlos/Xamarin.OneDrive.Connector - -using Android.App; -using Android.Content; -using Microsoft.Identity.Client; -using System; -using System.Threading.Tasks; -using System.Net.Http; -using System.Net; -using System.Threading; -using System.Linq; -using System.Runtime.Serialization; -using System.Collections.Generic; - -namespace Uno.OneDrive -{ - - #region "Xamarin.OneDrive.Connector" - partial class Connector - { - - public static void SetAuthenticationContinuationEventArgs(int requestCode, Result resultCode, Intent data) - { - Microsoft.Identity.Client.AuthenticationContinuationHelper.SetAuthenticationContinuationEventArgs(requestCode, resultCode, data); - } - - } - - - internal class Configs : IDisposable - { - - public string ClientID { get; set; } - public string[] Scopes { get; set; } - - internal string RedirectUri { get; set; } - internal object UiParent { get; set; } - - public void Dispose() - { - this.UiParent = null; - } - - } - - internal class DependencyImplementation : IDependency - { - internal Context _activity; - internal string _redirectUrl; - - public void Initialize(Configs configs) - { - if (_activity != null) - { - configs.UiParent = _activity; - } - else - { - // Uno.UI.BaseActivity.Current; // Android.App.Application.Context; - // Xamarin.Forms.Forms.Context as Forms.Platform.Android.FormsAppCompatActivity; - Context mainActivity = Android.App.Application.Context; - - configs.UiParent = mainActivity; - } - if (!string.IsNullOrEmpty(_redirectUrl)) - { - configs.RedirectUri = _redirectUrl; - } - else - { - //configs.RedirectUri = "https://login.microsoftonline.com/common/oauth2/nativeclient"; - configs.RedirectUri = $"msal{configs.ClientID}://auth"; - } - } - - public async Task GetAuthResult(Microsoft.Identity.Client.IPublicClientApplication client, Configs configs) - { - - Activity aktywnosc = Uno.UI.BaseActivity.Current; // (Activity)configs.UiParent; - try - { - return await client - .AcquireTokenInteractive(configs.Scopes) - .WithParentActivityOrWindow(aktywnosc) - .ExecuteAsync(); - } - catch (Exception) { throw; } - } - - } - - partial class Connector - { - - public static void Init(Context activity) { Init(activity, ""); } - - public static void Init(Context activity, string redirectUrl) - { - var dependency = (DependencyImplementation)Dependency.Current; - dependency._activity = activity; - dependency._redirectUrl = redirectUrl; - } - - } - - - internal interface IDependency - { - void Initialize(Configs configs); - Task GetAuthResult - (Microsoft.Identity.Client.IPublicClientApplication client, Configs configs); - } - - internal class Dependency - { - - static Lazy implementation = new Lazy( - () => CreateDependency(), LazyThreadSafetyMode.PublicationOnly); - - static IDependency CreateDependency() - { - // #pragma warning disable IDE0022 // Use expression body for methods - return new DependencyImplementation(); - // #pragma warning restore IDE0022 // Use expression body for methods - } - - public static IDependency Current - { - get - { - IDependency ret = implementation.Value; - if (ret == null) - { - throw new NotImplementedException( - "This functionality is not implemented in the portable version of this assembly. " + - "You should reference the NuGet package from your main application project " + - "in order to reference the platform-specific implementation."); - } - return ret; - } - } - - } - - partial class Connector - { - - public async Task ConnectAsync() - { - return await this.ConnectorAsync(ConnectorHandler.InnerConnectionConnect); - } - - public async Task DisconnectAsync() - { - return await this.ConnectorAsync(ConnectorHandler.InnerConnectionDisconnect); - } - - private async Task ConnectorAsync(string connectorState) - { - try - { - var httpParam = new StringContent(connectorState); - var httpMessage = await this.PostAsync(ConnectorHandler.InnerConnectionPath, httpParam); - if (httpMessage.IsSuccessStatusCode) { return true; } - else - { - var httpReason = httpMessage.ReasonPhrase; - var httpContent = string.Empty; - if (httpMessage.Content != null) - { - httpContent = await httpMessage.Content.ReadAsStringAsync(); - } - throw new Exception($"{httpReason}\n{httpContent}"); - } - } - catch (Exception) { throw; } - } - - } - - public partial class Connector : HttpClient - { - const string BaseURL = "https://graph.microsoft.com/v1.0/"; - internal Configs mConfig = null; - internal bool mWrite = false; - public Connector(string clientID, params string[] scopes) : - this( - new Configs { ClientID = clientID, Scopes = scopes } - ) - { } - - internal Connector(Configs configs) : base(new ConnectorHandler(configs)) - { - this.BaseAddress = new Uri(BaseURL); - mConfig = configs; - foreach (string scope in configs.Scopes) - { - if (scope.Contains("Write")) - mWrite = true; - } - } - - } - partial class ConnectorHandler - { - - public HttpResponseMessage CreateMessage(HttpStatusCode statusCode) - { - return this.CreateMessage(statusCode, string.Empty); - } - - public HttpResponseMessage CreateMessage(HttpStatusCode statusCode, string content) - { - var responseMessage = new HttpResponseMessage(statusCode); - if (!string.IsNullOrEmpty(content)) - { - responseMessage.Content = new StringContent(content); - } - return responseMessage; - } - - } - - internal partial class ConnectorHandler : DelegatingHandler - { - Token Token { get; set; } - internal const string InnerConnectionPath = "Xamarin-OneDrive-Connector"; - internal const string InnerConnectionConnect = "CONNECT"; - internal const string InnerConnectionDisconnect = "DISCONNECT"; - - public ConnectorHandler(Configs configs) - { - - // VALIDATION - if (configs == null) - { throw new NullReferenceException("The configs parameter must be defined with the " + - "microsoft graph definitions"); - } - - if (string.IsNullOrEmpty(configs.ClientID)) - { throw new ArgumentNullException("Your microsoft graph client id must be informed"); - } - - if (configs.Scopes == null || configs.Scopes.Length == 0) - { throw new ArgumentNullException("Your microsoft graph required scopes must be informed"); - } - - if (configs.Scopes.Count(x => !string.IsNullOrEmpty(x)) == 0) - { throw new ArgumentNullException("Your microsoft graph required scopes must be informed"); - } - - // INITIALIZATION - Dependency.Current.Initialize(configs); - this.Token = new Token(configs); - this.InnerHandler = new HttpClientHandler(); - } - - protected async override Task SendAsync - ( - HttpRequestMessage request, - CancellationToken cancellationToken - ) - { - - var InnerConnectionResult = await this.InnerConnectionHandlerAsync(request, cancellationToken); - if (InnerConnectionResult.StatusCode != HttpStatusCode.SeeOther) { return InnerConnectionResult; } - - if (!await this.Token.ConnectAsync()) - { - return this.CreateMessage(HttpStatusCode.Unauthorized, "The token connect method has failed"); - } - - request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("bearer", - this.Token.CurrentToken); - - return await base.SendAsync(request, cancellationToken); - - } - - private async Task InnerConnectionHandlerAsync(HttpRequestMessage request, - CancellationToken cancellationToken) - { - try - { - if (!request.RequestUri.AbsolutePath.EndsWith(InnerConnectionPath)) - { - return this.CreateMessage(HttpStatusCode.SeeOther); - } - - if (request.Method != HttpMethod.Post || request.Content == null) - { - return this.CreateMessage(HttpStatusCode.BadRequest, - "Method must be POST and content must be CONNECT or DISCONNECT"); - } - - var command = await request.Content.ReadAsStringAsync(); - - if (command == InnerConnectionConnect) - { - var result = await this.Token.ConnectAsync(); - if (result) - { - return this.CreateMessage(HttpStatusCode.OK); - } - else - { - return this.CreateMessage(HttpStatusCode.InternalServerError, - "The token connect method has failed"); - } - } - else if (command == InnerConnectionDisconnect) - { - await this.Token.DisconnectAsync(); - return this.CreateMessage(HttpStatusCode.OK); - } - else - { - return this.CreateMessage(HttpStatusCode.BadRequest, - "Method must be POST and content must be CONNECT or DISCONNECT"); - } - - } - catch (Exception ex) - { - return this.CreateMessage(HttpStatusCode.InternalServerError, ex.ToString()); - } - } - - } - partial class Token - { - - internal async Task AcquireAsync() - { - try - { - this.AuthResult = await Dependency.Current.GetAuthResult(this.Client, this.Configs); - return this.IsValid(); - } - catch (Exception) { throw; } - } - - } - partial class Token - { - - internal async Task ConnectAsync() - { - try - { - - // TOKEN STILL VALID - if (this.IsValid()) { return true; } - - // REFRESH AN EXPIRED TOKEN - if (await this.RefreshAsync()) { return true; } - - // ACQUIRE A NEW TOKEN - if (await this.AcquireAsync()) { return true; } - - // OTHERWISE - return false; - - } - catch (Exception) { throw; } - } - - internal async Task DisconnectAsync() - { - try - { - var accounts = await this.Client.GetAccountsAsync(); - if (accounts != null && accounts.Count() != 0) - { - foreach (var account in accounts) - { await this.Client.RemoveAsync(account); } - } - - } - catch (Exception) { throw; } - } - - } - partial class Token - { - AuthenticationResult AuthResult { get; set; } - - internal string CurrentToken - { - get - { - if (!this.IsValid()) { return string.Empty; } - return this.AuthResult.AccessToken; - } - } - - internal bool IsValid() - { - if (this.AuthResult == null) { return false; } - if (string.IsNullOrEmpty(this.AuthResult.AccessToken)) { return false; } - return (this.AuthResult.ExpiresOn > DateTimeOffset.UtcNow.AddMinutes(5)); - } - - } - partial class Token - { - - internal async Task RefreshAsync() - { - try - { - var accounts = await this.Client.GetAccountsAsync(); - if (accounts != null && accounts.Count() != 0) - { - var account = accounts.FirstOrDefault(); - if (account != null) - { - this.AuthResult = - await this.Client.AcquireTokenSilent(this.Configs.Scopes, account).ExecuteAsync(); - } - } - return this.IsValid(); - } - catch (Exception) { throw; } - } - - } - internal partial class Token : IDisposable - { - internal Configs Configs { get; private set; } - IPublicClientApplication Client { get; set; } - - internal Token(Configs configs) - { - this.Configs = configs; - - var builder = PublicClientApplicationBuilder.Create(configs.ClientID); - - if (!string.IsNullOrEmpty(configs.RedirectUri)) - { - builder = builder.WithRedirectUri(configs.RedirectUri); - } - - this.Client = builder.Build(); - } - - public void Dispose() - { - this.Client = null; - this.AuthResult = null; - this.Configs.Dispose(); - this.Configs = null; - } - - } - - #endregion - - #region "Xamarin.OneDrive.Connector.Files" - - #region "structy" - [DataContract] - public class FileData - { - - [DataMember(Name = "id")] - public string id { get; set; } - - [DataMember(Name = "name")] - public string FileName { get; set; } - - [DataMember(Name = "path")] - public string FilePath { get; set; } - - [DataMember(Name = "createdDateTime")] - internal string CreatedDateTimeText { get; set; } - public DateTime? CreatedDateTime { get; set; } - - [DataMember(Name = "size")] - public long? Size { get; set; } - - [DataMember(Name = "@microsoft.graph.downloadUrl")] - internal string downloadUrl { get; set; } - - [DataMember(Name = "parentReference")] - internal FileData parentReference { get; set; } - public string parentID { get; set; } - - [DataMember(Name = "folder")] - internal FolderData folderData { get; set; } - - [DataMember(Name = "file")] - internal FileDetailsData fileData { get; set; } - - } - - [DataContract] - internal class FileDetailsData - { - - [DataMember(Name = "mimeType")] - internal string mimeType { get; set; } - - } - - [DataContract] - internal class FolderData - { - - [DataMember(Name = "childCount")] - internal int childCount { get; set; } - - } - - [DataContract] - internal class SearchData - { - - [DataMember(Name = "value")] - public List Files { get; set; } - - [DataMember(Name = "@odata.nextLink")] - public string nextLink { get; set; } - - } - #endregion - #region "folders" - partial class Connector - { - public async Task> GetChildFoldersAsync() - { - try - { - var httpPath = $"me/drive/root/children"; - var folderList = await GetChildFoldersAsync(httpPath); - folderList.ForEach(x => x.FilePath = $"/ {x.FileName}"); - return folderList; - } - catch (Exception) { throw; } - } - - public async Task> GetChildFoldersAsync(FileData folder) - { - // MOJ DODATEK upraszczajacy moje funkcje - if (folder is null) - return await GetChildFoldersAsync(); - - try - { - var httpPath = $"me/drive/items/{folder.id}/children"; - var folderList = await GetChildFoldersAsync(httpPath); - folderList.ForEach(x => x.FilePath = $"{folder.FilePath} / {x.FileName}"); - return folderList; - } - catch (Exception) { throw; } - } - - private async Task> GetChildFoldersAsync(string httpPath) - { - try - { - var folderList = new List(); - httpPath += "?select=id,name,folder&$top=1000"; - - while (!string.IsNullOrEmpty(httpPath)) - { - - // REQUEST DATA FROM SERVER - var httpMessage = await GetAsync(httpPath); - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - // SERIALIZE AND STORE RESULT - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(SearchData)); - var httpResult = (SearchData)serializer.ReadObject(httpContent); - var folders = httpResult.Files.Where(x => x.folderData != null).ToList(); - folderList.AddRange(folders); - - // CHECK IF THERE IS ANOTHER PAGE OF RESULTS - httpPath = httpResult.nextLink; - if (!string.IsNullOrEmpty(httpPath)) - { httpPath = httpPath.Replace(BaseAddress.AbsoluteUri, string.Empty); } - - } - - // NORMALIZE FOLDER's PATHS - foreach (var folder in folderList) - { - if (string.IsNullOrEmpty(folder.FilePath)) - { folder.FilePath = string.Empty; } - - var sep = folder.FilePath.IndexOf(":"); - if (sep != -1) - { folder.FilePath = folder.FilePath.Substring(sep + 1); } - - folder.FilePath = Uri.UnescapeDataString(folder.FilePath); - } - - // RESULT - folderList = folderList - .OrderBy(x => x.FilePath) - .ThenBy(x => x.FileName) - .ToList(); - return folderList; - - } - catch (Exception) { throw; } - } - - - public async Task> GetChildFilesAsync(FileData folder) - { - try - { - var fileList = new List(); - var httpPath = $"me/drive/items/{folder.id}/children"; - httpPath += "?select=id,name,createdDateTime,size,file&$top=1000"; - - while (!string.IsNullOrEmpty(httpPath)) - { - - // REQUEST DATA FROM SERVER - var httpMessage = await GetAsync(httpPath); - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - // SERIALIZE AND STORE RESULT - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(SearchData)); - var httpResult = (SearchData)serializer.ReadObject(httpContent); - var files = httpResult.Files.Where(x => x.fileData != null).ToList(); - fileList.AddRange(files); - - // CHECK IF THERE IS ANOTHER PAGE OF RESULTS - httpPath = httpResult.nextLink; - if (!string.IsNullOrEmpty(httpPath)) - { httpPath = httpPath.Replace(BaseAddress.AbsoluteUri, string.Empty); } - - } - - // NORMALIZE FILE's PATHS - foreach (var file in fileList) - { - file.parentID = folder.id; - file.FilePath = folder.FilePath; - } - - // RESULT - return fileList; - - } - catch (Exception) { throw; } - } - } - #endregion - #region "Files" - - partial class Connector - { - public async Task GetDetailsAsync() - { - var httpPath = $"me/drive/root"; - var folder = await GetDetailsAsync(httpPath); - if (string.IsNullOrEmpty(folder.FilePath)) - { folder.FilePath = "/drive/root:"; } - return folder; - } - - public async Task GetDetailsAsync(FileData folder) - { - var httpPath = $"me/drive/items/{folder.id}"; - return await GetDetailsAsync(httpPath); - } - - private async Task GetDetailsAsync(string httpPath) - { - try - { - httpPath += "?select=id,name,parentReference"; - - // REQUEST DATA FROM SERVER - var httpMessage = await GetAsync(httpPath); - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - // SERIALIZE AND STORE RESULT - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(FileData)); - var httpResult = (FileData)serializer.ReadObject(httpContent); - - // RESULT - if (httpResult.parentReference != null) - { httpResult.FilePath = httpResult.parentReference.FilePath; } - return httpResult; - - } - catch (Exception) { throw; } - } - } - - #endregion - - #region "upload" - partial class Connector - { - - public async Task UploadAsync(FileData file, System.IO.Stream content) - { - try - { - - var httpPath = $"me/drive/items/{file.id}/content"; - if (string.IsNullOrEmpty(file.id)) - { httpPath = $"me/drive/items/{file.parentID}:/{file.FileName}:/content"; } - var httpData = new System.Net.Http.StreamContent(content); - var httpMessage = await PutAsync(httpPath, httpData); - - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(FileData)); - var httpResult = (FileData)serializer.ReadObject(httpContent); - - return httpResult; - - } - catch (Exception) { throw; } - } - - } - #endregion - - #endregion - - #region "moje dodatki" - - public partial class Connector - { - - public async Task GetThisAppFolderAsync() - { - var httpMessage = await GetAsync("drive/special/approot:/"); - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - // SERIALIZE AND STORE RESULT - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(FileData)); - var httpResult = (FileData)serializer.ReadObject(httpContent); - - // RESULT - if (httpResult.parentReference != null) - { httpResult.FilePath = httpResult.parentReference.FilePath; } - return httpResult; - } - - - public async Task CreateFolder(FileData parentFolder, string folderName) - { - // if cannot write, then don't even try - if (!mWrite) - return null; - - string httpPath; - if (parentFolder is null) - { - // zakladamy folder w glownym (rzadko, albo w ogole nie uzywany bedzie to kod - httpPath = "me/drive/root/children"; - } - else - { - httpPath = "me/drive/items/" + parentFolder.id + "/children"; - } - - var jsonCommand = "{ \"name\": \"" + folderName + "\", \"folder\": { }, \"@microsoft.graph.conflictBehavior\": \"rename\" }"; - var httpData = new StringContent(jsonCommand, System.Text.Encoding.UTF8, "application/json"); - var httpMessage = await PutAsync(httpPath, httpData); - - if (!httpMessage.IsSuccessStatusCode) - { throw new Exception(await httpMessage.Content.ReadAsStringAsync()); } - - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(FileData)); - var httpResult = (FileData)serializer.ReadObject(httpContent); - - return httpResult; - - } - - public async Task OpenOrCreateFolder(FileData parentFolder, string folderName) - { - if (parentFolder is null) return null; - if (string.IsNullOrEmpty(parentFolder.id)) return null; - if (string.IsNullOrEmpty(folderName)) return null; - - - FileData thisLevel = null; - foreach (var subfold in await GetChildFoldersAsync(parentFolder)) - { - if (subfold.FileName == folderName) - { - thisLevel = subfold; - break; - } - } - - if (thisLevel is null) - { - thisLevel = await CreateFolder(parentFolder, folderName); - } - - return null; - - } - - - public async Task OpenOrCreateFolder(string folderPath) - { - if (string.IsNullOrEmpty(folderPath)) - return null; - - folderPath = folderPath.Replace("\\", "/"); // na wszelki wypadek - string[] pathParts = folderPath.Split("/"); - - FileData thisLevel = null; - FileData parentLevel = null; - - for (int i = 0; i < pathParts.Count(); i++) - { - // jesli zapis jest /cos/cos, to pierwszy / jest do pominiecia, a i tak zaczynamy od root - if (pathParts[i] == "") - break; - - thisLevel = await OpenOrCreateFolder(parentLevel, pathParts[i]); - - if (thisLevel is null) - return null; - - parentLevel = thisLevel; - } - - return thisLevel; - } - - public async Task SaveFile(FileData parentFolder, string fileName, string fileContent) - { - // if cannot write, then don't even try - if (!mWrite) - return null; - - if (parentFolder is null) - return null; // nie obslugujemy zapisu do glownego katalogu - - try - { - - var httpPath = $"me/drive/items/{parentFolder.id}:/{fileName}:/content"; - - var httpData = new System.Net.Http.StringContent(fileContent); - var httpMessage = await PutAsync(httpPath, httpData); - - if (!httpMessage.IsSuccessStatusCode) - { - System.Diagnostics.Debug.WriteLine("--------OneDrive error: \n" + await httpMessage.Content.ReadAsStringAsync()); - return null; - } - - var httpContent = await httpMessage.Content.ReadAsStreamAsync(); - var serializer = new System.Runtime.Serialization.Json.DataContractJsonSerializer(typeof(FileData)); - var httpResult = (FileData)serializer.ReadObject(httpContent); - - return httpResult; - - } - catch - { - return null; - } - } - private async Task ReadFile(string httpPath) - { - var httpMessage = await GetAsync(httpPath); - - if (!httpMessage.IsSuccessStatusCode) - { - System.Diagnostics.Debug.WriteLine("--------OneDrive error: \n" + await httpMessage.Content.ReadAsStringAsync()); - return null; - } - return await httpMessage.Content.ReadAsStringAsync(); - } - - public async Task ReadFile(FileData file) - { - var httpPath = $"me/drive/items/{file.id}/content"; - return await ReadFile(httpPath); - } - - public async Task ReadFile(FileData parentFolder, string fileName) - { - if (parentFolder is null) - return null; // nie obslugujemy zapisu do glownego katalogu - - var httpPath = $"me/drive/items/{parentFolder.id}:/{fileName}:/content"; - return await ReadFile(httpPath); - } - private async Task GetFileStream(string httpPath) - { - var httpMessage = await GetAsync(httpPath); - - if (!httpMessage.IsSuccessStatusCode) - { - System.Diagnostics.Debug.WriteLine("--------OneDrive error: \n" + await httpMessage.Content.ReadAsStringAsync()); - return null; - } - - return await httpMessage.Content.ReadAsStreamAsync(); - } - - public async Task GetFileStream(FileData file) - { - var httpPath = $"me/drive/items/{file.id}/content"; - return await GetFileStream(httpPath); - } - - public async Task GetFileStream(FileData parentFolder, string fileName) - { - if (parentFolder is null) - return null; // nie obslugujemy zapisu do glownego katalogu - - var httpPath = $"me/drive/items/{parentFolder.id}:/{fileName}:/content"; - return await GetFileStream(httpPath); - } - - public async Task DeleteFile(FileData file) - { - if (string.IsNullOrEmpty(file.id)) - throw new ArgumentException("OneDrive.DeleteFile called with null FileData.id"); - - var httpMessage = await DeleteAsync("drive/items/" + file.id); - return httpMessage.IsSuccessStatusCode; - } - - public async Task DeleteFile(string httpFilePath) - { - if (string.IsNullOrEmpty(httpFilePath)) - throw new ArgumentException("OneDrive.DeleteFile called with null httpFilePath"); - - if (!httpFilePath.StartsWith("/")) - httpFilePath = "/" + httpFilePath; - var httpMessage = await DeleteAsync("drive/root:" + httpFilePath); - return httpMessage.IsSuccessStatusCode; - } - - public async Task DeleteFile(FileData parentFolder, string fileName) - { - if (string.IsNullOrEmpty(parentFolder.id)) - throw new ArgumentException("OneDrive.DeleteFile called with null parentFolder.id"); - if (string.IsNullOrEmpty(fileName)) - throw new ArgumentException("OneDrive.DeleteFile called with null fileName"); - - var httpMessage = await DeleteAsync("drive/items/" + parentFolder.id + ":/" + fileName); - return httpMessage.IsSuccessStatusCode; - } - - - } - #endregion -} diff --git a/Andro2UWP/Andro2UWP.Shared/AccountSelection.xaml.cs b/Andro2UWP/Andro2UWP.Shared/AccountSelection.xaml.cs index 5e63c19..1b2eca1 100644 --- a/Andro2UWP/Andro2UWP.Shared/AccountSelection.xaml.cs +++ b/Andro2UWP/Andro2UWP.Shared/AccountSelection.xaml.cs @@ -2,8 +2,8 @@ namespace Andro2UWP { #if __ANDROID__ - using Android.App; - using Android.Content; + using Android.App; + using Android.Content; #endif using Microsoft.Graph; using Microsoft.OneDrive.Sdk; @@ -14,7 +14,7 @@ namespace Andro2UWP using System.Threading.Tasks; using Windows.UI.Xaml; using Windows.UI.Xaml.Controls; - + /// /// An empty page that can be used on its own or navigated to within a Frame. /// @@ -26,7 +26,7 @@ private enum ClientType Consumer, ConsumerUwp } - + // Set these values to your app's ID and return URL. private readonly string oneDriveForBusinessClientId = "Insert your OneDrive for Business client id"; private readonly string oneDriveForBusinessReturnUrl = "http://localhost:8080"; @@ -36,11 +36,11 @@ private enum ClientType private readonly string oneDriveConsumerReturnUrl = "msal560b76b6-f929-4200-b8b0-70892f08f94a://auth";//"https://login.live.com/oauth20_desktop.srf"; private readonly string oneDriveConsumerBaseUrl = "https://api.onedrive.com/v1.0"; - private readonly string[] scopes = new string[] - { + private readonly string[] scopes = new string[] + { "onedrive.readonly", // ok! //"onedrive.readwrite", //RnD "onedrive.appfolder", // ok - "wl.signin", + "wl.signin", "offline_access" }; @@ -54,9 +54,9 @@ public AccountSelectionPage() private async void AccountSelection_Loaded(object sender, RoutedEventArgs e) { - - App app = ((App) Windows.UI.Xaml.Application.Current); - + + App app = ((App)Windows.UI.Xaml.Application.Current); + if (app.uOneDriveClient != null) { @@ -71,7 +71,7 @@ private async void AccountSelection_Loaded(object sender, RoutedEventArgs e) //{ // await adalAuthProvider.SignOutAsync(); //} - + app.uOneDriveClient = null; } @@ -106,8 +106,8 @@ private void OnlineId_Click(object sender, RoutedEventArgs e) private async void InitializeClient(ClientType clientType, RoutedEventArgs e) { - - var app = (App) Windows.UI.Xaml.Application.Current; + + var app = (App)Windows.UI.Xaml.Application.Current; if (app.uOneDriveClient == null) { @@ -132,23 +132,23 @@ private async void InitializeClient(ClientType clientType, RoutedEventArgs e) app.AuthProvider = adalAuthProvider; // ! */ - + } else if (clientType == ClientType.ConsumerUwp) { - /* - var onlineIdAuthProvider = new OnlineIdAuthenticationProvider - ( - this.scopes - ); + /* + var onlineIdAuthProvider = new OnlineIdAuthenticationProvider + ( + this.scopes + ); + + authTask = onlineIdAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); - authTask = onlineIdAuthProvider.RestoreMostRecentFromCacheOrAuthenticateUserAsync(); + app.uOneDriveClient = new OneDriveClient(this.oneDriveConsumerBaseUrl, onlineIdAuthProvider); + + app.AuthProvider = onlineIdAuthProvider; // ! + */ - app.uOneDriveClient = new OneDriveClient(this.oneDriveConsumerBaseUrl, onlineIdAuthProvider); - - app.AuthProvider = onlineIdAuthProvider; // ! - */ - } else { @@ -163,7 +163,7 @@ private async void InitializeClient(ClientType clientType, RoutedEventArgs e) ); #else Android.Content.Context ctxt = Android.App.Application.Context; - + var msaAuthProvider = new MsaAuthenticationProvider ( ctxt, // RnD @@ -186,9 +186,9 @@ private async void InitializeClient(ClientType clientType, RoutedEventArgs e) try { //await authTask; - + //app.NavigationStack.Add(new ItemModel(new Item())); - + this.Frame.Navigate(typeof(MainPage), e); } catch (Exception ex) //catch (ServiceException exception) @@ -205,16 +205,16 @@ private async void InitializeClient(ClientType clientType, RoutedEventArgs e) } //else //{ - // Go to Main page - this.Frame.Navigate(typeof(MainPage), e); + // Go to Main page + this.Frame.Navigate(typeof(MainPage), e); //} - + //temp //this.Frame.Navigate(typeof(MainPage), e); }//InitializeClient - + }//class end }//namespace end diff --git a/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.2021.07.11.zip b/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.2021.07.11.zip new file mode 100644 index 0000000..1728b45 Binary files /dev/null and b/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.2021.07.11.zip differ diff --git a/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.projitems b/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.projitems index 25e5a07..f6faeba 100644 --- a/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.projitems +++ b/Andro2UWP/Andro2UWP.Shared/Andro2UWP.Shared.projitems @@ -28,6 +28,7 @@ MainPage.xaml + Settings.xaml @@ -52,9 +53,14 @@ - + + + Designer + - + + + \ No newline at end of file diff --git a/Andro2UWP/Andro2UWP.Shared/App.xaml b/Andro2UWP/Andro2UWP.Shared/App.xaml index 103d8e8..cf5da64 100644 --- a/Andro2UWP/Andro2UWP.Shared/App.xaml +++ b/Andro2UWP/Andro2UWP.Shared/App.xaml @@ -3,5 +3,4 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:Andro2UWP"> - diff --git a/Andro2UWP/Andro2UWP.Shared/App.xaml.cs b/Andro2UWP/Andro2UWP.Shared/App.xaml.cs index 9a4d752..cb35aa2 100644 --- a/Andro2UWP/Andro2UWP.Shared/App.xaml.cs +++ b/Andro2UWP/Andro2UWP.Shared/App.xaml.cs @@ -2,7 +2,10 @@ // Shared code // 2022 - +//#if __ANDROID__ +//using Android.App; +//using Android.Content; +//#endif using Andro2UWP.Models; using Microsoft.Extensions.Logging; using Microsoft.Graph; @@ -29,7 +32,7 @@ using Windows.UI.Xaml.Navigation; namespace Andro2UWP -{ +{ sealed partial class App : Application { @@ -100,7 +103,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e) // PKAR added wedle https://stackoverflow.com/questions/39262926/uwp-hardware-back-press-work-correctly-in-mobile-but-error-with-pc rootFrame.Navigated += OnNavigatedAddBackButton; - + Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackButtonPressed; //if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) @@ -141,7 +144,7 @@ protected override void OnLaunched(LaunchActivatedEventArgs e) rootFrame.Navigate(typeof(MainPage), e.Arguments); } - + // Ensure the current window is active Windows.UI.Xaml.Window.Current.Activate(); @@ -156,7 +159,7 @@ public void SighOffIfNeeded() if (app.uOneDriveClient != null) { - MsaAuthenticationProvider msaAuthProvider = + MsaAuthenticationProvider msaAuthProvider = app.AuthProvider as MsaAuthenticationProvider; //var adalAuthProvider = app.AuthProvider as AdalAuthenticationProvider; @@ -182,7 +185,7 @@ public async void SighInIfNeeded(ClientType clientType, LaunchActivatedEventArgs { Frame rootFrame = Windows.UI.Xaml.Window.Current.Content as Frame; - var app = (App)Application.Current; + var app = (App)Application.Current; if (app.uOneDriveClient == null) { @@ -217,7 +220,7 @@ public async void SighInIfNeeded(ClientType clientType, LaunchActivatedEventArgs // RnD // = null; - app.uOneDriveClient = + app.uOneDriveClient = new OneDriveClient ( GoneDriveConsumerBaseUrl, //this.GoneDriveConsumerBaseUrl, @@ -225,7 +228,7 @@ public async void SighInIfNeeded(ClientType clientType, LaunchActivatedEventArgs ); app.AuthProvider = msaAuthProvider; // ! - + try { @@ -234,7 +237,7 @@ public async void SighInIfNeeded(ClientType clientType, LaunchActivatedEventArgs //app.NavigationStack.Add(new ItemModel(new Item())); //this.Frame.Navigate(typeof(MainPage), e); - + } catch (Exception ex) //catch (ServiceException exception) { @@ -245,16 +248,15 @@ public async void SighInIfNeeded(ClientType clientType, LaunchActivatedEventArgs Debug.WriteLine("AccountSelection - InitializeClient - exception: " + ex.Message); // TODO : error hadling - - // Redirect to MainPage - rootFrame.Navigate(typeof(MainPage));//, e.Arguments); + + // RnD: Redirect to MainPage from here... + //rootFrame.Navigate(typeof(MainPage));//, e.Arguments); } } - // Redirect to MainPage - // RnD - rootFrame.Navigate(typeof(MainPage));//, e.Arguments); + // RnD: Redirect to MainPage from here... + //rootFrame.Navigate(typeof(MainPage));//, e.Arguments); }//SignInIfNeeded @@ -312,10 +314,10 @@ static void ConfigureFilters(ILoggerFactory factory) #endif */ } - -#endregion -#region "BackButton" + #endregion + + #region "BackButton" // PKAR added wedle https://stackoverflow.com/questions/39262926/uwp-hardware-back-press-work-correctly-in-mobile-but-error-with-pc private void OnNavigatedAddBackButton(object sender, NavigationEventArgs e) { @@ -343,7 +345,7 @@ private void OnBackButtonPressed(object sender, Windows.UI.Core.BackRequestedEve { } } -#endregion + #endregion //public static string _timerString = ""; //public static int _timerCount = 0; @@ -377,7 +379,7 @@ protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs await LoadNews(false); int iNewCnt = App.gToasty.Count - iStanPrzed; - + p.k.DebugOut("iStanPo = " + App.gToasty.Count.ToString()); if (iNewCnt > 0) { @@ -401,11 +403,11 @@ protected override async void OnBackgroundActivated(BackgroundActivatedEventArgs public async static System.Threading.Tasks.Task LoadNews(bool bMsg) { p.k.DebugOut("LoadNews(" + bMsg.ToString()); - - if(! await initODandDict(bMsg) ) - { - return false; // przede wszystkim - odczytanie slownikow na nowo (żeby nie było reset słownika!) - } + + if (!await initODandDict(bMsg)) + { + return false; // przede wszystkim - odczytanie slownikow na nowo (żeby nie było reset słownika!) + } //await WczytajNowe(bMsg); await LoadNew(bMsg); @@ -423,38 +425,57 @@ public static async System.Threading.Tasks.Task EnsureOneDriveOpen(bool bM } #if __ANDROID__ + /* if (App.gOnedrive != null) return true; - await App.AddLogEntry("inicjalizacja gOneDrive",true); - Uno.OneDrive.Connector.Init(Android.App.Application.Context); + await App.AddLogEntry("inicjalizacja gOneDrive", true); + Uno.OneDrive.Connector.Init(Android.App.Application.Context); + + string[] scopes = { "Files.ReadWrite" }; + App.gOnedrive = new Uno.OneDrive.Connector + ( + //"287faaf5-69f4-46e7-977e-1980e19790d0" + //"560b76b6-f929-4200-b8b0-70892f08f94a" + GoneDriveConsumerClientId, + scopes + ); - string[] scopes = { "Files.ReadWrite" }; - App.gOnedrive = new Uno.OneDrive.Connector - ( - //"287faaf5-69f4-46e7-977e-1980e19790d0" - //"560b76b6-f929-4200-b8b0-70892f08f94a" - GoneDriveConsumerClientId, - scopes - ); - //RnD // await App.gOnedrive.DisconnectAsync(); - + if (!await App.gOnedrive.ConnectAsync()) - { - await App.AddLogEntry("FAIL initializing OneDrive",false); - await p.k.DialogBoxResAsync("errOneDriveInit"); - return false; - } + { + await App.AddLogEntry("FAIL initializing OneDrive", false); + await p.k.DialogBoxResAsync("errOneDriveInit"); + return false; + } if (App.gAppFolder is null) - { + { // to jest to samo niezaleznie od on/off samego konektora - await App.AddLogEntry("inicjalizacja gAppFolder",true); + await App.AddLogEntry("inicjalizacja gAppFolder", true); App.gAppFolder = await App.gOnedrive.GetThisAppFolderAsync(); } + */ + + if (p.od.IsOneDriveOpened()) + return true; + + // if (!bMsg) return false; + + try + { + if (!await p.od.OpenOneDrive(true, bMsg)) + return false; + + return true; + } + catch + { + // + } #else if (p.od.IsOneDriveOpened()) return true; @@ -488,7 +509,8 @@ private static async System.Threading.Tasks.Task LoadFilterDictionary() string dictionaryFile = ""; #if __ANDROID__ - dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "toasts.filters.txt"); + //dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "toasts.filters.txt"); + dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/toasts.filters.txt"); #else dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/toasts.filters.txt"); #endif @@ -527,7 +549,7 @@ private static async System.Threading.Tasks.Task LoadFilterDictionary() //App.glFiltry.Add(new App.JedenFiltr("android", "* is using battery", "")); //App.glFiltry.Add(new App.JedenFiltr("com.android.vending", "* new updates", "")); //App.glFiltry.Add(new App.JedenFiltr("com.microsoft.skydrive", "Backing up your photos...", "")); - + }//LoadFilterDictionary end // WczytajSlownikSource @@ -537,7 +559,8 @@ private async static System.Threading.Tasks.Task LoadDictionarySource() string dictionaryFile = ""; #if __ANDROID__ - dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "sender.renames.txt"); + //dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "sender.renames.txt"); + dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/sender.renames.txt"); #else dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/sender.renames.txt"); #endif @@ -550,7 +573,7 @@ private async static System.Threading.Tasks.Task LoadDictionarySource() App.gdSenderRenames.Clear(); var dictEntries = dictionaryFile.Split('\n'); - + foreach (string entry in dictEntries) { if (!string.IsNullOrEmpty(entry)) @@ -564,7 +587,7 @@ private async static System.Threading.Tasks.Task LoadDictionarySource() } } - + await App.AddLogEntry("Read " + App.gdSenderRenames.Count.ToString() + " sender.renames entries", false); }//LoadDictionarySource end @@ -575,7 +598,8 @@ private static async System.Threading.Tasks.Task CheckPkarFile() p.k.DebugOut("CheckPkarFile"); string dictionaryFile = ""; #if __ANDROID__ - dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "pkar.mode.txt"); + //dictionaryFile = await App.gOnedrive.ReadFile(App.gAppFolder, "pkar.mode.txt"); + dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/pkar.mode.txt"); #else dictionaryFile = await p.od.ReadOneDriveTextFile("Apps/Andro2UWP/pkar.mode.txt"); #endif @@ -589,6 +613,7 @@ public static async System.Threading.Tasks.Task initODandDict(bool bMsg) { p.k.DebugOut("initODandDict(" + bMsg.ToString()); + /* //ProgresywnyRing(true); if (bMsg) p.k.ProgRingShow(true); @@ -600,12 +625,13 @@ public static async System.Threading.Tasks.Task initODandDict(bool bMsg) //ProgresywnyRing(false); if (bMsg) - { - p.k.ProgRingShow(false); + { + p.k.ProgRingShow(false); } - + return false; } + */ // Load only when connected to OneDrive await LoadDictionarySource(); // CAUTION: there is no progressring! @@ -632,7 +658,7 @@ private async static System.Threading.Tasks.Task LoadNew(bool bMsg) if (!p.k.GetPlatform("uwp")) { - if(bMsg) await p.k.DialogBoxAsync("How did you press it not to be on UWP?"); + if (bMsg) await p.k.DialogBoxAsync("How did you press it not to be on UWP?"); return; } @@ -823,7 +849,7 @@ protected override void OnActivated(IActivatedEventArgs e) if (rootFrame.Content == null) { - + //MakeDebugToast("OnActivated - OPEN NULL"); // TODO rootFrame.Navigate(typeof(MainPage)); @@ -832,7 +858,7 @@ protected override void OnActivated(IActivatedEventArgs e) Window.Current.Activate(); } -#region "logfile" + #region "logfile" public static async System.Threading.Tasks.Task GetLogFile() { Windows.Storage.StorageFolder oFold = Windows.Storage.ApplicationData.Current.LocalFolder; @@ -848,12 +874,13 @@ public static async System.Threading.Tasks.Task AddLogEntry(string message, bool if (onlyInDebug && !p.k.GetSettingsBool("debugLog")) return; - var oFile = await GetLogFile(); + Windows.Storage.StorageFile oFile = await GetLogFile(); if (oFile is null) return; try { - await Windows.Storage.FileIO.AppendTextAsync(oFile, message + "\n", Windows.Storage.Streams.UnicodeEncoding.Utf8); + await Windows.Storage.FileIO.AppendTextAsync( + oFile, message + "\n", Windows.Storage.Streams.UnicodeEncoding.Utf8); } catch { @@ -863,7 +890,7 @@ public static async System.Threading.Tasks.Task AddLogEntry(string message, bool } -#endregion + #endregion public static List gToasty = new List(); @@ -875,18 +902,21 @@ public static async System.Threading.Tasks.Task AddLogEntry(string message, bool public static List glFiltry = new List(); #if __ANDROID__ - public static Uno.OneDrive.Connector gOnedrive = null; - public static Uno.OneDrive.FileData gAppFolder = null; + //public static Uno.OneDrive.Connector gOnedrive = null; + //public static Uno.OneDrive.FileData gAppFolder = null; static bool bInOneDriveSending = false; + // WriteToast (to OneDrive) public async void ZapiszToast(JedenToast toast) { // uzupelnij dane - mamy tylko czas i glowny tekst toast.sDevice = gsDeviceName; toast.iNumber = ++giCurrentNumber; + p.k.SetSettingsInt("currentFileNum", giCurrentNumber); + await AddLogEntry("numer kolejny: " + giCurrentNumber, true); gToasty.Add(toast); @@ -906,7 +936,7 @@ public async void ZapiszToast(JedenToast toast) // jesli jest siec, to mozemy wyslac do OneDrive wszystkie ktorych jeszcze sie nie wyslalo for (int iLoop = 0; iLoop < gToasty.Count; iLoop++) { - var oItem = gToasty.ElementAt(iLoop); + JedenToast oItem = gToasty.ElementAt(iLoop); if (oItem.bOnOneDrive) continue; // juz wyslany @@ -914,10 +944,27 @@ public async void ZapiszToast(JedenToast toast) oItem.sFileName = gsDeviceName + "." + oItem.iNumber.ToString("00000") + "-" + oItem.dDate.ToString("yyyy.MM.dd_HH.mm") + ".toast.txt"; + await AddLogEntry("filename: " + oItem.sFileName, false); - Uno.OneDrive.FileData oSent = await gOnedrive.SaveFile(gAppFolder, oItem.sFileName, oItem.sMessage); + // old scheme ("android" onedrive, gAppFolder) + //Uno.OneDrive.FileData oSent = await gOnedrive.SaveFile(gAppFolder, oItem.sFileName, oItem.sMessage); + + + // RnD: new scheme (universil shared code of ondrive service) + Windows.Storage.StorageFolder oFold = Windows.Storage.ApplicationData.Current.LocalFolder; + Windows.Storage.StorageFile sFile = await oFold.CreateFileAsync(oItem.sFileName, + Windows.Storage.CreationCollisionOption.OpenIfExists); + + + string oSent = await p.od.SaveFileToOneDrive + ( + sFile, + "Apps/Andro2UWP",// onedrive special folder + oItem.sMessage); + + // RnD: TEST IT!! // jesli sie nie udalo wyslanie, to nie wysylaj nastepnych if (oSent is null) { @@ -932,7 +979,7 @@ public async void ZapiszToast(JedenToast toast) bInOneDriveSending = false; } -#region "handling accessiblity trigger" + #region "handling accessiblity trigger" // // - + + + -