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 IChickenNugetProject ReadChickenNugetProject(IProjectReference reference, bool clearCache) { var cache = SimpleCache <Tuple <int, string>, IChickenNugetProject> .CreateCache("Source-Project-ChickenNugetProject"); if (!clearCache) { var cacheObj = cache.Get(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier())); if (cacheObj != null) { return(cacheObj); } } var project = (ProjectReference)reference; if (project.ChickenNugetProject != null) { return(project.ChickenNugetProject); } var client = CreateRestClient(); var request = CreateFileReadRequest(project, ChkngtProjectFilePath, "master"); var response = client.Execute(request); if (response.StatusCode == HttpStatusCode.NotFound) { return(null); } if (response.ErrorException != null) { throw new Exception("Failed to read ChickenNuget file", response.ErrorException); } var json = response.ToJsonObject(); var configsJson = (JArray)json["files"]["packages-config"]; var nuspecsJson = (JArray)json["files"]["package-nuspec"]; var configs = configsJson?.Select(x => (IProjectFile)CreateProjectFileFromPath(reference, x.Value <string>())).ToArray(); var nuspecs = nuspecsJson?.Select(x => (IProjectFile)CreateProjectFileFromPath(reference, x.Value <string>())).ToArray(); var chickenNugetProject = new ChickenNugetProject(configs ?? new IProjectFile[0], nuspecs ?? new IProjectFile[0]); project.ChickenNugetProject = chickenNugetProject; cache.Insert(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier()), chickenNugetProject); return(chickenNugetProject); }
public override IProjectReference[] GetAllProjects(bool clearCache) { var cache = SimpleCache <int, IProjectReference[]> .CreateCache("Source-AllProjects"); if (!clearCache) { var cacheObj = cache.Get(this.Config.Id); if (cacheObj != null) { return(cacheObj); } } var client = CreateRestClient(); var list = new List <IProjectReference>(); var page = 1; JArray projects; do { projects = client.Execute(CreateGetAllProjectsRequest(page++)).ToJsonArray(); foreach (var project in projects) { var id = project["id"].Value <int>(); var name = project["name"].Value <string>(); var webUrl = project["web_url"].Value <string>(); var repoUrl = project["http_url_to_repo"].Value <string>(); var reference = new ProjectReference(id, name, webUrl, repoUrl); list.Add(reference); } } while (projects.Count == 100); var projectReferences = list.ToArray(); cache.Insert(Config.Id, projectReferences); return(projectReferences); }
private IProjectFile[] GetAllProjectFiles(IProjectReference reference, bool clearCache) { var cache = SimpleCache <Tuple <int, string>, IProjectFile[]> .CreateCache("Source-Project-AllProjectFiles"); if (!clearCache) { var cacheObj = cache.Get(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier())); if (cacheObj != null) { return(cacheObj); } } var project = (ProjectReference)reference; var client = CreateRestClient(); var list = new List <IProjectFile>(); IterateTreeWithRequests(client, project, list, null); var allProjectFiles = list.ToArray(); cache.Insert(new Tuple <int, string>(this.Config.Id, reference.GetIdentifier()), allProjectFiles); return(allProjectFiles); }
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); }