Esempio n. 1
0
        public async Task <TrmrkActionResult <DriveItem> > GetFolderAsync(string folderId)
        {
            var actionResult = ExecuteDriveItemCore(
                () =>
            {
                var entry  = new DirectoryInfo(folderId);
                var folder = GetDriveItem(entry);

                folder.ParentFolderId = Path.GetDirectoryName(entry.FullName);

                var driveItemsArr = entry.EnumerateFileSystemInfos(
                    ).Select(GetDriveItem).ToArray();

                folder.SubFolders = driveItemsArr.Where(
                    item => item.IsFolder == true).ToList();

                folder.FolderFiles = driveItemsArr.Where(
                    item => item.IsFolder != true).ToList();

                var result = new TrmrkActionResult <DriveItem>(
                    true, folder, null, null);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 2
0
        public TrmrkActionResult <string> GetDriveFileUrl(string fileId)
        {
            var actionResult = new TrmrkActionResult <string>(
                true, this.GetDriveItemUrl(fileId));

            return(actionResult);
        }
Esempio n. 3
0
        public TrmrkActionResult <string> GetRootDriveFolderUrl()
        {
            var actionResult = new TrmrkActionResult <string>(
                true, string.Empty);

            return(actionResult);
        }
Esempio n. 4
0
        public async Task <TrmrkActionResult <DriveItem> > MoveFileAsync(string fileId, string newParentFolderId, string newFileName)
        {
            var actionResult = await ExecuteDriveItemCoreAsync(async() =>
            {
                string newPath = Path.Combine(newParentFolderId, newFileName);

                File.Move(fileId, newPath);
                var newEntry = new FileInfo(newPath);

                var item   = GetDriveItem(newEntry);
                var result = new TrmrkActionResult <DriveItem>(true, item);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 5
0
        public async Task <TrmrkActionResult <DriveItem> > DeleteFolderAsync(string folderId)
        {
            var actionResult = ExecuteDriveItemCore(() =>
            {
                var dirInfo   = new DirectoryInfo(folderId);
                var driveItem = GetDriveItem(dirInfo);

                dirInfo.Delete(true);

                var result = new TrmrkActionResult <DriveItem>(
                    true, driveItem);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 6
0
        public async Task <TrmrkActionResult <DriveItem> > DeleteFileAsync(string fileId)
        {
            var actionResult = ExecuteDriveItemCore(() =>
            {
                var fileInfo  = new FileInfo(fileId);
                var driveItem = GetDriveItem(fileInfo);

                fileInfo.Delete();

                var result = new TrmrkActionResult <DriveItem>(
                    true, driveItem);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 7
0
        public async Task <TrmrkActionResult <DriveItem> > MoveFolderAsync(string folderId, string newParentFolderId, string newFolderName)
        {
            var actionResult = ExecuteDriveItemCore(() =>
            {
                string newPath = Path.Combine(newParentFolderId, newFolderName);
                FsH.MoveDirectory(folderId, newPath);

                var newEntry = new DirectoryInfo(newPath);
                var item     = GetDriveItem(newEntry);

                var result = new TrmrkActionResult <DriveItem>(
                    true, item);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 8
0
        public async Task <TrmrkActionResult <DriveItem> > CreateTextFileAsync(string parentFolderId, string newFileName, string text)
        {
            var actionResult = ExecuteDriveItemCore(() =>
            {
                string newPath = Path.Combine(parentFolderId, newFileName);
                File.WriteAllText(newPath, text);

                var newEntry = new FileInfo(newPath);
                var item     = GetDriveItem(newEntry);

                var result = new TrmrkActionResult <DriveItem>(
                    true, item);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 9
0
        public async Task <TrmrkActionResult <DriveItem> > GetTextFileAsync(string fileId)
        {
            var actionResult = await ExecuteDriveItemCoreAsync(async() =>
            {
                var entry    = new FileInfo(fileId);
                var fileItem = GetDriveItem(entry);

                fileItem.ParentFolderId  = Path.GetDirectoryName(entry.FullName);
                fileItem.TextFileContent = File.ReadAllText(fileId);

                var result = new TrmrkActionResult <DriveItem>(
                    true, fileItem, null, null);

                return(result);
            });

            return(actionResult);
        }
Esempio n. 10
0
        public async Task <TrmrkActionResult <DriveItem> > GetRootFolderAsync()
        {
            var actionResult = ExecuteDriveItemCore(
                () =>
            {
                var fsEntriesList = new List <DriveItem>();

                var drives = DriveInfo.GetDrives(
                    ).Where(d => d.IsReady).Select(
                    d => new DriveItem
                {
                    Id       = d.Name,
                    Name     = d.Name,
                    IsFolder = true,
                });

                string userHomePath = GetFolderPath(SpecialFolder.UserProfile);

                var folders = new Dictionary <SpecialFolder, string>
                {
                    { SpecialFolder.UserProfile, "User Home" },
                    { SpecialFolder.ApplicationData, "Application Data" },
                    { SpecialFolder.MyDocuments, "Documents" },
                    { SpecialFolder.MyPictures, "Pictures" },
                    { SpecialFolder.MyVideos, "Videos" },
                    { SpecialFolder.MyMusic, "Music" },
                    { SpecialFolder.Desktop, "Desktop" }
                }.Select(
                    kvp =>
                {
                    string path = GetFolderPath(kvp.Key);
                    string name = path;

                    if (name.StartsWith(userHomePath))
                    {
                        name = name.Substring(userHomePath.Length).TrimStart('/', '\\');
                        name = $"~{Path.DirectorySeparatorChar}{name}";
                    }

                    DirectoryInfo dirInfo = new DirectoryInfo(path);
                    var item = GetDriveItem(dirInfo);

                    item.Name = name;
                    return(item);
                });

                fsEntriesList.AddRange(drives);
                fsEntriesList.AddRange(folders);

                var rootFolder = new DriveItem
                {
                    Id           = string.Empty,
                    Name         = "This PC",
                    IsFolder     = true,
                    IsRootFolder = true,
                    SubFolders   = fsEntriesList,
                    FolderFiles  = new List <DriveItem>()
                };

                var result = new TrmrkActionResult <DriveItem>(
                    true, rootFolder);

                return(result);
            });

            return(actionResult);
        }