Exemplo n.º 1
0
        public async Task <string> RepositoryFile(string repositoryName, string tag, string fileName)
        {
            try
            {
                var repositories = await _repositoriesRepository.GetAllAsync();

                var repositoryEntity = repositories.FirstOrDefault(x =>
                                                                   x.OriginalName == repositoryName &&
                                                                   tag == "" || x.Tag == tag &&
                                                                   x.FileName == fileName &&
                                                                   (fileName.Contains("_git_") ? x.GitUrl.Contains("github.com") : x.FileName.Contains("_bb_")));
                if (repositoryEntity == null)
                {
                    return(null);
                }

                await _connectionUrlHistoryRepository.SaveConnectionUrlHistoryAsync(
                    repositoryEntity.RepositoryId,
                    UserInfo.Ip,
                    Request.Headers["User-Agent"].FirstOrDefault());

                var repository = await _repositoriesRepository.GetAsync(repositoryEntity.RepositoryId);

                if (repository == null)
                {
                    return("Repository not found");
                }

                var correctFileName = repository.UseManualSettings ? MANUAL_FILE_PREFIX + fileName : fileName;

                var jsonData = await _repositoryDataRepository.GetDataAsync(correctFileName);

                var keyValues = await _keyValuesRepository.GetAsync();

                var servTokens = await _serviceTokensRepository.GetAllAsync();

                jsonData = jsonData.SubstituteServiceTokens(servTokens);
                var network = await _networkRepository.GetByIpAsync(UserInfo.Ip);

                var repositoryVersionSeparator = "-";
                jsonData = jsonData.Substitute(
                    keyValues,
                    network?.Id,
                    repositoryVersion: !string.IsNullOrEmpty(repository.Tag)
                        ? repository.Tag + repositoryVersionSeparator
                        : string.Empty);
                //TODO: do we need this?
                jsonData = jsonData.Replace(@"\/", @"/");

                return(jsonData);
            }
            catch (Exception ex)
            {
                var data = new { repositoryName, tag, fileName };
                _log.Error(ex, context: data);
                return(string.Empty);
            }
        }
        public async Task <string> GetFileData(string file)
        {
            try
            {
                var fileData = await _repositoryDataRepository.GetDataAsync(file);

                return(fileData);
            }
            catch (Exception ex)
            {
                _log.Error(ex, context: file);
                return(string.Empty);
            }
        }
Exemplo n.º 3
0
 public Task <string> GetDataAsync(string file = null)
 {
     return(_repositoryDataRepository.GetDataAsync(file));
 }