CloseAsync() public method

Begins an operation to close the ProgressDialog.
public CloseAsync ( ) : System.Threading.Tasks.Task
return System.Threading.Tasks.Task
Esempio n. 1
0
        private async void btnLogin_Click(object sender, RoutedEventArgs e)
        {
            var email = txtEMail.Text;
            var pwd = txtPwd.Password;

            if (string.IsNullOrEmpty(email) && string.IsNullOrEmpty(pwd))
            {
                txtError.Text = "Please enter a EMail and a Password!";
                return;
            }
            else if (string.IsNullOrEmpty(pwd))
            {
                txtError.Text = "Please enter a Password";
                return;
            }
            else if (string.IsNullOrEmpty(email))
            {
                txtError.Text = "Please enter a EMail";
                return;
            }
            txtError.Text = "";

            IsEnabled = false;
            _controller = await this.ShowProgressAsync("Logging in...", "Authenticating...");
            _controller.SetIndeterminate();

            var result = await Task.Factory.StartNew(() =>
            {
                return commander.AuthenticateUser(email, pwd);
            });

            txtPwd.Password = "";

            await _controller.CloseAsync();

            IsEnabled = true;
            if (result == true)
            {
                await this.ShowMessageAsync("Authenticated", "Login success!");
                MainWindow mainWindow = new MainWindow();
                mainWindow.Show();
                Close();
            }
            else
            {
                txtError.Text = "Combination of EMail and Password is incorrect!";
            }
            _controller.SetProgress(1);
        }
Esempio n. 2
0
        private async void PerformanceDay_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (!initialized)
                return;
            else {
                if (PerformanceDay.SelectedItem != null)
                {
                    var selectedItem = (DateTime)PerformanceDay.SelectedItem;
                    IsEnabled = false;
                    _controller = await mainWindow.ShowProgressAsync("Performances", "Loading...");
                    _controller.SetIndeterminate();

                    await Task.Factory.StartNew(() =>
                    {
                        ufoVM.LoadPerformancesOfDay(selectedItem);
                    });

                    await _controller.CloseAsync();

                    IsEnabled = true;
                    _controller.SetProgress(1);
                }
            }
        }
 private async void UpdateBtn_Click(object sender, RoutedEventArgs e)
 {
     _controller2 = await this.ShowProgressAsync("Updating...", "Updating the WebConfig File..." );
     _controller2.SetCancelable(false);
     _controller2.SetIndeterminate();
     config.webConfig_News = txt_News.Text;
     config.Software = txt_Software.Text;
     config.LatestVersion = txt_LatestVersion.Text;
     config.Language = txt_Language.Text;
     config.notAvailableMsg = txt_notAvailableMsg.Text;
     config.MasterIP = txt_MasterIP.Text;
     config.MasterIPDNS = txt_MasterIPDNS.Text;
     Core.JsonUpdate.Create.File();
     Core.JsonUpdate.Upload.File();
     pause(5);
     await _controller2.CloseAsync();
 }
        public async void eventloadBase()
        {
            if(eventUpdating == false)
            {
                comboMap.Items.Add("Stratis");
                comboMap.Items.Add("Altis");
                comboMap.Items.Add("Takistan");
                comboMap.Items.Add("Chernarous");
                comboMap.Items.Add("Bukovina");
                comboMap.Items.Add("Kunduz");

                comboType.Items.Add("COOP");
                comboType.Items.Add("PvP Public");
                comboType.Items.Add("PvP Private");

                comboMapMod.Items.Add("Stratis");
                comboMapMod.Items.Add("Altis");
                comboMapMod.Items.Add("Takistan");
                comboMapMod.Items.Add("Chernarous");
                comboMapMod.Items.Add("Bukovina");
                comboMapMod.Items.Add("Kunduz");

                comboTypeMod.Items.Add("COOP");
                comboTypeMod.Items.Add("PvP Public");
                comboTypeMod.Items.Add("PvP Private");

                try
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                    {
                        _controller = await this.ShowProgressAsync("Please wait...", "Setting up Events & Configs...\r\n\r\nThis operation may take some minutes...");
                        _controller.SetCancelable(false);
                        if (!string.IsNullOrEmpty(modPath))
                        {
                            string[] folders = System.IO.Directory.GetDirectories(modPath, "@*", System.IO.SearchOption.AllDirectories);

                            foreach (string folder in folders)
                            {
                                string input = folder;
                                string output = input.Split('@').Last();
                                modList.Items.Add("@" + output);
                                modListMod.Items.Add("@" + output);
                            }
                        }
                        else
                        {
                            modList.Items.Add("Please Select the Mods Path and restart the Application!");
                            modListMod.Items.Add("Please Select the Mods Path and restart the Application!");
                            eventCreate.IsEnabled = false;
                            eventMod.IsEnabled = false;
                        }

                        if (!Directory.Exists(workingDir + "\\Config"))
                        {
                            Directory.CreateDirectory(workingDir + "\\Config");

                        }
                        else
                        {
                            Directory.Delete(workingDir + "\\Config", true);
                            Directory.CreateDirectory(workingDir + "\\Config");
                        }


                        if (config.events != null)
                        {
                            foreach (string files in config.events)
                            {
                                DownloadFiles(files);
                            }
                        }

                        //Read events files

                        foreach (string _event in config.events)
                        {
                            eventListView.Items.Add(_event.Replace("_", " "));
                        }



                        pause(5);
                        await _controller.CloseAsync();

                    }));
                }
                catch (Exception ex)
                { System.Windows.MessageBox.Show(ex.ToString()); }
            }
            else
            {
                try
                {
                    Dispatcher.BeginInvoke(DispatcherPriority.Input, new ThreadStart(async () =>
                    {
                        _controller = await this.ShowProgressAsync("Please wait...", "Updating Events & Configs...");
                        _controller.SetCancelable(false);
                        if (!string.IsNullOrEmpty(modPath))
                        {
                            string[] folders = System.IO.Directory.GetDirectories(modPath, "@*", System.IO.SearchOption.AllDirectories);
                            modList.Items.Clear();
                            modListMod.Items.Clear();
                            
                            foreach (string folder in folders)
                            {
                                string input = folder;
                                string output = input.Split('@').Last();
                                modList.Items.Add("@" + output);
                                modListMod.Items.Add("@" + output);
                            }
                        }
                        else
                        {
                            modList.Items.Add("Please Select the Mods Path and restart the Application!");
                            modListMod.Items.Add("Please Select the Mods Path and restart the Application!");
                            eventCreate.IsEnabled = false;
                            eventMod.IsEnabled = false;
                        }

                        while(true)
                        {
 
                            if (!Directory.Exists(workingDir + "\\Config"))
                            {
                                Directory.CreateDirectory(workingDir + "\\Config");
                                break;
                            }
                            else
                            {
                                Directory.Delete(workingDir + "\\Config", true);
                                Directory.CreateDirectory(workingDir + "\\Config");
                                break;
                            }
                            
                                
                        }
                        


                        if (config.events != null)
                        {
                            foreach (string files in config.events)
                            {
                                DownloadFiles(files);
                            }
                        }

                        //Read events files

                        foreach (string _event in config.events)
                        {
                            eventListView.Items.Add(_event.Replace("_", " "));
                        }

                        eventUpdating = false;
                        pause(5);
                        await _controller.CloseAsync();

                    }));
                }
                catch (Exception ex)
                { System.Windows.MessageBox.Show(ex.ToString()); }
            }
            

        }
        private async void updateBtnUs_Click(object sender, RoutedEventArgs e)
        {
            _controller2 = await this.ShowProgressAsync("Updating...", "Updating the WebConfig File...");
            _controller2.SetCancelable(false);
            _controller2.SetIndeterminate();

            Core.JsonUpdate.Create.File();
            Core.JsonUpdate.Upload.File();
            pause(5);
            await _controller2.CloseAsync();
        }
        private static Task DownloadFile(string uri, string filename, MetroWindow window, ProgressDialogController controller)
        {
            return Task.Run(() =>
            {
                WebClient client = new WebClient();
                client.DownloadProgressChanged += async (sender, e) =>
                {
                    double bytesIn = double.Parse(e.BytesReceived.ToString());
                    double totalBytes = double.Parse(e.TotalBytesToReceive.ToString());
                    double percentage = bytesIn / totalBytes * 100;
                    try
                    {
                        await window.Dispatcher.InvokeAsync(() =>
                        {
                            controller.SetProgress(int.Parse(Math.Truncate(percentage).ToString()));
                        });
                    }
                    catch
                    {

                    }
                };
                client.DownloadFileCompleted += async (sender, e) =>
                {
                    await controller.CloseAsync();
                    client.Dispose();
                };
                client.DownloadFileAsync(new Uri(uri), Environment.CurrentDirectory + filename);
            });
        }
Esempio n. 7
0
        private async void Button_Click(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            var buttonCmdParam = button.CommandParameter;
            var command = button.Tag as ICommand;
            IsEnabled = false;
            _controller = await mainWindow.ShowProgressAsync("EMail", "Sending...");
            _controller.SetIndeterminate();

            await Task.Factory.StartNew(() =>
            {
                // Execute command in tag
                if (button != null)
                {
                    if (command != null)
                        command.Execute(buttonCmdParam);
                }
                return true;
            });

            await _controller.CloseAsync();

            IsEnabled = true;
            await mainWindow.ShowMessageAsync("EMail", "EMails were sent successfully!");
            _controller.SetProgress(1);
        }
        private async void CheckForUpdates()
        {
            await Task.Delay(3000);

            while (!DialogCoordinatorRegistered)
            {
                await Task.Delay(25);
            }

            if (await _updateHandler.IsUpdateAvailable())
            {
                IsUpdating = true;
                var result = await
                    DialogCoordinator.ShowMessageAsync(this, "Update available", $"An update is available.{Environment.NewLine}{Environment.NewLine}Current installed version: {_updateHandler.LocalVersion}.{Environment.NewLine}Available version: {_updateHandler.RemoteVersion}{Environment.NewLine}{Environment.NewLine}Do you want to install this update now?",
                        MessageDialogStyle.AffirmativeAndNegative);

                if (result == MessageDialogResult.Affirmative)
                {
                    _updateHandler.UpdateDownloadProgressChanged += (sender, args) =>
                    {
                        _progressController.SetProgress(args.ProgressPercentage / 100.0);
                        _progressController.SetMessage($"Downloading...{Environment.NewLine}Received: {args.MegabytesReceived} MB{Environment.NewLine}Total Size: {args.MegabytesToReceive} MB");
                    };

                    _updateHandler.UpdateDownloadCompleted += async (sender, args) =>
                    {
                        if (args.Aborted)
                        {
                            _progressController?.SetMessage("Failed to download update");
                        }
                        else
                        {
                            _progressController?.SetMessage("Completed!");
                            _progressController?.SetIndeterminate();
                        }

                        await Task.Delay(3000);
                        try
                        {
                            await _progressController?.CloseAsync();
                        }
                        catch (Exception)
                        {
                            // ignored
                        }
                        
                        IsUpdating = false;
                    };

                    var task = _updateHandler.DownloadUpdate();

                    _progressController = await DialogCoordinator.ShowProgressAsync(this, "Downloading update", "", true);
                    _progressController.Canceled += (sender, args) =>
                    {
                        _progressController.CloseAsync();
                        _updateHandler.CancelDownload();
                        IsUpdating = false;
                    };
                }
                else
                {
                    IsUpdating = false;
                }

            }
        }
Esempio n. 9
0
        private async void btnExportAll_Click(object sender, RoutedEventArgs e)
        {
            var folderDialog = new CommonOpenFileDialog();
            folderDialog.Title = "Where should I save your data?";
            folderDialog.IsFolderPicker = true;
            folderDialog.EnsureFileExists = true;
            folderDialog.EnsurePathExists = true;
            folderDialog.EnsureValidNames = true;
            folderDialog.EnsureReadOnly = false;
            folderDialog.Multiselect = false;
            folderDialog.ShowPlacesList = true;

            if (folderDialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                Telemetry.TrackEvent(TelemetryCategory.Export, Telemetry.TelemetryEvent.Export.Full);

                var folder = folderDialog.FileName;

                BandCloudManager.Instance.Events.Clear();

                _fullExportProgressDialog = await ((MetroWindow)(Window.GetWindow(this))).ShowProgressAsync("Exporting Full Activity Data", "Loading Activities list...");
                _fullExportProgressDialog.SetCancelable(true); // TODO: this needs to be implemented. No event?
                _fullExportProgressDialog.SetIndeterminate();

                // HACK HACK HACK HACK
                // TODO: add a Cancelled Event into the MahApps.Metro library

                // polling method to cancel the export if the user requests that it be cancelled
                Task.Run(async () =>
                {
                    while (_fullExportProgressDialog != null && _fullExportProgressDialog.IsOpen)
                    {
                        if (_fullExportProgressDialog.IsCanceled)
                        {
                            BandCloudManager.Instance.CancelFullExport = true;

                            Telemetry.TrackEvent(TelemetryCategory.Export, Telemetry.TelemetryEvent.Export.FullCancelled);

                            // we'd exit from the while loop anyway, but only when the progress dialog finally exits
                            // which can take up to 10 seconds, so might as well shut this down asap
                            return; 
                        }

                        await Task.Delay(500);
                    }
                });

                await LoadEvents();

                var progressIndicator = new Progress<BandCloudExportProgress>(ReportFullExportProgress);
                
                // TODO: progress reporter
                await BandCloudManager.Instance.ExportFullEventData(folder, ExportSettings, progressIndicator);

                _fullExportProgressDialog.CloseAsync();

                SaveExportSettings();
            }
        }
Esempio n. 10
0
        private async void ExportEventSummaryToCSV(int? count = null)
        {
            Telemetry.TrackEvent(TelemetryCategory.Export, Telemetry.TelemetryEvent.Export.Summary);

            var saveDialog = new SaveFileDialog();
            saveDialog.AddExtension = true;
            saveDialog.FileName = "band_export.csv";
            saveDialog.DefaultExt = ".csv";

            var result = saveDialog.ShowDialog();

            if (result == true)
            {
                _summaryExportProgressDialog = await ((MetroWindow)(Window.GetWindow(this))).ShowProgressAsync("Exporting Data", "...");
                _summaryExportProgressDialog.SetCancelable(true); // TODO: this needs to be implemented. No event?
                _summaryExportProgressDialog.SetProgress(0);

                var progressIndicator = new Progress<BandCloudExportProgress>(ReportSummaryExportProgress);

                await BandCloudManager.Instance.ExportEventsSummaryToCSV(count, ExportSettings, saveDialog.FileName, progressIndicator);

                _summaryExportProgressDialog.CloseAsync();

                if (ExportSettings.OpenFileAfterExport)
                {
                    Process.Start(saveDialog.FileName);                    
                }

                SaveExportSettings();
            }
        }
Esempio n. 11
0
        private static async Task WaitForCancel(ProgressDialogController dialog, string message)
        {
            dialog.SetMessage("Failed: " + message);
            dialog.SetCancelable(true);

            while (!dialog.IsCanceled)
                await Task.Delay(10);

            await dialog.CloseAsync();
        }
        private async void DownloadSelectedLanguageSubtitles( )
        {
            if ( LanguageList.SelectedItems.Count <= 0 )
                return;

            controller = await window.ShowProgressAsync( "Downloading subtitles", "Downloading subtitles for the selected languages from opensubtitles.org." );
            controller.SetIndeterminate( );

            string[ ] languages = new string[ LanguageList.SelectedItems.Count ];
            for ( int x = 0; x < languages.Length; ++x )
                languages[ x ] = ( ( SubtitleLanguage ) LanguageList.SelectedItems[ x ] ).ISO639_3;

            SubtitleData[ ] data = await Task.Run( ( ) => MainWindow.Client.SearchSubtitles( languages, MainWindow.Player.GetComponent<MediaComponent>( ).Media.File ) );

            SubsGroupBox.Visibility = Visibility.Visible;

            this.SubtitlesList.ItemsSource = data;

            CollectionView subsView = ( CollectionView ) CollectionViewSource.GetDefaultView( SubtitlesList.ItemsSource );
            subsView.SortDescriptions.Add( new SortDescription( "DownloadsCount", ListSortDirection.Descending ) );

            Scroller.ScrollToBottom( );

            await controller.CloseAsync( );
        }
        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( );
        }
        public async Task LoadTheGameDbGame()
        {
            await Task.Factory.StartNew(async () =>
            {
                GiochiCaricati = string.Empty;
                await App.Current.Dispatcher.BeginInvoke((Action)async delegate ()
                {
                    progressDialog = await _dialogCoordinator.ShowProgressAsync(this, "Attendi...", "Attendi mentre carico la lista dei giochi", false, new MetroDialogSettings()
                    {
                        ColorScheme = MetroDialogColorScheme.Accented
                    });
                    progressDialog.SetIndeterminate();
                });
                
                IsReadOnlyTitleSearch = true;
                if (GamesDto.Count > 0)
                    GamesDto.Clear();
                List<GameSummary> gs = new List<GameSummary>();
                if (CurrentPlatform.Name != "Tutti")
                    gs = await _currentWebApi.TheGamesDBGameListByPlatform(DataInizio, DataFine, CurrentPlatform);
                else
                    AvailablePlatforms.Where(x => x.Name != "Tutti").ToList().ForEach(async _currentPlatform =>
                    {
                        gs.AddRange(await _currentWebApi.TheGamesDBGameListByPlatform(DataInizio, DataFine, _currentPlatform));
                    });

                await App.Current.Dispatcher.BeginInvoke((Action)async delegate ()
                {
                    await progressDialog.CloseAsync();
                });

                int numGiochi = gs.Count;
                int giocoCorrente = 0;
                double percentageToIncrement = (double)100 / numGiochi;
                ProgressBarValue = 0;

                gs.ForEach(async currentGameSummary =>
                {
                    try
                    {
                        if (await _currentWebApi.GetGameByFieldSearch(new Game() { ImportId = currentGameSummary.ID }) == default(Game))
                        {
                            GameDto result = _mapper.Map<GameDto>(await _currentWebApi.TheGamesDBGetGameDetails(currentGameSummary));
                            await App.Current.Dispatcher.BeginInvoke((Action)delegate ()
                            {
                                GamesDto.Add(result);
                            });
                        }
                    }
                    catch (Exception ex)
                    {
                        numGiochi--;
                        giocoCorrente--;
                        string a = ex.Message;
                    }
                    finally
                    {
                        giocoCorrente++;
                        GiochiCaricati = string.Format("{0} / {1}", giocoCorrente, numGiochi);
                        ProgressBarValue += percentageToIncrement;
                        if (numGiochi == giocoCorrente)
                        {
                            await App.Current.Dispatcher.BeginInvoke((Action)async delegate ()
                            {
                                await _dialogCoordinator.ShowMessageAsync(this, "Caricamento completato...", "Puoi modificare i giochi prima dell'importazione",  MessageDialogStyle.Affirmative, new MetroDialogSettings()
                                {
                                    ColorScheme = MetroDialogColorScheme.Accented
                                });                                
                            });                            
                            IsReadOnlyTitleSearch = false;
                        }
                    }                
                });
            });
        }
Esempio n. 15
0
 private async Task ProgressFailed(ProgressDialogController controller, String reason)
 {
     controller.SetMessage("Failure to login: " + reason);
     await Task.Delay(1500);
     await controller.CloseAsync();
 }
Esempio n. 16
0
 public Task Close()
 {
     return(_controller.CloseAsync());
 }