GetPath() static private method

Converts a uri to a path. Only used for local paths.
static private GetPath ( Uri uri ) : string
uri System.Uri
return string
Exemplo n.º 1
0
        internal static bool IsPackageFile(PackagePart part)
        {
            string path      = UriUtility.GetPath(part.Uri);
            string directory = Path.GetDirectoryName(path);

            return(!Enumerable.Any <string>(ExcludePaths, p => directory.StartsWith(p, StringComparison.OrdinalIgnoreCase)) && !PackageHelper.IsManifest(path));
        }
Exemplo n.º 2
0
        public override IEnumerable <FrameworkName> GetSupportedFrameworks()
        {
            IEnumerable <FrameworkName> enumerable;
            IEnumerable <IPackageFile>  enumerable2;

            if (this._enableCaching && MemoryCache.Instance.TryGetValue <IEnumerable <IPackageFile> >(this.GetFilesCacheKey(), out enumerable2))
            {
                enumerable = from c in enumerable2 select c.TargetFramework;
            }
            else
            {
                using (Stream stream = this._streamFactory())
                {
                    enumerable = Enumerable.Select <PackagePart, FrameworkName>(from part in Package.Open(stream).GetParts()
                                                                                where IsPackageFile(part)
                                                                                select part, delegate(PackagePart part) {
                        string effectivePath;
                        return(VersionUtility.ParseFrameworkNameFromFilePath(UriUtility.GetPath(part.Uri), out effectivePath));
                    });
                }
            }
            return((from f in base.GetSupportedFrameworks().Concat <FrameworkName>(enumerable)
                    where f != null
                    select f).Distinct <FrameworkName>());
        }
Exemplo n.º 3
0
        private static bool IsPackageFile(PackagePart part)
        {
            string path = UriUtility.GetPath(part.Uri);

            // We exclude any opc files and the manifest file (.nuspec)
            return(!ExcludePaths.Any(p => path.StartsWith(p, StringComparison.OrdinalIgnoreCase)) &&
                   !PackageUtility.IsManifest(path));
        }
Exemplo n.º 4
0
        internal static bool IsPackageFile(PackagePart part, string packageId)
        {
            string path      = UriUtility.GetPath(part.Uri);
            string directory = Path.GetDirectoryName(path);

            // We exclude any opc files and the auto-generated package manifest file ({packageId}.nuspec)
            return(!ExcludePaths.Any(p => directory.StartsWith(p, StringComparison.OrdinalIgnoreCase)) &&
                   !PackageHelper.IsPackageManifest(path, packageId));
        }
Exemplo n.º 5
0
        internal static bool IsPackageFile(Uri uri)
        {
            string path      = UriUtility.GetPath(uri);
            string directory = Path.GetDirectoryName(path);

            // We exclude any opc files and the manifest file (.nuspec)
            return(!ExcludePaths.Any(p => directory.StartsWith(p, StringComparison.OrdinalIgnoreCase)) &&
                   !PackageHelper.IsManifest(path));
        }
Exemplo n.º 6
0
        private static bool IsAssemblyReference(PackagePart part)
        {
            // Assembly references are in lib/ and have a .dll/.exe extension
            string path = UriUtility.GetPath(part.Uri);

            return(path.StartsWith(AssemblyReferencesDir, StringComparison.OrdinalIgnoreCase) &&
                   // Exclude resource assemblies
                   !path.EndsWith(ResourceAssemblyExtension, StringComparison.OrdinalIgnoreCase) &&
                   AssemblyReferencesExtensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase));
        }
        public ZipPackageFile(PackagePart part)
            : base(UriUtility.GetPath(part.Uri))
        {
            Debug.Assert(part != null, "part should not be null");

            byte[] buffer;
            using (Stream partStream = part.GetStream())
            {
                buffer = partStream.ReadAllBytes();
            }
            _streamFactory = () => new MemoryStream(buffer);
        }
Exemplo n.º 8
0
 public static string GetRelativePath(string path1, string path2)
 {
     if (path1 == null)
     {
         throw new ArgumentNullException("path1");
     }
     if (path2 == null)
     {
         throw new ArgumentNullException("path2");
     }
     return(UriUtility.GetPath(new Uri(path1).MakeRelativeUri(new Uri(path2))));
 }
Exemplo n.º 9
0
        private void EnsurePackageFiles()
        {
            if (_files != null && _expandedFileSystem.DirectoryExists(_expandedFolderPath))
            {
                return;
            }

            _files = new Dictionary <string, PhysicalPackageFile>();
            _supportedFrameworks = null;

            using (Stream stream = GetStream())
            {
                Package package = Package.Open(stream);

                _expandedFolderPath = GetExpandedFolderPath();

                // unzip files inside package
                var files = from part in package.GetParts()
                            where ZipPackage.IsPackageFile(part)
                            select part;

                // now copy all package's files to disk
                foreach (PackagePart file in files)
                {
                    string path     = UriUtility.GetPath(file.Uri);
                    string filePath = Path.Combine(_expandedFolderPath, path);

                    using (Stream partStream = file.GetStream())
                    {
                        // only copy the package part to disk if there doesn't exist
                        // a file with the same name.
                        if (!_expandedFileSystem.FileExists(filePath))
                        {
                            using (Stream targetStream = _expandedFileSystem.CreateFile(filePath))
                            {
                                partStream.CopyTo(targetStream);
                            }
                        }
                    }

                    var packageFile = new PhysicalPackageFile
                    {
                        SourcePath = _expandedFileSystem.GetFullPath(filePath),
                        TargetPath = path
                    };

                    _files[path] = packageFile;
                }
            }
        }
Exemplo n.º 10
0
        public ZipPackageFile(PackagePart part)
        {
            Debug.Assert(part != null, "part should not be null");

            byte[] buffer;
            using (Stream partStream = part.GetStream()) {
                using (var stream = new MemoryStream()) {
                    partStream.CopyTo(stream);
                    buffer = stream.ToArray();
                }
            }
            _path          = UriUtility.GetPath(part.Uri);
            _streamFactory = () => new MemoryStream(buffer);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Returns path2 relative to path1
        /// </summary>
        public static string GetRelativePath(string path1, string path2)
        {
            if (path1 == null)
            {
                throw new ArgumentNullException("path1");
            }

            if (path2 == null)
            {
                throw new ArgumentNullException("path2");
            }

            Uri source = new Uri(path1);
            Uri target = new Uri(path2);

            return(UriUtility.GetPath(source.MakeRelativeUri(target)));
        }
Exemplo n.º 12
0
        public override void ExtractContents(IFileSystem fileSystem, string extractPath)
        {
            using (Stream stream = _streamFactory())
            {
                var package = Package.Open(stream);

                foreach (var part in package.GetParts()
                         .Where(p => IsPackageFile(p, package.PackageProperties.Identifier)))
                {
                    var relativePath = UriUtility.GetPath(part.Uri);

                    var targetPath = Path.Combine(extractPath, relativePath);
                    using (var partStream = part.GetStream())
                    {
                        fileSystem.AddFile(targetPath, partStream);
                    }
                }
            }
        }
Exemplo n.º 13
0
        private void EnsurePackageFiles()
        {
            if (_files != null &&
                _expandedFolderPath != null &&
                _expandedFileSystem.DirectoryExists(_expandedFolderPath))
            {
                return;
            }

            _files = new Dictionary <string, PhysicalPackageFile>();
            _supportedFrameworks = null;

            var packageName = new PackageName(Id, Version);

            // Only use the cache for expanded folders under %temp%, or set from unit tests
            if (_expandedFileSystem == TempFileSystem || _forceUseCache)
            {
                Tuple <string, DateTimeOffset> cacheValue;
                DateTimeOffset lastModifiedTime = _fileSystem.GetLastModified(_packagePath);

                // if the cache doesn't exist, or it exists but points to a stale package,
                // then we invalidate the cache and store the new entry.
                if (!_cachedExpandedFolder.TryGetValue(packageName, out cacheValue) ||
                    cacheValue.Item2 < lastModifiedTime)
                {
                    cacheValue = Tuple.Create(GetExpandedFolderPath(), lastModifiedTime);
                    _cachedExpandedFolder[packageName] = cacheValue;
                }

                _expandedFolderPath = cacheValue.Item1;
            }
            else
            {
                _expandedFolderPath = GetExpandedFolderPath();
            }

            using (Stream stream = GetStream())
            {
                Package package = Package.Open(stream);
                // unzip files inside package
                var files = from part in package.GetParts()
                            where ZipPackage.IsPackageFile(part, package.PackageProperties.Identifier)
                            select part;

                // now copy all package's files to disk
                foreach (PackagePart file in files)
                {
                    string path     = UriUtility.GetPath(file.Uri);
                    string filePath = Path.Combine(_expandedFolderPath, path);

                    bool copyFile = true;
                    if (_expandedFileSystem.FileExists(filePath))
                    {
                        using (Stream partStream = file.GetStream(),
                               targetStream = _expandedFileSystem.OpenFile(filePath))
                        {
                            // if the target file already exists,
                            // don't copy file if the lengths are equal.
                            copyFile = partStream.Length != targetStream.Length;
                        }
                    }

                    if (copyFile)
                    {
                        using (Stream partStream = file.GetStream())
                        {
                            try
                            {
                                using (Stream targetStream = _expandedFileSystem.CreateFile(filePath))
                                {
                                    partStream.CopyTo(targetStream);
                                }
                            }
                            catch (Exception)
                            {
                                // if the file is read-only or has an access denied issue, we just ignore it
                            }
                        }
                    }

                    var packageFile = new PhysicalPackageFile
                    {
                        SourcePath = _expandedFileSystem.GetFullPath(filePath),
                        TargetPath = path
                    };

                    _files[path] = packageFile;
                }
            }
        }
Exemplo n.º 14
0
 public ZipPackageFile(ZipEntry part)
     : this(UriUtility.GetPath(new Uri(part.FileName, UriKind.Relative)), part)
 {
 }
 public ZipPackageFile(PackagePart part)
     : this(UriUtility.GetPath(part.Uri), part.GetStream().ToStreamFactory())
 {
 }
Exemplo n.º 16
0
        public override IEnumerable <FrameworkName> GetSupportedFrameworks()
        {
            IEnumerable <FrameworkName> fileFrameworks;
            IEnumerable <IPackageFile>  cachedFiles;

            if (_enableCaching && MemoryCache.Instance.TryGetValue(GetFilesCacheKey(), out cachedFiles))
            {
                fileFrameworks = cachedFiles.Select(c => c.TargetFramework);
            }
            else
            {
                using (Stream stream = _streamFactory())
                {
                    var package = Package.Open(stream);

                    string effectivePath;
                    fileFrameworks = from part in package.GetParts()
                                     where IsPackageFile(part, Id)
                                     select VersionUtility.ParseFrameworkNameFromFilePath(UriUtility.GetPath(part.Uri), out effectivePath);
                }
            }

            return(base.GetSupportedFrameworks()
                   .Concat(fileFrameworks)
                   .Where(f => f != null)
                   .Distinct());
        }
Exemplo n.º 17
0
 public ZipPackageFile(PackagePart part)
     : base(UriUtility.GetPath(part.Uri))
 {
     Debug.Assert(part != null, "part should not be null");
     _streamFactory = () => part.GetStream();
 }
Exemplo n.º 18
0
        private void EnsurePackageFiles()
        {
            if ((this._files == null) || ((this._expandedFolderPath == null) || !this._expandedFileSystem.DirectoryExists(this._expandedFolderPath)))
            {
                this._files = new Dictionary <string, PhysicalPackageFile>();
                this._supportedFrameworks = null;
                PackageName key = new PackageName(base.Id, base.Version);
                if (!ReferenceEquals(this._expandedFileSystem, _tempFileSystem) && !this._forceUseCache)
                {
                    this._expandedFolderPath = this.GetExpandedFolderPath();
                }
                else
                {
                    Tuple <string, DateTimeOffset> tuple;
                    DateTimeOffset lastModified = this._fileSystem.GetLastModified(this._packagePath);
                    if (!_cachedExpandedFolder.TryGetValue(key, out tuple) || (tuple.Item2 < lastModified))
                    {
                        tuple = Tuple.Create <string, DateTimeOffset>(this.GetExpandedFolderPath(), lastModified);
                        _cachedExpandedFolder[key] = tuple;
                    }
                    this._expandedFolderPath = tuple.Item1;
                }
                using (Stream stream = this.GetStream())
                {
                    using (IEnumerator <PackagePart> enumerator = (from part in Package.Open(stream).GetParts()
                                                                   where ZipPackage.IsPackageFile(part)
                                                                   select part).GetEnumerator())
                    {
                        string path;
                        string str2;
                        goto TR_0023;
TR_000E:
                        PhysicalPackageFile file1 = new PhysicalPackageFile();
                        file1.SourcePath          = this._expandedFileSystem.GetFullPath(str2);
                        file1.TargetPath          = path;
                        this._files[path]         = file1;
TR_0023:
                        while (true)
                        {
                            if (enumerator.MoveNext())
                            {
                                PackagePart current = enumerator.Current;
                                path = UriUtility.GetPath(current.Uri);
                                str2 = Path.Combine(this._expandedFolderPath, path);
                                bool flag = true;
                                if (this._expandedFileSystem.FileExists(str2))
                                {
                                    using (Stream stream2 = current.GetStream())
                                    {
                                        using (Stream stream3 = this._expandedFileSystem.OpenFile(str2))
                                        {
                                            flag = stream2.Length != stream3.Length;
                                        }
                                    }
                                }
                                if (flag)
                                {
                                    Stream stream4 = current.GetStream();
                                    try
                                    {
                                        using (Stream stream5 = this._expandedFileSystem.CreateFile(str2))
                                        {
                                            stream4.CopyTo(stream5);
                                        }
                                    }
                                    catch (Exception)
                                    {
                                    }
                                    finally
                                    {
                                        if (stream4 != null)
                                        {
                                            stream4.Dispose();
                                        }
                                    }
                                }
                            }
                            else
                            {
                                return;
                            }
                            break;
                        }
                        goto TR_000E;
                    }
                }
            }
        }
Exemplo n.º 19
0
        public override IEnumerable <FrameworkName> GetSupportedFrameworks()
        {
            IEnumerable <FrameworkName> fileFrameworks;
            IEnumerable <IPackageFile>  cachedFiles;

            if (_enableCaching && MemoryCache.Instance.TryGetValue(GetFilesCacheKey(), out cachedFiles))
            {
                fileFrameworks = cachedFiles.Select(c => c.TargetFramework);
            }
            else
            {
                using (Stream stream = _streamFactory())
                {
                    using (ZipFile zip = ZipFile.Read(stream))
                    {
                        string effectivePath;
                        fileFrameworks = from part in zip.Entries
                                         where IsPackageFile(new Uri(part.FileName, UriKind.Relative))
                                         select VersionUtility.ParseFrameworkNameFromFilePath(UriUtility.GetPath(new Uri(part.FileName, UriKind.Relative)), out effectivePath);
                    }
                }
            }

            return(base.GetSupportedFrameworks()
                   .Concat(fileFrameworks)
                   .Where(f => f != null)
                   .Distinct());
        }
Exemplo n.º 20
0
 public ZipPackageFile(PackagePart part)
 {
     Path           = UriUtility.GetPath(part.Uri);
     _streamFactory = part.GetStream().ToStreamFactory();
 }
Exemplo n.º 21
0
 /// <summary>
 /// Returns path2 relative to path1, with given path separator
 /// </summary>
 public static string GetRelativePath(string path1, string path2, char separator)
 {
     return(UriUtility.GetPath(GetRelativeUri(path1, path2), separator));
 }