private async Task DisplayData() { if (ParentKey != "") { var articleSet = await RepositoryReference.GetArticlesAsync <string>(pager.PageIndex, pager.PageSize, "", this.searchQuery, this.sortOrder, ParentKey); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } else if (ParentId != 0) { var articleSet = await RepositoryReference.GetArticlesAsync <int>(pager.PageIndex, pager.PageSize, "", this.searchQuery, this.sortOrder, ParentId); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } else { var articleSet = await RepositoryReference.GetArticlesAsync <int>(pager.PageIndex, pager.PageSize, "", this.searchQuery, this.sortOrder, 0); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } StateHasChanged(); // Refresh }
private Task <IReadOnlyList <RepositoryContent> > DownloadRepositoryContents(RepositoryReference repoSpec, string path) { var(client, owner, name, @ref) = ( GitHubClient.Repository.Content, repoSpec.RepositoryOwner, repoSpec.RepositoryName, repoSpec.TreeReference ); if (string.IsNullOrEmpty(@ref)) { if (string.IsNullOrEmpty(path)) { return(client.GetAllContents(owner, name)); } else { return(client.GetAllContents(owner, name, path)); } } else { if (string.IsNullOrEmpty(path)) { return(client.GetAllContentsByRef(owner, name, @ref)); } else { return(client.GetAllContentsByRef(owner, name, path, @ref)); } } }
private async Task <string> CheckAndPopulateFileContentAsync(RepositoryReference repo, IReadOnlyList <TreeItem> tree, string value, string folder = null) { if (string.IsNullOrEmpty(value) || !Uri.IsWellFormedUriString(value, UriKind.Relative)) { return(value); } var fileName = value.Split('/', StringSplitOptions.RemoveEmptyEntries).Last(); var filePath = string.IsNullOrEmpty(folder) ? fileName : $"{folder}/{fileName}"; var fileItem = tree.FirstOrDefault(i => i.Path.Equals(filePath, StringComparison.Ordinal)); if (fileItem is null) { return(value); } try { var files = await client.Repository.Content .GetAllContents(repo.Organization, repo.Repository, fileItem.Path) .ConfigureAwait(false); return(files.FirstOrDefault()?.Content ?? value); } catch (NotFoundException) { return(value); } }
public override bool Evaluate(string sourcePath, RepositoryReference sourceRepo, RepositoryContent sourceContent, string targetPath, RepositoryReference targetRepo, RepositoryContent targetContent) { return(!(targetContent is null)); }
private async Task <string> GetTargetPath(RepositoryContent sourceContent, PathGroupSpec pathSpec, RepositoryReference targetRepo) { var targetPath = pathSpec.DestinationPath; RepositoryContentEntry targetEntry; try { targetEntry = await GetRepositoryContentEntry(targetRepo, targetPath) .ConfigureAwait(continueOnCapturedContext: false); } catch (NotFoundException) { targetEntry = null; } switch (targetEntry) { case null when pathSpec.SourcePaths.Count > 1: case RepositoryContentEntry _ when !(targetEntry.Leaf is null) && targetEntry.Leaf.Type.TryParse(out var targetType) && targetType == ContentType.Dir: case RepositoryContentEntry _ when targetEntry.Leaf is null: return(pathSpec.DestinationPath.TrimEnd('/').TrimEnd() + "/" + sourceContent.Name); case null: return(targetPath); case RepositoryContentEntry _ when !(targetEntry.Leaf is null): return(targetEntry.Leaf.Path); } return(null); }
/// <summary> /// 페이지 초기화 이벤트 처리기 /// </summary> protected override async Task OnInitializedAsync() { Model = await RepositoryReference.GetByIdAsync(Id); Content = Dul.HtmlUtility.EncodeWithTabAndSpace(Model.Content); ParentId = Model.ParentId.ToString(); }
public void DeserializeRepository() { var repositoryReference = new RepositoryReference() { Url = "https://github.com/foo/bar.git", Provider = RepositoryProvider.GitHub, Type = RepositoryReferenceType.Unknown }; var projectTemplate = new ProjectTemplate() { Id = Guid.NewGuid().ToString(), Organization = Guid.NewGuid().ToString(), Repository = repositoryReference }; var componentPath = "/foo/bar/component.yaml"; var componentJson = GetComponentDefinitionAsJson("repository"); var componentTemplate = TeamCloudSerialize .DeserializeObject <ComponentTemplate>(componentJson, new ComponentTemplateConverter(projectTemplate, componentPath)); Assert.NotNull(componentTemplate); Assert.IsAssignableFrom <ComponentRepositoryTemplate>(componentTemplate); Assert.NotNull(componentTemplate.Configuration); Assert.IsAssignableFrom <ComponentRepositoryConfiguration>(componentTemplate.Configuration); }
private async Task ExecuteCopyFileContent(string sourcePath, RepositoryContent sourceContent, PathGroupSpec copySpec, RepositoryReference sourceRepo, RepositoryReference targetRepo, CancellationToken cancelToken) { var targetPath = await GetTargetPath(sourceContent, copySpec, targetRepo) .ConfigureAwait(continueOnCapturedContext: false); if (cancelToken.IsCancellationRequested) { return; } RepositoryContentEntry targetEntry; try { targetEntry = await GetRepositoryContentEntry(targetRepo, targetPath) .ConfigureAwait(false); } catch (NotFoundException) { targetEntry = null; } var targetContent = targetEntry?.Leaf; bool copyCond = copySpec.Condition?.Evaluate( sourcePath, sourceRepo, sourceContent, targetPath, targetRepo, targetContent ) ?? true; if (!copyCond) { Logger.LogDebug($"Not copying path '{{{nameof(sourcePath)}}}' from {{{nameof(sourceRepo)}}} to '{{{nameof(targetPath)}}}' in {{{nameof(targetRepo)}}}. Condition of type {{conditionType}} evaluated {{conditionValue}}.", sourcePath, sourceRepo.ToLogString(), targetPath, targetRepo.ToLogString(), copySpec.Condition?.GetType(), copyCond); } }
/// <summary> /// 수정 버튼 이벤트 처리기 /// </summary> protected async void FormSubmit() { int.TryParse(ParentId, out int parentId); Model.ParentId = parentId; #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { fileName = file.Name; fileSize = Convert.ToInt32(file.Size); // 첨부 파일 삭제 await FileStorageManagerInjector.DeleteAsync(Model.FileName, "Memos"); // 다시 업로드 fileName = await FileStorageManagerInjector.UploadAsync(file.Data, file.Name, "", true); Model.FileName = fileName; Model.FileSize = fileSize; } } #endregion await RepositoryReference.EditAsync(Model); NavigationManagerInjector.NavigateTo("/Memos"); }
private void AddRepositoryContentsToCache(RepositoryReference repoSpec, IEnumerable <RepositoryContent> contentList) { foreach (var repoContent in contentList) { var subKey = new RepositoryPathReference { RepositoryOwner = repoSpec.RepositoryOwner, RepositoryName = repoSpec.RepositoryName, TreeReference = repoSpec.TreeReference, Path = repoContent.Path }; if (RepositoryCache.TryGetValue(subKey, out RepositoryContentEntry subEntry)) { subEntry.Leaf = repoContent; } else { subEntry = new RepositoryContentEntry { Leaf = repoContent } }; var subOptions = new MemoryCacheEntryOptions { Size = repoContent.Size }; RepositoryCache.Set(subKey, subEntry, subOptions); if (repoContent.Type.TryParse(out var repoContentType) && repoContentType == ContentType.File) { subEntry.Contents = new List <RepositoryContent>(capacity: 1) { repoContent } } ; } }
/// <summary> /// 파일 업로드 버튼 클릭 이벤트 처리기 /// </summary> protected async void FormSubmit() { int.TryParse(ParentId, out int parentId); model.ParentId = parentId; #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { fileName = file.Name; fileSize = Convert.ToInt32(file.Size); fileName = await FileStorageManagerReference.UploadAsync(file.Data, file.Name, "", true); model.FileName = fileName; model.FileSize = fileSize; } } #endregion foreach (var m in Models) { m.FileName = model.FileName; m.FileSize = model.FileSize; await RepositoryReference.AddAsync(m); } NavigationManagerInjector.NavigateTo("/Replys"); }
public void DeserializeProject() { var repositoryReference = new RepositoryReference() { Url = "https://github.com/foo/bar.git", Provider = RepositoryProvider.GitHub, Type = RepositoryReferenceType.Unknown }; var projectTemplate = new ProjectTemplate() { Id = Guid.NewGuid().ToString(), Organization = Guid.NewGuid().ToString(), DisplayName = "Foo", Repository = repositoryReference }; var porjectPath = "/foo/bar/project.yaml"; var projectJson = GetProjectDefinitionAsJson("project"); var projectTemplate2 = TeamCloudSerialize .DeserializeObject <ProjectTemplate>(projectJson, new ProjectTemplateConverter(projectTemplate, porjectPath)); Assert.NotNull(projectTemplate2); Assert.IsAssignableFrom <ProjectTemplate>(projectTemplate2); }
private async Task DisplayData() { // ParentKey와 ParentId를 사용하는 목적은 특정 부모의 Details 페이지에서 리스트로 표현하기 위함 if (ParentKey != "") { var articleSet = await RepositoryReference.GetArticlesAsync <string>(pager.PageIndex, pager.PageSize, searchField : "", this.searchQuery, this.sortOrder, ParentKey); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } else if (ParentId != 0) { var articleSet = await RepositoryReference.GetArticlesAsync <int>(pager.PageIndex, pager.PageSize, searchField : "", this.searchQuery, this.sortOrder, ParentId); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } else { var articleSet = await RepositoryReference.GetArticlesAsync <int>(pager.PageIndex, pager.PageSize, searchField : "", this.searchQuery, this.sortOrder, parentIdentifier : 0); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); } StateHasChanged(); // Refresh }
/// <summary> /// 삭제 모달 폼에서 현재 선택한 항목 삭제 /// </summary> protected async void DeleteClick() { await RepositoryReference.DeleteAsync(this.model.Id); DeleteDialogReference.Hide(); this.model = new DepartmentModel(); // 선택했던 모델 초기화 await DisplayData(); // 다시 로드 }
protected async void CreateOrEditClick() { // 변경 내용 저장 Model.Name = ModelEdit.Name; Model.Title = ModelEdit.Title; Model.Content = ModelEdit.Content; Model.Password = ModelEdit.Password; #region 일 업로드 관련 추가 코드 영역 if (selectedFiles != null && selectedFiles.Length > 0) { // 파일 업로드 var file = selectedFiles.FirstOrDefault(); var fileName = ""; int fileSize = 0; if (file != null) { //file.Name = $"{DateTime.Now.ToString("yyyyMMddhhmmss")}{file.Name}"; fileName = file.Name; fileSize = Convert.ToInt32(file.Size); //[A] byte[] 형태 //var ms = new MemoryStream(); //await file.Data.CopyToAsync(ms); //await FileStorageManager.ReplyAsync(ms.ToArray(), file.Name, "", true); //[B] Stream 형태 //string folderPath = Path.Combine(WebHostEnvironment.WebRootPath, "files"); await FileStorageManagerReference.UploadAsync(file.Data, file.Name, "Memos", true); Model.FileName = fileName; Model.FileSize = fileSize; } } #endregion if (!int.TryParse(parentId, out int newParentId)) { newParentId = 0; } Model.ParentId = newParentId; Model.ParentKey = Model.ParentKey; if (Model.Id == 0) { // Create await RepositoryReference.AddAsync(Model); CreateCallback?.Invoke(); } else { // Edit await RepositoryReference.EditAsync(Model); await EditCallback.InvokeAsync(true); } //IsShow = false; // this.Hide() }
private static RepositoryReference ParseGitHubUrl(this RepositoryReference repository) { repository.Url = repository.Url .Replace("git@", "https://", StringComparison.OrdinalIgnoreCase) .Replace("github.com:", "github.com/", StringComparison.OrdinalIgnoreCase); if (repository.Url.EndsWith(".git", StringComparison.OrdinalIgnoreCase)) { repository.Url = repository.Url[0..^ 4];
private async Task DisplayData() { var articleSet = await RepositoryReference.GetArticlesAsync <int>(pager.PageIndex, pager.PageSize, "", this.searchQuery, this.sortOrder, 0); pager.RecordCount = articleSet.TotalCount; models = articleSet.Items.ToList(); StateHasChanged(); }
public Task <RepositoryReference> GetRepositoryReferenceAsync(RepositoryReference repository) { repository = repository.ParseUrl(); return(repository.Provider switch { RepositoryProvider.DevOps => DevOpsService.GetRepositoryReferenceAsync(repository), RepositoryProvider.GitHub => github.GetRepositoryReferenceAsync(repository), _ => throw new NotSupportedException($"Repository provider {repository.Provider} is not supported.") });
/// <summary> /// 토글: Pinned /// </summary> protected async void ToggleClick() { model.Active = !model.Active; // 변경된 내용 업데이트 await RepositoryReference.UpdateAsync(this.model); IsInlineDialogShow = false; // 표시 속성 초기화 this.model = new DepartmentModel(); // 선택한 모델 초기화 await DisplayData(); // 다시 로드 }
public override bool Evaluate(string sourcePath, RepositoryReference sourceRepo, RepositoryContent sourceContent, string targetPath, RepositoryReference targetRepo, RepositoryContent targetContent) { var cond = Condition?.Evaluate( sourcePath, sourceRepo, sourceContent, targetPath, targetRepo, targetContent ) ?? true; return(!cond); }
/// <summary> /// 토글: Pinned /// </summary> protected async void ToggleClick() { this.model.IsPinned = (this.model?.IsPinned == true) ? false : true; // 변경된 내용 업데이트 await RepositoryReference.UpdateAsync(this.model); IsInlineDialogShow = false; // 표시 속성 초기화 this.model = new Archive(); // 선택한 모델 초기화 await DisplayData(); // 다시 로드 }
/// <summary> /// 삭제 모달 폼에서 현재 선택한 항목 삭제 /// </summary> protected async void DeleteClick() { if (!string.IsNullOrEmpty(model?.FileName)) { // 첨부 파일 삭제 await FileStorageManagerReference.DeleteAsync(model.FileName, "Archives"); } await RepositoryReference.DeleteAsync(this.model.Id); DeleteDialogReference.Hide(); this.model = new Archive(); // 선택했던 모델 초기화 await DisplayData(); // 다시 로드 }
protected async void DownloadBy(Archive model) { if (!string.IsNullOrEmpty(model.FileName)) { byte[] fileBytes = await FileStorageManagerReference.DownloadAsync(model.FileName, "Archives"); if (fileBytes != null) { model.DownCount = model.DownCount + 1; await RepositoryReference.EditAsync(model); await FileUtil.SaveAs(JSRuntimeInjector, model.FileName, fileBytes); } } }
private RepositoryContentChangeTracker GetOrCreateRepositoryChangeTracker(RepositoryReference repo) { RepositoryContentChangeTracker changeTracker; lock (RepositoryChangeTracker) { if (!RepositoryChangeTracker.TryGetValue(repo, out changeTracker)) { changeTracker = new RepositoryContentChangeTracker { Reference = repo }; RepositoryChangeTracker[repo] = changeTracker; } } return(changeTracker); }
private async Task UploadRepositoryContent( RepositoryReference targetRepo, string path, string commitMessage, string sourceContentBase64, CancellationToken cancelToken) { var changeTracker = GetOrCreateRepositoryChangeTracker(targetRepo); await changeTracker.Lock.WaitAsync(cancelToken).ConfigureAwait(false); try { await UploadRepositoryContent(changeTracker, path, commitMessage, sourceContentBase64, cancelToken ).ConfigureAwait(continueOnCapturedContext: false); } finally { changeTracker.Lock.Release(); } }
public async Task <IActionResult> GetIssuesToDispatch(string ownerName, string repoName) { var accessToken = await HttpContext.GetTokenAsync("access_token"); var gitHub = GitHubUtils.GetGitHubClient(accessToken); // Issue the three queries simultaneously and wait for results var allRepoIssuesTask = gitHub.Issue.GetAllForRepository(ownerName, repoName); var allLabelsTask = gitHub.Issue.Labels.GetAllForRepository(ownerName, repoName); await Task.WhenAll(allRepoIssuesTask, allLabelsTask); var allRepoIssues = await allRepoIssuesTask; var allLabels = await allLabelsTask; var sortedRepoLabelNames = allLabels .Where(label => label.Name.StartsWith("repo:", StringComparison.OrdinalIgnoreCase)) .Select(label => label.Name) .OrderBy(labelName => labelName, StringComparer.OrdinalIgnoreCase) .ToList(); // TODO: Ignore Backlog/Discussion(s) milestones? // TODO: Project the issues to a simpler item that also includes action links for dispatching, etc. var repoRef = new RepositoryReference { Owner = new UserReference { Login = ownerName, }, Name = repoName, }; var allIssuesWithoutRepoLabels = allRepoIssues .Where(issue => issue.Labels.All(label => !sortedRepoLabelNames.Contains(label.Name, StringComparer.OrdinalIgnoreCase)) && !IsExcludedMilestone(issue.Milestone?.Title)) .Select(issue => GetIssueDataFromIssue(issue, repoRef)) .ToList(); return(Json(new { issuesWithoutRepoLabels = allIssuesWithoutRepoLabels, repoLabels = sortedRepoLabelNames, })); }
/// <summary> /// 페이지 초기화 이벤트 처리기 /// </summary> protected override async Task OnInitializedAsync() { // 답변 글쓰기 페이지라면, 기존 데이터 읽어오기 if (Id != 0) { // 기존 글의 데이터를 읽어오기 Model = await RepositoryReference.GetByIdAsync(Id); Model.Id = 0; // 답변 페이지는 새로운 글로 초기화 Model.Name = ""; Model.Title = "Re: " + Model.Title; Model.Content = "\r\n====\r\n" + Model.Content; ParentRef = (int)Model.Ref; ParentStep = (int)Model.Step; ParentRefOrder = (int)Model.RefOrder; } }
public override bool Evaluate(string sourcePath, RepositoryReference sourceRepo, RepositoryContent sourceContent, string targetPath, RepositoryReference targetRepo, RepositoryContent targetContent) { foreach (var condSpec in Conditions ?? Enumerable.Empty <ConditionSpec>()) { bool condItem = condSpec?.Evaluate( sourcePath, sourceRepo, sourceContent, targetPath, targetRepo, targetContent ) ?? true; if (!condItem) { return(false); } } return(true); }
/// <summary> /// 삭제 버튼 클릭 이벤트 처리기 /// </summary> protected async void DeleteClick() { bool isDelete = await JSRuntimeInjector.InvokeAsync <bool>("confirm", $"Are you sure you want to delete it?"); if (isDelete) { if (!string.IsNullOrEmpty(Model?.FileName)) { // 첨부 파일 삭제 await FileStorageManagerReference.DeleteAsync(Model.FileName, ""); } await RepositoryReference.DeleteAsync(Id); // 삭제 NavigationManagerInjector.NavigateTo("/Memos"); // 리스트 페이지로 이동 } else { await JSRuntimeInjector.InvokeAsync <object>("alert", "Canceled."); } }
/// <summary> /// 삭제 버튼 클릭 이벤트 처리기 /// </summary> protected async void DeleteClick() { bool isDelete = await JSRuntimeInjector.InvokeAsync <bool>("confirm", $"{Id}번 글을 정말로 삭제하시겠습니까?"); if (isDelete) { if (!string.IsNullOrEmpty(Model?.FileName)) { // 첨부 파일 삭제 await FileStorageManagerReference.DeleteAsync(Model.FileName, ""); } await RepositoryReference.DeleteAsync(Id); // 삭제 NavigationManagerInjector.NavigateTo("/Replys"); // 리스트 페이지로 이동 } else { await JSRuntimeInjector.InvokeAsync <object>("alert", "취소되었습니다."); } }