public async Task DownloadAsync(BuildConfig config, ISourceItem item, string filePath)
 {
     using (var source = File.OpenRead(item.Url)) {
         using (var destination = File.OpenWrite(filePath))
         {
             await source.CopyToAsync(destination);
         }
     }
 }
Example #2
0
        public void Initialize(BuildConfig config)
        {
            NetworkCredential credentials = new NetworkCredential(config.Username, config.Password);
            BasicAuthCredential basicCredentials = new BasicAuthCredential(credentials);
            TfsClientCredentials cred = new TfsClientCredentials(basicCredentials);
            cred.AllowInteractive = false;
            tpc = new TfsTeamProjectCollection(new Uri(config.SourceUrl + "/" + config.Collection),cred);

            tpc.Authenticate();

            this.Server = tpc.GetService<Microsoft.TeamFoundation.VersionControl.Client.VersionControlServer>();
        }
Example #3
0
        public Task DownloadAsync(BuildConfig config, ISourceItem item, string filePath)
        {
            return Task.Run(()=> {

                var local = item as LocalRepositoryFile;
                var file = local==null ? (item as TFS2015FileItem) : local.Source as TFS2015FileItem;
                if (file == null) {
                    throw new InvalidOperationException("Input=" + (item == null ? "null" : item.ToString()));
                }
                file.Item.DownloadFile(filePath);
            });
        }
        public void Initialize(BuildConfig config)
        {
            zipFile = config.BuildFolder = "\\_source.zip";
            if(File.Exists(zipFile)){
                File.Delete(zipFile);
            }

            zipFolder = config.BuildFolder = "\\_zipSource";
            if (Directory.Exists(zipFolder)) {
                Directory.Delete(zipFolder, true);
            }
            Directory.CreateDirectory(zipFolder);
        }
        public async Task<List<ISourceItem>> FetchAllFiles(BuildConfig config)
        {
            using (System.Net.Http.HttpClient client = new System.Net.Http.HttpClient()) {
                using (var stream = await client.GetStreamAsync(config.SourceUrl)) {
                    using (var fs = File.OpenWrite(zipFile)) {
                        await stream.CopyToAsync(fs);
                    }
                }
            }

            List<ISourceItem> files = new List<ISourceItem>();

            using (ZipFile zip = new ZipFile(zipFile)) {
                foreach (ZipEntry entry in zip)
                {
                    if (entry.IsDirectory)
                        continue;
                    using (var s = zip.GetInputStream(entry)) {
                        string filePath = zipFolder + "\\" + entry.Name;
                        FileInfo fi = new FileInfo(filePath);
                        if (!fi.Directory.Exists)
                        {
                            fi.Directory.Create();
                        }
                        using (FileStream fs = fi.OpenWrite()) {
                            await fs.CopyToAsync(s);
                        }

                        string fileName = System.IO.Path.GetFileName(filePath);

                        ZipSourceItem file = new ZipSourceItem { 
                            Url = filePath,
                            Name = System.IO.Path.GetFileName(filePath),
                            Folder = entry.Name.Substring(0,entry.Name.Length-fileName.Length),
                            IsDirectory = false
                        };
                        files.Add(file);
                    }                    
                }
            }

            var md5 = System.Security.Cryptography.MD5.Create();

            Parallel.ForEach(files, file => {
                ((ZipSourceItem)file).Version = Convert.ToBase64String(md5.ComputeHash(File.ReadAllBytes(file.Url)));
            });

            return files;
        }
Example #6
0
 public Task<List<ISourceItem>> FetchAllFiles(BuildConfig config)
 {
     return Task.Run(() =>
     {
         List<ISourceItem> list = new List<ISourceItem>();
         var result = Server.GetItems(config.RootFolder, VersionSpec.Latest, RecursionType.Full, DeletedState.Any, ItemType.Any);
         foreach (var item in result.Items) {
             if (item.DeletionId == 0)
             {
                 list.Add(new TFS2015FileItem(item, config));
             }
         }
         return list;
     });
 }
Example #7
0
        public void Initialize(BuildConfig config)
        {
            zipFile = config.BuildFolder = "\\_source.zip";
            if (File.Exists(zipFile))
            {
                File.Delete(zipFile);
            }

            zipFolder = config.BuildFolder = "\\_zipSource";
            if (Directory.Exists(zipFolder))
            {
                Directory.Delete(zipFolder, true);
            }
            Directory.CreateDirectory(zipFolder);
        }
Example #8
0
 public TFS2015FileItem(Item item,BuildConfig config)
 {
     this.Item = item;
     Version = item.ChangesetId.ToString();
     string path = item.ServerItem;
     path = path.Substring(config.RootFolder.Length);
     this.Folder = path;
     this.IsDirectory = item.ItemType == ItemType.Folder;
     this.Name = System.IO.Path.GetFileName(path);
     if (!this.IsDirectory) {
         Folder = Folder.Substring(0, Folder.Length - Name.Length);
     }
     this.Url = item.ServerItem;
 }