/// <summary>
        /// Create target entry object model for given directory
        /// </summary>
        /// <param name="fullPath">Target directory path info</param>
        /// <returns>Result target entry object model</returns>
        public static BaseDirectoryEntryObjectModel CreateTargetEntryObjectModel(
            this FileSystemVolumeDirectoryInfo fullPath)
        {
            // Check if we are targeting the root directory
            if (fullPath.IsDirectorySameAsRoot)
            {
                // Result instance as root
                return(RootDirectoryEntryObjectModel.Create(fullPath.Directory, fullPath.Root));
            }

            // Result instance as directory
            return(DirectoryEntryObjectModel.Create(fullPath.Directory, fullPath.Root));
        }
コード例 #2
0
        /// <summary>
        /// Initialize file/directory open
        /// </summary>
        /// <param name="target">Target</param>
        /// <returns>Response result</returns>
        InitCommandResult IConnectorDriver.Init(string target)
        {
            // Declare target directory path info
            FileSystemVolumeDirectoryInfo fullPath;

            // Check if target was defined
            if (string.IsNullOrEmpty(target))
            {
                // Target not defined

                // Get startup volume
                var startupVolume = RootVolumes.GetStartupVolume();

                // Get directory target path info
                fullPath = new FileSystemVolumeDirectoryInfo(
                    startupVolume, startupVolume.StartDirectory ?? startupVolume.Directory);
            }
            else
            {
                // Target defined

                // Get directory target path info
                fullPath = ParseDirectoryPath(target);
            }

            // Create command result
            var commandResult = new InitCommandResult(
                fullPath.CreateTargetEntryObjectModel(),
                new OptionsResultData(fullPath));

            // Add visible files
            foreach (var fileItem in fullPath.Directory.GetVisibleFiles())
            {
                // Check if file is supported for imaging
                if (ImagingUtils.CanProcessFile(fileItem))
                {
                    // Is supported
                    // Add file item as image entry
                    commandResult.Files.Add(
                        ImageEntryObjectModel.Create(fileItem, fullPath.Root));
                }
                else
                {
                    // Not supported
                    // Add file item as standard entry
                    commandResult.Files.Add(
                        FileEntryObjectModel.Create(fileItem, fullPath.Root));
                }
            }

            // Add visible directories
            foreach (var directoryItem in fullPath.Directory.GetVisibleDirectories())
            {
                commandResult.Files.Add(DirectoryEntryObjectModel.Create(directoryItem, fullPath.Root));
            }

            // Add root directories
            foreach (var rootVolume in RootVolumes)
            {
                commandResult.Files.Add(RootDirectoryEntryObjectModel.Create(rootVolume.Directory, rootVolume));
            }

            // Add root directories, if different from root
            if (!fullPath.IsDirectorySameAsRoot)
            {
                foreach (var directoryItem in fullPath.Root.Directory.GetVisibleDirectories())
                {
                    commandResult.Files.Add(DirectoryEntryObjectModel.Create(directoryItem, fullPath.Root));
                }
            }

            // Set max upload size
            if (fullPath.Root.MaxUploadSizeKb.HasValue)
            {
                commandResult.UploadMaxSize = $"{fullPath.Root.MaxUploadSizeKb.Value}K";
            }

            // Return it
            return(commandResult);
        }