Create() public abstract method

public abstract Create ( ) : void
return void
示例#1
0
        public void Organise(IMedia media, DirectoryInfoBase outputDirectory, OrganiserConversionOptions conversionOption, bool strictSeason)
        {
            // Create working directory.
            WorkingDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(_fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), "WorkingArea"));

            // Create working directory if it does not exist.
            if(!WorkingDirectory.Exists)
            {
                WorkingDirectory.Create();
            }

            // Copy to working area.
            CopyMediaToWorkingArea(media);

            // Convert if required.
            if(conversionOption == OrganiserConversionOptions.Force)
            {
                Logger.Log("Organiser").StdOut.WriteLine("Conversion set to \"force\". Will convert. {0}", media.MediaFile.FullName);
                ConvertMedia(media);
            }
            else if(media.RequiresConversion)
            {
                if(conversionOption == OrganiserConversionOptions.Skip)
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
                }
                else
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Media requires conversion. Will convert. {0}", media.MediaFile.FullName);
                    ConvertMedia(media);
                }
            }

            // Extract media details exhaustivly.
            ExtractExhaustiveMediaDetails(media, strictSeason);

            // Save media meta data.
            var saveResponse = SaveMediaMetaData(media);
            if(!saveResponse)
            {
                if(conversionOption == OrganiserConversionOptions.Skip)
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Conversion set to \"skip\", skipping conversion. {0}", media.MediaFile.FullName);
                }
                else
                {
                    Logger.Log("Organiser").StdOut.WriteLine("Unable to save metadata. Will convert. {0}", media.MediaFile.FullName);
                    ConvertMedia(media);
                    SaveMediaMetaData(media);
                }
            }

            // Rename media.
            RenameMediaToCleanFileName(media);

            // If output directory not provided, delete file. Otherwise move to output directory.
            MoveMediaToOutputDirectory(media, outputDirectory);
        }
        public TVDBTVShowMetadataSource(IFileSystem fileSystem, string apiKey)
        {
            // Set fileSystem.
            _fileSystem = fileSystem;

            // Make cache directory.
            var assemblyName = Assembly.GetExecutingAssembly().GetName().Name;
            _tvdbCacheDirectory = _fileSystem.DirectoryInfo.FromDirectoryName(_fileSystem.Path.Combine(_fileSystem.Path.GetTempPath(), assemblyName + _fileSystem.Path.DirectorySeparatorChar +"TVDBCache"));
            if(!_tvdbCacheDirectory.Exists)
            {
                _tvdbCacheDirectory.Create();
            }

            // Initalise handler with cache.
            _tvdbHandler = new TvdbHandler(new XmlCacheProvider(_tvdbCacheDirectory.FullName), apiKey);
            if(!_tvdbHandler.IsCacheInitialised)
            {
                _tvdbHandler.InitCache();
            }
        }
示例#3
0
        internal static void Copy(string sourcePath,
                                  string destinationPath,
                                  DirectoryInfoBase sourceDirectory,
                                  DirectoryInfoBase destinationDirectory,
                                  Func<string, DirectoryInfoBase> createDirectoryInfo,
                                  bool skipScmFolder)
        {
            // Skip hidden directories and directories that begin with .
            if (skipScmFolder && IsSourceControlFolder(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            foreach (var sourceFile in sourceDirectory.GetFiles())
            {
                string path = GetDestinationPath(sourcePath, destinationPath, sourceFile);

                sourceFile.CopyTo(path, overwrite: true);
            }

            var destDirectoryLookup = GetDirectories(destinationDirectory);
            foreach (var sourceSubDirectory in sourceDirectory.GetDirectories())
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                Copy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipScmFolder);
            }
        }
示例#4
0
        protected override Task<HttpResponseMessage> CreateDirectoryPutResponse(DirectoryInfoBase info, string localFilePath)
        {
            if (info != null && info.Exists)
            {
                // Return a conflict result
                return base.CreateDirectoryPutResponse(info, localFilePath);
            }

            try
            {
                info.Create();
            }
            catch (IOException ex)
            {
                Tracer.TraceError(ex);
                HttpResponseMessage conflictDirectoryResponse = Request.CreateErrorResponse(
                    HttpStatusCode.Conflict, Resources.VfsControllerBase_CannotDeleteDirectory);
                return Task.FromResult(conflictDirectoryResponse);
            }

            // Return 201 Created response
            HttpResponseMessage successFileResponse = Request.CreateResponse(HttpStatusCode.Created);
            return Task.FromResult(successFileResponse);
        }
示例#5
0
        internal static void SmartCopy(string sourcePath,
                                       string destinationPath,
                                       Func<string, bool> existsInPrevious,
                                       DirectoryInfoBase sourceDirectory,
                                       DirectoryInfoBase destinationDirectory,
                                       Func<string, DirectoryInfoBase> createDirectoryInfo)
        {
            // Skip source control folder
            if (FileSystemHelpers.IsSourceControlFolder(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            // var previousFilesLookup = GetFiles(previousDirectory);
            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start path
                string previousPath = destFile.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceFilesLookup.ContainsKey(destFile.Name) &&
                    ((existsInPrevious == null) ||
                    (existsInPrevious != null &&
                    existsInPrevious(previousPath))))
                {
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                // Skip the .deployment file
                if (sourceFile.Name.Equals(DeploymentConfiguration.DeployConfigFile, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                OperationManager.Attempt(() => sourceFile.CopyTo(path, overwrite: true));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectores(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectores(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                string previousPath = destSubDirectory.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) &&
                    ((existsInPrevious == null) ||
                    (existsInPrevious != null &&
                    existsInPrevious(previousPath))))
                {
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, existsInPrevious, sourceSubDirectory, targetSubDirectory, createDirectoryInfo);
            }
        }
示例#6
0
        private void SmartCopy(string sourcePath,
                               string destinationPath,
                               string targetSubFolder,
                               DirectoryInfoBase sourceDirectory,
                               DirectoryInfoBase destinationDirectory)
        {
            if (IgnorePath(sourceDirectory))
            {
                return;
            }

            // No need to copy a directory to itself
            if (destinationPath == sourceDirectory.FullName)
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
                if (_options.CopyMetaData)
                {
                    destinationDirectory.Attributes = sourceDirectory.Attributes;
                }
            }

            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                if (IgnorePath(destFile))
                {
                    continue;
                }

                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start destinationFilePath
                string previousPath = FileSystemHelpers.GetRelativePath(destinationPath, destFile.FullName);
                if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath, targetSubFolder))
                {
                    _logger.Log("Deleting file: '{0}'", previousPath);
                    OperationManager.Attempt(() => SmartDeleteFile(destFile));
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                if (IgnorePath(sourceFile))
                {
                    continue;
                }

                _nextManifest.AddPath(sourcePath, sourceFile.FullName, targetSubFolder);

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                var details = FileSystemHelpers.GetRelativePath(sourcePath, sourceFile.FullName) + (_options.CopyMetaData ? " " + ShorthandAttributes(sourceFile) : String.Empty);
                _logger.Log("Copying file: '{0}'", details);
                OperationManager.Attempt(() => SmartCopyFile(sourceFile, path));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name))
                {
                    SmartDirectoryDelete(destSubDirectory, destinationPath, targetSubFolder);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = CreateDirectoryInfo(path);
                }

                _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName, targetSubFolder);

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, targetSubFolder, sourceSubDirectory, targetSubDirectory);
            }
        }
示例#7
0
        private void SmartCopy(string sourcePath,
                               string destinationPath,
                               DirectoryInfoBase sourceDirectory,
                               DirectoryInfoBase destinationDirectory)
        {
            // Skip source control folder
            if (IgnorePath(sourceDirectory))
            {
                return;
            }

            if (!destinationDirectory.Exists)
            {
                destinationDirectory.Create();
            }

            var destFilesLookup = FileSystemHelpers.GetFiles(destinationDirectory);
            var sourceFilesLookup = FileSystemHelpers.GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values)
            {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                // Trim the start path
                string previousPath = destFile.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceFilesLookup.ContainsKey(destFile.Name) && DoesPathExistsInManifest(previousPath))
                {
                    Logger.Log("Deleting file: {0}", destFile.FullName);
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values)
            {
                // Skip the .deployment file
                if (IgnorePath(sourceFile))
                {
                    continue;
                }

                _nextManifest.AddPath(sourcePath, sourceFile.FullName);

                // if the file exists in the destination then only copy it again if it's
                // last write time is different than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc == targetFile.LastWriteTimeUtc)
                {
                    continue;
                }

                // Otherwise, copy the file
                string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceFile);

                Logger.Log("Copying file from: {0} to: {1}", sourceFile.FullName, path);
                OperationManager.Attempt(() => sourceFile.CopyTo(path, overwrite: true));
            }

            var sourceDirectoryLookup = FileSystemHelpers.GetDirectories(sourceDirectory);
            var destDirectoryLookup = FileSystemHelpers.GetDirectories(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values)
            {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there

                string previousPath = destSubDirectory.FullName.Substring(destinationPath.Length).TrimStart('\\');
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) && DoesPathExistsInManifest(previousPath))
                {
                    Logger.Log("Deleting directory: {0}", destSubDirectory.FullName);
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values)
            {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory))
                {
                    string path = FileSystemHelpers.GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = CreateDirectoryInfo(path);
                }

                _nextManifest.AddPath(sourcePath, sourceSubDirectory.FullName);

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, sourceSubDirectory, targetSubDirectory);
            }
        }
示例#8
0
        internal static void SmartCopy(string sourcePath,
                                       string destinationPath,
                                       DirectoryInfoBase previousDirectory,
                                       DirectoryInfoBase sourceDirectory,
                                       DirectoryInfoBase destinationDirectory,
                                       Func<string, DirectoryInfoBase> createDirectoryInfo,
                                       bool skipOldFiles)
        {
            // Skip hidden directories and directories that begin with .
            if (sourceDirectory.Attributes.HasFlag(FileAttributes.Hidden) ||
                sourceDirectory.Name.StartsWith(".")) {
                return;
            }

            if (!destinationDirectory.Exists) {
                destinationDirectory.Create();
            }

            var previousFilesLookup = GetFiles(previousDirectory);
            var destFilesLookup = GetFiles(destinationDirectory);
            var sourceFilesLookup = GetFiles(sourceDirectory);

            foreach (var destFile in destFilesLookup.Values) {
                // If the file doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there
                if (!sourceFilesLookup.ContainsKey(destFile.Name) &&
                    ((previousFilesLookup == null) ||
                    (previousFilesLookup != null &&
                    previousFilesLookup.ContainsKey(destFile.Name)))) {
                    destFile.Delete();
                }
            }

            foreach (var sourceFile in sourceFilesLookup.Values) {
                // Skip files that start with .
                if (sourceFile.Name.StartsWith(".")) {
                    continue;
                }

                // If a file exists in the destination then only copy it again if it's
                // last write time is greater than the same file in the source (only if it changed)
                FileInfoBase targetFile;
                if (skipOldFiles &&
                    destFilesLookup.TryGetValue(sourceFile.Name, out targetFile) &&
                    sourceFile.LastWriteTimeUtc <= targetFile.LastWriteTimeUtc) {
                    continue;
                }

                // Otherwise, copy the file
                string path = GetDestinationPath(sourcePath, destinationPath, sourceFile);

                sourceFile.CopyTo(path, overwrite: true);
            }

            var previousDirectoryLookup = GetDirectores(previousDirectory);
            var sourceDirectoryLookup = GetDirectores(sourceDirectory);
            var destDirectoryLookup = GetDirectores(destinationDirectory);

            foreach (var destSubDirectory in destDirectoryLookup.Values) {
                // If the directory doesn't exist in the source, only delete if:
                // 1. We have no previous directory
                // 2. We have a previous directory and the file exists there
                if (!sourceDirectoryLookup.ContainsKey(destSubDirectory.Name) &&
                    ((previousDirectoryLookup == null) ||
                    (previousDirectoryLookup != null &&
                    previousDirectoryLookup.ContainsKey(destSubDirectory.Name)))) {
                    destSubDirectory.Delete(recursive: true);
                }
            }

            foreach (var sourceSubDirectory in sourceDirectoryLookup.Values) {
                DirectoryInfoBase targetSubDirectory;
                if (!destDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out targetSubDirectory)) {
                    string path = GetDestinationPath(sourcePath, destinationPath, sourceSubDirectory);
                    targetSubDirectory = createDirectoryInfo(path);
                }

                DirectoryInfoBase previousSubDirectory = null;
                if (previousDirectoryLookup != null) {
                    // Try to get the sub folder from the previous directory
                    previousDirectoryLookup.TryGetValue(sourceSubDirectory.Name, out previousSubDirectory);
                }

                // Sync all sub directories
                SmartCopy(sourcePath, destinationPath, previousSubDirectory, sourceSubDirectory, targetSubDirectory, createDirectoryInfo, skipOldFiles);
            }
        }