Exemplo n.º 1
0
        public FilePath CreateDestinationPath(FileInformation information, FilePath sourcePath)
        {
            PrintingAvailibleInformations(information, sourcePath);

            var result = Replace.Replace(_configuration.PathRule, delegate(Match match)
            {
                var group1 = match.Groups["Value"];
                var group2 = match.Groups["Format"];
                if (group1.Success)
                {
                    var varName = group1.Value;
                    if (information.ContainsKey(varName))
                    {
                        var value = information[varName];

                        if (group2.Success)
                        {
                            var formater        = group2.Value;
                            var formatingString = "{0:" + formater + "}";
                            var newValue        = string.Format(formatingString, value);
                            _logger.Debug("Substitude variable '{0}' with '{1}'", varName, newValue);
                            return(newValue);
                        }
                        else
                        {
                            var newValue = value.ToString();
                            _logger.Debug("Substitude variable '{0}' with '{1}'", varName, newValue);
                            return(newValue);
                        }
                    }
                    else
                    {
                        throw new ArgumentOutOfRangeException(string.Format("No value for variable '{0}' availible", varName));
                    }
                }
                throw new InvalidOperationException();
            });

            var destinationPath = new FilePath(_configuration.DestinationBasePath, Path.Combine(_configuration.DestinationBasePath, result), sourcePath.FileFinder);

            if (CheckForDuplicates(destinationPath.FullPath, sourcePath))
            {
                _logger.Debug("A file at new path {0} already exists", destinationPath.FullPath);

                var newFilePath = new FilePath(_configuration.DestinationBasePath, Path.Combine(_configuration.DestinationBasePath, "Duplicate", result), sourcePath.FileFinder);
                var counter     = 1;
                while (CheckForDuplicates(newFilePath.FullPath, sourcePath))
                {
                    newFilePath = new FilePath(_configuration.DestinationBasePath, Path.Combine(_configuration.DestinationBasePath, "Duplicate", result + "_" + counter++), sourcePath.FileFinder);
                }
                return(newFilePath);
            }

            return(destinationPath);
        }
Exemplo n.º 2
0
        private FileInformation MergeFileInformation(IEnumerable <FileInformation> fileInformations)
        {
            var informations = new FileInformation();

            foreach (var oldInfo in fileInformations.SelectMany(x => x))
            {
                if (informations.ContainsKey(oldInfo.Key))
                {
                    _logger.Warn("Overiding already existing key '{0}'", oldInfo.Key);
                }
                informations[oldInfo.Key] = oldInfo.Value;
            }

            return(informations);
        }
Exemplo n.º 3
0
 public override bool MatchFile(FilePath file, FileInformation information)
 {
     return(information.ContainsKey(_configuration.Key));
 }