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 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
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
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()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
if (!Resolver.IsSet)
InitializeComponent();
Suspending += OnSuspending;
if(!Resolver.IsSet)
{
SetIoc();
}
}
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)
{
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();
}
}
/// <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)
{
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)
{
var deferral = e.SuspendingOperation.GetDeferral();
@ -121,7 +74,6 @@ namespace Bit.UWP
deferral.Complete();
}
private void SetIoc()
{
var container = new Container();

View file

@ -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
{
/// <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 MainPage()
{
this.InitializeComponent();
InitializeComponent();
LoadApplication(new Bit.App.App(
null,
false,
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IConnectivity>(),
Resolver.Resolve<IUserDialogs>(),
Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<ISyncService>(),
Resolver.Resolve<ISettings>(),
Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>(),
Resolver.Resolve<ILocalizeService>(),
Resolver.Resolve<IAppInfoService>(),
Resolver.Resolve<IAppSettingsService>(),
Resolver.Resolve<IDeviceActionService>()));
null,
false,
Resolver.Resolve<IAuthService>(),
Resolver.Resolve<IConnectivity>(),
Resolver.Resolve<IUserDialogs>(),
Resolver.Resolve<IDatabaseService>(),
Resolver.Resolve<ISyncService>(),
Resolver.Resolve<ISettings>(),
Resolver.Resolve<ILockService>(),
Resolver.Resolve<IGoogleAnalyticsService>(),
Resolver.Resolve<ILocalizeService>(),
Resolver.Resolve<IAppInfoService>(),
Resolver.Resolve<IAppSettingsService>(),
Resolver.Resolve<IDeviceActionService>()));
}
}
}

View file

@ -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}";
}
}

View file

@ -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<byte[], string>(buffer.ToArray(), file.Name));
}
}

View file

@ -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;
}
}

View file

@ -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)

View file

@ -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

View file

@ -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();
}
}

View file

@ -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;

View file

@ -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);
}
}

View file

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

View file

@ -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
{

View file

@ -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;
}