예제 #1
0
        public string GetReleaseNotes(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadEntity(uid).ReleaseNotes);
        }
예제 #2
0
        public RepositoryEntityMetaData GetMetaData(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadEntity(uid).MetaData);
        }
예제 #3
0
        public string GetDescription(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            return(LoadEntity(uid).Description);
        }
예제 #4
0
        public string get_file_uri(string uid, string filename)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var entityUid = RepositoryEntityUid.Parse(uid);

            return($"/repository/{entityUid.Id}/{entityUid.Version}/{filename}");
        }
예제 #5
0
        public async Task DownloadEntityAsync(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            _storageService.TryReadOrCreate(out RepositoryServiceOptions options, "RepositoryServiceConfiguration.json");

            var downloader = new GitHubRepositoryEntityDownloader(options, _loggerFactory);
            await downloader.DownloadAsync(uid, GetEntityRootPath(uid)).ConfigureAwait(false);
        }
예제 #6
0
        public void DeleteEntity(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

            var rootPath = GetEntityRootPath(uid);

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

            Directory.Delete(rootPath, true);
            _logger.Log(LogLevel.Information, $"Deleted entity '{uid}'.");
        }
예제 #7
0
        public RepositoryEntity LoadEntity(RepositoryEntityUid uid)
        {
            if (uid == null)
            {
                throw new ArgumentNullException(nameof(uid));
            }

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

            var path   = GetEntityRootPath(uid);
            var source = LoadEntity(uid, path);

            return(source);
        }
예제 #8
0
        private static RepositoryEntity LoadEntity(RepositoryEntityUid uid, string path)
        {
            if (!Directory.Exists(path))
            {
                throw new WirehomeRepositoryEntityNotFoundException(uid);
            }

            var source = new RepositoryEntity();

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

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

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

            source.Uid = new RepositoryEntityUid
            {
                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);
        }
예제 #9
0
        private string GetEntityRootPath(RepositoryEntityUid uid)
        {
            _storageService.TryRead(out RepositoryServiceOptions options, RepositoryServiceOptions.Filename);

            var rootPath = options.RootPath;

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

            var path = rootPath;

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

            return(path);
        }