public static async Task <PairingResult> PairAsync() { if (Current.Pairing.IsPaired) { DeviceManager.UpdateLastSavedDeviceInfo(Current.Id, Current.Name); return(PairingResult.Success); } if (!Current.Pairing.CanPair) { return(new PairingResult(ResourcesHelper.GetLocalizedString("DeviceServiceCannotPairError"))); } var pairingResult = await Current.Pairing.PairAsync(); if (pairingResult.Status == DevicePairingResultStatus.Paired || pairingResult.Status == DevicePairingResultStatus.AlreadyPaired) { DeviceManager.UpdateLastSavedDeviceInfo(Current.Id, Current.Name); return(PairingResult.Success); } if (pairingResult.Status == DevicePairingResultStatus.Failed) { return(PairingResult.PairingRequired); } return(new PairingResult(ResourcesHelper.GetLocalizedString("DeviceServicePairingOperationDeniedOrFailed"))); }
private async void LoadScreenshotPreview(ScreenshotAcquiredMessage message) { await DispatcherHelper.RunAsync(async() => { var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync(); var file = await screenshotsFolder.GetFileAsync(message.FileName); if (file == null) { await this.DialogService.ShowError( string.Format(ResourcesHelper.GetLocalizedString("SharedFileNotFoundMessageFormat"), message.FileName), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); return; } this.ScreenshotName = message.FileName; this.ScreenshotPreview = new BitmapImage(); using (var ras = await file.OpenReadAsync()) { await this.ScreenshotPreview.SetSourceAsync(ras); } this.IsBusy = false; this.ScreenshotSuccessfullyExported = false; this.UpdateScreenshotHistoryFilesCount(); }); }
/// <summary> /// Updates the workflow status. /// </summary> /// <param name="item">The item.</param> private void UpdateWorkflowStatus(SPListItem item) { try { string workflowInstanceFieldName = ResourcesHelper.GetLocalizedString("workflow_approval_instancename", item.Web); string statusInProgress = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_inprogress", item.Web); string statusCancelled = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_cancelled", item.Web); if (item.Fields.ContainsField(workflowInstanceFieldName)) { if (item[workflowInstanceFieldName] != null) { string currentStatus = item[workflowInstanceFieldName].ToString().ToLower(); if (currentStatus.Contains("in progress") || currentStatus.Contains(statusInProgress)) { string toReplace = currentStatus.Contains("in progress") ? "in progress" : statusInProgress; currentStatus = currentStatus.Replace(toReplace, statusCancelled); this.EventFiringEnabled = false; item[workflowInstanceFieldName] = currentStatus; item.SystemUpdate(); this.EventFiringEnabled = true; } } } } catch { } }
public async Task <ApplicationPreference[]> ImportDataAsync() { var file = await FilesHelper.PickFileAsync(".json"); if (file == null) { return(new ApplicationPreference[0]); } var json = await FileIO.ReadTextAsync(file); if (string.IsNullOrWhiteSpace(json)) { //EMPTY FILE throw new ArgumentException(ResourcesHelper.GetLocalizedString("ApplicationsServiceImportDataEmptyFileError")); } var applicationPreferences = JsonConvert.DeserializeObject <ApplicationPreference[]>(json); if (applicationPreferences == null) { //INVALID FORMAT throw new ArgumentException(ResourcesHelper.GetLocalizedString("ApplicationsServiceImportDataInvalidFileError")); } return(applicationPreferences); }
private async void Upload() { if (this.SelectedFile == null) { return; } var successfulUpload = false; this.IsBusy = true; var scpCredentialsDialog = new ScpCredentialsDialog(); var result = await scpCredentialsDialog.ShowAsync(); if (result != ContentDialogResult.Primary) { this.IsBusy = false; return; } this.IsUploading = true; try { using (var scpClient = SecureConnectionsFactory.CreateScpClient( scpCredentialsDialog.ViewModel.HostIP, scpCredentialsDialog.ViewModel.Username, scpCredentialsDialog.ViewModel.Password)) { scpClient.ErrorOccurred += OnClientErrorOccured; var bytes = await ImageHelper.EncodeToSquareJpegImageAsync(this.SelectedFile, DefaultImageSize); using (var memoryStream = new MemoryStream()) { memoryStream.Write(bytes, 0, bytes.Length); memoryStream.Seek(0, SeekOrigin.Begin); scpClient.Upload(memoryStream, "/usr/share/asteroid-launcher/wallpapers/WinSteroid_" + this.SelectedFile.Name); } scpClient.ErrorOccurred -= OnClientErrorOccured; } successfulUpload = true; } catch (Exception exception) { await this.DialogService.ShowError(exception, ResourcesHelper.GetLocalizedString("SharedErrorTitle")); } this.IsUploading = false; if (successfulUpload) { ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsWallpapersWallpaperInstalledMessage")); } this.IsBusy = false; }
/// <summary> /// Gets the workflow status string. /// </summary> /// <param name="itemInfo">The item info.</param> /// <param name="web">The web.</param> /// <returns>status string</returns> private string GetWorkflowStatusString(WorkflowItemInfo itemInfo, SPWeb web) { string output = string.Empty; switch (itemInfo.Status.ToLower()) { case "in progress": output = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_inprogress", web); break; case "cancelled": output = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_cancelled", web); break; case "completed": output = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_completed", web); break; } if (string.IsNullOrEmpty(output)) { output = ResourcesHelper.GetLocalizedString("workflow_approvaltaskstatus_completed", web); } return(output); }
private async void ManageExportIconPreferencesMessageResult(bool exportFile) { if (exportFile) { var result = await this.ApplicationsService.ExportDataAsync(); if (!result) { await this.DialogService.ShowMessage( message : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationExportDataFailedOrCanceledMessage"), title : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationExportDataTitle"), buttonConfirmText : ResourcesHelper.GetLocalizedString("SharedYesMessage"), buttonCancelText : ResourcesHelper.GetLocalizedString("SharedNoMessage"), afterHideCallback : ManageExportIconPreferencesMessageResult); return; } } ViewModelLocator.Home.Reset(); ViewModelLocator.HomeWelcome.Reset(); await DeviceManager.DisconnectAsync(removeLastDeviceInfo : true); App.Reset(); }
private async void LoadFile() { this.IsBusy = true; var file = await FilesHelper.PickFileAsync(".jpeg", ".jpg"); if (file == null) { this.IsBusy = false; return; } ImageProperties imageProperties = null; try { imageProperties = await file.Properties.GetImagePropertiesAsync(); } catch (Exception exception) { //Corrupted image? Or file isn't an image after all... var message = App.InDebugMode ? exception.ToString() : ResourcesHelper.GetLocalizedString("SettingsWallpapersInvalidImageMessage"); await this.DialogService.ShowError(message, ResourcesHelper.GetLocalizedString("SharedErrorTitle")); } if (imageProperties == null) { return; } if (imageProperties.Width != imageProperties.Height) { await this.DialogService.ShowError( ResourcesHelper.GetLocalizedString("SettingsWallpapersUnsupportedImageErrorMessage"), ResourcesHelper.GetLocalizedString("SettingsWallpapersUnsupportedImageTitle")); this.IsBusy = false; return; //var cropImageTaskAllowed = await this.DialogService.ShowConfirmMessage( // ResourcesHelper.GetLocalizedString("SettingsWallpapersUnsupportedImageMessage"), // ResourcesHelper.GetLocalizedString("SettingsWallpapersUnsupportedImageTitle")); //if (!cropImageTaskAllowed) //{ // this.IsBusy = false; // return; //} //file = await ImageHelper.CropImageFileAsync(file, cropWidthPixels: DefaultImageSize, cropHeightPixels: DefaultImageSize); } this.SelectedFile = file; this.SelectedFileName = file?.Name; this.IsBusy = false; this.MessengerInstance.Send(file, nameof(ViewModelLocator.TransfersWallpapers)); }
private async void Export() { var result = await this.ApplicationsService.ExportDataAsync(); if (result) { ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsApplicationsDataExportedMessage")); } }
public static Task <bool> ShowConfirmMessage(this IDialogService dialogService, string message, string title) { return(dialogService.ShowMessage( message, title, buttonConfirmText: ResourcesHelper.GetLocalizedString("SharedYesMessage"), buttonCancelText: ResourcesHelper.GetLocalizedString("SharedNoMessage"), afterHideCallback: b => { })); }
private async void ResetApplication() { await this.DialogService.ShowMessage( message : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationMessage"), title : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationTitle"), buttonConfirmText : ResourcesHelper.GetLocalizedString("SharedYesMessage"), buttonCancelText : ResourcesHelper.GetLocalizedString("SharedNoMessage"), afterHideCallback : ManageResetMessageResult); }
public override Task <bool> CanGoBack() { if (!this.CheckUnsavedChanges()) { return(Task.FromResult(true)); } return(this.DialogService.ShowConfirmMessage( message: ResourcesHelper.GetLocalizedString("SettingsApplicationUnsavedChangesMessage"), title: ResourcesHelper.GetLocalizedString("SettingsApplicationUnsavedChangesTitle"))); }
private async void ApplyUsbMode() { var success = this.SshClient.SetUsbMode(this.SelectedUsbMode.Key); if (!success) { await this.DialogService.ShowError( ResourcesHelper.GetLocalizedString("SettingsToolsApplyUsbModeFailedError"), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); } }
public override void Initialize() { this.TutorialItems = new List <TutorialItem> { new TutorialItem { Title = ResourcesHelper.GetLocalizedString("TutorialsMainUsbItemLabel"), PageKey = nameof(ViewModelLocator.TutorialsUsb), Glyph = "" } }; }
private async void LoadBenchmarkResults(ScreenshotBenchmarkMessage message) { await DispatcherHelper.RunAsync(() => { this.IsBusy = false; this.TestGlyph = message.ServiceReady ? "" : ""; this.TestPassed = message.ServiceReady; this.TestBrush = new SolidColorBrush(message.ServiceReady ? Colors.Green : Colors.Red); this.ErrorMessage = message.ServiceReady ? string.Empty : string.Format(ResourcesHelper.GetLocalizedString("ScreenshotServiceMaxDtuSizeErrorMessageFormat"), Asteroid.CurrentMinimalBtsyncdPacketSize); }); }
private async void StartBenchmark() { var screenshotServiceReady = await DeviceManager.RegisterToScreenshotContentServiceBenchmark(); if (!screenshotServiceReady) { this.ErrorMessage = ResourcesHelper.GetLocalizedString("ScreenshotServiceInitializationErrorMessage"); return; } this.IsBusy = true; await DeviceManager.TestScreenshotContentServiceAsync(); }
private async void Pair(string deviceId) { this.IsBusy = true; this.BusyMessage = ResourcesHelper.GetLocalizedString("HomeWelcomePairingMessage"); this.ConnectionFailed = false; var errorMessage = await DeviceManager.ConnectAsync(deviceId, isBackgroundActivity : false); if (!string.IsNullOrWhiteSpace(errorMessage)) { this.IsBusy = false; this.BusyMessage = string.Empty; this.ConnectionFailed = true; await this.DialogService.ShowMessage(errorMessage, ResourcesHelper.GetLocalizedString("SharedErrorTitle")); return; } var pairingResult = await DeviceManager.PairAsync(); this.IsBusy = false; this.BusyMessage = string.Empty; if (!pairingResult.IsSuccess) { this.ConnectionFailed = true; if (pairingResult.NeedSystemPairing) { var openSettings = await this.DialogService.ShowConfirmMessage( ResourcesHelper.GetLocalizedString("DeviceServiceSystemPairingRequiredMessage"), ResourcesHelper.GetLocalizedString("DeviceServiceSystemPairingRequiredTitle")); if (openSettings) { await Launcher.LaunchUriAsync(new Uri("ms-settings:bluetooth")); return; } } await this.DialogService.ShowMessage( ResourcesHelper.GetLocalizedString("HomeWelcomePairingOperationFailedError"), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); return; } this.NavigationService.NavigateTo(nameof(ViewModelLocator.Home)); }
private async void ManageResetMessageResult(bool confirmed) { if (!confirmed) { return; } await this.DialogService.ShowMessage( message : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationKeepIconPreferencesMessage"), title : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationKeepIconPreferencesTitle"), buttonConfirmText : ResourcesHelper.GetLocalizedString("SharedYesMessage"), buttonCancelText : ResourcesHelper.GetLocalizedString("SharedNoMessage"), afterHideCallback : ManageKeepPreferencesMessageResult); }
private async void SyncDate() { var dateSynced = await DeviceManager.SetTimeAsync(DateTime.Now); this.TimeSetSuccessfully = dateSynced; if (dateSynced) { return; } await this.DialogService.ShowError( ResourcesHelper.GetLocalizedString("SettingsMainSetTimeErrorMessage"), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); }
private static async void OnScreenshotContentCharacteristicValueChanged(GattCharacteristic sender, GattValueChangedEventArgs args) { var bytes = new byte[args.CharacteristicValue.Length]; DataReader.FromBuffer(args.CharacteristicValue).ReadBytes(bytes); if (!TotalSize.HasValue) { var size = BitConverter.ToInt32(bytes, 0); TotalData = new byte[size]; TotalSize = size; Progress = 0; return; } if (Progress.Value + bytes.Length <= TotalData.Length) { Array.Copy(bytes, 0, TotalData, Progress.Value, bytes.Length); } Progress += bytes.Length; if (Progress.Value < TotalSize.Value) { var percentage = (int)Math.Ceiling((Progress.Value * 100d) / TotalSize.Value); Messenger.Default.Send(new Messages.ScreenshotProgressMessage(percentage)); return; } var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync(); var fileName = $"{Package.Current.DisplayName}_Screenshot_{DateTime.Now.ToString("yyyyMMdd")}_{DateTime.Now.ToString("HHmmss")}.jpg"; var screenshotFile = await screenshotsFolder.CreateFileAsync(fileName, CreationCollisionOption.ReplaceExisting); await FileIO.WriteBytesAsync(screenshotFile, TotalData); ToastsHelper.Show(string.Format(ResourcesHelper.GetLocalizedString("ScreenshotAcquiredMessageFormat"), fileName)); sender.ValueChanged -= OnScreenshotContentCharacteristicValueChanged; TotalSize = null; TotalData = null; Progress = null; Messenger.Default.Send(new Messages.ScreenshotAcquiredMessage(fileName)); }
private async void TakeScreenshot() { var screenshotServiceReady = await DeviceManager.RegisterToScreenshotContentService(); if (!screenshotServiceReady) { await this.DialogService.ShowError( ResourcesHelper.GetLocalizedString("ScreenshotServiceInitializationErrorMessage"), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); return; } this.IsBusy = true; await DeviceManager.TakeScreenshotAsync(); }
private async void ManageKeepPreferencesMessageResult(bool keepIconsPreferences) { this.Reset(); if (!keepIconsPreferences) { await this.ApplicationsService.DeleteUserIcons(); App.Reset(); } await this.DialogService.ShowMessage( message : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationExportDataMessage"), title : ResourcesHelper.GetLocalizedString("SettingsMainResetApplicationExportDataTitle"), buttonConfirmText : ResourcesHelper.GetLocalizedString("SharedYesMessage"), buttonCancelText : ResourcesHelper.GetLocalizedString("SharedNoMessage"), afterHideCallback : ManageExportIconPreferencesMessageResult); }
public static async Task <string> ConnectAsync(string deviceId, bool isBackgroundActivity) { try { var bluetoothDevice = await BluetoothLEDevice.FromIdAsync(deviceId); if (bluetoothDevice == null) { return(isBackgroundActivity ? "DeviceServiceDisappearedDeviceError" : ResourcesHelper.GetLocalizedString("DeviceServiceDisappearedDeviceError")); } var timeServicesResult = await bluetoothDevice.GetGattServicesForUuidAsync(Asteroid.TimeServiceUuid); if (timeServicesResult.Status != GattCommunicationStatus.Success || (timeServicesResult.Status == GattCommunicationStatus.Success && timeServicesResult.Services.Count < 1)) { return(isBackgroundActivity ? "DeviceServiceNoAsteroidDeviceError" : ResourcesHelper.GetLocalizedString("DeviceServiceNoAsteroidDeviceError")); } BluetoothDevice = bluetoothDevice; BluetoothDevice.ConnectionStatusChanged += OnBluetoothDeviceConnectionStatusChanged; Current = bluetoothDevice.DeviceInformation; } catch (Exception exception) { Microsoft.HockeyApp.HockeyClient.Current.TrackException(exception); return(isBackgroundActivity ? "DeviceServiceGenericConnectionError" : ResourcesHelper.GetLocalizedString("DeviceServiceGenericConnectionError")); } return(BluetoothDevice != null && Current != null ? string.Empty : isBackgroundActivity ? "DeviceServiceConnectionFailedError" : ResourcesHelper.GetLocalizedString("DeviceServiceConnectionFailedError")); }
public override void InitializeMenuOptions() { if (!this.MenuOptions.IsNullOrEmpty()) { return; } this.MenuOptions.Add(new MenuOptionViewModel { Glyph = "", Label = ResourcesHelper.GetLocalizedString("SettingsMainHomeItemLabel"), Command = HomeCommand }); this.MenuOptions.Add(new MenuOptionViewModel { Glyph = "", Label = ResourcesHelper.GetLocalizedString("SettingsMainAboutItemLabel"), Command = AboutCommand }); this.MenuOptions.Add(new MenuOptionViewModel { Glyph = "", Label = ResourcesHelper.GetLocalizedString("SettingsMainApplicationsItemLabel"), Command = ApplicationsCommand }); this.MenuOptions.Add(new MenuOptionViewModel { Glyph = "", Label = ResourcesHelper.GetLocalizedString("SettingsMainToolsItemLabel"), Command = ToolsCommand }); }
private async void DeleteScreenshotsHistory() { var confirmed = await this.DialogService.ShowConfirmMessage( ResourcesHelper.GetLocalizedString("HomeScreenshotsDeleteScreenshotsHistoryMessage"), ResourcesHelper.GetLocalizedString("HomeScreenshotsDeleteScreenshotsHistoryTitle")); if (!confirmed) { return; } var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync(); if (screenshotsFolder != null) { await screenshotsFolder.DeleteAsync(StorageDeleteOption.PermanentDelete); } this.UpdateScreenshotHistoryFilesCount(); }
private async void Import() { try { var importedIconPreferences = await this.ApplicationsService.ImportDataAsync(); if (importedIconPreferences.IsNullOrEmpty()) { return; } var overWriteExistingApplicationPreferences = false; if (importedIconPreferences.Any(ap => this.IconPreferences.Any(i => i.Id == ap.AppId))) { overWriteExistingApplicationPreferences = await this.DialogService.ShowConfirmMessage( ResourcesHelper.GetLocalizedString("SettingsApplicationsImportFoundConflictMessage"), ResourcesHelper.GetLocalizedString("SettingsApplicationsImportFoundConflictTitle")); } foreach (var importedIconPreference in importedIconPreferences) { var iconPreferenceExists = this.IconPreferences.Any(i => i.Id == importedIconPreference.AppId); if (iconPreferenceExists && !overWriteExistingApplicationPreferences) { continue; } this.ApplicationsService.UpsertUserIcon(importedIconPreference); } ToastsHelper.Show(ResourcesHelper.GetLocalizedString("SettingsApplicationsDataImportedMessage")); this.RefreshIconsPreferences(); } catch (Exception exception) { Microsoft.HockeyApp.HockeyClient.Current.TrackException(exception); await this.DialogService.ShowError(exception.Message, ResourcesHelper.GetLocalizedString("SharedErrorTitle")); } }
public override async void Initialize() { this.IsBusy = true; this.BusyMessage = ResourcesHelper.GetLocalizedString("HomeMainInitializingMessage"); this.DeviceName = DeviceManager.DeviceName; var newPercentage = await DeviceManager.GetBatteryPercentageAsync(); var oldPercentage = this.BatteryPercentage; this.BatteryPercentage = newPercentage; this.BatteryLevel = BatteryHelper.Parse(newPercentage); App.RemoveWelcomePageFromBackStack(); this.IsBusy = false; this.BusyMessage = string.Empty; this.MessengerInstance.Register <DeviceBatteryMessage>(this, OnDeviceBatteryPercentageChanged); }
private async void ExportToPictureLibrary() { var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync(); var file = await screenshotsFolder.GetFileAsync(this.ScreenshotName); if (file == null) { await this.DialogService.ShowError( string.Format(ResourcesHelper.GetLocalizedString("SharedFileNotFoundMessageFormat"), this.ScreenshotName), ResourcesHelper.GetLocalizedString("SharedErrorTitle")); return; } var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync(Package.Current.DisplayName, CreationCollisionOption.OpenIfExists); await file.CopyOrReplaceAsync(folder); this.ScreenshotSuccessfullyExported = true; }
public async void Refresh() { this.IsBusy = true; var scpCredentialsDialog = new ScpCredentialsDialog(); var result = await scpCredentialsDialog.ShowAsync(); if (result != ContentDialogResult.Primary) { this.IsBusy = false; this.NavigationService.GoBack(); return; } try { this.SshClient = SecureConnectionsFactory.CreateSshClient( scpCredentialsDialog.ViewModel.HostIP, scpCredentialsDialog.ViewModel.Username, scpCredentialsDialog.ViewModel.Password); } catch (Exception exception) { await this.DialogService.ShowError(exception, ResourcesHelper.GetLocalizedString("SharedErrorTitle")); } if (this.SshClient == null) { this.IsBusy = false; this.NavigationService.GoBack(); return; } this.UsbModes = this.SshClient.GetUsbModes(); this.SelectedUsbMode = this.SshClient.GetCurrentUsbMode(); this.IsBusy = false; this.Initialized = true; }
private async void ExportScreenshotsHistory() { var screenshotsFolder = await FilesHelper.GetScreenshotsFolderAsync(); var files = await screenshotsFolder.GetFilesAsync(); if (files.IsNullOrEmpty()) { return; } var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync(Package.Current.DisplayName); foreach (var file in files) { await file.CopyOrReplaceAsync(folder); } await this.DialogService.ShowMessage( ResourcesHelper.GetLocalizedString("HomeScreenshotsHistoryExportedMessage"), ResourcesHelper.GetLocalizedString("SharedOperationCompletedTitle")); }