Exemplo n.º 1
0
        private static string BuildFullName(string destPath, File file)
        {
            //split the unix like name that comes from TC
            string[] pathParts = file.Name.Split('/');

            //join them back using the proper separator for the environment
            string properPath = string.Join(Path.DirectorySeparatorChar.ToString(), pathParts);

            return(Path.Combine(destPath, properPath));
        }
Exemplo n.º 2
0
            public void Should_encode_white_spaces()
            {
                string source   = "Cwi.Core-2.10-dev.zip!/My Path/Cwi.Core.dll";
                var    expected = new File
                {
                    ContentHref = source,
                    Name        = "Cwi.Core.dll"
                };

                File file = ArtifactRule.ParseSource(source);

                Assert.Equal("Cwi.Core-2.10-dev.zip!/My%20Path/Cwi.Core.dll", file.ContentHref);
            }
Exemplo n.º 3
0
            public void Root_file()
            {
                string source = "Cwi.Core.dll";

                var expected = new File
                {
                    ContentHref = source,
                    Name        = "Cwi.Core.dll"
                };

                File file = ArtifactRule.ParseSource(source);

                Assert.Equal(expected.ContentHref, file.ContentHref);
                Assert.Equal(expected.Name, file.Name);
            }
Exemplo n.º 4
0
            public void Extract_full_zip()
            {
                string source = "MyFile.zip!**";

                var expected = new File
                {
                    ContentHref = "MyFile.zip",
                    Name        = "MyFile.zip!**"
                };

                File file = ArtifactRule.ParseSource(source);

                Assert.Equal(expected.ContentHref, file.ContentHref);
                Assert.Equal(expected.Name, file.Name);
            }
Exemplo n.º 5
0
            public void Directory()
            {
                string source = "/bin/release";

                var expected = new File
                {
                    ChildrenHref = source,
                    Name         = "release"
                };

                File file = ArtifactRule.ParseSource(source);

                Assert.Null(file.ContentHref);
                Assert.Equal(expected.ChildrenHref, file.ChildrenHref);
                Assert.Equal(expected.Name, file.Name);
            }
Exemplo n.º 6
0
            public void File_within_zip()
            {
                string source = "Cwi.Core-2.10-dev.zip!/Cwi.Core.dll";
                //string source = "en-us/BIFInstall_*.msi";
                //string source = "BIFLoader-2.9.7-dev.zip!**";
                var expected = new File
                {
                    ContentHref = source,
                    Name        = "Cwi.Core.dll"
                };

                File file = ArtifactRule.ParseSource(source);

                Assert.Equal(expected.ContentHref, file.ContentHref);
                Assert.Equal(expected.Name, file.Name);
            }
Exemplo n.º 7
0
        public async Task Download(string destPath, File file)
        {
            bool unzip = false;

            if (file.Name.EndsWith("!**"))
            {
                file.Name = file.Name.Replace("!**", string.Empty);
                unzip     = true;
            }

            if (file.Name == "**")
            {
                file.ContentHref = file.ChildrenHref.Replace("!/**", string.Empty);
                string[] parts = file.ContentHref.Split('/');
                file.Name = parts[parts.Length - 1];
                unzip     = true;
            }

            var destFileName = BuildFullName(destPath, file);

            EnsureDirectoryExists(destFileName);

            using (Stream stream = await _http.GetStream(file.ContentHref))
            {
                EnsureDirectoryExists(destFileName);
                if (System.IO.File.Exists(destFileName) == false)
                {
                    await _fileSystem.CreateFileFromStreamAsync(destFileName, stream);
                }
            }

            if (unzip)
            {
                Log.Debug("Unzipping " + destFileName);

                var tempFileName = _fileSystem.CreateTempFile();
                _fileSystem.CopyFile(destFileName, tempFileName, true);
                //if (_fileSystem.DirectoryExists(destPath))
                //{
                //    _fileSystem.DeleteDirectory(destPath, true);
                //}
                _fileSystem.ExtractToDirectory(tempFileName, destPath);
                _fileSystem.DeleteFile(tempFileName);
            }
        }