diff --git a/src/UWP/App.xaml.cs b/src/UWP/App.xaml.cs
index 894c13479..e4d58843c 100644
--- a/src/UWP/App.xaml.cs
+++ b/src/UWP/App.xaml.cs
@@ -10,110 +10,63 @@ using Plugin.Settings.Abstractions;
using PushNotification.Plugin;
using SimpleInjector;
using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using XLabs.Ioc;
using XLabs.Ioc.SimpleInjectorContainer;
namespace Bit.UWP
{
- ///
- /// Provides application-specific behavior to supplement the default Application class.
- ///
sealed partial class App : Application
{
-
- ///
- /// Initializes the singleton application object. This is the first line of authored code
- /// executed, and as such is the logical equivalent of main() or WinMain().
- ///
public App()
{
- this.InitializeComponent();
- this.Suspending += OnSuspending;
- if (!Resolver.IsSet)
+ InitializeComponent();
+ Suspending += OnSuspending;
+ if(!Resolver.IsSet)
{
SetIoc();
}
-
}
-
public ISettings Settings { get; set; }
- ///
- /// Invoked when the application is launched normally by the end user. Other entry points
- /// will be used such as when the application is launched to open a specific file.
- ///
- /// Details about the launch request and process.
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)
+ var rootFrame = Window.Current.Content as Frame;
+ if(rootFrame == null)
{
- // Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();
-
rootFrame.NavigationFailed += OnNavigationFailed;
-
Xamarin.Forms.Forms.Init(e);
- if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
+ if(e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
- // Place the frame in the current Window
Window.Current.Content = rootFrame;
}
- if (e.PrelaunchActivated == false)
+ if(e.PrelaunchActivated == false)
{
- if (rootFrame.Content == null)
+ if(rootFrame.Content == null)
{
- // When the navigation stack isn't restored navigate to the first page,
- // configuring the new page by passing required information as a navigation
- // parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
- // Ensure the current window is active
+
Window.Current.Activate();
}
}
- ///
- /// Invoked when Navigation to a certain page fails
- ///
- /// The Frame which failed navigation
- /// Details about the navigation failure
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}
- ///
- /// Invoked when application execution is being suspended. Application state is saved
- /// without knowing whether the application will be terminated or resumed with the contents
- /// of memory still intact.
- ///
- /// The source of the suspend request.
- /// Details about the suspend request.
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
@@ -121,7 +74,6 @@ namespace Bit.UWP
deferral.Complete();
}
-
private void SetIoc()
{
var container = new Container();
diff --git a/src/UWP/MainPage.xaml.cs b/src/UWP/MainPage.xaml.cs
index c887f3d44..a112ca81d 100644
--- a/src/UWP/MainPage.xaml.cs
+++ b/src/UWP/MainPage.xaml.cs
@@ -2,51 +2,31 @@
using Bit.App.Abstractions;
using Plugin.Connectivity.Abstractions;
using Plugin.Settings.Abstractions;
-using System;
-using System.Collections.Generic;
-using System.IO;
-using System.Linq;
-using System.Runtime.InteropServices.WindowsRuntime;
-using Windows.Foundation;
-using Windows.Foundation.Collections;
-using Windows.UI.Xaml;
-using Windows.UI.Xaml.Controls;
-using Windows.UI.Xaml.Controls.Primitives;
-using Windows.UI.Xaml.Data;
-using Windows.UI.Xaml.Input;
-using Windows.UI.Xaml.Media;
-using Windows.UI.Xaml.Navigation;
using Xamarin.Forms.Platform.UWP;
using XLabs.Ioc;
-// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
-
namespace Bit.UWP
{
- ///
- /// An empty page that can be used on its own or navigated to within a Frame.
- ///
public sealed partial class MainPage : WindowsPage
{
public MainPage()
{
- this.InitializeComponent();
+ InitializeComponent();
LoadApplication(new Bit.App.App(
- null,
- false,
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve(),
- Resolver.Resolve()));
-
+ null,
+ false,
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve(),
+ Resolver.Resolve()));
}
}
}
diff --git a/src/UWP/Services/AppInfoService.cs b/src/UWP/Services/AppInfoService.cs
index c7c53a58d..c50068b55 100644
--- a/src/UWP/Services/AppInfoService.cs
+++ b/src/UWP/Services/AppInfoService.cs
@@ -1,36 +1,17 @@
using Bit.App.Abstractions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Windows.ApplicationModel;
namespace Bit.UWP.Services
{
public class AppInfoService : IAppInfoService
{
-
- public string Build
- {
- get
- {
- Package package = Package.Current;
- PackageId packageId = package.Id;
- PackageVersion version = packageId.Version;
-
- return version.Build.ToString();
- }
- }
+ public string Build => Package.Current.Id.Version.Build.ToString();
public string Version
{
get
{
- Package package = Package.Current;
- PackageId packageId = package.Id;
- PackageVersion version = packageId.Version;
-
+ var version = Package.Current.Id.Version;
return $"{version.Major}.{version.Minor}.{version.Build}";
}
}
diff --git a/src/UWP/Services/DeviceActionService.cs b/src/UWP/Services/DeviceActionService.cs
index dce8c3ece..16aa2a52f 100644
--- a/src/UWP/Services/DeviceActionService.cs
+++ b/src/UWP/Services/DeviceActionService.cs
@@ -1,10 +1,7 @@
using Bit.App.Abstractions;
using System;
-using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
-using System.Text;
-using System.Threading;
using System.Threading.Tasks;
using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer;
@@ -26,7 +23,7 @@ namespace Bit.UWP.Services
{
Task.Run(async () =>
{
- foreach (var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync())
+ foreach(var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync())
{
await item.DeleteAsync();
}
@@ -35,10 +32,11 @@ namespace Bit.UWP.Services
public void CopyToClipboard(string text)
{
- DataPackage dataPackage = new DataPackage();
- dataPackage.RequestedOperation = DataPackageOperation.Copy;
+ var dataPackage = new DataPackage
+ {
+ RequestedOperation = DataPackageOperation.Copy
+ };
dataPackage.SetText(text);
-
Clipboard.SetContent(dataPackage);
}
@@ -72,16 +70,17 @@ namespace Bit.UWP.Services
return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{
var file = await picker.PickSingleFileAsync();
- if (file != null)
+ if(file != null)
+ {
await SelectFileResult(file);
+ }
}).AsTask();
}
private async Task SelectFileResult(StorageFile file)
{
var buffer = await FileIO.ReadBufferAsync(file);
-
- MessagingCenter.Send(Xamarin.Forms.Application.Current, "SelectFileResult",
+ MessagingCenter.Send(Application.Current, "SelectFileResult",
new Tuple(buffer.ToArray(), file.Name));
}
}
diff --git a/src/UWP/Services/DeviceInfoService.cs b/src/UWP/Services/DeviceInfoService.cs
index 05418facf..cd9835191 100644
--- a/src/UWP/Services/DeviceInfoService.cs
+++ b/src/UWP/Services/DeviceInfoService.cs
@@ -1,9 +1,7 @@
using Bit.App.Abstractions;
using Microsoft.Toolkit.Uwp.Helpers;
using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Text;
using System.Threading.Tasks;
using Windows.Graphics.Display;
using Windows.Devices.SmartCards;
@@ -13,18 +11,20 @@ namespace Bit.UWP.Services
{
public class DeviceInfoService : IDeviceInfoService
{
+ private const string SmartCardEmulatorType = "Windows.Devices.SmartCards.SmartCardEmulator";
+
public string Model => SystemInformation.DeviceModel;
-
public int Version => SystemInformation.OperatingSystemVersion.Build;
-
public float Scale => (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
public bool NfcEnabled
{
get
{
- if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardEmulator"))
+ if(!Windows.Foundation.Metadata.ApiInformation.IsTypePresent(SmartCardEmulatorType))
+ {
return false;
+ }
return Task.Run(async () => await SmartCardEmulator.GetDefaultAsync()).Result != null;
}
@@ -34,8 +34,8 @@ namespace Bit.UWP.Services
{
get
{
- var cameraList = Task.Run(async () => await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).Result;
-
+ var cameraList = Task.Run(async () =>
+ await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture)).Result;
return cameraList?.Any() ?? false;
}
}
diff --git a/src/UWP/Services/GoogleAnalyticsService.cs b/src/UWP/Services/GoogleAnalyticsService.cs
index 0dcf991c7..550e5f729 100644
--- a/src/UWP/Services/GoogleAnalyticsService.cs
+++ b/src/UWP/Services/GoogleAnalyticsService.cs
@@ -1,9 +1,5 @@
using Bit.App.Abstractions;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Bit.UWP.Services
{
@@ -11,22 +7,18 @@ namespace Bit.UWP.Services
{
public void Dispatch(Action completionHandler = null)
{
-
}
public void SetAppOptOut(bool optOut)
{
-
}
public void TrackAppEvent(string eventName, string label = null)
{
-
}
public void TrackEvent(string category, string eventName, string label = null)
{
-
}
public void TrackException(string message, bool fatal)
@@ -35,7 +27,6 @@ namespace Bit.UWP.Services
public void TrackExtensionEvent(string eventName, string label = null)
{
-
}
public void TrackPage(string pageName)
diff --git a/src/UWP/Services/HttpService.cs b/src/UWP/Services/HttpService.cs
index 5b70569b5..9f4613123 100644
--- a/src/UWP/Services/HttpService.cs
+++ b/src/UWP/Services/HttpService.cs
@@ -1,9 +1,4 @@
using Bit.App.Abstractions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Bit.App;
namespace Bit.UWP.Services
diff --git a/src/UWP/Services/KeyDerivationService.cs b/src/UWP/Services/KeyDerivationService.cs
index 98b7a6b96..49b660279 100644
--- a/src/UWP/Services/KeyDerivationService.cs
+++ b/src/UWP/Services/KeyDerivationService.cs
@@ -1,15 +1,7 @@
using Bit.App.Abstractions;
-using System;
-using System.Collections.Generic;
using System.Linq;
-using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
-using System.Security.Cryptography;
-using System.Text;
-using System.Threading.Tasks;
-using Windows.Security.Cryptography;
using Windows.Security.Cryptography.Core;
-using Windows.Storage.Streams;
namespace Bit.UWP.Services
{
@@ -19,18 +11,13 @@ namespace Bit.UWP.Services
public byte[] DeriveKey(byte[] password, byte[] salt, uint rounds)
{
- IBuffer buffSalt = salt.AsBuffer();
- IBuffer buffPassword = password.AsBuffer();
- KeyDerivationAlgorithmProvider provider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha256);
- KeyDerivationParameters pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, rounds);
- CryptographicKey keyOriginal = provider.CreateKey(buffPassword);
-
- IBuffer keyDerived = CryptographicEngine.DeriveKeyMaterial(
- keyOriginal,
- pbkdf2Params,
- KeyLength
- );
+ var buffSalt = salt.AsBuffer();
+ var buffPassword = password.AsBuffer();
+ var provider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha256);
+ var pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, rounds);
+ var keyOriginal = provider.CreateKey(buffPassword);
+ var keyDerived = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Params, KeyLength);
return keyDerived.ToArray();
}
}
diff --git a/src/UWP/Services/LocalizeService.cs b/src/UWP/Services/LocalizeService.cs
index 98c86066d..00d552553 100644
--- a/src/UWP/Services/LocalizeService.cs
+++ b/src/UWP/Services/LocalizeService.cs
@@ -1,9 +1,4 @@
using Bit.App.Abstractions;
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using System.Globalization;
using Windows.Globalization;
diff --git a/src/UWP/Services/LogService.cs b/src/UWP/Services/LogService.cs
index d4e59906b..bdfe90263 100644
--- a/src/UWP/Services/LogService.cs
+++ b/src/UWP/Services/LogService.cs
@@ -1,18 +1,10 @@
using Bit.App.Abstractions;
-using System;
-using System.Collections.Generic;
using System.Diagnostics;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
namespace Bit.UWP.Services
{
public class LogService : ILogService
{
- public void WriteLine(string message)
- {
- Debug.WriteLine(message);
- }
+ public void WriteLine(string message) => Debug.WriteLine(message);
}
}
diff --git a/src/UWP/Services/ReflectionService.cs b/src/UWP/Services/ReflectionService.cs
index 896daf9be..d1d47f83c 100644
--- a/src/UWP/Services/ReflectionService.cs
+++ b/src/UWP/Services/ReflectionService.cs
@@ -10,7 +10,7 @@ namespace Bit.UWP.Services
{
public Func GetVisualElementOnSizeRequest(ExtendedTableView tableView)
{
- //todo
+ // TODO
throw new NotImplementedException();
}
}
diff --git a/src/UWP/Services/SecureStorageService.cs b/src/UWP/Services/SecureStorageService.cs
index 8f432a2fd..2b0871f91 100644
--- a/src/UWP/Services/SecureStorageService.cs
+++ b/src/UWP/Services/SecureStorageService.cs
@@ -1,9 +1,5 @@
using Bit.App.Abstractions;
using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
using Windows.Security.Credentials;
namespace Bit.UWP.Services
@@ -11,14 +7,13 @@ namespace Bit.UWP.Services
public class SecureStorageService : ISecureStorageService
{
private const string ResourceName = "bitwarden";
- private PasswordVault _vault = new PasswordVault();
+ private readonly PasswordVault _vault = new PasswordVault();
public bool Contains(string key)
{
try
{
- var entry = _vault.Retrieve(ResourceName, key);
- return entry != null;
+ return _vault.Retrieve(ResourceName, key) != null;
}
catch
{
@@ -29,8 +24,10 @@ namespace Bit.UWP.Services
public void Delete(string key)
{
var entry = _vault.Retrieve(ResourceName, key);
- if (entry != null)
+ if(entry != null)
+ {
_vault.Remove(entry);
+ }
}
public byte[] Retrieve(string key)
@@ -38,10 +35,14 @@ namespace Bit.UWP.Services
try
{
var entry = _vault.Retrieve(ResourceName, key);
- if (entry != null)
+ if(entry != null)
+ {
return Convert.FromBase64String(entry.Password);
+ }
else
+ {
return null;
+ }
}
catch
{
diff --git a/src/UWP/Services/SqlService.cs b/src/UWP/Services/SqlService.cs
index a9ba7c59d..e672379ef 100644
--- a/src/UWP/Services/SqlService.cs
+++ b/src/UWP/Services/SqlService.cs
@@ -1,8 +1,6 @@
using Bit.App.Abstractions;
using SQLite;
-using System;
using System.IO;
-using Windows.ApplicationModel;
using Windows.Storage;
namespace Bit.UWP.Services
@@ -12,9 +10,11 @@ namespace Bit.UWP.Services
public SQLiteConnection GetConnection()
{
var sqliteFilename = "bitwarden.db3";
+ var path = Path.Combine(ApplicationData.Current.LocalFolder.Path, sqliteFilename);
+ var conn = new SQLiteConnection(path,
+ SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create |
+ SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.SharedCache);
- string path = Path.Combine(ApplicationData.Current.LocalFolder.Path, sqliteFilename);
- var conn = new SQLite.SQLiteConnection(path, SQLiteOpenFlags.ReadWrite | SQLiteOpenFlags.Create | SQLiteOpenFlags.FullMutex | SQLiteOpenFlags.SharedCache);
// Return the database connection
return conn;
}