Exemple #1
0
        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);
        }
Exemple #2
0
 private static Task FetchDependencyMapItems(IProjectSource source, IProjectReference project, List <Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]>, Dictionary <IProjectFile, NugetDefinition> > > model)
 {
     return(Task.Run(() =>
     {
         try
         {
             var nugetDep = source.GetAllNugetDependencies(project, false);
             var nugetDef = source.GetAllNugetDefinitions(project, false);
             // Dictionary<Tuple<IProjectFile, IProjectInformation>, NugetDependency[]>
             if (nugetDep.Count > 0 || nugetDep.Count > 0)
             {
                 model.Add(new Tuple <IProjectReference, Dictionary <Tuple <IProjectFile, IProjectInformation>, NugetDependency[]>, Dictionary <IProjectFile, NugetDefinition> >
                               (project, nugetDep, nugetDef));
             }
         }
         catch (Exception ex)
         {
             throw new Exception("Failed for project: " + project.GetName(), ex);
         }
     }));
 }
Exemple #3
0
        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);
        }