Exemplo n.º 1
0
        public async Task Save(Stream stream, string path)
        {
            var api = await GetApi();

            var node = await api.GetNodeByPath(path);

            AmazonNode result;

            if (node != null)
            {
                result = await api.Files.Overwrite(node.id, () => stream);
            }
            else // not found: creating new
            {
                var folderName = CloudPath.GetDirectoryName(path);
                var fileName   = CloudPath.GetFileName(path);

                var folder = await api.GetNodeByPath(folderName);

                if (folder == null)
                {
                    throw new InvalidOperationException(string.Format("Folder does not exist: {0}", folderName));
                }

                result = await api.Files.UploadNew(folder.id, fileName, () => stream);
            }

            if (result == null)
            {
                throw new InvalidOperationException("Save to Amazon Drive failed.");
            }
        }
Exemplo n.º 2
0
        public async Task Copy(string sourcePath, string destPath)
        {
            var api = await OneDriveHelper.GetApi(_account);

            var escapedpath = Uri.EscapeDataString(sourcePath);

            var destFolder   = Uri.EscapeDataString(CloudPath.GetDirectoryName(destPath));
            var destFilename = CloudPath.GetFileName(destPath);
            var destItem     = await api.Drive.Root.ItemWithPath(destFolder).Request().GetAsync();

            if (destItem == null)
            {
                throw new FileNotFoundException("OneDrive: Folder not found.", destFolder);
            }

            await api
            .Drive
            .Root
            .ItemWithPath(escapedpath)
            .Copy(destFilename, new ItemReference {
                Id = destItem.Id
            })
            .Request(/*new[] {new HeaderOption("Prefer", "respond-async"), }*/)
            .PostAsync();
        }
Exemplo n.º 3
0
        private async Task Copy(string path, FolderContent content, bool postDelete)
        {
            var filesToCopy = new List <(File File, S3Object S3Object, string DestinationKey)>();

            foreach (var folder in content.Folders)
            {
                var originalPath = new CloudPath(folder.Path, folder.Name);

                var newFolderKey         = $"{GetAbsolutePath(path)}/{folder.Name}";
                var destinationFolderKey = await GetNewDirectoryPathIfExists(newFolderKey, newFolderKey);

                var folderKey = GetAbsolutePath(originalPath.TargetPath);

                var files = await GetInnerFolderFiles(folderKey);

                filesToCopy.AddRange(files.Select(x => (x.File, x.S3Object, $"{destinationFolderKey}{x.S3Object.Key.Substring(folderKey.Length)}")));
            }

            if (content.Files.Any())
            {
                var response = await ListContainerObjects(GetAbsolutePath(path));

                filesToCopy.AddRange(content.Files.Select(x => (x, new S3Object {
                    Key = GetAbsolutePath(x.Path)
                }, GetNewFilePathIfExists(response.S3Objects.Select(x => x.Key), $"{GetAbsolutePath(path)}/{x.Name}", $"{GetAbsolutePath(path)}/{x.Name}"))));
            }

            await CopyFile(filesToCopy, postDelete);
        }
        public async Task <bool> Save(Stream stream, string path)
        {
            if (stream == null)
            {
                throw new ArgumentNullException("stream");
            }
            if (path == null)
            {
                throw new ArgumentNullException("path");
            }

            var container = await GetDefaultContainer();

            var client = await GetClient();

            var normalizedPath = path.StartsWith("/") ? path.Remove(0, 1) : path;
            var folderName     = CloudPath.GetDirectoryName(normalizedPath);

            var folder = await client.GetObjects(container, folderName);

            if (folder == null || !folder.Any())
            {
                throw new InvalidOperationException(string.Format("Folder does not exist: {0}", folderName));
            }

            var isOk = await client.UploadObject(container, normalizedPath, stream);

            return(isOk);
        }
Exemplo n.º 5
0
        public async Task CreateFile(FileContent file)
        {
            var cloudPath        = new CloudPath(file.Path, file.Filename);
            var fileAbsolutePath = GetAbsolutePath(cloudPath.TargetPath);

            var extension = Path.GetExtension(file.Filename);

            if (!AllowedExtensions.Contains(extension) && !file.ContentType.Contains("image"))
            {
                throw new StorageException("Invalid file(s). Note that allowed type files are all image types, video type mp4, webm, ogg, audio types mp3, ogg, wav, pdf, xlsx, xls, docx, ppt, pptx, zip, xml, html, css, js, json, woff and dicos files.");
            }

            var folderKey = GetAbsolutePath(cloudPath.Path);

            var response = await ListContainerObjects(folderKey);

            var newFileKey = GetNewFilePathIfExists(response.S3Objects.Select(x => x.Key), fileAbsolutePath, fileAbsolutePath);

            var putRequest = new PutObjectRequest
            {
                BucketName  = _amazonS3Config.Bucket,
                Key         = newFileKey,
                InputStream = new MemoryStream(file.FileBytes)
            };

            await _amazonS3.PutObjectAsync(putRequest);
        }
        public async Task Copy(string sourcePath, string destPath)
        {
            var api = await GetApi();

            var sourceFile = await api.GetFileByPath(sourcePath);

            if (sourceFile == null)
            {
                throw new FileNotFoundException("Google Drive: File not found.", sourcePath);
            }

            var destFolder   = CloudPath.GetDirectoryName(destPath);
            var parentFolder = await api.GetFileByPath(destFolder);

            if (parentFolder == null)
            {
                throw new FileNotFoundException("Google Drive: File not found.", destFolder);
            }

            var destFilename = CloudPath.GetFileName(destPath);
            var destFile     = new File
            {
                Name    = destFilename,
                Parents = new[] { parentFolder.Id }
            };

            var result = await api.Files.Copy(destFile, sourceFile.Id).ExecuteAsync();
        }
        public async Task <bool> Save(Stream stream, string path)
        {
            var api = await GetApi();

            IUploadProgress progress;

            var file = await api.GetFileByPath(path);

            if (file != null)
            {
                progress = await api.Files.Update(null, file.Id, stream, "application/octet-stream").UploadAsync();
            }
            else // not found: creating new
            {
                var folderName = CloudPath.GetDirectoryName(path);
                var fileName   = CloudPath.GetFileName(path);

                var folder = await api.GetFileByPath(folderName);

                if (folder == null)
                {
                    throw new InvalidOperationException(string.Format("Folder does not exist: {0}", folderName));
                }

                file = new File()
                {
                    Name    = fileName,
                    Parents = new[] { folder.Id },
                };

                progress = await api.Files.Create(file, stream, "application/octet-stream").UploadAsync();
            }

            return(progress.Status == UploadStatus.Completed && progress.Exception == null);
        }
Exemplo n.º 8
0
        private async Task Copy(string path, FolderContent content, bool postDelete)
        {
            foreach (var folder in content.Folders)
            {
                var deleted      = 0;
                var originalPath = new CloudPath(folder.Path, folder.Name);

                var absolutePath = $"{GetAbsolutePath(path)}/{folder.Name}";
                var toDirectory  = GetNewDirectoryPathIfExists(absolutePath, absolutePath);

                Directory.CreateDirectory(toDirectory);

                var directory        = GetAbsolutePath(originalPath.TargetPath);
                var directoryContent = GetInnerFolderFiles(directory);

                foreach (var fileTuple in directoryContent)
                {
                    Directory.CreateDirectory($"{toDirectory}{fileTuple.FileInfo.DirectoryName.Substring(directory.Length)}");
                    var toPath = $"{toDirectory}{fileTuple.FileInfo.FullName.Substring(directory.Length)}";
                    await Task.Run(() =>
                    {
                        if (postDelete)
                        {
                            System.IO.File.Move(fileTuple.FileInfo.FullName, toPath);
                        }
                        else
                        {
                            System.IO.File.Copy(fileTuple.FileInfo.FullName, toPath);
                        }

                        deleted++;
                    });
                }

                if (postDelete && deleted == directoryContent.Count)
                {
                    Directory.Delete(directory, true);
                }
            }

            foreach (var file in content.Files)
            {
                var cloudPath = new CloudPath(file.Path, file.Name);
                var filePath  = GetAbsolutePath(cloudPath.TargetPath);
                var toPath    = GetNewFilePathIfExists($"{GetAbsolutePath(path)}/{file.Name}", $"{GetAbsolutePath(path)}/{file.Name}");

                await Task.Run(() =>
                {
                    if (postDelete)
                    {
                        System.IO.File.Move(filePath, toPath);
                    }
                    else
                    {
                        System.IO.File.Copy(filePath, toPath);
                    }
                });
            }
        }
Exemplo n.º 9
0
        public async Task CreateFiles(IEnumerable <FileContent> files)
        {
            foreach (var file in files)
            {
                var cloudPath = new CloudPath(file.Path, file.Filename);

                if (IsZip(file.FileBytes, file.Filename))
                {
                    var filenamePart = file.Filename.Split('.');
                    var newParts     = filenamePart.Take(filenamePart.Count() - 1).ToList();
                    var zipFolder    = string.Join(".", newParts);

                    var newFolderKey = string.IsNullOrWhiteSpace(cloudPath.Path) ? zipFolder : $"{cloudPath.Path}/{zipFolder}";
                    var folder       = await CreateFolder(newFolderKey);

                    using (var stream = new MemoryStream(file.FileBytes))
                    {
                        using (var archive = new ZipArchive(stream))
                        {
                            foreach (var entry in archive.Entries)
                            {
                                if (entry.Length > 0)
                                {
                                    var fileContent = new FileContent
                                    {
                                        ContentLength = (int)entry.Length,
                                        FileBytes     = ZipEntryToByteArray(entry),
                                        Filename      = entry.Name,
                                        ContentType   = GetContentType(entry.Name),
                                        Path          = $"{folder.Path}/{folder.Name}"
                                    };

                                    var extension = Path.GetExtension(fileContent.Filename);

                                    if (!AllowedExtensions.Contains(extension) && !fileContent.ContentType.Contains("image"))
                                    {
                                        throw new StorageException("Invalid file(s). Note that allowed type files are all image types, video type mp4, webm, ogg, audio types mp3, ogg, wav, pdf, xlsx, xls, docx, ppt, pptx, zip, xml, html, css, js, json, woff and dicos files.");
                                    }

                                    if (entry.FullName.Length > entry.Name.Length)
                                    {
                                        fileContent.Path = $"{folder.Path}/{folder.Name}/{entry.FullName.Substring(0, entry.FullName.Length - entry.Name.Length)}";
                                    }

                                    await CreateFile(fileContent);
                                }
                            }
                        }
                    }
                }
                else
                {
                    await CreateFile(file);
                }
            }
        }
        public CloudSubLayout()
        {
            Cloud1Path = new CloudPath((mainLayer, x, y) => mainLayer.DrawImage(Assets.Images.Layouts.Cloud1, x, y));
            Cloud2Path = new CloudPath((mainLayer, x, y) => mainLayer.DrawImage(Assets.Images.Layouts.Cloud2, x, y));
            Cloud3Path = new CloudPath((mainLayer, x, y) => mainLayer.DrawImage(Assets.Images.Layouts.Cloud3, x, y));

            Cloud1Path.Start();
            Cloud2Path.Start();
            Cloud3Path.Start();
            BgSlidingState = BgSlidingState.Left;
        }
Exemplo n.º 11
0
        private Folder ToFolder(string folderKey)
        {
            var isMainContainer = folderKey == GetAbsolutePath();
            var cloudPath       = new CloudPath(isMainContainer ? "/" : folderKey.Substring(GetAbsolutePath().Length));

            return(new Folder
            {
                Name = isMainContainer || cloudPath.Target == null ? "" : cloudPath.Target,
                Path = isMainContainer ? null : $"/{cloudPath.Path}"
            });
        }
        private string GetIconKey(string filename)
        {
            var extension = CloudPath.GetExtension(filename);

            if (string.IsNullOrEmpty(extension))
            {
                return(IconDocument);
            }

            return(extension.ToLower() == ".kdbx" ? IconDatabase : IconDocument);
        }
Exemplo n.º 13
0
        public async Task <bool> Save(Stream stream, string path)
        {
            var api = await GetApi();

            var pid = await GetHomeId();

            var pathname = CloudPath.GetDirectoryName(path);
            var filename = CloudPath.GetFileName(path);

            var item = await api.File.Upload(filename, pathname, pid).ExecuteAsync(stream);

            return(item != null);
        }
Exemplo n.º 14
0
        private Folder ToFolder(string directory)
        {
            var directoryInfo   = new DirectoryInfo(directory);
            var isMainContainer = directory == GetAbsolutePath();
            var directoryPath   = new CloudPath(isMainContainer ? "/" : directory.Substring(GetAbsolutePath().Length));

            return(new Folder
            {
                Created = directoryInfo.CreationTime,
                Edited = directoryInfo.LastWriteTime,
                Name = isMainContainer || directoryPath.Target == null ? "" : directoryPath.Target,
                Path = isMainContainer ? null : $"/{directoryPath.Path}"
            });
        }
Exemplo n.º 15
0
        private File ToFile(string directory, FileInfo fileInfo)
        {
            var filePath = new CloudPath(directory.Substring(GetAbsolutePath().Length));

            return(new File
            {
                Created = fileInfo?.CreationTime ?? new DateTime(2017, 1, 1),
                ContentType = GetContentType(directory),
                Edited = fileInfo?.LastWriteTime,
                Name = filePath.Target,
                Path = $"/{filePath.Path}/".Replace("//", "/"),
                Size = fileInfo.Length,
                Url = GetUrl(filePath.TargetPath)
            });
        }
Exemplo n.º 16
0
        private File ToFile(S3Object file)
        {
            var cloudPath = new CloudPath(file.Key.Substring(GetAbsolutePath().Length));

            return(new File
            {
                Created = file?.LastModified ?? new DateTime(2017, 1, 1),
                ContentType = GetContentType(file.Key),
                Edited = file?.LastModified,
                Name = cloudPath.Target,
                Path = $"/{cloudPath.Path}/".Replace("//", "/"),
                Size = file.Size,
                Url = GetS3PreSignedUrl(cloudPath.TargetPath),
            });
        }
Exemplo n.º 17
0
        public async Task Save(Stream stream, string path)
        {
            var api = await GetApi();

            var pid = await GetHomeId();

            var pathname = CloudPath.GetDirectoryName(path);
            var filename = CloudPath.GetFileName(path);

            var item = await api.File.Upload(filename, String.IsNullOrEmpty(pathname)?null : pathname, pid, UploadMode.CreateOrUpdate).ExecuteAsync(stream);

            if (item == null)
            {
                throw new InvalidOperationException("HiDrive: Save failed.");
            }
        }
Exemplo n.º 18
0
        private async Task <bool> TryBackupRemote(string path, DateTime saveDateTime)
        {
            var backupFilename = GetBackupFilename(CloudPath.GetFileName(path), saveDateTime);
            var backupFolder   = CloudPath.GetDirectoryName(path);
            var backupPath     = CloudPath.Combine(backupFolder, backupFilename);

            try
            {
                await this.BaseProvider.Copy(path, backupPath);

                return(true);
            }
            catch (Exception)
            {
                // Try to copy file to backup: it fails if file is saved for the first time
                return(false);
            }
        }
Exemplo n.º 19
0
        public async Task CreateFile(FileContent file)
        {
            var path             = new CloudPath(file.Path, file.Filename);
            var fileAbsolutePath = GetAbsolutePath(path.TargetPath);

            var extension = Path.GetExtension(file.Filename);

            if (!AllowedExtensions.Contains(extension) && !file.ContentType.Contains("image"))
            {
                throw new StorageException("Invalid file(s). Note that allowed type files are all image types, video type mp4, webm, ogg, audio types mp3, ogg, wav, pdf, xlsx, xls, docx, ppt, pptx, zip, xml, html, css, js, json, woff and dicos files.");
            }

            var newFilePath = GetNewFilePathIfExists(fileAbsolutePath, fileAbsolutePath);
            await Task.Run(() =>
            {
                System.IO.File.WriteAllBytes(newFilePath, file.FileBytes);
            });
        }
Exemplo n.º 20
0
        public async Task BulkDelete(FolderContent content)
        {
            var keys = new List <Guid>();

            foreach (var folder in content.Folders)
            {
                var cloudPath = new CloudPath(folder.Path, folder.DeletedName);
                keys.AddRange(content.Folders.Select(x => Guid.Parse(cloudPath.TargetPath)));
                await DeleteFolder(cloudPath.TargetPath);
            }

            foreach (var file in content.Files)
            {
                var cloudPath = new CloudPath(file.Path, file.DeletedName);
                keys.AddRange(content.Folders.Select(x => Guid.Parse(cloudPath.TargetPath)));
                await DeleteFile(cloudPath.TargetPath);
            }
        }
Exemplo n.º 21
0
        private async Task RotateRemote(string path)
        {
            var folder = CloudPath.GetDirectoryName(path);
            var items  = await this.BaseProvider.GetChildrenByParentPath(folder);

            var pattern = "^" + Regex.Escape(GetBackupFilenamePattern(path))
                          .Replace("\\*", ".*")
                          .Replace("\\?", ".") + "$";

            var regex = new Regex(pattern);
            var files = items.Where(item => regex.IsMatch(item.Name)).Select(item => item.Name).ToArray();

            Array.Sort(files);

            for (var i = 0; i < files.Length - _configService.PluginConfiguration.BackupCopies; i++)
            {
                await this.BaseProvider.Delete(CloudPath.Combine(folder, files[i]));
            }
        }
Exemplo n.º 22
0
        public async Task Save(Stream stream, string path)
        {
            using (var api = AmazonS3Helper.GetApi(_account))
            {
                string bucket;
                string filename;

                GetBucketAndKey(path, out bucket, out filename);

                try // Does parent folder exists, if not root?
                {
                    var folderName = CloudPath.GetDirectoryName(filename);

                    if (!string.IsNullOrEmpty(folderName))
                    {
                        await api.GetObjectMetadataAsync(bucket, folderName + "/");
                    }
                }
                catch (AmazonS3Exception ex)
                {
                    //if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                    //    throw new FileNotFoundException("Amazon S3: File not found.", );

                    //status wasn't not found, so throw the exception
                    throw;
                }

                var request = new PutObjectRequest
                {
                    BucketName  = bucket,
                    Key         = filename,
                    InputStream = stream
                };

                var response = await api.PutObjectAsync(request);

                if (response == null)
                {
                    throw new InvalidOperationException("Save to Amazon S3 failed.");
                }
            }
        }
        public async Task Save(Stream stream, string path)
        {
            var api = await GetApi();

            IUploadProgress progress;

            var file = await api.GetFileByPath(path);

            if (file != null)
            {
                progress = await api.Files.Update(null, file.Id, stream, "application/octet-stream").UploadAsync();
            }
            else // not found: creating new
            {
                var folderName = CloudPath.GetDirectoryName(path);
                var fileName   = CloudPath.GetFileName(path);

                file = new File()
                {
                    Name = fileName
                };

                if (!string.IsNullOrEmpty(folderName))
                {
                    var folder = await api.GetFileByPath(folderName);

                    if (folder == null)
                    {
                        throw new InvalidOperationException(string.Format("Folder does not exist: {0}", folderName));
                    }

                    file.Parents = new[] { folder.Id };
                }

                progress = await api.Files.Create(file, stream, "application/octet-stream").UploadAsync();
            }

            if (progress.Status != UploadStatus.Completed || progress.Exception != null)
            {
                throw new InvalidOperationException("Save to Google Drive failed.");
            }
        }
Exemplo n.º 24
0
        public async Task Copy(string sourcePath, string destPath)
        {
            var api = await GetApi();

            var node = await api.GetNodeByPath(sourcePath);

            var destFilename = CloudPath.GetFileName(destPath);
            var destFolder   = CloudPath.GetDirectoryName(destPath);

            if (!sourcePath.StartsWith(destFolder))
            {
                throw new InvalidOperationException("Amazon Drive: Copy failed - Dest must be in the same folder as source.");
            }

            var result = await api.Nodes.Rename(node.id, destFilename);

            if (result == null)
            {
                throw new InvalidOperationException("Amazon Drive: Copy failed.");
            }
        }
Exemplo n.º 25
0
        public async Task Save(Stream stream, string path)
        {
            var api = await GetApi();

            BoxFile item;

            var file = await api.GetFileByPath(path);

            if (file != null)
            {
                item = await api.FilesManager.UploadNewVersionAsync(file.Name, file.Id, stream, file.ETag);
            }
            else // not found: creating new
            {
                var folderName = CloudPath.GetDirectoryName(path);
                var fileName   = CloudPath.GetFileName(path);

                var folder = await api.GetFileByPath(folderName);

                if (folder == null)
                {
                    throw new InvalidOperationException(string.Format("Folder does not exist: {0}", folderName));
                }

                var request = new BoxFileRequest()
                {
                    Name   = fileName,
                    Parent = new BoxRequestEntity {
                        Id = folder.Id
                    },
                };

                item = await api.FilesManager.UploadAsync(request, stream);
            }

            if (item == null)
            {
                throw new InvalidOperationException("Save to Box failed.");
            }
        }
Exemplo n.º 26
0
        public IActionResult CreateCampaign([FromBody] CreateCampaignRequest request)
        {
            if (request.campaignSize >= 1 && request.campaignSize <= 30000)
            {
                var campaign = new Campaign()
                {
                    CampaignName = request.campaignName,
                    CampaignSize = request.campaignSize
                };

                var cloudPath = new CloudPath(_config.GetSection("SeedBlobUrl")["BlobUrl"]);
                var sql       = new SQL(_config.GetConnectionString("SQLConnnection"));

                var offsetUpdate = sql.UpdateOffset(campaign.CampaignSize);
                var listOfCodes  = cloudPath.GenerateCodesFromCloudFile(offsetUpdate);

                sql.CreateCampaign(listOfCodes, campaign);

                return(Ok(campaign));
            }
            return(BadRequest());
        }
        private int GetIconIndex(string filename)
        {
            var extension = CloudPath.GetExtension(filename);

            if (string.IsNullOrEmpty(extension))
            {
                return(-1);
            }

            if (!m_ilFiletypeIcons.Images.ContainsKey(extension))
            {
                var image = IconHelper.IconFromExtension(extension, IconHelper.SystemIconSize.Small);
                if (image == null)
                {
                    return(0);
                }

                m_ilFiletypeIcons.Images.Add(extension, image);
            }

            return(m_ilFiletypeIcons.Images.IndexOfKey(extension));
        }
        public async Task <bool> Save(Stream stream, string path)
        {
            using (var api = AmazonS3Helper.GetApi(_account))
            {
                string bucket;
                string filename;

                GetBucketAndKey(path, out bucket, out filename);

                try // Does parent folder exists?
                {
                    var folderName  = CloudPath.GetDirectoryName(filename);
                    var getResponse = await api.GetObjectMetadataAsync(bucket, folderName + "/");
                }
                catch (AmazonS3Exception ex)
                {
                    if (ex.StatusCode == System.Net.HttpStatusCode.NotFound)
                    {
                        return(false);
                    }

                    //status wasn't not found, so throw the exception
                    throw;
                }

                var request = new PutObjectRequest
                {
                    BucketName  = bucket,
                    Key         = filename,
                    InputStream = stream
                };

                var response = await api.PutObjectAsync(request);

                return(response != null);
            }
        }
Exemplo n.º 29
0
        public async Task Copy(string sourcePath, string destPath)
        {
            var api = await GetApi();

            var item = await api.GetFileByPath(sourcePath);

            if (item == null)
            {
                throw new FileNotFoundException("Box: File not found.", sourcePath);
            }

            var destFilename = CloudPath.GetFileName(destPath);
            var destFolder   = CloudPath.GetDirectoryName(destPath);

            var destParent = await api.GetFileByPath(destFolder);

            if (destParent == null)
            {
                throw new FileNotFoundException("Box: File not found.", destFolder);
            }

            var request = new BoxFileRequest
            {
                Id     = item.Id,
                Parent = new BoxFileRequest {
                    Id = destParent.Id
                },
                Name = destFilename,
            };

            var result = await api.FilesManager.CopyAsync(request);

            if (result == null)
            {
                throw new InvalidOperationException("Box: Copy failed.");
            }
        }
        private async void OnOkClick(object sender, EventArgs e)
        {
            DialogResult = DialogResult.None;
            if (string.IsNullOrEmpty(m_txtFilename.Text))
            {
                return;
            }

            // Ckech whether an extension is given for saving
            if (m_mode == Mode.Save && !CloudPath.HasExtension(m_txtFilename.Text))
            {
                m_txtFilename.Text = CloudPath.ChangeExtension(m_txtFilename.Text, "kdbx");
            }

            var filename = m_txtFilename.Text;

            if (string.IsNullOrEmpty(filename))
            {
                return;
            }

            var itemInfo = await GetItemInfo(m_selectedItem);

            var subItem = itemInfo.Children.SingleOrDefault(_ => _.Name == filename);

            switch (m_mode)
            {
            case Mode.Open:
                if (subItem == null)
                {
                    MessageService.ShowWarning("File/Folder does not exist.");
                }
                else
                {
                    switch (subItem.Type)
                    {
                    case StorageProviderItemType.File:
                        DialogResult = DialogResult.OK;
                        break;

                    case StorageProviderItemType.Folder:
                        SetWaitState(true);

                        m_txtFilename.Text = null;
                        m_stack.Push(subItem);
                        await SetSelectedItem(subItem);

                        SetWaitState(false);
                        break;
                    }
                }

                break;

            case Mode.Save:
                if (!m_provider.IsFilenameValid(filename))
                {
                    MessageService.ShowWarning("Filename is invalid.");
                }
                else if (subItem == null)
                {
                    DialogResult = DialogResult.OK;
                }
                else
                {
                    switch (subItem.Type)
                    {
                    case StorageProviderItemType.File:
                        var result = MessageService.AskYesNo("The file already exists.\nWould you like to override?",
                                                             "Overwrite file");

                        if (result)
                        {
                            DialogResult = DialogResult.OK;
                        }
                        break;

                    case StorageProviderItemType.Folder:
                        SetWaitState(true);

                        m_txtFilename.Text = null;
                        m_stack.Push(subItem);
                        await SetSelectedItem(subItem);

                        SetWaitState(false);
                        break;
                    }
                }

                break;

            default:
                throw new NotImplementedException();
            }
        }