public override Dictionary <IProjectFile, NugetDefinition> GetAllNugetDefinitions(IProjectReference reference, bool clearCache) { var cache = SimpleCache <Tuple <int, string>, Dictionary <IProjectFile, NugetDefinition> > .CreateCache("Source-Project-AllNugetDefinitions"); if (!clearCache) { var cacheObj = cache.Get(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier())); if (cacheObj != null) { return(cacheObj); } } var result = new Dictionary <IProjectFile, NugetDefinition>(); var packageFiles = GetAllNugetSpecFiles(reference, clearCache); if (packageFiles == null || packageFiles.Length == 0) { return(result); } var client = CreateRestClient(); foreach (var packageFile in packageFiles) { var file = (ProjectFile)packageFile; var request = CreateFileReadRequest((ProjectReference)reference, file.Path, "master"); var response = client.Execute(request); if (response.ErrorException != null) { throw new Exception("Failed to read " + file.Path + " from " + reference.GetName(), response.ErrorException); } if (response.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Failed to read " + file.Path + " from " + reference.GetName() + ": 404 not found"); } if (file.Name.Split('.').Last().Equals("nuspec", StringComparison.OrdinalIgnoreCase)) { result.Add(file, PackageNuspecReader.ParseNuspec(response.Content)); } else if (file.Name.Split('.').Last().Equals("csproj", StringComparison.OrdinalIgnoreCase)) { result.Add(file, PackageNuspecReader.ParseCsproj(response.Content)); } else { throw new Exception("Could not handle nuspec file: " + file.Name); } } cache.Insert(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier()), result); return(result); }
public override Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]> GetAllNugetDependencies(IProjectReference reference, bool clearCache) { var cache = SimpleCache <Tuple <int, string>, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]> > .CreateCache("Source-Project-AllNugetDependencies"); if (!clearCache) { var cacheObj = cache.Get(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier())); if (cacheObj != null) { return(cacheObj); } } var result = new Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]>(); var packageFiles = GetAllNugetPackagesConfig(reference, clearCache); if (packageFiles == null || packageFiles.Length == 0) { return(result); } var client = CreateRestClient(); var allFiles = Task.Run(() => GetAllProjectFiles(reference, clearCache)); foreach (var packageFile in packageFiles) { var file = (ProjectFile)packageFile; var request = CreateFileReadRequest((ProjectReference)reference, file.Path, "master"); var response = client.Execute(request); if (response.ErrorException != null) { throw new Exception("Failed to read " + file.Path + " from " + reference.GetName(), response.ErrorException); } if (response.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Failed to read " + file.Path + " from " + reference.GetName() + ": 404 not found"); } var csprojFiles = allFiles.Result.Where(f => { var fPath = f.FilePath().AsPath(true); return(fPath.FileExtension == "csproj" && fPath.IsInSameDirectory(file.FilePath())); }).ToArray(); string assemblyName; string csprojFilePath; if (csprojFiles.Length > 0) { if (csprojFiles.Length > 1) { throw new Exception("Failed because of multiple csproj files: " + string.Join(", ", csprojFiles.Select(x => x.FilePath()))); } var csprojFile = csprojFiles[0]; var csprojFileRequest = CreateFileReadRequest((ProjectReference)reference, csprojFile.FilePath(), "master"); var csprojFileResponse = client.Execute(csprojFileRequest); if (csprojFileResponse.ErrorException != null) { throw new Exception("Failed to read " + csprojFile.FilePath() + " from " + reference.GetName(), csprojFileResponse.ErrorException); } if (csprojFileResponse.StatusCode == HttpStatusCode.NotFound) { throw new Exception("Failed to read " + csprojFile.FilePath() + " from " + reference.GetName() + ": 404 not found"); } var csprojContnet = PackageNuspecReader.ParseCsproj(csprojFileResponse.Content); assemblyName = csprojContnet.Id; csprojFilePath = csprojFile.FilePath(); } else { throw new Exception("Could not find any matching csproj for: " + file.FilePath()); } IProjectInformation projectInformation = new ProjectInformation(assemblyName, csprojFilePath); result.Add(new Tuple <IProjectFile, IProjectInformation>(file, projectInformation), PackagesConfigReader.Parse(response.Content).ToArray()); } cache.Insert(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier()), result); return(result); }