formatting updates

This commit is contained in:
Kyle Spearrin 2017-10-02 22:38:10 -04:00
parent d651606800
commit a43a3db098
13 changed files with 64 additions and 191 deletions

View file

@ -10,110 +10,63 @@ using Plugin.Settings.Abstractions;
using PushNotification.Plugin; using PushNotification.Plugin;
using SimpleInjector; using SimpleInjector;
using System; using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel; using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation; using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml; using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls; 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 Windows.UI.Xaml.Navigation;
using XLabs.Ioc; using XLabs.Ioc;
using XLabs.Ioc.SimpleInjectorContainer; using XLabs.Ioc.SimpleInjectorContainer;
namespace Bit.UWP namespace Bit.UWP
{ {
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application sealed partial class App : Application
{ {
/// <summary>
/// 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().
/// </summary>
public App() public App()
{ {
this.InitializeComponent(); InitializeComponent();
this.Suspending += OnSuspending; Suspending += OnSuspending;
if (!Resolver.IsSet) if(!Resolver.IsSet)
{ {
SetIoc(); SetIoc();
} }
} }
public ISettings Settings { get; set; } public ISettings Settings { get; set; }
/// <summary>
/// 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.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e) protected override void OnLaunched(LaunchActivatedEventArgs e)
{ {
Frame rootFrame = Window.Current.Content as Frame; var rootFrame = Window.Current.Content as Frame;
if(rootFrame == null)
// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{ {
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame(); rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed; rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e); Xamarin.Forms.Forms.Init(e);
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) if(e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{ {
//TODO: Load state from previously suspended application //TODO: Load state from previously suspended application
} }
// Place the frame in the current Window
Window.Current.Content = rootFrame; 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); rootFrame.Navigate(typeof(MainPage), e.Arguments);
} }
// Ensure the current window is active
Window.Current.Activate(); Window.Current.Activate();
} }
} }
/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e) void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{ {
throw new Exception("Failed to load Page " + e.SourcePageType.FullName); throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
} }
/// <summary>
/// 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.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e) private void OnSuspending(object sender, SuspendingEventArgs e)
{ {
var deferral = e.SuspendingOperation.GetDeferral(); var deferral = e.SuspendingOperation.GetDeferral();
@ -121,7 +74,6 @@ namespace Bit.UWP
deferral.Complete(); deferral.Complete();
} }
private void SetIoc() private void SetIoc()
{ {
var container = new Container(); var container = new Container();

View file

@ -2,51 +2,31 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Plugin.Connectivity.Abstractions; using Plugin.Connectivity.Abstractions;
using Plugin.Settings.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 Xamarin.Forms.Platform.UWP;
using XLabs.Ioc; using XLabs.Ioc;
// The Blank Page item template is documented at https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace Bit.UWP namespace Bit.UWP
{ {
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : WindowsPage public sealed partial class MainPage : WindowsPage
{ {
public MainPage() public MainPage()
{ {
this.InitializeComponent(); InitializeComponent();
LoadApplication(new Bit.App.App( LoadApplication(new Bit.App.App(
null, null,
false, false,
Resolver.Resolve<IAuthService>(), Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IConnectivity>(), Resolver.Resolve<IConnectivity>(),
Resolver.Resolve<IUserDialogs>(), Resolver.Resolve<IUserDialogs>(),
Resolver.Resolve<IDatabaseService>(), Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<ISyncService>(), Resolver.Resolve<ISyncService>(),
Resolver.Resolve<ISettings>(), Resolver.Resolve<ISettings>(),
Resolver.Resolve<ILockService>(), Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>(), Resolver.Resolve<IGoogleAnalyticsService>(),
Resolver.Resolve<ILocalizeService>(), Resolver.Resolve<ILocalizeService>(),
Resolver.Resolve<IAppInfoService>(), Resolver.Resolve<IAppInfoService>(),
Resolver.Resolve<IAppSettingsService>(), Resolver.Resolve<IAppSettingsService>(),
Resolver.Resolve<IDeviceActionService>())); Resolver.Resolve<IDeviceActionService>()));
} }
} }
} }

View file

@ -1,36 +1,17 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.ApplicationModel; using Windows.ApplicationModel;
namespace Bit.UWP.Services namespace Bit.UWP.Services
{ {
public class AppInfoService : IAppInfoService public class AppInfoService : IAppInfoService
{ {
public string Build => Package.Current.Id.Version.Build.ToString();
public string Build
{
get
{
Package package = Package.Current;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
return version.Build.ToString();
}
}
public string Version public string Version
{ {
get get
{ {
Package package = Package.Current; var version = Package.Current.Id.Version;
PackageId packageId = package.Id;
PackageVersion version = packageId.Version;
return $"{version.Major}.{version.Minor}.{version.Build}"; return $"{version.Major}.{version.Minor}.{version.Build}";
} }
} }

View file

@ -1,10 +1,7 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime; using System.Runtime.InteropServices.WindowsRuntime;
using System.Text;
using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.ApplicationModel.Core; using Windows.ApplicationModel.Core;
using Windows.ApplicationModel.DataTransfer; using Windows.ApplicationModel.DataTransfer;
@ -26,7 +23,7 @@ namespace Bit.UWP.Services
{ {
Task.Run(async () => Task.Run(async () =>
{ {
foreach (var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync()) foreach(var item in await ApplicationData.Current.LocalCacheFolder.GetItemsAsync())
{ {
await item.DeleteAsync(); await item.DeleteAsync();
} }
@ -35,10 +32,11 @@ namespace Bit.UWP.Services
public void CopyToClipboard(string text) public void CopyToClipboard(string text)
{ {
DataPackage dataPackage = new DataPackage(); var dataPackage = new DataPackage
dataPackage.RequestedOperation = DataPackageOperation.Copy; {
RequestedOperation = DataPackageOperation.Copy
};
dataPackage.SetText(text); dataPackage.SetText(text);
Clipboard.SetContent(dataPackage); Clipboard.SetContent(dataPackage);
} }
@ -72,16 +70,17 @@ namespace Bit.UWP.Services
return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => return CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
{ {
var file = await picker.PickSingleFileAsync(); var file = await picker.PickSingleFileAsync();
if (file != null) if(file != null)
{
await SelectFileResult(file); await SelectFileResult(file);
}
}).AsTask(); }).AsTask();
} }
private async Task SelectFileResult(StorageFile file) private async Task SelectFileResult(StorageFile file)
{ {
var buffer = await FileIO.ReadBufferAsync(file); var buffer = await FileIO.ReadBufferAsync(file);
MessagingCenter.Send(Application.Current, "SelectFileResult",
MessagingCenter.Send(Xamarin.Forms.Application.Current, "SelectFileResult",
new Tuple<byte[], string>(buffer.ToArray(), file.Name)); new Tuple<byte[], string>(buffer.ToArray(), file.Name));
} }
} }

View file

@ -1,9 +1,7 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using Microsoft.Toolkit.Uwp.Helpers; using Microsoft.Toolkit.Uwp.Helpers;
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Windows.Graphics.Display; using Windows.Graphics.Display;
using Windows.Devices.SmartCards; using Windows.Devices.SmartCards;
@ -13,18 +11,20 @@ namespace Bit.UWP.Services
{ {
public class DeviceInfoService : IDeviceInfoService public class DeviceInfoService : IDeviceInfoService
{ {
private const string SmartCardEmulatorType = "Windows.Devices.SmartCards.SmartCardEmulator";
public string Model => SystemInformation.DeviceModel; public string Model => SystemInformation.DeviceModel;
public int Version => SystemInformation.OperatingSystemVersion.Build; public int Version => SystemInformation.OperatingSystemVersion.Build;
public float Scale => (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel; public float Scale => (float)DisplayInformation.GetForCurrentView().RawPixelsPerViewPixel;
public bool NfcEnabled public bool NfcEnabled
{ {
get get
{ {
if (!Windows.Foundation.Metadata.ApiInformation.IsTypePresent("Windows.Devices.SmartCards.SmartCardEmulator")) if(!Windows.Foundation.Metadata.ApiInformation.IsTypePresent(SmartCardEmulatorType))
{
return false; return false;
}
return Task.Run(async () => await SmartCardEmulator.GetDefaultAsync()).Result != null; return Task.Run(async () => await SmartCardEmulator.GetDefaultAsync()).Result != null;
} }
@ -34,8 +34,8 @@ namespace Bit.UWP.Services
{ {
get 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; return cameraList?.Any() ?? false;
} }
} }

View file

@ -1,9 +1,5 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.UWP.Services namespace Bit.UWP.Services
{ {
@ -11,22 +7,18 @@ namespace Bit.UWP.Services
{ {
public void Dispatch(Action completionHandler = null) public void Dispatch(Action completionHandler = null)
{ {
} }
public void SetAppOptOut(bool optOut) public void SetAppOptOut(bool optOut)
{ {
} }
public void TrackAppEvent(string eventName, string label = null) public void TrackAppEvent(string eventName, string label = null)
{ {
} }
public void TrackEvent(string category, string eventName, string label = null) public void TrackEvent(string category, string eventName, string label = null)
{ {
} }
public void TrackException(string message, bool fatal) 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 TrackExtensionEvent(string eventName, string label = null)
{ {
} }
public void TrackPage(string pageName) public void TrackPage(string pageName)

View file

@ -1,9 +1,4 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Bit.App; using Bit.App;
namespace Bit.UWP.Services namespace Bit.UWP.Services

View file

@ -1,15 +1,7 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime; 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.Security.Cryptography.Core;
using Windows.Storage.Streams;
namespace Bit.UWP.Services namespace Bit.UWP.Services
{ {
@ -19,18 +11,13 @@ namespace Bit.UWP.Services
public byte[] DeriveKey(byte[] password, byte[] salt, uint rounds) public byte[] DeriveKey(byte[] password, byte[] salt, uint rounds)
{ {
IBuffer buffSalt = salt.AsBuffer(); var buffSalt = salt.AsBuffer();
IBuffer buffPassword = password.AsBuffer(); var buffPassword = password.AsBuffer();
KeyDerivationAlgorithmProvider provider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha256); var provider = KeyDerivationAlgorithmProvider.OpenAlgorithm(KeyDerivationAlgorithmNames.Pbkdf2Sha256);
KeyDerivationParameters pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, rounds); var pbkdf2Params = KeyDerivationParameters.BuildForPbkdf2(buffSalt, rounds);
CryptographicKey keyOriginal = provider.CreateKey(buffPassword); var keyOriginal = provider.CreateKey(buffPassword);
IBuffer keyDerived = CryptographicEngine.DeriveKeyMaterial(
keyOriginal,
pbkdf2Params,
KeyLength
);
var keyDerived = CryptographicEngine.DeriveKeyMaterial(keyOriginal, pbkdf2Params, KeyLength);
return keyDerived.ToArray(); return keyDerived.ToArray();
} }
} }

View file

@ -1,9 +1,4 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization; using System.Globalization;
using Windows.Globalization; using Windows.Globalization;

View file

@ -1,18 +1,10 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System;
using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Bit.UWP.Services namespace Bit.UWP.Services
{ {
public class LogService : ILogService public class LogService : ILogService
{ {
public void WriteLine(string message) public void WriteLine(string message) => Debug.WriteLine(message);
{
Debug.WriteLine(message);
}
} }
} }

View file

@ -10,7 +10,7 @@ namespace Bit.UWP.Services
{ {
public Func<double, double, SizeRequest> GetVisualElementOnSizeRequest(ExtendedTableView tableView) public Func<double, double, SizeRequest> GetVisualElementOnSizeRequest(ExtendedTableView tableView)
{ {
//todo // TODO
throw new NotImplementedException(); throw new NotImplementedException();
} }
} }

View file

@ -1,9 +1,5 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using System; using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Security.Credentials; using Windows.Security.Credentials;
namespace Bit.UWP.Services namespace Bit.UWP.Services
@ -11,14 +7,13 @@ namespace Bit.UWP.Services
public class SecureStorageService : ISecureStorageService public class SecureStorageService : ISecureStorageService
{ {
private const string ResourceName = "bitwarden"; private const string ResourceName = "bitwarden";
private PasswordVault _vault = new PasswordVault(); private readonly PasswordVault _vault = new PasswordVault();
public bool Contains(string key) public bool Contains(string key)
{ {
try try
{ {
var entry = _vault.Retrieve(ResourceName, key); return _vault.Retrieve(ResourceName, key) != null;
return entry != null;
} }
catch catch
{ {
@ -29,8 +24,10 @@ namespace Bit.UWP.Services
public void Delete(string key) public void Delete(string key)
{ {
var entry = _vault.Retrieve(ResourceName, key); var entry = _vault.Retrieve(ResourceName, key);
if (entry != null) if(entry != null)
{
_vault.Remove(entry); _vault.Remove(entry);
}
} }
public byte[] Retrieve(string key) public byte[] Retrieve(string key)
@ -38,10 +35,14 @@ namespace Bit.UWP.Services
try try
{ {
var entry = _vault.Retrieve(ResourceName, key); var entry = _vault.Retrieve(ResourceName, key);
if (entry != null) if(entry != null)
{
return Convert.FromBase64String(entry.Password); return Convert.FromBase64String(entry.Password);
}
else else
{
return null; return null;
}
} }
catch catch
{ {

View file

@ -1,8 +1,6 @@
using Bit.App.Abstractions; using Bit.App.Abstractions;
using SQLite; using SQLite;
using System;
using System.IO; using System.IO;
using Windows.ApplicationModel;
using Windows.Storage; using Windows.Storage;
namespace Bit.UWP.Services namespace Bit.UWP.Services
@ -12,9 +10,11 @@ namespace Bit.UWP.Services
public SQLiteConnection GetConnection() public SQLiteConnection GetConnection()
{ {
var sqliteFilename = "bitwarden.db3"; 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 the database connection
return conn; return conn;
} }