public void OnLoginStateChanged(object sender, LoginStateEventArgs e) { if (controller == null) { return; } if (e.Code == LoginState.LOGINNING) { controller.SetTitle(LanguageManager.Model.LoginLogIn); } else if (e.Code == LoginState.GETTING_DATA) { controller.SetTitle(LanguageManager.Model.LoginGettingData); } string message = string.Format(LanguageManager.Model.LoginTry, e.AttemptNumber); if (e.LastError != -1) { message += string.Format(" ({0} {1})", LanguageManager.Model.LoginWasError, e.LastError); } controller.SetMessage(message); if (controller.IsCanceled) { ILoginProvider loginProvider = sender as ILoginProvider; if (loginProvider != null) { loginProvider.CancelLogin(); } } }
public ImageFile Scan(ProgressDialogController ctrl, bool colorSetting = true) { try { var image = new ImageFile(); var dialog = new CommonDialog(); ctrl.SetTitle("STARTING SCANNER"); ctrl.SetMessage("This can take a few seconds..."); var x = dialog.ShowSelectDevice(WiaDeviceType.ScannerDeviceType, false, false); var item = x.Items[1]; // HorizontalResolution item.Properties["6147"].set_Value(75); // VerticalResolution item.Properties["6148"].set_Value(75); // CurrentInten, 1 - Color, 4 - Black & White if (colorSetting) { item.Properties["6146"].set_Value(1); } else { item.Properties["6146"].set_Value(4); } image = dialog.ShowTransfer(item, "{B96B3CB1-0728-11D3-9D7B-0000F81EF32E}", true); if (image != null) { ctrl.SetTitle("SCANNING FINISHED!"); ctrl.SetMessage($"File Scanned Successfully..."); } return(image); } catch (COMException ex) { if (ex.ErrorCode == -2145320939) { throw new ScannerNotFoundException(); } else { throw new ScannerException(ex.Message, ex); } } }
public bool SaveOnPDF(BitmapFrame img, ProgressDialogController ctrl) { try { int c = 0; ctrl.SetTitle("Converting to PDF"); ctrl.SetMessage($"{c}/1 Wait a moment..."); var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(img)); using (FileStream stream = new FileStream($@"{_containerNname}.png", FileMode.Create)) encoder.Save(stream); ConvertImageToPDF(); if (File.Exists($"{_containerNname}.png")) { File.Delete($"{_containerNname}.png"); } c++; ctrl.SetMessage($"{c}/1 Wait a moment..."); return(true); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
private async void BtnRegister_Click(object sender, RoutedEventArgs e) { if (!CheckBoxPrivacyPolicy.IsChecked == true) { return; } var email = TextBoxRegisterEmail.Text; if (string.IsNullOrEmpty(email) || !Regex.IsMatch(email, @".*@.*\..*")) { DisplayLoginError("Please enter an valid email address"); return; } if (string.IsNullOrEmpty(TextBoxRegisterPassword.Password)) { DisplayLoginError("Please enter a password"); return; } if (TextBoxRegisterPassword.Password.Length < 6) { DisplayLoginError("Your password needs to be at least 6 characters"); return; } if (string.IsNullOrEmpty(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Please confirm your password"); return; } if (!TextBoxRegisterPassword.Password.Equals(TextBoxRegisterPasswordConfirm.Password)) { DisplayLoginError("Entered passwords do not match"); return; } IsEnabled = false; _controller = await this.ShowProgressAsync("Registering account...", ""); var result = await HearthStatsAPI.RegisterAsync(email, TextBoxRegisterPassword.Password); if (result.Success) { _controller.SetTitle("Logging in..."); result = await HearthStatsAPI.LoginAsync(email, TextBoxRegisterPassword.Password); } else if (result.Message.Contains("422")) { DisplayLoginError("Email already registered"); } else { DisplayLoginError(result.Message); } TextBoxRegisterPassword.Clear(); TextBoxRegisterPasswordConfirm.Clear(); if (result.Success) { LoginResult = true; Close(); } }
private async void OnFlyoutFirstOpen( ) { if (MainWindow.Client.IsLoggedIn) { return; } controller = await window.ShowProgressAsync("Signing in.", "Signing into opensubtitles.org."); controller.SetIndeterminate( ); LogInOutput output = await SignInClient( ); if (output.LogInSuccesful && MainWindow.Client.IsLoggedIn) { controller.SetTitle("Downloading subtitle languages."); controller.SetMessage("Downloading the available subtitle languages from opensubtitles.org."); this.languages = await GetSubtitleLanguages( ); this.LanguageList.ItemsSource = this.languages; CollectionView languagesView = ( CollectionView )CollectionViewSource.GetDefaultView(LanguageList.ItemsSource); languagesView.SortDescriptions.Add(new SortDescription("LanguageName", ListSortDirection.Ascending)); } else { await window.ShowMessageAsync("Signing in failed", $"Unable to sign in to opensubtitles.org. Please try again later. (Status: {output.Status}, {output.StatusStringWithoutCode})"); } await controller.CloseAsync( ); OnFlyoutOpen( ); }
/// <summary> /// Stuff that needs to be done after loading data from a statement. /// </summary> private async Task PostStatementLoadProcedures(Dictionary <string, DataContainer> newData, ProgressDialogController progressDialog) { progressDialog.SetProgress(0); progressDialog.SetTitle("Importing data"); progressDialog.SetMessage("Importing data"); //backup db before import System.IO.File.Copy("qpas.db", "qpas-backup.db", true); //prevent gaps in data bool continueImport = await ImportDateCheck(newData, progressDialog); if (!continueImport) { return; } //Perform the data import try { foreach (var kvp in newData) { await DataImporter.Import(Data, kvp.Value, kvp.Key, _contextFactory, _tradesRepository); } } catch (Exception ex) { await progressDialog.CloseAsync(); await DialogService.ShowMessageAsync(this, "Data Import Error", ex.Message); _logger.Error(ex, "Data import exception"); return; } //Run scripts progressDialog.SetProgress(0); progressDialog.SetTitle("Running scripts"); await RunOrderScripts(Data.Orders.Where(y => y.Trade == null).OrderBy(y => y.TradeDate).ToList(), progressDialog); await RunTradeScripts(progressDialog); await progressDialog.CloseAsync(); await RefreshCurrentPage(); }
public PdfDocument CopyPages(PdfDocument from, PdfDocument to, ProgressDialogController ctrl, FileInfo _in, FileInfo _out) { for (int i = 0; i < from.PageCount; i++) { ctrl.SetTitle($"Adding pages to {_out.Name}"); ctrl.SetMessage($"{i+1}/{from.PageCount} pages from {_in.Name}"); to.AddPage(from.Pages[i]); var progress = (((((i + 1f) * 100f)) / ((from.PageCount) * (100f)))); ctrl.SetProgress(progress); } return(to); }
private void LoadDataWorker_DoWork(object sender, DoWorkEventArgs e) { while (Tasks.Count > 0) { progressDialog.SetTitle(Tasks[0].Title); progressDialog.SetMessage(Tasks[0].Description); if (Tasks[0].WorkerNotification != null) { workerNotifications.Add(Tasks[0].WorkerNotification); } Tasks[0].Action(); Tasks.RemoveAt(0); } }
public async Task ShowDefaultProgressAsync(string title, string message) { if (_defaultProgressDialogController == null) { _defaultProgressDialogController = await _dialogCoordinator.ShowProgressAsync(_dialogHost.DataContext, title, message); _defaultProgressDialogController.SetIndeterminate(); } else { _defaultProgressDialogController.SetTitle(title); _defaultProgressDialogController.SetMessage(message); } }
public void SavePDFsOn(ObservableCollection <ImageFile> imgs, ProgressDialogController ctrl) { try { int c = 0; ctrl.SetTitle("Converting to PDF"); ctrl.SetMessage($"{c}/{imgs.Count} Wait a moment..."); var bitmapsource = new ObservableCollection <BitmapSource>(); var outPdf = new PdfDocument(); foreach (ImageFile item in imgs) { bitmapsource.Add(ConvertScannedImage(item)); } foreach (BitmapSource item in bitmapsource) { var encoder = new PngBitmapEncoder(); encoder.Frames.Add(BitmapFrame.Create(item as BitmapFrame)); using (FileStream stream = new FileStream($@"{_containerNname}.png", FileMode.Create)) encoder.Save(stream); ConvertImageToPDF(); var inputPdf = PdfReader.Open($"{_containerNname}.pdf", PdfDocumentOpenMode.Import); outPdf = CopyPages(inputPdf, outPdf); if (File.Exists($"{_containerNname}.pdf")) { File.Delete($"{_containerNname}.pdf"); } if (File.Exists($"{_containerNname}.png")) { File.Delete($"{_containerNname}.png"); } c++; ctrl.SetMessage($"{c}/{imgs.Count} Wait a moment..."); ctrl.SetProgress(c / imgs.Count); } outPdf.Save($"{_containerNname}.pdf"); } catch (Exception ex) { throw new Exception(ex.Message, ex); } }
private async void StartBuildAsync() { ProgressDialogController progress = null; try { IsBuilding = true; foreach (var page in Configuration.Pages) { if (!page.Validate()) { SelectedPage = page; return; } } if (SelectedDrive == null) { await _messageService.ShowMessageAsync("No Drive Selected", "Please select a USB drive to copy install files."); return; } if (!SelectedDrive.IsFatFormat) { await _messageService.ShowMessageAsync("The selected drive is not formatted for FAT (FAT16 or FAT32) and cannot " + "be used for this purpose.Please format the drive and try again.", "Invalid Drive Format"); return; } var settings = new MetroDialogSettings { AffirmativeButtonText = "Continue", NegativeButtonText = "Stop", AnimateShow = true, AnimateHide = false }; var result = await _messageService.ShowMessageAsync("Build Warning!", "All files on the destination drive are about to be erased. Do you wish to continue?", MessageDialogStyle.AffirmativeAndNegative, settings); if (result == MessageDialogResult.Negative) { return; } var mainWindow = (MetroWindow)ServiceLocator.Current.GetInstance <Window>(ViewNames.MainWindow); progress = await mainWindow.ShowProgressAsync("Building...", "Preparing build..."); await _configurator.BuildAsync(_key, SelectedDrive.Name, (title, message, value) => { progress.SetTitle(title); progress.SetMessage(message); progress.SetProgress(value); }); } catch (Exception ex) { await _messageService.ShowMessageAsync("Build Failed", "Please check the logs for error details"); _logger.Log(ex); } finally { if (progress != null) { await progress.CloseAsync(); } IsBuilding = false; } }
public void SetTitle(string title) { pd.SetTitle(title); }
private async void OnPacketReceived(DrawniteCore.Networking.IConnection connection, dynamic args) { Message packet = (Message)args; switch (packet.Command) { case "player/connected": { Player player = ((JObject)args.Data.Player).ToObject <Player>(); Dispatcher.Invoke(() => { lvConnectedPlayers.Children.Add(new Controls.ConnectedPlayer(player.Username, player.IsLeader)); }); } break; case "player/disconnected": { this.NetworkConnection.Write(new Message("lobby/playerlist", null)); } break; case "lobby/playerlist": { List <Player> playerList = ((JArray)packet.Data.PlayerList).ToObject <List <Player> >(); Dispatcher.Invoke(() => { lvConnectedPlayers.Children.Clear(); for (int i = 0; i < playerList.Count; i++) { lvConnectedPlayers.Children.Add(new Controls.ConnectedPlayer(playerList[i].Username, playerList[i].IsLeader)); if (playerList[i].PlayerId == MyPlayerId && playerList[i].IsLeader) { LeaderSwitched(); } } }); } break; case "lobby/error": { string errorMessage = packet.Data.ErrorMessage; await Dispatcher.Invoke(async() => { await ParentWindow.ShowMessageAsync("Error", errorMessage, MessageDialogStyle.Affirmative); }); } break; case "lobby/starting": { await Dispatcher.Invoke(async() => { controller = await ParentWindow.ShowProgressAsync("Starting", "The game is starting soon...", IsLobbyLeader); controller.Maximum = 10010; controller.Minimum = 0; }); controller.Canceled += (x, y) => { if (IsLobbyLeader) { NetworkConnection.Write(new Message("lobby/cancel", null)); } }; Thread t = new Thread(async() => { //Yes every 60 seconds in Africa a minute passes, together we can stop this. long secondPassedCheck = DateTimeOffset.Now.ToUnixTimeMilliseconds(); long actualStart = secondPassedCheck; int currentSecond = 0; while (controller.IsOpen) { long currentTime = DateTimeOffset.Now.ToUnixTimeMilliseconds(); if (currentSecond == 10) { break; } if (currentTime - secondPassedCheck >= 1000) { Dispatcher.Invoke(() => { controller.SetTitle($"Starting in 00:{string.Format("{0:D2}", 10 - currentSecond++)}"); }); secondPassedCheck = currentTime; } if (currentSecond < 10) { long ms = currentTime - actualStart; controller.SetProgress(ms); } } if (currentSecond == 10) { await controller.CloseAsync(); if (IsLobbyLeader) { NetworkConnection.Write(new Message("lobby/start", new { PlayerId = MyPlayerId, })); } } }); t.SetApartmentState(ApartmentState.STA); t.Start(); } break; case "lobby/cancelled": { await Dispatcher.Invoke(async() => { await controller?.CloseAsync(); }); } break; case "game/start": { if (controller.IsOpen) { await Dispatcher.Invoke(async() => { await controller?.CloseAsync(); }); } await Dispatcher.BeginInvoke(new Action(async() => { this.NavigationService.Navigate(new GamePage(LobbyId, MyPlayerId)); }), null); } break; } }
public static async void Progress(string title, string msg, bool isCancelable, Action <ProgressDialogController> configAction, Action <ProgressDialogController> doAction) { ProgressDialogController controller = null; lock (controllerLock) { if (null != currentController) { controller = currentController; } } if (null == currentController) { var win = (Application.Current.MainWindow as MetroWindow); controller = await win.ShowProgressAsync(title, msg, isCancelable, dlgsetting); SetController(controller); } try { controller.SetCancelable(false); if (null != configAction) { configAction(controller); } else { //默认配置 controller.Canceled += (sender, e) => { controller.CloseAsync(); }; } //这个最后配置 controller.Closed += (sender, e) => { SetController(null); }; System.Threading.Thread thread = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((obj) => { var c = obj as ProgressDialogController; if (null != c) { doAction(c); } else { doAction(controller); } })); thread.IsBackground = true; thread.Start(controller); } catch (Exception exp) { if (isCancelable) { controller.SetCancelable(true); controller.SetTitle("发生异常"); controller.SetMessage(exp.Message); } else { //直接关闭 await controller.CloseAsync(); } } }
public void SetTitle(string title) { _controller.SetTitle(title); }