Exemplo n.º 1
0
 public FolderProcessor(IRoadieSettings configuration, IHttpEncoder httpEncoder, string destinationRoot, IRoadieDbContext context, ICacheManager cacheManager, ILogger logger, IArtistLookupEngine artistLookupEngine, IArtistFactory artistFactory, IReleaseFactory releaseFactory, IImageFactory imageFactory, IReleaseLookupEngine releaseLookupEngine, IAudioMetaDataHelper audioMetaDataHelper)
     : base(configuration, httpEncoder, destinationRoot, context, cacheManager, logger, artistLookupEngine, artistFactory, releaseFactory, imageFactory, releaseLookupEngine, audioMetaDataHelper)
 {
     SimpleContract.Requires <ArgumentNullException>(!string.IsNullOrEmpty(destinationRoot), "Invalid Destination Folder");
     this._fileProcessor = new FileProcessor(configuration, httpEncoder, destinationRoot, context, cacheManager, logger, artistLookupEngine, artistFactory, releaseFactory, imageFactory, releaseLookupEngine, audioMetaDataHelper);
 }
Exemplo n.º 2
0
        public async Task <OperationResult <bool> > Process(FileInfo fileInfo, bool doJustInfo = false)
        {
            var result = new OperationResult <bool>();

            try
            {
                // Determine what type of file this is
                var fileType = FileProcessor.DetermineFileType(fileInfo);

                OperationResult <bool> pluginResult = null;
                foreach (var p in this.Plugins)
                {
                    // See if there is a plugin
                    if (p.HandlesTypes.Contains(fileType))
                    {
                        pluginResult = await p.Process(this.DestinationRoot, fileInfo, doJustInfo, this.SubmissionId);

                        break;
                    }
                }

                if (!doJustInfo)
                {
                    // If no plugin, or if plugin not successfull and toggle then move unknown file
                    if ((pluginResult == null || !pluginResult.IsSuccess) && this.DoMoveUnknowns)
                    {
                        var uf = this.UnknownFolder;
                        if (!string.IsNullOrEmpty(uf))
                        {
                            if (!Directory.Exists(uf))
                            {
                                Directory.CreateDirectory(uf);
                            }
                            if (!fileInfo.DirectoryName.Equals(this.UnknownFolder))
                            {
                                if (File.Exists(fileInfo.FullName))
                                {
                                    var df = Path.Combine(this.UnknownFolder, string.Format("{0}~{1}~{2}", Guid.NewGuid(), fileInfo.Directory.Name, fileInfo.Name));
                                    this.Logger.LogDebug("Moving Unknown/Invalid File [{0}] -> [{1}] to UnknownFolder", fileInfo.FullName, df);
                                    fileInfo.MoveTo(df);
                                }
                            }
                        }
                    }
                }
                result = pluginResult;
            }
            catch (System.IO.PathTooLongException ex)
            {
                this.Logger.LogError(ex, string.Format("Error Processing File. File Name Too Long. Deleting."));
                if (!doJustInfo)
                {
                    fileInfo.Delete();
                }
            }
            catch (Exception ex)
            {
                var willMove = !fileInfo.DirectoryName.Equals(this.UnknownFolder);
                this.Logger.LogError(ex, string.Format("Error Processing File [{0}], WillMove [{1}]\n{2}", fileInfo.FullName, willMove, ex.Serialize()));
                string newPath = null;
                try
                {
                    newPath = Path.Combine(this.UnknownFolder, fileInfo.Directory.Parent.Name, fileInfo.Directory.Name, fileInfo.Name);
                    if (willMove && !doJustInfo)
                    {
                        var directoryPath = Path.GetDirectoryName(newPath);
                        if (!Directory.Exists(directoryPath))
                        {
                            Directory.CreateDirectory(directoryPath);
                        }
                        fileInfo.MoveTo(newPath);
                    }
                }
                catch (Exception ex1)
                {
                    this.Logger.LogError(ex1, string.Format("Unable to move file [{0}] to [{1}]", fileInfo.FullName, newPath));
                }
            }
            return(result);
        }