Exemplo n.º 1
0
        private static async Task ShowSaveFileDialogAsync(SaveFileMessage message)
        {
            string filename = null;

            try
            {
                var dialog = new SaveFileDialog()
                {
                    Title            = message.Title,
                    Filters          = GetSaveFilters(message.FileType == FileType.ExportedImage),
                    DefaultExtension = GetSaveDefaultExtension(message.FileType == FileType.ExportedImage),
                    Directory        = null != message.ExistingFile ? Path.GetDirectoryName(message.ExistingFile) : null,
                    InitialFileName  = null != message.ExistingFile ? Path.GetFileName(message.ExistingFile) : null,
                };

                filename = await dialog.ShowAsync(MainWindow);
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(filename);
            }
        }
Exemplo n.º 2
0
        private static void ShowSaveGame(SaveGameMessage message)
        {
            string fileName = null;

            try
            {
                SaveFileDialog dialog = new SaveFileDialog
                {
                    Title        = "Save Game",
                    DefaultExt   = ".pgn",
                    Filter       = "Portable Game Notation|*.pgn",
                    AddExtension = true,
                    FileName     = Path.GetFileNameWithoutExtension(message.GameRecording.FileName)
                };

                if (dialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault())
                {
                    using (Stream outputStream = dialog.OpenFile())
                    {
                        message.GameRecording.SavePGN(outputStream);
                        fileName = dialog.SafeFileName;
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(fileName);
            }
        }
Exemplo n.º 3
0
        private void UpdateBoardHistory()
        {
            ObservableBoardHistory boardHistory = null;

            if (null != Board)
            {
                if (IsPlayMode)
                {
                    boardHistory = new ObservableBoardHistory(Board.BoardHistory);
                }
                else if (IsReviewMode)
                {
                    boardHistory = new ObservableBoardHistory(ReviewBoard.BoardHistory, Board.BoardHistory, (moveNum) =>
                    {
                        try
                        {
                            AppVM.EngineWrapper.MoveToMoveNumber(moveNum);
                        }
                        catch (Exception ex)
                        {
                            ExceptionUtils.HandleException(ex);
                        }
                    });
                }
            }

            BoardHistory = boardHistory;
        }
Exemplo n.º 4
0
        private static async Task ShowOpenFileDialogAsync(OpenFileMessage message)
        {
            string filename = null;

            try
            {
                var dialog = new OpenFileDialog()
                {
                    AllowMultiple = false,
                    Title         = message.Title,
                    Filters       = GetFilters(message.FileType),
                };

                string[] filenames = await dialog.ShowAsync(MainWindow);

                if (filenames is not null && filenames.Length > 0 && !string.IsNullOrWhiteSpace(filenames[0]))
                {
                    filename = filenames[0];
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(filename);
            }
        }
Exemplo n.º 5
0
        private void FirstRun()
        {
            // Turn off first-run so it doesn't run next time
            IsFirstRun = false;

            AppVM.AppView.DoOnUIThread(() =>
            {
                if (UpdateUtils.UpdateEnabled)
                {
                    Messenger.Default.Send(new ConfirmationMessage(Strings.FirstRunUpdateEnabledPrompt, (enableAutoUpdate) =>
                    {
                        try
                        {
                            UpdateUtils.CheckUpdateOnStart = enableAutoUpdate;
                        }
                        catch (Exception ex)
                        {
                            ExceptionUtils.HandleException(ex);
                        }
                    }));
                }
                else
                {
                    Messenger.Default.Send(new ChordiousMessage(Strings.FirstRunMessage));
                }
            });
        }
Exemplo n.º 6
0
        private static void ShowEngineOptions(EngineOptionsMessage message)
        {
            try
            {
                if (message.EngineOptionsVM.Options.Count == 0)
                {
                    throw new Exception("This engine exposes no options to set.");
                }

                EngineOptionsWindow window = new EngineOptionsWindow
                {
                    DataContext = message.EngineOptionsVM,
                    Owner       = Application.Current.MainWindow,
                };
                message.EngineOptionsVM.RequestClose += (sender, e) =>
                {
                    window.Close();
                };
                window.ShowDialog();
                message.Process();
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
        }
Exemplo n.º 7
0
        private static async Task ShowOpenFileDialogAsync(OpenFileMessage message)
        {
            string filename = null;

            try
            {
                var dialog = new OpenFileDialog()
                {
                    AllowMultiple   = false,
                    Title           = message.Title,
                    Filters         = GetOpenFilters(message.FileType == FileType.ImportedImage),
                    Directory       = null != message.ExistingFile ? Path.GetDirectoryName(message.ExistingFile) : null,
                    InitialFileName = null != message.ExistingFile ? Path.GetFileName(message.ExistingFile) : null,
                };

                string[] filenames = await dialog.ShowAsync(MainWindow);

                if (null != filenames && filenames.Length > 0 && !string.IsNullOrWhiteSpace(filenames[0]))
                {
                    filename = filenames[0];
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(filename);
            }
        }
Exemplo n.º 8
0
        public void OnLoaded()
        {
            Task.Factory.StartNew(async() =>
            {
                try
                {
                    IsIdle = false;

                    AppVM.TryHandleFailedUserConfigLoad();

                    if (IsFirstRun)
                    {
                        FirstRun();
                    }

                    if (UpdateUtils.UpdateEnabled && UpdateUtils.CheckUpdateOnStart && UpdateUtils.IsConnectedToInternet)
                    {
                        await UpdateUtils.UpdateCheckAsync(true, false);
                    }
                }
                catch (Exception ex)
                {
                    ExceptionUtils.HandleException(ex);
                }
                finally
                {
                    IsIdle = true;
                }
            });
        }
Exemplo n.º 9
0
        private static void ShowLoadGame(LoadGameMessage message)
        {
            GameRecording gr = null;

            try
            {
                OpenFileDialog dialog = new OpenFileDialog
                {
                    Title        = "Open Game",
                    DefaultExt   = ".pgn",
                    Filter       = "All Supported Files|*.pgn;*.sgf|Portable Game Notation|*.pgn|BoardSpace Smart Game Format|*.sgf",
                    AddExtension = true
                };

                if (dialog.ShowDialog(Application.Current.MainWindow).GetValueOrDefault())
                {
                    using (Stream inputStream = dialog.OpenFile())
                    {
                        string fileName = dialog.SafeFileName;
                        gr = Path.GetExtension(fileName).ToLower() == ".sgf" ? GameRecording.LoadSGF(inputStream, fileName) : GameRecording.LoadPGN(inputStream, fileName);
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(gr);
            }
        }
Exemplo n.º 10
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            if (null != VM.AppVM.EngineExceptionOnStart)
            {
                ExceptionUtils.HandleException(new Exception("Unable to start the external engine so used the internal one instead.", VM.AppVM.EngineExceptionOnStart));
            }

            VM.AppVM.EngineWrapper.OptionsList();
        }
Exemplo n.º 11
0
 private static void LaunchUrl(LaunchUrlMessage message)
 {
     try
     {
         Process.Start(message.Url, null);
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 12
0
 private static void ShowConfirmation(ConfirmationMessage message)
 {
     try
     {
         MessageBoxResult result = MessageBox.Show(message.Message, "Mzinga", MessageBoxButton.YesNo);
         message.Process(result == MessageBoxResult.Yes);
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 13
0
 private void App_Exit(object sender, ExitEventArgs e)
 {
     try
     {
         AppVM.Close();
         MessageHandlers.UnregisterMessageHandlers(this);
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 14
0
        void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                // Fix annoying Windows 8.1 tablet forced maximization
                WindowState = WindowState.Normal;

                ((MainViewModelExtended)DataContext).OnLoaded();
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
        }
Exemplo n.º 15
0
 private void App_Exit(object sender, ExitEventArgs e)
 {
     try
     {
         SaveConfig();
         AppVM.EngineWrapper.StopEngine();
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
     finally
     {
         MessageHandlers.UnregisterMessageHandlers(this);
     }
 }
Exemplo n.º 16
0
        private void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if (null != VM.AppVM.EngineExceptionOnStart)
                {
                    throw new Exception("Unable to start the external engine so used the internal one instead.", VM.AppVM.EngineExceptionOnStart);
                }

                VM.OnLoaded();
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
        }
Exemplo n.º 17
0
        private static void ShowEngineConsole(EngineConsoleMessage message)
        {
            try
            {
                EngineConsoleWindow window = EngineConsoleWindow.Instance;

                window.Show();

                if (!window.IsActive)
                {
                    window.Activate();
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
        }
Exemplo n.º 18
0
        public void HandleUserConfigLoadException(Exception ex)
        {
            string userFile = UserConfigPath;

            Messenger.Default.Send(new ConfirmationMessage(Strings.ResetAndBackupUserConfigConfirmationMessage, (confirmed) =>
            {
                if (!confirmed)       // No, exit app
                {
                    Exit -= App_Exit; // Remove the handler so we don't overwrite the corruupt config with whatever we may have loaded
                    Shutdown(1);
                }
                else // Yes, backup and continue
                {
                    string backupFile = ResetAndBackupUserConfig(userFile);
                    string message    = string.Format(Strings.ResetAndBackupUserConfigBackupFileMessageFormat, backupFile);
                    ExceptionUtils.HandleException(new Exception(message, ex));
                }
            }));
        }
Exemplo n.º 19
0
 private static async Task ShowAceptRejectDialogAsync <TWindow, TViewModel>(ShowAcceptRejectViewModelMessage <TViewModel> message) where TWindow : Window, IView <TViewModel>, new() where TViewModel : AcceptRejectViewModelBase
 {
     try
     {
         var window = new TWindow
         {
             VM = message.ViewModel
         };
         await window.ShowDialog(MainWindow);
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
     finally
     {
         message.Process();
     }
 }
Exemplo n.º 20
0
        private void FirstRun()
        {
            AppVM.DoOnUIThread(() =>
            {
                // Turn off first-run so it doesn't run next time
                ViewerConfig.FirstRun = false;

                Messenger.Default.Send(new ConfirmationMessage(string.Join(Environment.NewLine + Environment.NewLine, "Welcome to Mzinga.Viewer!", "Would you like to check for updates when Mzinga.Viewer starts?", "You can change your mind later in Viewer Options."), (enableAutoUpdate) =>
                {
                    try
                    {
                        ViewerConfig.CheckUpdateOnStart = enableAutoUpdate;
                    }
                    catch (Exception ex)
                    {
                        ExceptionUtils.HandleException(ex);
                    }
                }));
            });
        }
Exemplo n.º 21
0
 private static void ShowGameMetadata(GameMetadataMessage message)
 {
     try
     {
         GameMetadataWindow window = new GameMetadataWindow
         {
             DataContext = message.GameMetadataVM,
             Owner       = Application.Current.MainWindow,
         };
         message.GameMetadataVM.RequestClose += (sender, e) =>
         {
             window.Close();
         };
         window.ShowDialog();
         message.Process();
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 22
0
 private static void ShowViewerConfig(ViewerConfigMessage message)
 {
     try
     {
         ViewerConfigWindow window = new ViewerConfigWindow
         {
             DataContext = message.ViewerConfigVM,
             Owner       = Application.Current.MainWindow,
         };
         message.ViewerConfigVM.RequestClose += (sender, e) =>
         {
             window.Close();
         };
         window.ShowDialog();
         message.Process();
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 23
0
 private static void ShowInformation(InformationMessage message)
 {
     try
     {
         InformationWindow window = new InformationWindow
         {
             DataContext = message.InformationVM,
             Owner       = Application.Current.MainWindow,
         };
         message.InformationVM.RequestClose += (sender, e) =>
         {
             window.Close();
         };
         window.Closed += (sender, args) =>
         {
             message.Process();
         };
         window.Show();
     }
     catch (Exception ex)
     {
         ExceptionUtils.HandleException(ex);
     }
 }
Exemplo n.º 24
0
        private static async Task ShowSaveFileDialogAsync(SaveFileMessage message)
        {
            string filename = null;

            try
            {
                var dialog = new SaveFileDialog()
                {
                    Title            = message.Title,
                    Filters          = GetFilters(message.FileType),
                    DefaultExtension = GetDefaultExtension(message.FileType),
                };

                filename = await dialog.ShowAsync(MainWindow);
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(ex);
            }
            finally
            {
                message.Process(filename);
            }
        }
Exemplo n.º 25
0
        protected override Task ExportDiagramAsync(int diagramIndex)
        {
            return(Task.Factory.StartNew(() =>
            {
                try
                {
                    ObservableDiagram od = DiagramsToExport[diagramIndex];

                    string svgText = od.SvgText;
                    int width = od.TotalWidth;
                    int height = od.TotalHeight;

                    string filePath = GetFullFilePath(diagramIndex, OverwriteFiles);

                    ImageUtils.ExportImageFile(svgText, width, height, ExportFormat, ScaleFactor, filePath);

                    _createdFiles.Add(filePath);
                }
                catch (Exception ex)
                {
                    ExceptionUtils.HandleException(ex);
                }
            }));
        }
Exemplo n.º 26
0
        public void OnLoaded()
        {
            Task.Factory.StartNew(async() =>
            {
                try
                {
                    AppVM.DoOnUIThread(() =>
                    {
                        IsIdle = false;
                    });

                    if (ViewerConfig.FirstRun)
                    {
                        FirstRun();
                    }

#if WINDOWS_WPF
                    if (ViewerConfig.CheckUpdateOnStart && UpdateUtils.IsConnectedToInternet)
                    {
                        await UpdateUtils.UpdateCheckAsync(true, false);
                    }
#endif
                }
                catch (Exception ex)
                {
                    ExceptionUtils.HandleException(ex);
                }
                finally
                {
                    AppVM.DoOnUIThread(() =>
                    {
                        IsIdle = true;
                    });
                }
            });
        }
Exemplo n.º 27
0
        public static void UpdateCheck(bool confirmUpdate, bool showUpToDate)
        {
            try
            {
                IsCheckingforUpdate = true;

                List <UpdateInfo> updateInfos = GetLatestUpdateInfos();

                ReleaseChannel targetReleaseChannel = GetReleaseChannel();

                ulong maxVersion = LongVersion(AppVM.FullVersion);

                UpdateInfo latestVersion = null;

                bool updateAvailable = false;
                foreach (UpdateInfo updateInfo in updateInfos)
                {
                    if (updateInfo.ReleaseChannel == targetReleaseChannel)
                    {
                        ulong updateVersion = LongVersion(updateInfo.Version);

                        if (updateVersion > maxVersion)
                        {
                            updateAvailable = true;
                            latestVersion   = updateInfo;
                            maxVersion      = updateVersion;
                        }
                    }
                }

                if (updateAvailable)
                {
                    if (confirmUpdate)
                    {
                        string message = string.Format("Mzinga v{0} is available. Would you like to update now?", latestVersion.Version);
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new ConfirmationMessage(message, (confirmed) =>
                            {
                                try
                                {
                                    if (confirmed)
                                    {
                                        Messenger.Default.Send(new LaunchUrlMessage(latestVersion.Url));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ExceptionUtils.HandleException(new UpdateException(ex));
                                }
                            }));
                        });
                    }
                    else
                    {
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new LaunchUrlMessage(latestVersion.Url));
                        });
                    }
                }
                else
                {
                    if (showUpToDate)
                    {
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new InformationMessage("Mzinga is up-to-date."));
                        });
                    }
                }
            }
            catch (WebException ex)
            {
                if (ex.Status == WebExceptionStatus.Timeout)
                {
                    TimeoutMS = (int)Math.Min(TimeoutMS * 1.5, MaxTimeoutMS);
                }

                if (showUpToDate)
                {
                    ExceptionUtils.HandleException(new UpdateException(ex));
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(new UpdateException(ex));
            }
            finally
            {
                IsCheckingforUpdate = false;
            }
        }
Exemplo n.º 28
0
        public static void UpdateCheck(bool confirmUpdate, bool showUpToDate)
        {
            try
            {
                IsCheckingforUpdate = true;

                List <InstallerInfo> installerInfos = GetLatestInstallerInfos();

                ReleaseChannel targetReleaseChannel = GetReleaseChannel();

                ulong maxVersion = LongVersion(AppViewModel.FullVersion);

                InstallerInfo latestVersion = null;

                bool updateAvailable = false;
                foreach (InstallerInfo installerInfo in installerInfos)
                {
                    if (installerInfo.ReleaseChannel == targetReleaseChannel)
                    {
                        ulong installerVersion = LongVersion(installerInfo.Version);

                        if (installerVersion > maxVersion)
                        {
                            updateAvailable = true;
                            latestVersion   = installerInfo;
                            maxVersion      = installerVersion;
                        }
                    }
                }

                SetLastUpdateCheck(DateTime.Now);

                if (updateAvailable)
                {
                    if (confirmUpdate)
                    {
                        string message = string.Format("Mzinga v{0} is available. Would you like to update now?", latestVersion.Version);
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new ConfirmationMessage(message, (confirmed) =>
                            {
                                try
                                {
                                    if (confirmed)
                                    {
                                        Update(latestVersion);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ExceptionUtils.HandleException(new UpdateException(ex));
                                }
                            }));
                        });
                    }
                    else
                    {
                        Update(latestVersion);
                    }
                }
                else
                {
                    if (showUpToDate)
                    {
                        AppVM.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new InformationMessage("Mzinga is up-to-date."));
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(new UpdateException(ex));
            }
            finally
            {
                IsCheckingforUpdate = false;
            }
        }
Exemplo n.º 29
0
        public static void UpdateCheck(bool confirmUpdate, bool showUpToDate)
        {
            try
            {
                IsCheckingforUpdate = true;

                List <UpdateInfo> updateInfos = GetLatestUpdateInfos();

                ReleaseChannel targetReleaseChannel = GetReleaseChannel();

                ulong maxVersion = LongVersion(AppVM.FullVersion);

                UpdateInfo latestVersion = null;

                bool updateAvailable = false;
                foreach (UpdateInfo updateInfo in updateInfos)
                {
                    if (updateInfo.ReleaseChannel == targetReleaseChannel)
                    {
                        ulong installerVersion = LongVersion(updateInfo.Version);

                        if (installerVersion > maxVersion)
                        {
                            updateAvailable = true;
                            latestVersion   = updateInfo;
                            maxVersion      = installerVersion;
                        }
                    }
                }

                LastUpdateCheck = DateTime.Now;

                if (updateAvailable)
                {
                    if (confirmUpdate)
                    {
                        string message = string.Format(Strings.ChordiousUpdateAvailableUpdateNowMessageFormat, latestVersion.Version);
                        AppVM.AppView.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new ConfirmationMessage(message, (confirmed) =>
                            {
                                try
                                {
                                    if (confirmed)
                                    {
                                        Messenger.Default.Send(new LaunchUrlMessage(latestVersion.Url));
                                    }
                                }
                                catch (Exception ex)
                                {
                                    ExceptionUtils.HandleException(new UpdateException(ex));
                                }
                            }));
                        });
                    }
                    else
                    {
                        AppVM.AppView.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new LaunchUrlMessage(latestVersion.Url));
                        });
                    }
                }
                else
                {
                    if (showUpToDate)
                    {
                        AppVM.AppView.DoOnUIThread(() =>
                        {
                            Messenger.Default.Send(new ChordiousMessage(Strings.ChordiousUpdateNotAvailableMessage));
                        });
                    }
                }
            }
            catch (Exception ex)
            {
                ExceptionUtils.HandleException(new UpdateException(ex));
            }
            finally
            {
                IsCheckingforUpdate = false;
            }
        }