コード例 #1
0
        private void ExecuteAddFolder()
        {
            IStringRequest request = new StringRequest();

            if (Input.AskFolder(request))
            {
                string path = request.Input;

                if (IsDirectory(path) &&
                    Directory.Exists(path))
                {
                    var existing = FolderController.GetList().SingleOrDefault(f => f.Path == path);
                    if (existing == null)
                    {
                        IFolder folder = new Folder()
                        {
                            Path = path,
                            Name = Path.GetFileNameWithoutExtension(path)
                        };

                        folder = FolderController.Add(folder);

                        Folders.Add(folder);

                        ScanFolder(folder);
                    }
                    else
                    {
                        var retry = MessageBox.Show(
                            "Folder already added to library. Would you like to add another?",
                            "Folder in library",
                            MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);
                        if (retry == DialogResult.Yes)
                        {
                            ExecuteAddFolder();
                        }
                    }
                }
                else
                {
                    throw new InvalidOperationException("Not a valid directory");
                }
            }
        }