Exemple #1
0
        private bool ShowVersionList(CookieContainer container, out FactorioOnlineVersion selectedVersion)
        {
            selectedVersion = null;
            List <FactorioOnlineVersion> versions;

            try
            {
                if (!FactorioWebsite.GetVersions(container, out versions))
                {
                    MessageBox.Show(Window,
                                    App.Instance.GetLocalizedMessage("RetrievingVersions", MessageType.Error),
                                    App.Instance.GetLocalizedMessageTitle("RetrievingVersions", MessageType.Error),
                                    MessageBoxButton.OK, MessageBoxImage.Error);
                    return(false);
                }
            }
            catch (WebException)
            {
                MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("RetrievingVersions", MessageType.Error),
                                App.Instance.GetLocalizedMessageTitle("RetrievingVersions", MessageType.Error),
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(false);
            }
            versions.ForEach(item => item.Downloadable = GetVersionDownloadable(item));

            var versionListWindow = new VersionListWindow {
                Owner = Window
            };
            var versionListViewModel = (VersionListViewModel)versionListWindow.ViewModel;

            versions.ForEach(item => versionListViewModel.FactorioVersions.Add(item));

            bool?versionResult = versionListWindow.ShowDialog();

            selectedVersion = versionListViewModel.SelectedVersion;
            return(versionResult.HasValue && versionResult.Value);
        }
Exemple #2
0
        private async Task <FactorioOnlineVersion> ShowVersionList(string token)
        {
            List <FactorioOnlineVersion> versions = null;

            try
            {
                var progressWindow = new ProgressWindow {
                    Owner = Window
                };
                var progressViewModel = (ProgressViewModel)progressWindow.ViewModel;
                progressViewModel.ActionName      = App.Instance.GetLocalizedResourceString("FetchingVersionsAction");
                progressViewModel.IsIndeterminate = true;
                progressViewModel.CanCancel       = false;

                Task closeWindowTask = null;
                try
                {
                    var getVersionsTask = FactorioWebsite.GetVersionsAsync();

                    closeWindowTask = getVersionsTask.ContinueWith(t => progressWindow.Dispatcher.Invoke(progressWindow.Close));
                    progressWindow.ShowDialog();

                    versions = await getVersionsTask;
                }
                finally
                {
                    if (closeWindowTask != null)
                    {
                        await closeWindowTask;
                    }
                }
            }
            catch (WebException)
            {
                MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("RetrievingVersions", MessageType.Error),
                                App.Instance.GetLocalizedMessageTitle("RetrievingVersions", MessageType.Error),
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            if (versions == null)
            {
                MessageBox.Show(Window,
                                App.Instance.GetLocalizedMessage("RetrievingVersions", MessageType.Error),
                                App.Instance.GetLocalizedMessageTitle("RetrievingVersions", MessageType.Error),
                                MessageBoxButton.OK, MessageBoxImage.Error);
                return(null);
            }

            var versionListWindow = new VersionListWindow {
                Owner = Window
            };
            var versionListViewModel = (VersionListViewModel)versionListWindow.ViewModel;

            versions.ForEach(item => versionListViewModel.FactorioVersions.Add(item));

            bool?versionResult = versionListWindow.ShowDialog();

            if (!(versionResult.HasValue && versionResult.Value))
            {
                return(null);
            }
            return(versionListViewModel.SelectedVersion);
        }