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
        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);
        }
Exemple #3
0
        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);
        }
Exemple #4
0
        public void StoreCacheProjectFiles(string key, IProjectReference project, IProjectFile[] value)
        {
            using (var db = CreateStorage())
            {
                var caches     = GetProjectFileCache(db);
                var identifier = project.GetIdentifier();
                caches.Delete(c => c.ConfigurationId == _config.Id && c.Key == key && c.ProjectIdentifier == identifier);

                var cache = new ProjectFileListCache()
                {
                    Key               = key,
                    ConfigurationId   = _config.Id,
                    ProjectIdentifier = identifier,
                    Files             = value.Select(x => _source.PackProjectFile(x)).ToArray(),
                };

                caches.Upsert(cache);
            }
        }
Exemple #5
0
        public IProjectFile[] GetCacheProjectFiles(string key, IProjectReference project)
        {
            using (var db = CreateStorage())
            {
                var identifier = project.GetIdentifier();
                var cache      = GetProjectFileCache(db).FindOne(c => c.ConfigurationId == _config.Id && c.Key == key && c.ProjectIdentifier == identifier);

                if (cache == null)
                {
                    return(null);
                }

                var list = new List <IProjectFile>();

                foreach (var file in cache.Files)
                {
                    var projectFile = _source.ConstructProjectFile(file);
                    list.Add(projectFile);
                }

                return(list.ToArray());
            }
        }
Exemple #6
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);
        }