/// <summary> /// The background worker run worker completed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void BackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { ButtonProgressAssist.SetIsIndeterminate(this.ButtonRefresh, false); this.TextBlockWait.Visibility = Visibility.Collapsed; this.ButtonRefresh.IsEnabled = true; MessageBox.Show("Data Updated Successfully!"); }
private void buttonOnClick(object sender, EventArgs e) { Button button = sender as Button; ButtonProgressAssist.SetIsIndicatorVisible(button, true); ButtonProgressAssist.SetIsIndeterminate(button, true); int i = (int)button.Tag; Debug.WriteLine(i + "-" + links[i]); downloadAndOpen(links[i], button); }
/// <summary> /// The tile refresh on click. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void ButtonRefreshOnClick(object sender, RoutedEventArgs e) { ButtonProgressAssist.SetIsIndeterminate(this.ButtonRefresh, true); this.TextBlockWait.Visibility = Visibility.Visible; this.ButtonRefresh.IsEnabled = false; this.backgroundWorker = new BackgroundWorker(); this.backgroundWorker.DoWork += this.BackgroundWorkerDoWork; this.backgroundWorker.RunWorkerCompleted += this.BackgroundWorkerRunWorkerCompleted; try { this.backgroundWorker.RunWorkerAsync(); } catch (Exception exception) { MessageBox.Show(exception.Message); } }
private async void downloadAndOpen(string v, Button button) { var path = await v.DownloadFileAsync(AppDomain.CurrentDomain.BaseDirectory, "filed.torrent"); ButtonProgressAssist.SetIsIndicatorVisible(button, false); ButtonProgressAssist.SetIsIndeterminate(button, false); Debug.WriteLine("Path : " + path); try { Process.Start(new ProcessStartInfo(path) { UseShellExecute = true }); } catch { Debug.WriteLine("Error"); MessageBox.Show("Make sure any Torrent client is installed"); } }
/// <summary> /// The background worker do work. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private async void BackgroundWorkerDoWork(object sender, DoWorkEventArgs e) { this.Dispatcher.Invoke(() => ButtonProgressAssist.SetIsIndeterminate(this.ButtonRefresh, true)); #region Zone And Division var zoneAndDivisionModel = StaticDbContext.ConnectFireStore.GetCollectionFields <ZoneAndDivision>("Root", "Employee"); DataHelper.ZoneAndDivisionModel = zoneAndDivisionModel; var jsonResult = JsonConvert.SerializeObject(zoneAndDivisionModel, Formatting.Indented); var zoneAndDivisionFile = Path.Combine(DataHelper.JsonFolderPath, Properties.Resources.ZoneAndDivisionJson); if (File.Exists(zoneAndDivisionFile)) { File.Delete(zoneAndDivisionFile); } using (var streamWriter = new StreamWriter(zoneAndDivisionFile, true)) { await streamWriter.WriteLineAsync(jsonResult).ConfigureAwait(false); streamWriter.Close(); } #endregion #region Stations if (DataHelper.ZoneAndDivisionModel != null) { var stationsList = new StationsList { Stations = new Dictionary <string, Station>() }; foreach (var zone in DataHelper.ZoneAndDivisionModel.ZoneList) { var collectionList = StaticDbContext.ConnectFireStore.GetCollections( "Root", "Stations", "StationDetails", zone); foreach (var collectionReference in collectionList) { var stations = StaticDbContext.ConnectFireStore.GetAllDocumentData <Station>( "Root", "Stations", "StationDetails", zone, collectionReference.Id); foreach (var station in stations) { stationsList.Stations.Add(new KeyValuePair <string, Station>(station.StationCode, station)); } } } DataHelper.StationsList = stationsList; var jsonResult2 = JsonConvert.SerializeObject(stationsList, Formatting.Indented); var stationsJson = Path.Combine(DataHelper.JsonFolderPath, Properties.Resources.StationsListJson); if (File.Exists(stationsJson)) { File.Delete(stationsJson); } using (var streamWriter = new StreamWriter(stationsJson, true)) { await streamWriter.WriteLineAsync(jsonResult2).ConfigureAwait(false); streamWriter.Close(); } } #endregion }
/// <summary> /// The background worker run worker completed. /// </summary> /// <param name="sender"> /// The sender. /// </param> /// <param name="e"> /// The e. /// </param> private void BackgroundWorkerRunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { ButtonProgressAssist.SetIsIndeterminate(this.ButtonRefresh, false); }
public HomeView() { InitializeComponent(); this.WhenActivated(disposables => { // Link and Start this.Bind(ViewModel, viewModel => viewModel.Link, view => view.linkTextBox.Text) .DisposeWith(disposables); linkTextBox.Events().KeyDown .Where(x => x.Key == Key.Enter) .Select(x => Unit.Default) .InvokeCommand(ViewModel !.StartDownloadCommand) // Null forgiving reason: upstream limitation. .DisposeWith(disposables); this.OneWayBind(ViewModel, viewModel => viewModel.BackendService.GlobalDownloadProgressPercentage, view => view.downloadButton.Content, percentage => percentage > 0.0 ? percentage.ToString("P1") : "_Download") .DisposeWith(disposables); // ButtonProgressAssist bindings ViewModel.WhenAnyValue(x => x.BackendInstance.IsRunning) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => { ButtonProgressAssist.SetIsIndicatorVisible(downloadButton, x); ButtonProgressAssist.SetIsIndicatorVisible(listFormatsButton, x); }) .DisposeWith(disposables); ViewModel.WhenAnyValue(x => x.BackendService.ProgressState) .Select(x => x == TaskbarItemProgressState.Indeterminate) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => ButtonProgressAssist.SetIsIndeterminate(downloadButton, x)) .DisposeWith(disposables); ViewModel.WhenAnyValue(x => x.BackendService.GlobalDownloadProgressPercentage) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => ButtonProgressAssist.SetValue(downloadButton, x * 100)) .DisposeWith(disposables); ViewModel.WhenAnyValue(x => x.BackendService.ProgressState) .Select(x => x == TaskbarItemProgressState.Indeterminate) .ObserveOn(RxApp.MainThreadScheduler) .Subscribe(x => ButtonProgressAssist.SetIsIndeterminate(listFormatsButton, x)) .DisposeWith(disposables); // presetComboBox this.OneWayBind(ViewModel, viewModel => viewModel.Presets, view => view.presetComboBox.ItemsSource) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.SelectedPreset, view => view.presetComboBox.SelectedItem) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.SelectedPresetText, view => view.presetComboBox.Text) .DisposeWith(disposables); // Subtitles this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadSubtitles, view => view.subtitlesDefaultCheckBox.IsChecked) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadSubtitlesAllLanguages, view => view.subtitlesAllLanguagesCheckBox.IsChecked) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadAutoGeneratedSubtitles, view => view.subtitlesAutoGeneratedCheckBox.IsChecked) .DisposeWith(disposables); // Options row 1 this.Bind(ViewModel, viewModel => viewModel.SharedSettings.AddMetadata, view => view.metadataToggle.IsChecked) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadThumbnail, view => view.thumbnailToggle.IsChecked) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadPlaylist, view => view.playlistToggle.IsChecked) .DisposeWith(disposables); // Options row 2 this.Bind(ViewModel, viewModel => viewModel.SharedSettings.UseCustomOutputTemplate, view => view.filenameTemplateToggle.IsChecked) .DisposeWith(disposables); this.OneWayBind(ViewModel, viewModel => viewModel.SharedSettings.UseCustomOutputTemplate, view => view.filenameTemplateTextBox.IsEnabled) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.CustomOutputTemplate, view => view.filenameTemplateTextBox.Text) .DisposeWith(disposables); // Options row 3 this.Bind(ViewModel, viewModel => viewModel.SharedSettings.UseCustomPath, view => view.pathToggle.IsChecked) .DisposeWith(disposables); this.OneWayBind(ViewModel, viewModel => viewModel.SharedSettings.UseCustomPath, view => view.pathComboBox.IsEnabled) .DisposeWith(disposables); this.OneWayBind(ViewModel, viewModel => viewModel.DownloadPathHistory, view => view.pathComboBox.ItemsSource) .DisposeWith(disposables); this.Bind(ViewModel, viewModel => viewModel.SharedSettings.DownloadPath, view => view.pathComboBox.Text) .DisposeWith(disposables); // Arguments this.OneWayBind(ViewModel, viewModel => viewModel.DownloadArguments, view => view.argumentsItemsControl.ItemsSource) .DisposeWith(disposables); // Output this.Bind(ViewModel, viewModel => viewModel.QueuedTextBoxSink.Content, view => view.resultTextBox.Text) .DisposeWith(disposables); resultTextBox.Events().TextChanged .Where(_ => WpfHelper.IsScrolledToEnd(resultTextBox)) .Subscribe(_ => resultTextBox.ScrollToEnd()) .DisposeWith(disposables); // Download, list, abort button this.BindCommand(ViewModel, viewModel => viewModel.StartDownloadCommand, view => view.downloadButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.ListFormatsCommand, view => view.listFormatsButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.AbortDlCommand, view => view.abortButton) .DisposeWith(disposables); // Browse and open folder button this.BindCommand(ViewModel, viewModel => viewModel.BrowseDownloadFolderCommand, view => view.browseButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.OpenDownloadFolderCommand, view => view.openFolderButton) .DisposeWith(disposables); // Reset custom filename template button this.BindCommand(ViewModel, viewModel => viewModel.ResetCustomFilenameTemplateCommand, view => view.resetFilenameTemplateButton) .DisposeWith(disposables); // Custom preset buttons this.BindCommand(ViewModel, viewModel => viewModel.OpenAddCustomPresetDialogCommand, view => view.addPresetButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.OpenEditCustomPresetDialogCommand, view => view.editPresetButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.DuplicatePresetCommand, view => view.duplicatePresetButton) .DisposeWith(disposables); this.BindCommand(ViewModel, viewModel => viewModel.DeleteCustomPresetCommand, view => view.deletePresetButton) .DisposeWith(disposables); }); }
private void LoginBTN_Clicked(object sender, RoutedEventArgs e) { Button btn = sender as Button; MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(btn, true); MaterialDesignThemes.Wpf.ButtonProgressAssist.SetValue(btn, -1); MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(btn, true); btn.IsEnabled = false; SignupBTN.IsEnabled = false; bool EverythingFine = true; if (String.IsNullOrEmpty(UsernameBox.Text)) { UsernameBox.GetBindingExpression(TextBox.TextProperty); ValidationError validationError = new ValidationError(new NotEmptyValidationRule(), UsernameBox.GetBindingExpression(TextBox.TextProperty)); validationError.ErrorContent = "Field is required."; Validation.MarkInvalid( UsernameBox.GetBindingExpression(TextBox.TextProperty), validationError); EverythingFine = false; } else { Validation.ClearInvalid(UsernameBox.GetBindingExpression(TextBox.TextProperty)); } if (String.IsNullOrEmpty(PasswordBox.Password)) { PasswordBox.GetBindingExpression(TextBox.TextProperty); ValidationError validationError = new ValidationError(new NotEmptyValidationRule(), PasswordBox.GetBindingExpression(PasswordBox.DataContextProperty)); validationError.ErrorContent = "Field is required."; Validation.MarkInvalid( PasswordBox.GetBindingExpression(PasswordBox.DataContextProperty), validationError); EverythingFine = false; } else if (PasswordBox.Password.Length < 1) { PasswordBox.GetBindingExpression(TextBox.TextProperty); ValidationError validationError = new ValidationError(new NotEmptyValidationRule(), PasswordBox.GetBindingExpression(PasswordBox.DataContextProperty)); validationError.ErrorContent = "At least 8 characters."; Validation.MarkInvalid( PasswordBox.GetBindingExpression(PasswordBox.DataContextProperty), validationError); EverythingFine = false; } else { Validation.ClearInvalid(PasswordBox.GetBindingExpression(PasswordBox.DataContextProperty)); } if (EverythingFine) { LoginRequest loginRequest = new LoginRequest(); loginRequest.username = UsernameBox.Text; loginRequest.password = PasswordBox.Password; app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(loginRequest, Constants.LOGIN_REQUEST_CODE)).ContinueWith(task => { ResponseInfo response = task.Result; LoginResponse loginResponse = JsonDeserializer.deserializeResponse <LoginResponse>(response.buffer); switch (loginResponse.status) { case Constants.LOGIN_SUCCESS: MyMessageQueue.Enqueue("Sign in Successfully!"); this.Dispatcher.Invoke(() => { app.username = UsernameBox.Text; NavigationService ns = NavigationService.GetNavigationService(this); ns.Navigate(new Uri("Menu.xaml", UriKind.Relative)); }); break; case Constants.LOGIN_INCORRECT_PASSWORD: MyMessageQueue.Enqueue("Incorrect password."); break; case Constants.LOGIN_USERNAME_NOT_EXIST: MyMessageQueue.Enqueue("Username not exist."); break; case Constants.LOGIN_UNEXPECTED_ERR: MyMessageQueue.Enqueue("There was an unexpected error."); break; case Constants.LOGIN_ALREADY_ONLINE: MyMessageQueue.Enqueue("This Username is already online."); break; } this.Dispatcher.Invoke(() => { ButtonProgressAssist.SetIsIndeterminate(btn, false); ButtonProgressAssist.SetIsIndicatorVisible(btn, false); btn.IsEnabled = true; SignupBTN.IsEnabled = true; }); }); } else { MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(btn, false); MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(btn, false); btn.IsEnabled = true; SignupBTN.IsEnabled = true; } }
private void btnImport_Click_1(object sender, RoutedEventArgs e) { ButtonProgressAssist.SetIsIndeterminate(btnImport, true); BancoInfo info = new BancoInfo(); info.Instancia1 = lblInstancia.Text; info.NomeServidor1 = lblNomeServe.Text; Conexao conec = new Conexao(info); ImportacaoEnti inserirEnti = new ImportacaoEnti(conec); ImportacaoProd inserirProd = new ImportacaoProd(conec); ImportacaoDoc inserirDoc = new ImportacaoDoc(conec); ImportacaoFilial inserirFil = new ImportacaoFilial(conec); ImportacaoEmp inserirEmp = new ImportacaoEmp(conec); ImportConsignado inserirCon = new ImportConsignado(conec); checkEntidade.IsChecked = inserirEnti.ChecarEntidade(); if (checkHiper.IsChecked == true) { try { inserirEmp.InsertCME(); MessageBox.Show("Empresa Cadastrada"); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } if (checkFilial.IsChecked == true) { try { inserirFil.InserFilial(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkEntidade.IsChecked == true) { try { inserirEnti.ImportPerf(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkProd.IsChecked == true) { try { inserirProd.InserEnderec(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkDoc.IsChecked == true) { try { inserirDoc.DocumentoDuplicado(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkCon.IsChecked == true) { try { inserirCon.ImportarConsignado(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkCfop.IsChecked == true) { inserirProd.UpdateCFOP(); try { inserirProd.InserCFOP(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } MessageBox.Show("Importação do Hiper Legado concluída"); } ImportMiniEnti InserMiniEnti = new ImportMiniEnti(conec); ImportMiniProd InserMiniProd = new ImportMiniProd(conec); if (checkHiperMini.IsChecked == true) { if (checkMiniEnt.IsChecked == true) { try { InserMiniEnti.InsertEnti(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkMiniProd.IsChecked == true) { try { InserMiniProd.InsertMarca(); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } if (checkMiniCFOP.IsChecked == true) { InserMiniProd.UpdateMiniCFOP(); InserMiniProd.InserMiniCFOP(); } MessageBox.Show("Importação do Hiper Mini Concluída"); } ButtonProgressAssist.SetIsIndeterminate(btnImport, false); }
private void CreateBTN_Click(object sender, RoutedEventArgs e) { Button btn = sender as Button; MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndeterminate(btn, true); MaterialDesignThemes.Wpf.ButtonProgressAssist.SetValue(btn, -1); MaterialDesignThemes.Wpf.ButtonProgressAssist.SetIsIndicatorVisible(btn, true); btn.IsEnabled = false; bool allFine = true; MaxPlayersBox.Text = new String(MaxPlayersBox.Text.Where(Char.IsDigit).ToArray()); if (MaxPlayersBox.Text.Length > 3) { MaxPlayersBox.Text = MaxPlayersBox.Text.Substring(0, 3); } if (String.IsNullOrEmpty(MaxPlayersBox.Text)) { setError(MaxPlayersBox, "Field is required."); allFine = false; } else { int count = int.Parse(MaxPlayersBox.Text); if (count > 15) { setError(MaxPlayersBox, "Can't be more than 15 players."); allFine = false; } else if (count < 2) { setError(MaxPlayersBox, "Can't be less than 2 players."); allFine = false; } else { Validation.ClearInvalid(MaxPlayersBox.GetBindingExpression(TextBox.TextProperty)); } } QuestionsBox.Text = new String(QuestionsBox.Text.Where(Char.IsDigit).ToArray()); if (QuestionsBox.Text.Length > 3) { QuestionsBox.Text = QuestionsBox.Text.Substring(0, 3); } if (String.IsNullOrEmpty(QuestionsBox.Text)) { setError(QuestionsBox, "Field is required."); allFine = false; } else { int count = int.Parse(QuestionsBox.Text); if (count > 20) { setError(QuestionsBox, "Can't be more than 20 questions."); allFine = false; } else if (count < 2) { setError(QuestionsBox, "Can't be less than 2 questions."); allFine = false; } else { Validation.ClearInvalid(QuestionsBox.GetBindingExpression(TextBox.TextProperty)); } } SecondsBox.Text = new String(SecondsBox.Text.Where(Char.IsDigit).ToArray()); if (SecondsBox.Text.Length > 3) { SecondsBox.Text = SecondsBox.Text.Substring(0, 3); } if (String.IsNullOrEmpty(SecondsBox.Text)) { setError(SecondsBox, "Field is required."); allFine = false; } else { int count = int.Parse(SecondsBox.Text); if (count > 100) { setError(SecondsBox, "Can't be more than 100 seconds."); allFine = false; } else if (count < 10) { setError(SecondsBox, "Can't be less than 10 seconds."); allFine = false; } else { Validation.ClearInvalid(SecondsBox.GetBindingExpression(TextBox.TextProperty)); } } if (String.IsNullOrEmpty(RoomNameBox.Text)) { setError(RoomNameBox, "Field is required."); allFine = false; } else { Validation.ClearInvalid(RoomNameBox.GetBindingExpression(TextBox.TextProperty)); } if (allFine) { CreateRoomRequest createRoomRequest = new CreateRoomRequest(); createRoomRequest.answerTimeout = int.Parse(SecondsBox.Text); createRoomRequest.maxUsers = int.Parse(MaxPlayersBox.Text); createRoomRequest.questionCount = int.Parse(QuestionsBox.Text); createRoomRequest.roomName = RoomNameBox.Text; app.communicator.SocketSendReceive(JsonSerializer.serializeRequest(createRoomRequest, Constants.CREATE_ROOM_REQUEST_CODE)).ContinueWith(task => { ResponseInfo response = task.Result; CreateRoomResponse createRoomResponse = JsonDeserializer.deserializeResponse <CreateRoomResponse>(response.buffer); switch (createRoomResponse.status) { case Constants.CREATE_ROOM_SUCCESS: MyMessageQueue.Enqueue("Room Created Successfully!"); this.Dispatcher.Invoke(() => { app.admin = true; NavigationService ns = NavigationService.GetNavigationService(this); ns.Navigate(new Uri("RoomLobby.xaml", UriKind.Relative)); }); break; case Constants.CREATE_ROOM_MAXIMUM_ROOMS_IN_SERVER: MyMessageQueue.Enqueue("Max rooms reached.\nTry again later."); break; } this.Dispatcher.Invoke(() => { ButtonProgressAssist.SetIsIndeterminate(btn, false); ButtonProgressAssist.SetIsIndicatorVisible(btn, false); btn.IsEnabled = true; }); }); } else { ButtonProgressAssist.SetIsIndeterminate(btn, false); ButtonProgressAssist.SetIsIndicatorVisible(btn, false); btn.IsEnabled = true; } }
private async void Button_OnClick(object sender, RoutedEventArgs e) { if (CurrentWork?.Result == ResultCodes.Success) { MainTransitioner.SelectedIndex = 3; Content.SelectedIndex = 2; return; } var NextButton = (Button)sender; if (MainViewModel.Instance.Encoder == null) { MainTransitioner.SelectedIndex = 1; PeerDiscovery.DiscoverPeersAsync(PeerDiscovery.DiscoveryMethod.UDPBroadcast); return; } if (workFetched) { return; } workFetched = true; ButtonProgressAssist.SetIsIndicatorVisible(NextButton, true); ButtonProgressAssist.SetIsIndeterminate(NextButton, true); var work = await Client.GetNextWork(); CurrentWork = work; Student.DataContext = work.Student; ButtonProgressAssist.SetIsIndicatorVisible(NextButton, false); ButtonProgressAssist.SetIsIndeterminate(NextButton, false); //_encoderMagic.IsGenieOut = false; var errorMessage = ""; switch (work.Result) { case ResultCodes.Success: WorkDataGrid.ItemsSource = work.ClassSchedules; //_workMagic.IsGenieOut = true; MainTransitioner.SelectedIndex = 3; Content.SelectedIndex = 2; LoginLamp.Visibility = Visibility.Collapsed; StudentId.Text = work.StudentId; StudentName.Text = work.StudentName; break; case ResultCodes.NotFound: //MessageBox.Show("No more pending items."); errorMessage = "No more requests"; break; case ResultCodes.Offline: errorMessage = "Can not find server"; break; case ResultCodes.Timeout: errorMessage = "Request timeout"; break; case ResultCodes.Error: errorMessage = "Request timeout"; break; } await ShowMessage(errorMessage); workFetched = false; }