Esempio n. 1
0
        public string GetPackageDescription(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadPackage(uid).Description);
        }
Esempio n. 2
0
        public string GetPackageReleaseNotes(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadPackage(uid).ReleaseNotes);
        }
Esempio n. 3
0
        public PackageMetaData GetPackageMetaData(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadPackage(uid).MetaData);
        }
Esempio n. 4
0
        public bool PackageExists(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var path = GetPackageRootPath(uid);

            return(Directory.Exists(path));
        }
Esempio n. 5
0
        public void download_package(string uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var packageUid = PackageUid.Parse(uid);

            _packageManagerService.DownloadPackageAsync(packageUid).GetAwaiter().GetResult();
        }
Esempio n. 6
0
        public string get_file_uri(string uid, string filename)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var packageUid = PackageUid.Parse(uid);

            return($"/packages/{packageUid.Id}/{packageUid.Version}/{filename}");
        }
Esempio n. 7
0
        public Task DownloadPackageAsync(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            _storageService.TryReadOrCreate(out PackageManagerServiceOptions options, PackageManagerServiceOptions.Filename);

            var downloader = new GitHubRepositoryPackageDownloader(options, _logger);

            return(downloader.DownloadAsync(uid, GetPackageRootPath(uid)));
        }
Esempio n. 8
0
        public Task DownloadPackageAsync(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            _storageService.SafeReadSerializedValue(out PackageManagerServiceOptions options, DefaultDirectoryNames.Configuration, PackageManagerServiceOptions.Filename);

            var downloader = new GitHubRepositoryPackageDownloader(options, _logger);

            return(downloader.DownloadAsync(uid, GetPackageRootPath(uid)));
        }
Esempio n. 9
0
        private static string GetLatestVersionPath(string rootPath, string id)
        {
            rootPath = Path.Combine(rootPath, id);

            if (!Directory.Exists(rootPath))
            {
                throw new WirehomePackageNotFoundException(PackageUid.Parse(id));
            }

            var versions = Directory.GetDirectories(rootPath)
                           .OrderByDescending(d => d.ToLowerInvariant());

            return(versions.First());
        }
Esempio n. 10
0
        public string GetPackageRootPath(PackageUid uid)
        {
            var path = GetPackagesRootPath();

            if (string.IsNullOrEmpty(uid.Version))
            {
                path = GetLatestVersionPath(path, uid.Id);
            }
            else
            {
                path = Path.Combine(path, uid.Id, uid.Version);
            }

            return(path);
        }
Esempio n. 11
0
        public Package LoadPackage(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            if (string.IsNullOrEmpty(uid.Id))
            {
                throw new ArgumentException("The ID of the package UID is not set.");
            }

            var path   = GetPackageRootPath(uid);
            var source = LoadPackage(uid, path);

            return(source);
        }
Esempio n. 12
0
        public void DeletePackage(PackageUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var rootPath = GetPackageRootPath(uid);

            if (!Directory.Exists(rootPath))
            {
                return;
            }

            Directory.Delete(rootPath, true);
            _logger.Log(LogLevel.Information, $"Deleted package '{uid}'.");
        }
        public string GetPackageRootPath(PackageUid uid)
        {
            if (uid is null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var path = GetPackagesRootPath();

            if (string.IsNullOrEmpty(uid.Version))
            {
                path = GetLatestVersionPath(path, uid.Id);
            }
            else
            {
                path = Path.Combine(path, uid.Id, uid.Version);
            }

            return(path);
        }
Esempio n. 14
0
        public Task ForkPackageAsync(PackageUid packageUid, PackageUid packageForkUid)
        {
            if (packageUid == null)
            {
                throw new ArgumentNullException(nameof(packageUid));
            }
            if (packageForkUid == null)
            {
                throw new ArgumentNullException(nameof(packageForkUid));
            }

            if (!PackageExists(packageUid))
            {
                throw new WirehomePackageNotFoundException(packageUid);
            }

            if (PackageExists(packageForkUid))
            {
                throw new InvalidOperationException($"Package '{packageForkUid}' already exists.");
            }

            var sourcePath      = GetPackageRootPath(packageUid);
            var destinationPath = GetPackageRootPath(packageForkUid);

            Directory.CreateDirectory(destinationPath);

            foreach (var directory in Directory.GetDirectories(sourcePath, "*", SearchOption.AllDirectories))
            {
                Directory.CreateDirectory(directory.Replace(sourcePath, destinationPath));
            }

            foreach (var file in Directory.GetFiles(sourcePath, "*.*", SearchOption.AllDirectories))
            {
                File.Copy(file, file.Replace(sourcePath, destinationPath), true);
            }

            return(Task.CompletedTask);
        }
Esempio n. 15
0
        private static Package LoadPackage(PackageUid uid, string path)
        {
            if (!Directory.Exists(path))
            {
                throw new WirehomePackageNotFoundException(uid);
            }

            var source = new Package();

            var metaFile = Path.Combine(path, "meta.json");

            if (!File.Exists(metaFile))
            {
                throw new WirehomePackageException($"Package directory '{path}' contains no 'meta.json'.");
            }

            try
            {
                var metaData = File.ReadAllText(metaFile, Encoding.UTF8);
                source.MetaData = JsonConvert.DeserializeObject <PackageMetaData>(metaData);
            }
            catch (Exception exception)
            {
                throw new WirehomePackageException("Unable to parse 'meta.json'.", exception);
            }

            source.Uid = new PackageUid
            {
                Id      = Directory.GetParent(path).Name,
                Version = new DirectoryInfo(path).Name
            };

            source.Description  = ReadFileContent(path, "description.md");
            source.ReleaseNotes = ReadFileContent(path, "releaseNotes.md");
            source.Script       = ReadFileContent(path, "script.py");

            return(source);
        }
Esempio n. 16
0
        private string GetPackageRootPath(PackageUid uid)
        {
            _storageService.TryReadOrCreate(out PackageManagerServiceOptions options, PackageManagerServiceOptions.Filename);

            var rootPath = options.RootPath;

            if (string.IsNullOrEmpty(rootPath))
            {
                rootPath = Path.Combine(_storageService.DataPath, "Packages");
            }

            var path = rootPath;

            if (string.IsNullOrEmpty(uid.Version))
            {
                path = GetLatestVersionPath(path, uid.Id);
            }
            else
            {
                path = Path.Combine(path, uid.Id, uid.Version);
            }

            return(path);
        }