示例#1
0
        public PathMapping?FindFile(RelativePath file)
        {
            var path = file.GetPathFromWorkingFolder();

            foreach (var m in Mappings)
            {
                if (m.IsFolder)
                {
                    var localPath = path - m.LogicalPath;
                    if (m.AllowMoveOut || localPath.ParentDirectoryCount == 0)
                    {
                        var physicalPath = Path.Combine(m.PhysicalPath, localPath.ToString());
                        if (File.Exists(Environment.ExpandEnvironmentVariables(physicalPath)))
                        {
                            return(new PathMapping(path, physicalPath)
                            {
                                Properties = m.Properties
                            });
                        }
                    }
                }
                else if (m.LogicalPath == path)
                {
                    return(m);
                }
            }
            return(null);
        }
示例#2
0
        public override Stream Create(RelativePath file)
        {
            var         key = file.GetPathFromWorkingFolder();
            bool        getResult;
            PathMapping pm;

            lock (_mapping)
            {
                getResult = _mapping.TryGetValue(key, out pm);
            }
            if (getResult && pm.PhysicalPath.StartsWith(OutputFolder))
            {
                try
                {
                    return(File.Create(Environment.ExpandEnvironmentVariables(pm.PhysicalPath)));
                }
                catch (IOException)
                {
                }
            }
            var pair = CreateRandomFileStream();

            pm = new PathMapping(key, Path.Combine(OutputFolder, pair.Item1));
            lock (_mapping)
            {
                _mapping[key] = pm;
            }
            return(pair.Item2);
        }
示例#3
0
        public override void Copy(PathMapping sourceFilePath, RelativePath destFilePath)
        {
            var key = destFilePath.GetPathFromWorkingFolder();

            _mapping[key] = new PathMapping(key, sourceFilePath.PhysicalPath)
            {
                Properties = sourceFilePath.Properties,
            };
        }
示例#4
0
 public PathMapping(RelativePath logicalPath, string physicalPath)
 {
     if (logicalPath == null)
     {
         throw new ArgumentNullException(nameof(logicalPath));
     }
     LogicalPath  = logicalPath.GetPathFromWorkingFolder();
     PhysicalPath = physicalPath ?? throw new ArgumentNullException(nameof(physicalPath));
     AllowMoveOut = false;
     Properties   = ImmutableDictionary <string, string> .Empty;
 }
示例#5
0
        public override Stream Create(RelativePath file)
        {
            var         key = file.GetPathFromWorkingFolder();
            PathMapping pm;

            if (_mapping.TryGetValue(key, out pm) &&
                pm.PhysicalPath.StartsWith(OutputFolder))
            {
                return(File.Create(Environment.ExpandEnvironmentVariables(pm.PhysicalPath)));
            }
            var pair = CreateRandomFileStream();

            _mapping[key] =
                new PathMapping(
                    key,
                    Path.Combine(OutputFolder, pair.Item1));
            return(pair.Item2);
        }
示例#6
0
        public IEnumerable <string> GetExpectedPhysicalPath(RelativePath file)
        {
            var path = file.GetPathFromWorkingFolder();

            foreach (var m in Mappings)
            {
                if (m.IsFolder)
                {
                    var localPath = path - m.LogicalPath;
                    if (m.AllowMoveOut || localPath.ParentDirectoryCount == 0)
                    {
                        var physicalPath = Path.Combine(m.PhysicalPath, localPath.ToString());
                        if (File.Exists(Environment.ExpandEnvironmentVariables(physicalPath)))
                        {
                            yield return(physicalPath);
                        }
                    }
                }
                else if (m.LogicalPath == path)
                {
                    yield return(m.PhysicalPath);
                }
            }
        }