void PopulateDetails() { if (_version != null) { return; } var json = GitHub.GetString( new Uri($"https://raw.githubusercontent.com/{Owner}/{Repository}/master/package.json")); var details = JObject.Parse(json); var version = (string)details["version"]; if (!Version.TryParse(version, out _version)) { _version = new Version(1, 0, 0); _log.Warning("Package {0} has invalid version {1}; assuming {2}", version, _version); } _contributors = details["contributors"].Select(x => (string)x).ToList(); _files = details["files"].Select(x => (string)x).ToList(); _dependencies = (details["dependencies"] ?? new JArray()).Select(x => (string)x).ToList(); _conflicts = (details["conflicts"] ?? new JArray()).Select(x => (string)x).ToList(); _assets = (details["assets"] ?? new JArray()).Select( x => (AssetKind)Enum.Parse(typeof(AssetKind), (string)x)).ToList(); }
public PackageManager() { var csharp = Configuration.CSharpPackageDirectory; var python = Configuration.PythonPackageDirectory; Directory.CreateDirectory(csharp); Directory.CreateDirectory(python); _log.Info("Fetching package registry..."); var json = GitHub.GetString(Configuration.PackageRegistryUri); var manifest = JArray.Parse(json); Registry = manifest.Select(x => new Package((JObject)x)).ToDictionary(x => x.Name); void CheckReferredPackages(bool dependencies) { foreach (var pkg in Registry.Values) { foreach (var name in dependencies ? pkg.Dependencies : pkg.Conflicts) { if (!Registry.ContainsKey(name)) { _log.Warning("Package {0} has {1} package {2} which does not exist; ignoring", pkg.Name, dependencies ? "dependency" : "conflicting", name); } } } } CheckReferredPackages(true); CheckReferredPackages(false); _log.Info("Reading local package manifests..."); void AddLocalPackages(PackageKind kind) { foreach (var dir in Directory.EnumerateDirectories( kind == PackageKind.CSharp ? csharp : python)) { if (!File.Exists(Path.Combine(dir, ManifestFileName))) { continue; } var pkg = new LocalPackage(kind, Path.GetFileName(dir)); _locals.Add(pkg.Name, pkg); } } AddLocalPackages(PackageKind.CSharp); AddLocalPackages(PackageKind.Python); }
public Package(JObject obj) { Name = (string)obj["name"]; Path = GetPath(Name); Description = (string)obj["description"]; License = (string)obj["license"]; Owner = (string)obj["owner"]; Repository = (string)obj["repository"]; var details = JObject.Parse(GitHub.GetString(new Uri( $"https://raw.githubusercontent.com/{Owner}/{Repository}/master/{PackageManager.PackageFileName}"))); Version = Version.Parse((string)details["version"]); Contributors = details["contributors"].Select(x => (string)x).ToList(); Files = details["files"].Select(x => (string)x).ToList(); Dependencies = (details["dependencies"] ?? new JArray()).Select(x => (string)x).ToList(); Conflicts = (details["conflicts"] ?? new JArray()).Select(x => (string)x).ToList(); Assets = (details["assets"] ?? new JArray()).Select( x => (AssetKind)Enum.Parse(typeof(AssetKind), (string)x, true)).ToList(); }
public AssetManager() { var assets = Configuration.AssetDirectory; Directory.CreateDirectory(assets); _log.Info("Fetching asset manifest..."); var json = JObject.Parse(GitHub.GetString(Configuration.AssetManifestUri)); _log.Info("Loading local assets..."); var dcs = new List <IAsset>(); foreach (var region in Configuration.Regions) { dcs.Add(new DataCenterAsset(assets, region, (JObject)json[region.ToString().ToLowerInvariant()])); } _dataCenters = dcs; }
public AssetManager() { var assets = Configuration.AssetDirectory; Directory.CreateDirectory(assets); _log.Info("Fetching asset manifest..."); var json = GitHub.GetString(Configuration.AssetManifestUri); var manifest = JObject.Parse(json); var region = Configuration.Region.ToString().ToLowerInvariant(); var obj = manifest[region]; if (obj == null) { _log.Warning("{0} data center file not available", region); } else { _dc = new DataCenterAsset(assets, (JObject)obj); } }
public PackageManager() { var pkgs = Configuration.PackageDirectory; Directory.CreateDirectory(pkgs); _log.Info("Fetching package registry..."); var registry = JArray.Parse(GitHub.GetString(Configuration.PackageRegistryUri)) .Select(x => new Package((JObject)x)).ToDictionary(x => x.Name); foreach (var pkg in registry.Values.ToArray()) { var abs = Path.GetFullPath(pkg.Path); var bad = false; void CheckReferredPackages(bool dependencies) { foreach (var name in dependencies ? pkg.Dependencies : pkg.Conflicts) { if (!registry.ContainsKey(name)) { _log.Warning("Package {0} has {1} package {2} which does not exist; ignoring package", pkg.Name, dependencies ? "dependency" : "conflicting", name); bad = true; } } } CheckReferredPackages(true); CheckReferredPackages(false); foreach (var file in pkg.Files) { var loc = Path.GetFullPath(Path.Combine(abs, file)); if (!loc.StartsWith(abs + Path.DirectorySeparatorChar) && !loc.StartsWith(abs + Path.AltDirectorySeparatorChar)) { _log.Warning("Package {0} has file path {1} which is illegal; ignoring package", pkg.Name, file); bad = true; } if (loc == Path.Combine(abs, PackageFileName) || loc == Path.Combine(abs, ManifestFileName) || loc == Path.Combine(abs, ConfigurationFileName)) { _log.Warning("Package {0} has file path {1} which is for internal use; ignoring package", pkg.Name, file); bad = true; } } if (bad) { registry.Remove(pkg.Name); } } Registry = registry; _log.Info("Reading local package manifests..."); foreach (var dir in Directory.EnumerateDirectories(pkgs)) { if (!File.Exists(Path.Combine(dir, ManifestFileName))) { continue; } var pkg = new LocalPackage(Path.GetFileName(dir)); _locals.Add(pkg.Name, pkg); } }