+
+
+
+
+ @if (!string.IsNullOrEmpty(Model.NotificationMessage))
+ {
+
+ @Model.NotificationMessage
+
+
+ }
diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs
index e496203cf..376640738 100644
--- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs
+++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Index.cshtml.cs
@@ -8,37 +8,52 @@ using APIViewWeb.Repositories;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using APIViewWeb.Managers;
-using Microsoft.TeamFoundation.Common;
using APIViewWeb.Helpers;
using Microsoft.VisualStudio.Services.Common;
using APIViewWeb.Hubs;
using Microsoft.AspNetCore.SignalR;
-using System.Text;
using APIViewWeb.LeanModels;
+using System.Text;
+using APIViewWeb.Managers.Interfaces;
+using System.IO;
+using ApiView;
+using Microsoft.AspNetCore.Http;
namespace APIViewWeb.Pages.Assemblies
{
public class IndexPageModel : PageModel
{
private readonly IReviewManager _reviewManager;
+ private readonly IAPIRevisionsManager _apiRevisionsManager;
private readonly IHubContext
_notificationHubContext;
public readonly UserPreferenceCache _preferenceCache;
public readonly IUserProfileManager _userProfileManager;
+ private readonly ICodeFileManager _codeFileManager;
+
public const int _defaultPageSize = 50;
public const string _defaultSortField = "LastUpdatedOn";
- public IndexPageModel(IReviewManager reviewManager, IUserProfileManager userProfileManager, UserPreferenceCache preferenceCache, IHubContext notificationHub)
+ public IndexPageModel(IReviewManager reviewManager, IAPIRevisionsManager apiRevisionsManager, IUserProfileManager userProfileManager,
+ UserPreferenceCache preferenceCache, IHubContext notificationHub, ICodeFileManager codeFileManager)
{
_notificationHubContext = notificationHub;
_reviewManager = reviewManager;
+ _apiRevisionsManager = apiRevisionsManager;
_preferenceCache = preferenceCache;
_userProfileManager = userProfileManager;
+ _codeFileManager = codeFileManager;
}
+ [FromForm]
+ public UploadModel Upload { get; set; }
+ [FromForm]
+ public string Label { get; set; }
public ReviewsProperties ReviewsProperties { get; set; } = new ReviewsProperties();
public (IEnumerable Reviews, int TotalCount, int TotalPages,
int CurrentPage, int? PreviousPage, int? NextPage) PagedResults { get; set; }
+ [BindProperty(Name = "notificationMessage", SupportsGet = true)]
+ public string NotificationMessage { get; set; }
public async Task OnGetAsync(
IEnumerable search, IEnumerable languages, IEnumerable state,
@@ -66,6 +81,79 @@ namespace APIViewWeb.Pages.Assemblies
return Partial("_ReviewsPartial", PagedResults);
}
+ public async Task OnPostUploadAsync()
+ {
+ if (!ModelState.IsValid)
+ {
+ var errors = new StringBuilder();
+ foreach (var modelState in ModelState.Values)
+ {
+ foreach (var error in modelState.Errors)
+ {
+ errors.AppendLine(error.ErrorMessage);
+ }
+ }
+ var notifcation = new NotificationModel() { Message = errors.ToString(), Level = NotificatonLevel.Error };
+ await _notificationHubContext.Clients.Group(User.GetGitHubLogin()).SendAsync("RecieveNotification", notifcation);
+ return new NoContentResult();
+ }
+
+ var file = Upload.Files?.SingleOrDefault();
+ var review = await GetOrCreateReview(file, Upload.FilePath);
+
+ if (review != null)
+ {
+ APIRevisionListItemModel apiRevision = null;
+
+ if (file != null)
+ {
+ using (var openReadStream = file.OpenReadStream())
+ {
+ apiRevision = await _apiRevisionsManager.AddAPIRevisionAsync(user: User, review: review, apiRevisionType: APIRevisionType.Manual,
+ name: file.FileName, label: Label, fileStream: openReadStream, language: Upload.Language);
+ }
+ }
+ else if (!string.IsNullOrEmpty(Upload.FilePath))
+ {
+ apiRevision = await _apiRevisionsManager.AddAPIRevisionAsync(user: User, review: review, apiRevisionType: APIRevisionType.Manual,
+ name: file.FileName, label: Label, fileStream: null, language: Upload.Language);
+ }
+ return RedirectToPage("Review", new { id = review.Id, revisionId = apiRevision.Id });
+ }
+ return RedirectToPage();
+ }
+
+ private async Task GetOrCreateReview(IFormFile file, string filePath)
+ {
+ CodeFile codeFile = null;
+ ReviewListItemModel review = null;
+
+ using var memoryStream = new MemoryStream();
+ if (file != null)
+ {
+ using (var openReadStream = file.OpenReadStream())
+ {
+ codeFile = await _codeFileManager.CreateCodeFileAsync(
+ originalName: file?.FileName, fileStream: openReadStream, runAnalysis: Upload.RunAnalysis, memoryStream: memoryStream, language: Upload.Language);
+ }
+ }
+ else if (!string.IsNullOrEmpty(filePath))
+ {
+ codeFile = await _codeFileManager.CreateCodeFileAsync(
+ originalName: Upload.FilePath, runAnalysis: Upload.RunAnalysis, memoryStream: memoryStream, language: Upload.Language);
+ }
+
+ if (codeFile != null)
+ {
+ review = await _reviewManager.GetReviewAsync(packageName: codeFile.PackageName, language: codeFile.Language);
+ if (review == null)
+ {
+ review = await _reviewManager.CreateReviewAsync(packageName: codeFile.PackageName, language: codeFile.Language, isClosed: false);
+ }
+ }
+ return review;
+ }
+
private async Task RunGetRequest(IEnumerable search, IEnumerable languages,
IEnumerable state, IEnumerable status, int pageNo, int pageSize, string sortField, bool fromUrl = true)
{
diff --git a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
index af17db399..062a13a78 100644
--- a/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
+++ b/src/dotnet/APIView/APIViewWeb/Pages/Assemblies/Review.cshtml
@@ -262,8 +262,8 @@
}
@if (Model.ReviewContent.ActiveAPIRevision.APIRevisionType == APIRevisionType.PullRequest)
{
- var prsOfAssociatedReviews = await Model.GetPRsOfAssoicatedReviews();
- @if (prsOfAssociatedReviews != null && prsOfAssociatedReviews.Count() > 1)
+ var prsOfAssociatedAPIRevisions = await Model.GetPRsOfAssoicatedReviews();
+ @if (prsOfAssociatedAPIRevisions != null && prsOfAssociatedAPIRevisions.Count() > 1)
{
var associatedReviewsState = String.Empty;
if (Request.Cookies.ContainsKey("associatedReviewsCollapse"))
@@ -272,16 +272,17 @@
associatedReviewsState = " show";
}
- Associated Reviews
+ Associated APIRevisions
- @foreach (var pr in prsOfAssociatedReviews)
+ @foreach (var pr in prsOfAssociatedAPIRevisions)
{
if (pr.ReviewId != Model.ReviewContent.Review.Id)
{
var url = @Url.ActionLink("Review", "Assemblies", new
{
id = pr.ReviewId,
+ revisionId = pr.APIRevisionId
});
-
@pr.Language/@pr.PackageName
@@ -325,21 +326,6 @@
-
-
-
-
-
Page Settings
@@ -607,6 +593,13 @@