コード例 #1
0
        public DataSource(ILogger logger, IDirectoryBrowserService directoryBrowserService, IMessageBoxService messageBoxService)
        {
            this.logger = logger;

            string filename = Path.Combine(AppContext.BaseDirectory, "ass_path.txt");

            if (File.Exists(filename))
            {
                string[] allLines = File.ReadAllLines(filename)
                                    ?.Select(x => x.Trim())
                                    ?.Where(x => x.Length > 0)
                                    ?.ToArray();

                if (allLines != null && allLines.Length > 0)
                {
                    dataFolderPath = allLines[0];
                    if (string.IsNullOrWhiteSpace(dataFolderPath) || Directory.Exists(dataFolderPath) == false)
                    {
                        dataFolderPath = null;
                    }
                }
            }

            if (dataFolderPath == null && directoryBrowserService != null && messageBoxService != null)
            {
                dataFolderPath = DetermineAssPath(directoryBrowserService, messageBoxService);
            }

            if (dataFolderPath == null)
            {
                if (messageBoxService != null)
                {
                    messageBoxService.Show(new MessageBoxServiceOptions
                    {
                        MessageBoxText = "Data source is missing, the application will exit.",
                        Title          = "Application will exit",
                        Buttons        = MessageBoxButton.OK,
                        Icon           = MessageBoxImage.Error
                    });
                }

                throw new InvalidDataSourceException();
            }

            LoadData();
        }
コード例 #2
0
        private string DetermineAssPath(IDirectoryBrowserService directoryBrowserService, IMessageBoxService messageBoxService)
        {
            string selectedPath;

            bool showIntroduction = true;

            while (true)
            {
                while (true)
                {
                    if (showIntroduction)
                    {
                        showIntroduction = false;

                        MessageBoxResult messageBoxResult = messageBoxService.Show(new MessageBoxServiceOptions
                        {
                            MessageBoxText = "Data from Athena's ASS application is required.\nClick OK to continue providing it, or Cancel to exit the application.",
                            Title          = "Data required",
                            Buttons        = MessageBoxButton.OKCancel,
                            DefaultResult  = MessageBoxResult.Cancel,
                            Icon           = MessageBoxImage.Question
                        });

                        if (messageBoxResult != MessageBoxResult.OK)
                        {
                            return(null);
                        }
                    }

                    var directoryOptions = new DirectoryBrowserServiceOptions
                    {
                        Description         = "Select the 'Data' directory of the Athena's ASS application",
                        ShowNewFolderButton = false
                    };

                    DialogResult directoryResult = directoryBrowserService.ShowDialog(directoryOptions);

                    if (directoryResult == DialogResult.OK)
                    {
                        selectedPath = directoryOptions.SelectedPath;
                        break;
                    }

                    showIntroduction = true;
                }

                if (File.Exists(Path.Combine(selectedPath, HeadsFilename)))
                {
                    return(selectedPath);
                }

                string altPath = Path.Combine(selectedPath, "Data");
                if (File.Exists(Path.Combine(altPath, HeadsFilename)))
                {
                    return(altPath);
                }

                messageBoxService.Show(new MessageBoxServiceOptions
                {
                    MessageBoxText = "Selected directory is invalid.",
                    Title          = "Invalid data source",
                    Buttons        = MessageBoxButton.OK,
                    DefaultResult  = MessageBoxResult.OK,
                    Icon           = MessageBoxImage.Warning
                });

                showIntroduction = false;
            }
        }
コード例 #3
0
 public DirectoryBrowserController(IDirectoryBrowserService directoryBrowserService)
 {
     _directoryBrowserService = directoryBrowserService;
 }