Compare commits
2 Commits
738e8308a8
...
91097940fc
| Author | SHA1 | Date | |
|---|---|---|---|
| 91097940fc | |||
| c80b2759a9 |
@ -8,6 +8,7 @@
|
||||
<entry key="Flawless.Client/Theme/ToggleSwitch.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HelloSetup/LoginPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HelloSetup/RegisterPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HelloSetup/ServerSetupPageView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HelloView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HelloWindowView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
<entry key="Flawless.Client/Views/HomeView.axaml" value="Flawless.Client/Flawless.Client.csproj" />
|
||||
|
||||
@ -106,6 +106,12 @@ public static class WorkPath
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string FormatPathDirectorySeparator(string path)
|
||||
{
|
||||
return path.Replace(Path.DirectorySeparatorChar, DirectorySeparatorChar)
|
||||
.Replace(Path.AltDirectorySeparatorChar, DirectorySeparatorChar);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Split work path into path vector.
|
||||
/// </summary>
|
||||
|
||||
@ -13,6 +13,8 @@ public static class AppDefaultValues
|
||||
|
||||
public const string RepoLocalStorageDepotFolder = "depots";
|
||||
|
||||
public const string RepoLocalStorageTempFolder = "temp";
|
||||
|
||||
public static string ProgramDataDirectory { get; } =
|
||||
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Ca2dWorks", "FlawlessClient");
|
||||
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
using System;
|
||||
using Avalonia.Controls.Notifications;
|
||||
|
||||
namespace Flawless.Client;
|
||||
|
||||
public static class ErrorGUIHandler
|
||||
{
|
||||
public static void OnError(Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
@ -1,7 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Text.Json.Serialization;
|
||||
using Flawless.Client.Service;
|
||||
using Newtonsoft.Json;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
|
||||
namespace Flawless.Client.Models;
|
||||
@ -18,8 +18,13 @@ public partial class RepositoryLocalDatabaseModel : ReactiveModel
|
||||
[JsonIgnore]
|
||||
public RepositoryFileTreeAccessor? RepoAccessor { get; set; }
|
||||
|
||||
[JsonProperty("currentCommit")]
|
||||
[Reactive] private Guid? _currentCommit;
|
||||
|
||||
[JsonProperty("commitMessage")]
|
||||
[Reactive] private string? _commitMessage;
|
||||
|
||||
[JsonProperty("lastOperationTime")]
|
||||
[Reactive] private DateTime _lastOprationTime;
|
||||
|
||||
}
|
||||
@ -99,7 +99,7 @@ public class Api : BaseService<Api>
|
||||
public bool RequireRefreshToken()
|
||||
{
|
||||
if (_token.Value == null) return true;
|
||||
if (DateTime.UtcNow.AddMinutes(1) > _token.Value.Expiration) return true;
|
||||
if (DateTime.UtcNow > _token.Value.Expiration!.Value.UtcDateTime.AddMinutes(-2)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@ -44,20 +44,25 @@ public class LocalFileTreeAccessor
|
||||
|
||||
private IReadOnlyDictionary<string, WorkspaceFile> _baseline;
|
||||
|
||||
private Dictionary<string, ChangeRecord> _difference;
|
||||
private Dictionary<string, ChangeRecord> _changes = new();
|
||||
|
||||
private Dictionary<string, WorkspaceFile> _currentFiles = new();
|
||||
|
||||
private object _optLock = new();
|
||||
|
||||
public DateTime LastScanTimeUtc { get; private set; }
|
||||
|
||||
public string WorkingDirectory => _rootDirectory;
|
||||
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> BaselineFiles => _baseline;
|
||||
|
||||
public IReadOnlyDictionary<string, ChangeRecord> Changes => _difference;
|
||||
public IReadOnlyDictionary<string, ChangeRecord> Changes => _changes;
|
||||
|
||||
public IReadOnlyDictionary<string, WorkspaceFile> CurrentFiles => _currentFiles;
|
||||
|
||||
public LocalFileTreeAccessor(RepositoryModel repo, IEnumerable<WorkspaceFile> baselines)
|
||||
{
|
||||
_repo = repo;
|
||||
_difference = new Dictionary<string, ChangeRecord>();
|
||||
_baseline = baselines.ToImmutableDictionary(b => b.WorkPath);
|
||||
_rootDirectory = PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name);
|
||||
}
|
||||
@ -67,7 +72,7 @@ public class LocalFileTreeAccessor
|
||||
lock (_optLock)
|
||||
{
|
||||
_baseline = baselines.ToImmutableDictionary(b => b.WorkPath);
|
||||
_difference.Clear();
|
||||
_changes.Clear();
|
||||
|
||||
RefreshInternal();
|
||||
}
|
||||
@ -77,7 +82,7 @@ public class LocalFileTreeAccessor
|
||||
{
|
||||
lock (_optLock)
|
||||
{
|
||||
_difference.Clear();
|
||||
_changes.Clear();
|
||||
|
||||
RefreshInternal();
|
||||
}
|
||||
@ -85,7 +90,7 @@ public class LocalFileTreeAccessor
|
||||
|
||||
private void RefreshInternal()
|
||||
{
|
||||
Dictionary<string, WorkspaceFile> currentFiles = new();
|
||||
_currentFiles.Clear();
|
||||
foreach (var f in Directory.GetFiles(_rootDirectory, "*", SearchOption.AllDirectories))
|
||||
{
|
||||
var workPath = WorkPath.FromPlatformPath(f, _rootDirectory);
|
||||
@ -93,16 +98,18 @@ public class LocalFileTreeAccessor
|
||||
continue;
|
||||
|
||||
var modifyTime = File.GetLastWriteTimeUtc(f);
|
||||
currentFiles.Add(workPath, new WorkspaceFile { WorkPath = workPath, ModifyTime = modifyTime });
|
||||
_currentFiles.Add(workPath, new WorkspaceFile { WorkPath = workPath, ModifyTime = modifyTime });
|
||||
}
|
||||
|
||||
// Find those are changed
|
||||
var changes = currentFiles.Values.Where(v => _baseline.TryGetValue(v.WorkPath, out var fi) && fi.ModifyTime != v.ModifyTime);
|
||||
var news = currentFiles.Values.Where(v => !_baseline.ContainsKey(v.WorkPath));
|
||||
var removed = _baseline.Values.Where(v => !currentFiles.ContainsKey(v.WorkPath));
|
||||
LastScanTimeUtc = DateTime.UtcNow;
|
||||
|
||||
foreach (var f in changes) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Modify, f));
|
||||
foreach (var f in news) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Add, f));
|
||||
foreach (var f in removed) _difference.Add(f.WorkPath, new ChangeRecord(ChangeType.Remove, f));
|
||||
// Find those are changed
|
||||
var changes = _currentFiles.Values.Where(v => _baseline.TryGetValue(v.WorkPath, out var fi) && fi.ModifyTime != v.ModifyTime);
|
||||
var news = _currentFiles.Values.Where(v => !_baseline.ContainsKey(v.WorkPath));
|
||||
var removed = _baseline.Values.Where(v => !_currentFiles.ContainsKey(v.WorkPath));
|
||||
|
||||
foreach (var f in changes) _changes.Add(f.WorkPath, new ChangeRecord(ChangeType.Modify, f));
|
||||
foreach (var f in news) _changes.Add(f.WorkPath, new ChangeRecord(ChangeType.Add, f));
|
||||
foreach (var f in removed) _changes.Add(f.WorkPath, new ChangeRecord(ChangeType.Remove, f));
|
||||
}
|
||||
}
|
||||
@ -5,6 +5,7 @@
|
||||
|
||||
using Refit;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
@ -113,25 +114,25 @@ namespace Flawless.Client.Remote
|
||||
/// <returns>OK</returns>
|
||||
/// <exception cref="ApiException">Thrown when the request returns a non-success status code.</exception>
|
||||
[Headers("Accept: text/plain, application/json, text/json")]
|
||||
[Get("/api/repo/{userName}/{repositoryName}/fetch_manifest")]
|
||||
Task<FileResponse> FetchManifest(string userName, string repositoryName, [Query] string commitId);
|
||||
[Post("/api/repo/{userName}/{repositoryName}/fetch_manifest")]
|
||||
Task<CommitManifest> FetchManifest(string userName, string repositoryName, [Query] string commitId);
|
||||
|
||||
/// <returns>OK</returns>
|
||||
/// <exception cref="ApiException">Thrown when the request returns a non-success status code.</exception>
|
||||
[Headers("Accept: text/plain, application/json, text/json")]
|
||||
[Get("/api/repo/{userName}/{repositoryName}/fetch_depot")]
|
||||
Task<FileResponse> FetchDepot(string userName, string repositoryName, [Query] string depotId);
|
||||
[Post("/api/repo/{userName}/{repositoryName}/fetch_depot")]
|
||||
Task<ApiResponse<Stream>> FetchDepot(string userName, string repositoryName, [Query] string depotId);
|
||||
|
||||
/// <returns>OK</returns>
|
||||
/// <exception cref="ApiException">Thrown when the request returns a non-success status code.</exception>
|
||||
[Headers("Accept: text/plain, application/json, text/json")]
|
||||
[Get("/api/repo/{userName}/{repositoryName}/list_commit")]
|
||||
[Post("/api/repo/{userName}/{repositoryName}/list_commit")]
|
||||
Task<RepositoryCommitResponseListingResponse> ListCommit(string userName, string repositoryName);
|
||||
|
||||
/// <returns>OK</returns>
|
||||
/// <exception cref="ApiException">Thrown when the request returns a non-success status code.</exception>
|
||||
[Headers("Accept: text/plain, application/json, text/json")]
|
||||
[Get("/api/repo/{userName}/{repositoryName}/list_locked_files")]
|
||||
[Post("/api/repo/{userName}/{repositoryName}/list_locked_files")]
|
||||
Task<LockFileInfoListingResponse> ListLockedFiles(string userName, string repositoryName);
|
||||
|
||||
/// <returns>OK</returns>
|
||||
@ -155,7 +156,7 @@ namespace Flawless.Client.Remote
|
||||
[Multipart]
|
||||
[Headers("Accept: text/plain, application/json, text/json")]
|
||||
[Post("/api/repo/{userName}/{repositoryName}/create_commit")]
|
||||
Task<CommitSuccessResponse> CreateCommit(string userName, string repositoryName, StreamPart depot, string message, IEnumerable<WorkspaceFile> workspaceSnapshot, IEnumerable<string> requiredDepots, string mainDepotId);
|
||||
Task<CommitSuccessResponse> CreateCommit(string userName, string repositoryName, StreamPart depot, string message, IEnumerable<string> workspaceSnapshot, IEnumerable<string> requiredDepots, string mainDepotId);
|
||||
|
||||
/// <returns>OK</returns>
|
||||
/// <exception cref="ApiException">Thrown when the request returns a non-success status code.</exception>
|
||||
@ -232,6 +233,21 @@ namespace Flawless.Client.Remote
|
||||
|
||||
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class CommitManifest
|
||||
{
|
||||
|
||||
[JsonPropertyName("manifestId")]
|
||||
public System.Guid ManifestId { get; set; }
|
||||
|
||||
[JsonPropertyName("depot")]
|
||||
public ICollection<DepotLabel> Depot { get; set; }
|
||||
|
||||
[JsonPropertyName("filePaths")]
|
||||
public ICollection<WorkspaceFile> FilePaths { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class CommitSuccessResponse
|
||||
{
|
||||
@ -242,6 +258,21 @@ namespace Flawless.Client.Remote
|
||||
[JsonPropertyName("commitId")]
|
||||
public System.Guid CommitId { get; set; }
|
||||
|
||||
[JsonPropertyName("mainDepotId")]
|
||||
public System.Guid MainDepotId { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
public partial class DepotLabel
|
||||
{
|
||||
|
||||
[JsonPropertyName("id")]
|
||||
public System.Guid Id { get; set; }
|
||||
|
||||
[JsonPropertyName("length")]
|
||||
public long Length { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCode("NJsonSchema", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
@ -535,6 +566,12 @@ namespace Flawless.Client.Remote
|
||||
public partial class WorkspaceFile
|
||||
{
|
||||
|
||||
[JsonPropertyName("modifyTime")]
|
||||
public System.DateTimeOffset ModifyTime { get; set; }
|
||||
|
||||
[JsonPropertyName("workPath")]
|
||||
public string WorkPath { get; set; }
|
||||
|
||||
}
|
||||
|
||||
[System.CodeDom.Compiler.GeneratedCode("NSwag", "14.2.0.0 (NJsonSchema v11.1.0.0 (Newtonsoft.Json v13.0.0.0))")]
|
||||
|
||||
@ -1,14 +1,16 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Immutable;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Flawless.Core.BinaryDataFormat;
|
||||
using Flawless.Core.Modal;
|
||||
|
||||
namespace Flawless.Client.Service;
|
||||
|
||||
public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable
|
||||
public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable, IEnumerable<WorkspaceFile>
|
||||
{
|
||||
|
||||
private struct FileReadInfoCache
|
||||
@ -77,6 +79,7 @@ public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable
|
||||
|
||||
foreach (var (id, stream) in _mappings)
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
var header = DataTransformer.ExtractStandardDepotHeaderV1(stream);
|
||||
_headers.Add(id, header);
|
||||
await foreach (var inf in DataTransformer.ExtractDepotFileInfoMapAsync(stream, header.FileMapSize))
|
||||
@ -109,7 +112,7 @@ public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryWriteDataIntoStream(string workPath, Stream stream)
|
||||
public bool TryWriteDataIntoStream(string workPath, Stream stream, out DateTime modifyTime)
|
||||
{
|
||||
DisposeCheck();
|
||||
if (stream == null || !stream.CanWrite) throw new ArgumentException("Stream is not writable!");
|
||||
@ -118,6 +121,24 @@ public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable
|
||||
{
|
||||
var baseStream = DataTransformer.ExtractStandardDepotFile(_mappings[r.DepotId], r.FileInfo);
|
||||
baseStream.CopyTo(stream);
|
||||
modifyTime = r.FileInfo.ModifyTime;
|
||||
return true;
|
||||
}
|
||||
|
||||
modifyTime = DateTime.MinValue;
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool TryWriteDataIntoStream(string workPath, string destinationPath)
|
||||
{
|
||||
DisposeCheck();
|
||||
|
||||
if (_cached.TryGetValue(workPath, out var r))
|
||||
{
|
||||
using var ws = new FileStream(destinationPath, FileMode.OpenOrCreate, FileAccess.Write);
|
||||
var baseStream = DataTransformer.ExtractStandardDepotFile(_mappings[r.DepotId], r.FileInfo);
|
||||
baseStream.CopyTo(ws);
|
||||
File.SetLastWriteTimeUtc(destinationPath, r.FileInfo.ModifyTime);
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -129,4 +150,14 @@ public class RepositoryFileTreeAccessor : IDisposable, IAsyncDisposable
|
||||
if (_disposed) throw new ObjectDisposedException("Accessor has already been disposed");
|
||||
}
|
||||
|
||||
public IEnumerator<WorkspaceFile> GetEnumerator()
|
||||
{
|
||||
return _cached.Values
|
||||
.Select(cv => new WorkspaceFile(cv.FileInfo.ModifyTime, cv.FileInfo.Path)).GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return GetEnumerator();
|
||||
}
|
||||
}
|
||||
@ -3,12 +3,14 @@ using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
using Flawless.Abstraction;
|
||||
using Flawless.Client.Models;
|
||||
using Flawless.Core.BinaryDataFormat;
|
||||
using Flawless.Core.Modal;
|
||||
using Newtonsoft.Json;
|
||||
using ValueTaskSupplement;
|
||||
using Refit;
|
||||
|
||||
namespace Flawless.Client.Service;
|
||||
|
||||
@ -42,18 +44,16 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
|
||||
public bool SaveRepositoryLocalDatabaseChanges(RepositoryModel repo)
|
||||
{
|
||||
var localRepo = GetRepositoryLocalDatabase(repo);
|
||||
localRepo.LastOprationTime = DateTime.Now;
|
||||
|
||||
var dbPath = PathUtility.GetWorkspaceDbPath(repo.OwnerName, repo.Name);
|
||||
if (File.Exists(dbPath)) return false;
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(dbPath)!);
|
||||
|
||||
if (!_localRepoDbModel.TryGetValue(repo, out var localRepo))
|
||||
{
|
||||
using var writeFs = new StreamWriter(new FileStream(dbPath, FileMode.Truncate));
|
||||
JsonSerializer.CreateDefault().Serialize(writeFs, localRepo);
|
||||
using var writeFs = new StreamWriter(new FileStream(dbPath, FileMode.OpenOrCreate));
|
||||
JsonSerializer.CreateDefault().Serialize(writeFs, localRepo);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public RepositoryLocalDatabaseModel GetRepositoryLocalDatabase(RepositoryModel repo)
|
||||
@ -115,6 +115,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
@ -164,6 +165,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
@ -183,16 +185,6 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> UpdateDownloadedStatusFromDiskAsync(RepositoryModel repo)
|
||||
{
|
||||
var isFolderExists = Directory.Exists(PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name));
|
||||
var isDbFileExists = File.Exists(PathUtility.GetWorkspaceDbPath(repo.OwnerName, repo.Name));
|
||||
|
||||
repo.IsDownloaded = isFolderExists && isDbFileExists;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<bool> UpdateMembersFromServerAsync(RepositoryModel repo)
|
||||
{
|
||||
var api = Api.C;
|
||||
@ -236,6 +228,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
@ -267,17 +260,22 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
|
||||
public async ValueTask<bool> OpenRepositoryOnStorageAsync(RepositoryModel repo)
|
||||
{
|
||||
if (!await UpdateDownloadedStatusFromDiskAsync(repo) || repo.IsDownloaded == false) return false;
|
||||
if (!await UpdateRepositoriesDownloadedStatusFromDiskAsync() || repo.IsDownloaded == false) return false;
|
||||
if (!await UpdateCommitsFromServerAsync(repo)) return false;
|
||||
var ls = GetRepositoryLocalDatabase(repo);
|
||||
|
||||
if (ls.CurrentCommit != null)
|
||||
{
|
||||
var accessor = await DownloadDepotsToGetCommitFileTreeFromServerAsync(repo, ls.CurrentCommit.Value);
|
||||
var accessor = await DownloadDepotsAndUseLocalCachesToGenerateRepositoryFileTreeAccessorFromServerAsync(repo, ls.CurrentCommit.Value);
|
||||
if (accessor == null) return false;
|
||||
ls.RepoAccessor = accessor;
|
||||
|
||||
// Remember to cache accessor everytime it will being used.
|
||||
await accessor.CreateCacheAsync();
|
||||
ls.LocalAccessor.SetBaseline(accessor);
|
||||
}
|
||||
|
||||
SaveRepositoryLocalDatabaseChanges(repo);
|
||||
_openedRepos.Add(repo);
|
||||
return true;
|
||||
}
|
||||
@ -287,6 +285,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
// Create basic structures.
|
||||
if (!TryCreateRepositoryBaseStorageStructure(repo)) return false;
|
||||
|
||||
SaveRepositoryLocalDatabaseChanges(repo);
|
||||
repo.IsDownloaded = true;
|
||||
_openedRepos.Add(repo);
|
||||
return true;
|
||||
@ -301,20 +300,21 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
var peekCommit = repo.Commits.MaxBy(sl => sl.CommittedOn);
|
||||
if (peekCommit == null) return false; // Should not use this function!
|
||||
|
||||
// Create basic structures.
|
||||
if (!TryCreateRepositoryBaseStorageStructure(repo)) return false;
|
||||
|
||||
// Download base repo info
|
||||
var accessor = await DownloadDepotsToGetCommitFileTreeFromServerAsync(repo, peekCommit.CommitId);
|
||||
var accessor = await DownloadDepotsAndUseLocalCachesToGenerateRepositoryFileTreeAccessorFromServerAsync(repo, peekCommit.CommitId);
|
||||
if (accessor == null)
|
||||
{
|
||||
await DeleteFromDiskAsync(repo);
|
||||
return false;
|
||||
};
|
||||
|
||||
// Remember to cache accessor everytime it will being used.
|
||||
await accessor.CreateCacheAsync();
|
||||
|
||||
var ls = GetRepositoryLocalDatabase(repo);
|
||||
ls.CurrentCommit = peekCommit.CommitId;
|
||||
ls.RepoAccessor = accessor;
|
||||
ls.LocalAccessor.SetBaseline(accessor);
|
||||
|
||||
try
|
||||
{
|
||||
@ -325,17 +325,19 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
|
||||
// Write into fs
|
||||
if (directory != null) Directory.CreateDirectory(directory);
|
||||
await using var write = File.Create(pfs);
|
||||
accessor.TryWriteDataIntoStream(f.WorkPath, write);
|
||||
if (!accessor.TryWriteDataIntoStream(f.WorkPath, pfs))
|
||||
throw new InvalidDataException($"Can not write {f.WorkPath} into repository.");
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
await DeleteFromDiskAsync(repo);
|
||||
return false;
|
||||
}
|
||||
|
||||
SaveRepositoryLocalDatabaseChanges(repo);
|
||||
repo.IsDownloaded = true;
|
||||
_openedRepos.Add(repo);
|
||||
return true;
|
||||
@ -363,6 +365,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
@ -419,6 +422,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
@ -426,7 +430,8 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<RepositoryFileTreeAccessor?> DownloadDepotsToGetCommitFileTreeFromServerAsync
|
||||
public async ValueTask<RepositoryFileTreeAccessor?>
|
||||
DownloadDepotsAndUseLocalCachesToGenerateRepositoryFileTreeAccessorFromServerAsync
|
||||
(RepositoryModel repo, Guid commit, bool storeDownloadedDepots = true)
|
||||
{
|
||||
if (commit == Guid.Empty) return null;
|
||||
@ -436,9 +441,8 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
if (manifest == null) return null;
|
||||
|
||||
// Prepare folders
|
||||
var path = PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name);
|
||||
var depotsRoot = PathUtility.GetWorkspaceDepotCachePath(repo.OwnerName, repo.Name);
|
||||
Directory.CreateDirectory(path);
|
||||
Directory.CreateDirectory(depotsRoot);
|
||||
|
||||
// Generate download depots list
|
||||
var mainDepotLabel = manifest.Value.Depot;
|
||||
@ -452,12 +456,10 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
|
||||
// Download them
|
||||
var downloadedDepots = await DownloadDepotsAndCopyNetworkStreamIntoNewMemoryStreamFromServerAsync(repo, willDownload);
|
||||
if (downloadedDepots == null) return null;
|
||||
|
||||
try
|
||||
{
|
||||
// Check if anyone download failed
|
||||
if (downloadedDepots == null || downloadedDepots.Any(dl => dl.Item2 == null))
|
||||
throw new Exception("Some depots are not able to be downloaded.");
|
||||
|
||||
if (storeDownloadedDepots)
|
||||
{
|
||||
@ -467,18 +469,22 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
|
||||
// Create mapping dictionary
|
||||
var mappingDict = downloadedDepots.ToDictionary(i => i.Item1, i => i.Item2!);
|
||||
var streamMap = downloadedDepots.ToDictionary(i => i.Item1, i => i.Item2!);
|
||||
foreach (var dl in mainDepotLabel)
|
||||
{
|
||||
if (mappingDict.ContainsKey(dl.Id)) continue;
|
||||
var dst = Path.Combine(depotsRoot, dl.Id.ToString());
|
||||
mappingDict.Add(dl.Id, new FileStream(dst, FileMode.Create));
|
||||
// If this file is not being opened, open it from file system
|
||||
if (!streamMap.ContainsKey(dl.Id))
|
||||
{
|
||||
var dst = Path.Combine(depotsRoot, dl.Id.ToString());
|
||||
streamMap.Add(dl.Id, new FileStream(dst, FileMode.Open, FileAccess.Read, FileShare.Read));
|
||||
}
|
||||
}
|
||||
|
||||
return new RepositoryFileTreeAccessor(mappingDict, manifest.Value);
|
||||
return new RepositoryFileTreeAccessor(streamMap, manifest.Value);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
if (downloadedDepots != null)
|
||||
foreach (var t in downloadedDepots)
|
||||
{
|
||||
@ -494,21 +500,22 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
|
||||
public async ValueTask WriteDownloadedDepotsFromServerToStorageAsync
|
||||
(RepositoryModel repo, IEnumerable<(Guid, Stream)> depots)
|
||||
(RepositoryModel repo, IEnumerable<(Guid id, Stream stream)> depots)
|
||||
{
|
||||
var depotsRoot = PathUtility.GetWorkspaceDepotCachePath(repo.OwnerName, repo.Name);
|
||||
var tasks = depots.Select(async d =>
|
||||
foreach (var d in depots)
|
||||
{
|
||||
var dst = Path.Combine(depotsRoot, d.Item1.ToString());
|
||||
var dst = Path.Combine(depotsRoot, d.id.ToString());
|
||||
await using var ws = new FileStream(dst, FileMode.Create);
|
||||
await d.Item2.CopyToAsync(ws);
|
||||
d.Item2.Seek(0, SeekOrigin.Begin);
|
||||
});
|
||||
|
||||
await Task.WhenAll(tasks);
|
||||
// Make sure always to be at begin.
|
||||
d.stream.Seek(0, SeekOrigin.Begin);
|
||||
await d.stream.CopyToAsync(ws);
|
||||
d.stream.Seek(0, SeekOrigin.Begin);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<(Guid, Stream?)[]?> DownloadDepotsAndCopyNetworkStreamIntoNewMemoryStreamFromServerAsync
|
||||
public async ValueTask<(Guid, Stream)[]?> DownloadDepotsAndCopyNetworkStreamIntoNewMemoryStreamFromServerAsync
|
||||
(RepositoryModel repo, IEnumerable<DepotLabel> depotsId)
|
||||
{
|
||||
try
|
||||
@ -520,24 +527,29 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return null;
|
||||
}
|
||||
|
||||
return await ValueTaskEx.WhenAll(depotsId.Select(p => DownloadDepotInternalAsync(p.Id, p.Length)));
|
||||
var result = new List<(Guid, Stream)>();
|
||||
foreach (var dl in depotsId)
|
||||
{
|
||||
using var rsp = await Api.C.Gateway.FetchDepot(repo.OwnerName, repo.Name, dl.Id.ToString());
|
||||
if (rsp.StatusCode != HttpStatusCode.OK)
|
||||
{
|
||||
Console.WriteLine($"Failed to fetch depot {dl.Id}");
|
||||
return null;
|
||||
}
|
||||
|
||||
var memoryStream = new MemoryStream(new byte[dl.Length]);
|
||||
await rsp.Content!.CopyToAsync(memoryStream);
|
||||
result.Add((dl.Id, memoryStream));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
async ValueTask<(Guid, Stream?)> DownloadDepotInternalAsync(Guid depotId, long length)
|
||||
{
|
||||
using var rsp = await Api.C.Gateway.FetchDepot(repo.OwnerName, repo.Name, depotId.ToString());
|
||||
if (rsp.StatusCode != 200) return (depotId, null);
|
||||
if (rsp.Stream.Length != length) return (depotId, null);
|
||||
|
||||
var memoryStream = new MemoryStream(new byte[rsp.Stream.Length]);
|
||||
await rsp.Stream.CopyToAsync(memoryStream);
|
||||
return (depotId, memoryStream);
|
||||
}
|
||||
}
|
||||
|
||||
public async ValueTask<CommitManifest?> DownloadManifestFromServerAsync(RepositoryModel repo, Guid manifestId)
|
||||
@ -551,13 +563,15 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
return null;
|
||||
}
|
||||
|
||||
using var manifestResponse = await api.Gateway.FetchManifest(repo.OwnerName, repo.Name, manifestId.ToString());
|
||||
if (manifestResponse.StatusCode != 200) return null;
|
||||
|
||||
return await System.Text.Json.JsonSerializer.DeserializeAsync<CommitManifest>(manifestResponse.Stream);
|
||||
var rsp = await api.Gateway.FetchManifest(repo.OwnerName, repo.Name, manifestId.ToString());
|
||||
return new(
|
||||
rsp.ManifestId,
|
||||
rsp.Depot.Select(x => new DepotLabel(x.Id, x.Length)).ToArray(),
|
||||
rsp.FilePaths.Select(x => new WorkspaceFile(x.ModifyTime.UtcDateTime, x.WorkPath)).ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
@ -572,6 +586,7 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
@ -579,4 +594,173 @@ public class RepositoryService : BaseService<RepositoryService>
|
||||
repo.IsDownloaded = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public async ValueTask<CommitManifest?> CommitWorkspaceAsBaselineAsync
|
||||
(RepositoryModel repo, IEnumerable<LocalFileTreeAccessor.ChangeRecord> changes, string message)
|
||||
{
|
||||
var localDb = GetRepositoryLocalDatabase(repo);
|
||||
var manifestList = CreateCommitManifestByCurrentBaselineAndChanges(localDb.LocalAccessor, changes);
|
||||
var api = Api.C;
|
||||
|
||||
try
|
||||
{
|
||||
|
||||
// Renew for once.
|
||||
if (api.RequireRefreshToken() && !(await api.TryRefreshTokenAsync()))
|
||||
{
|
||||
api.ClearGateway();
|
||||
return null;
|
||||
}
|
||||
|
||||
// Generate depot
|
||||
var tempDepotPath = await CreateDepotIntoTempFileAsync(repo, manifestList);
|
||||
if (tempDepotPath == null) return null;
|
||||
|
||||
// Upload and create commit
|
||||
await using var str = File.OpenRead(tempDepotPath);
|
||||
var snapshot = manifestList.Select(l => $"{l.ModifyTime.ToBinary()}${l.WorkPath}");
|
||||
if (api.RequireRefreshToken() && !(await api.TryRefreshTokenAsync()))
|
||||
{
|
||||
api.ClearGateway();
|
||||
return null;
|
||||
}
|
||||
|
||||
var rsp = await api.Gateway.CreateCommit(repo.OwnerName, repo.Name,
|
||||
new StreamPart(str, Path.GetFileName(tempDepotPath)), message, snapshot, null!, null!);
|
||||
|
||||
// Move depot file to destination
|
||||
var depotsPath = PathUtility.GetWorkspaceDepotCachePath(repo.OwnerName, repo.Name);
|
||||
var finalPath = Path.Combine(depotsPath, rsp.MainDepotId.ToString());
|
||||
Directory.CreateDirectory(depotsPath);
|
||||
File.Move(tempDepotPath, finalPath, true);
|
||||
|
||||
// Fetch mapped manifest
|
||||
var manifest = await DownloadManifestFromServerAsync(repo, rsp.CommitId);
|
||||
if (manifest == null) return null;
|
||||
|
||||
var accessor = await DownloadDepotsAndUseLocalCachesToGenerateRepositoryFileTreeAccessorFromServerAsync(repo, rsp.CommitId);
|
||||
if (accessor == null) return null; //todo this is a really fatal issue...
|
||||
if (localDb.RepoAccessor != null)
|
||||
{
|
||||
try
|
||||
{
|
||||
await localDb.RepoAccessor.DisposeAsync();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
}
|
||||
}
|
||||
|
||||
// Point to newest state.
|
||||
localDb.RepoAccessor = accessor;
|
||||
localDb.CurrentCommit = rsp.CommitId;
|
||||
localDb.LocalAccessor.SetBaseline(accessor);
|
||||
SaveRepositoryLocalDatabaseChanges(repo);
|
||||
|
||||
return manifest;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public List<WorkspaceFile> CreateCommitManifestByCurrentBaselineAndChanges
|
||||
(LocalFileTreeAccessor accessor, IEnumerable<LocalFileTreeAccessor.ChangeRecord> changes, bool hard = false)
|
||||
{
|
||||
// Create a new depot file manifest.
|
||||
var files = accessor.BaselineFiles.Values.ToList();
|
||||
foreach (var c in changes)
|
||||
{
|
||||
switch (c.Type)
|
||||
{
|
||||
case LocalFileTreeAccessor.ChangeType.Folder:
|
||||
{
|
||||
if (hard) throw new InvalidProgramException(
|
||||
$"Can not commit folder into version control: {c.File.WorkPath}");
|
||||
|
||||
Console.WriteLine($"Can not commit folder into version control...Ignored: {c.File.WorkPath}");
|
||||
continue;
|
||||
}
|
||||
case LocalFileTreeAccessor.ChangeType.Add:
|
||||
{
|
||||
if (files.Any(f => f.WorkPath == c.File.WorkPath))
|
||||
{
|
||||
if (hard) throw new InvalidProgramException(
|
||||
$"Can not create an existed record into version control: {c.File.WorkPath}");
|
||||
|
||||
Console.WriteLine($"Can not create an existed record into version control...Ignored: {c.File.WorkPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
files.Add(c.File);
|
||||
break;
|
||||
}
|
||||
case LocalFileTreeAccessor.ChangeType.Remove:
|
||||
{
|
||||
var idx = files.FindIndex(f => f.WorkPath == c.File.WorkPath);
|
||||
if (idx < 0)
|
||||
{
|
||||
if (hard) throw new InvalidProgramException(
|
||||
$"Can not delete a missed record into version control: {c.File.WorkPath}");
|
||||
|
||||
Console.WriteLine($"Can not delete a missed record into version control...Ignored: {c.File.WorkPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
files.RemoveAt(idx);
|
||||
break;
|
||||
}
|
||||
case LocalFileTreeAccessor.ChangeType.Modify:
|
||||
{
|
||||
var idx = files.FindIndex(f => f.WorkPath == c.File.WorkPath);
|
||||
if (idx < 0)
|
||||
{
|
||||
if (hard) throw new InvalidProgramException(
|
||||
$"Can not modify a missed record into version control: {c.File.WorkPath}");
|
||||
|
||||
Console.WriteLine($"Can not modify a missed record into version control...Ignored: {c.File.WorkPath}");
|
||||
continue;
|
||||
}
|
||||
|
||||
files[idx] = c.File;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
public async ValueTask<string?> CreateDepotIntoTempFileAsync(RepositoryModel repo, IEnumerable<WorkspaceFile> depotFiles)
|
||||
{
|
||||
var repoWs = PathUtility.GetWorkspacePath(repo.OwnerName, repo.Name);
|
||||
var commitTempFolder = Directory.CreateTempSubdirectory("FlawlessDepot_");
|
||||
var depotFile = Path.Combine(commitTempFolder.FullName, "depot.bin");
|
||||
|
||||
try
|
||||
{
|
||||
// No UI thread blocked
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await using var fs = new FileStream(depotFile, FileMode.Create);
|
||||
DataTransformer.CreateAndInsertStandardDepotFile(fs, depotFiles,
|
||||
wf => File.OpenRead(WorkPath.ToPlatformPath(wf.WorkPath, repoWs)));
|
||||
|
||||
});
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Directory.Delete(repoWs, true);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
|
||||
return depotFile;
|
||||
}
|
||||
}
|
||||
@ -50,6 +50,7 @@ public partial class UserService : BaseService<UserService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return null;
|
||||
}
|
||||
@ -80,6 +81,7 @@ public partial class UserService : BaseService<UserService>
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
UIHelper.NotifyError(e);
|
||||
Console.WriteLine(e);
|
||||
return false;
|
||||
}
|
||||
|
||||
96
Flawless.Client/UIHelper.cs
Normal file
96
Flawless.Client/UIHelper.cs
Normal file
@ -0,0 +1,96 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls.ApplicationLifetimes;
|
||||
using Avalonia.Controls.Notifications;
|
||||
using Flawless.Client.ViewModels.ModalBox;
|
||||
using Flawless.Client.Views.ModalBox;
|
||||
using Ursa.Controls;
|
||||
using Notification = Ursa.Controls.Notification;
|
||||
using WindowNotificationManager = Ursa.Controls.WindowNotificationManager;
|
||||
|
||||
namespace Flawless.Client;
|
||||
|
||||
public static class UIHelper
|
||||
{
|
||||
|
||||
private static WindowNotificationManager _notificationManager = null!;
|
||||
|
||||
public static WindowNotificationManager Notify
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_notificationManager != null) return _notificationManager!;
|
||||
|
||||
var lf = ((IClassicDesktopStyleApplicationLifetime)App.Current.ApplicationLifetime);
|
||||
if (!WindowNotificationManager.TryGetNotificationManager(lf.MainWindow!, out _notificationManager))
|
||||
throw new Exception("Can not get notification manager");
|
||||
|
||||
_notificationManager!.Position = NotificationPosition.TopCenter;
|
||||
return _notificationManager!;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void NotifyError(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
var content = ex.ToString();
|
||||
if (content.Length > 100) content = content.Substring(0, 100) + "...";
|
||||
var nf = new Notification(ex.GetType().Name, content, NotificationType.Error);
|
||||
Notify.Show(nf);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine("Can not notify error to users: " + e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void NotifyError(string title, string content)
|
||||
{
|
||||
try
|
||||
{
|
||||
var nf = new Notification(title, content, NotificationType.Error);
|
||||
Notify.Show(nf);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Console.WriteLine($"Can not notify error to users: {title} - {content}, {e}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Task<DialogResult> SimpleAskAsync(string content, DialogMode mode = DialogMode.None)
|
||||
{
|
||||
var opt = new OverlayDialogOptions
|
||||
{
|
||||
FullScreen = false,
|
||||
Buttons = DialogButton.YesNo,
|
||||
CanResize = false,
|
||||
CanDragMove = false,
|
||||
IsCloseButtonVisible = true,
|
||||
CanLightDismiss = true,
|
||||
Mode = mode
|
||||
};
|
||||
|
||||
var vm = new SimpleMessageDialogViewModel(content);
|
||||
return OverlayDialog.ShowModal<SimpleMessageDialogView, SimpleMessageDialogViewModel>(vm, AppDefaultValues.HostId, opt);
|
||||
}
|
||||
|
||||
public static Task SimpleAlert(string content, DialogMode mode = DialogMode.Error)
|
||||
{
|
||||
var opt = new OverlayDialogOptions
|
||||
{
|
||||
FullScreen = false,
|
||||
Buttons = DialogButton.YesNo,
|
||||
CanResize = false,
|
||||
CanDragMove = false,
|
||||
IsCloseButtonVisible = true,
|
||||
CanLightDismiss = true,
|
||||
Mode = mode
|
||||
};
|
||||
|
||||
var vm = new SimpleMessageDialogViewModel(content);
|
||||
return OverlayDialog.ShowModal<SimpleMessageDialogView, SimpleMessageDialogViewModel>(vm, AppDefaultValues.HostId, opt);
|
||||
}
|
||||
}
|
||||
@ -109,7 +109,7 @@ public partial class HomeViewModel : ViewModelBase, IRoutableViewModel
|
||||
if (mr == DialogResult.Yes)
|
||||
{
|
||||
if (await RepositoryService.C.DeleteFromDiskAsync(_selectedRepository))
|
||||
await RepositoryService.C.UpdateDownloadedStatusFromDiskAsync(_selectedRepository);
|
||||
await RepositoryService.C.UpdateRepositoriesDownloadedStatusFromDiskAsync();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -21,8 +21,6 @@ public partial class LoginPageViewModel : ViewModelBase, IRoutableViewModel
|
||||
|
||||
[Reactive] private string _password = "4453A2b33";
|
||||
|
||||
[Reactive(SetModifier = AccessModifier.Protected)] private string _issue = String.Empty;
|
||||
|
||||
public IObservable<bool> CanLogin;
|
||||
|
||||
public IObservable<bool> CanRegister => Api.C.Status.Select(s => s != null && s.AllowPublicRegister);
|
||||
@ -56,12 +54,12 @@ public partial class LoginPageViewModel : ViewModelBase, IRoutableViewModel
|
||||
catch (ApiException ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync($"Login as '{Username}' Failed: {ex.Content}");
|
||||
Issue = ex.Content ?? String.Empty;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync($"Login as '{Username}' Failed: {ex}");
|
||||
Issue = ex.Message;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Login as '{Username}' success!");
|
||||
|
||||
@ -23,8 +23,6 @@ public partial class RegisterPageViewModel : ViewModelBase, IRoutableViewModel
|
||||
|
||||
[Reactive] private string _password;
|
||||
|
||||
[Reactive(SetModifier = AccessModifier.Protected)] private string _issue;
|
||||
|
||||
public RegisterPageViewModel(IScreen hostScreen)
|
||||
{
|
||||
HostScreen = hostScreen;
|
||||
@ -49,12 +47,12 @@ public partial class RegisterPageViewModel : ViewModelBase, IRoutableViewModel
|
||||
catch (ApiException ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex.Content}");
|
||||
Issue = ex.Content ?? String.Empty;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync($"Register as '{Username}' Failed: {ex}");
|
||||
Issue = ex.Message;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
|
||||
Console.WriteLine($"Register as '{Username}' success!");
|
||||
|
||||
@ -4,13 +4,16 @@ using System.Collections.ObjectModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reactive.Linq;
|
||||
using System.Reactive.Threading.Tasks;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Models.TreeDataGrid;
|
||||
using DynamicData;
|
||||
using DynamicData.Binding;
|
||||
using Flawless.Abstraction;
|
||||
using Flawless.Client.Models;
|
||||
using Flawless.Client.Service;
|
||||
using Flawless.Core.Modal;
|
||||
using ReactiveUI;
|
||||
using ReactiveUI.SourceGenerators;
|
||||
using ChangeType = Flawless.Client.Service.LocalFileTreeAccessor.ChangeType;
|
||||
@ -64,6 +67,38 @@ public class LocalChangesNode
|
||||
}
|
||||
}
|
||||
|
||||
public class CommitTransitNode
|
||||
{
|
||||
public required string Guid { get; set; }
|
||||
|
||||
public required string Author { get; set; }
|
||||
|
||||
public required string Message { get; set; }
|
||||
|
||||
public required DateTime? CommitAt { get; set; }
|
||||
|
||||
public static CommitTransitNode FromCommit(RepositoryModel.Commit cm)
|
||||
{
|
||||
string msg;
|
||||
if (cm.Message.Length > 28)
|
||||
{
|
||||
msg = cm.Message.Substring(0, 28) + "...";
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = cm.Message;
|
||||
}
|
||||
|
||||
return new CommitTransitNode
|
||||
{
|
||||
Guid = cm.CommitId.ToString(),
|
||||
Author = cm.Author,
|
||||
CommitAt = cm.CommittedOn.ToLocalTime(),
|
||||
Message = msg,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
{
|
||||
public RepositoryModel Repository { get; }
|
||||
@ -72,8 +107,14 @@ public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
|
||||
public HierarchicalTreeDataGridSource<LocalChangesNode> LocalChange { get; }
|
||||
|
||||
public HierarchicalTreeDataGridSource<LocalChangesNode> FileTree { get; }
|
||||
|
||||
public FlatTreeDataGridSource<CommitTransitNode> Commits { get; }
|
||||
|
||||
public ObservableCollection<LocalChangesNode> LocalChangeSetRaw { get; } = new();
|
||||
|
||||
public ObservableCollection<LocalChangesNode> CurrentCommitFileTreeRaw { get; } = new();
|
||||
|
||||
public UserModel User { get; }
|
||||
|
||||
[Reactive] private bool _autoDetectChanges = true;
|
||||
@ -91,12 +132,6 @@ public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
Repository.Members.ObserveCollectionChanges().Subscribe(_ => RefreshRepositoryRoleInfo());
|
||||
|
||||
// Setup local change set
|
||||
LocalChangeSetRaw.Add(new LocalChangesNode
|
||||
{
|
||||
Type = "Add",
|
||||
FullPath = "test.md",
|
||||
ModifiedTime = DateTime.Now,
|
||||
});
|
||||
LocalChange = new HierarchicalTreeDataGridSource<LocalChangesNode>(LocalChangeSetRaw)
|
||||
{
|
||||
Columns =
|
||||
@ -104,10 +139,54 @@ public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
new CheckBoxColumn<LocalChangesNode>(
|
||||
string.Empty, n => n.Included, (n, v) => n.Included = v),
|
||||
|
||||
new HierarchicalExpanderColumn<LocalChangesNode>(
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"Name",
|
||||
n => Path.GetFileName(n.FullPath)),
|
||||
n => n.Contents),
|
||||
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"Change",
|
||||
n => n.Contents != null ? String.Empty : n.Type),
|
||||
n => n.Contents != null ? String.Empty : n.Type.ToString()),
|
||||
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"File Type",
|
||||
n => n.Contents != null ? "Folder" : Path.GetExtension(n.FullPath)),
|
||||
|
||||
new TextColumn<LocalChangesNode, ulong>(
|
||||
"Size",
|
||||
n => 0),
|
||||
|
||||
new TextColumn<LocalChangesNode, DateTime?>(
|
||||
"ModifiedTime", n => n.ModifiedTime.HasValue ? n.ModifiedTime.Value.ToLocalTime() : null),
|
||||
}
|
||||
};
|
||||
|
||||
Commits = new FlatTreeDataGridSource<CommitTransitNode>(Repository.Commits.Select(CommitTransitNode.FromCommit))
|
||||
{
|
||||
Columns =
|
||||
{
|
||||
new TextColumn<CommitTransitNode, string>(
|
||||
string.Empty, n => n.Guid == LocalDatabase.CurrentCommit.ToString() ? "*" : String.Empty),
|
||||
|
||||
new TextColumn<CommitTransitNode, string>(
|
||||
"Message", x => x.Message),
|
||||
|
||||
new TextColumn<CommitTransitNode, string>(
|
||||
"Author", x => x.Author),
|
||||
|
||||
new TextColumn<CommitTransitNode, DateTime>(
|
||||
"Time", x => x.CommitAt!.Value),
|
||||
|
||||
new TextColumn<CommitTransitNode, string>(
|
||||
"Id", x => x.Guid.Substring(0, 13)),
|
||||
}
|
||||
};
|
||||
|
||||
FileTree = new HierarchicalTreeDataGridSource<LocalChangesNode>(CurrentCommitFileTreeRaw)
|
||||
{
|
||||
Columns =
|
||||
{
|
||||
new HierarchicalExpanderColumn<LocalChangesNode>(
|
||||
new TextColumn<LocalChangesNode, string>(
|
||||
"Name",
|
||||
@ -127,8 +206,108 @@ public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
}
|
||||
};
|
||||
|
||||
// Do refresh when entered
|
||||
// DetectLocalChangesAsyncCommand.Execute();
|
||||
_ = StartupTasksAsync();
|
||||
}
|
||||
|
||||
private async Task StartupTasksAsync()
|
||||
{
|
||||
await DetectLocalChangesAsyncCommand.Execute();
|
||||
await RendererFileTreeAsync();
|
||||
}
|
||||
|
||||
private async ValueTask RendererFileTreeAsync()
|
||||
{
|
||||
if (LocalDatabase.RepoAccessor == null) return;
|
||||
var accessor = LocalDatabase.RepoAccessor;
|
||||
var nodes = await CalculateFileTreeOfChangesNodeAsync(accessor.Select(
|
||||
f => new LocalFileTreeAccessor.ChangeRecord(ChangeType.Add, f)));
|
||||
|
||||
CurrentCommitFileTreeRaw.Clear();
|
||||
CurrentCommitFileTreeRaw.AddRange(nodes);
|
||||
}
|
||||
|
||||
private void CollectChanges(List<LocalFileTreeAccessor.ChangeRecord> store, IEnumerable<LocalChangesNode> changesNode)
|
||||
{
|
||||
foreach (var n in changesNode)
|
||||
{
|
||||
if (n.Contents != null) CollectChanges(store, n.Contents);
|
||||
else if (n.Included)
|
||||
{
|
||||
store.Add(new LocalFileTreeAccessor.ChangeRecord(Enum.Parse<ChangeType>(n.Type), new WorkspaceFile
|
||||
{
|
||||
WorkPath = n.FullPath,
|
||||
ModifyTime = n.ModifiedTime!.Value
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Task<List<LocalChangesNode>> CalculateFileTreeOfChangesNodeAsync(IEnumerable<LocalFileTreeAccessor.ChangeRecord> changesNode)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
// Generate a map of all folders
|
||||
var folderMap = new Dictionary<string, LocalChangesNode>();
|
||||
var nodes = new List<LocalChangesNode>();
|
||||
|
||||
foreach (var file in changesNode)
|
||||
{
|
||||
var n = LocalChangesNode.FromWorkspaceFile(file);
|
||||
var parentNode = AddParentToMap(file.File.WorkPath);
|
||||
if (parentNode == null) nodes.Add(n);
|
||||
else parentNode.Contents!.Add(n);
|
||||
}
|
||||
|
||||
return nodes;
|
||||
|
||||
LocalChangesNode? AddParentToMap(string path)
|
||||
{
|
||||
path = WorkPath.FormatPathDirectorySeparator(Path.GetDirectoryName(path) ?? string.Empty);
|
||||
|
||||
// 如果为空,则其直接文件夹就是根目录
|
||||
if (string.IsNullOrEmpty(path)) return null;
|
||||
|
||||
// 如果直接文件夹已经存在,则不再生成,直接返回即可
|
||||
if (folderMap.TryGetValue(path, out var node)) return node;
|
||||
|
||||
// 生成当前文件夹,并先找到这个文件夹的直接文件夹
|
||||
node = LocalChangesNode.FromFolder(path);
|
||||
var parent = AddParentToMap(path);
|
||||
folderMap.Add(path, node);
|
||||
if (parent != null) parent.Contents!.Add(node);
|
||||
else nodes.Add(node);
|
||||
|
||||
// 将新建的文件夹告知调用方
|
||||
return node;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private async Task CommitSelectedChangesAsync()
|
||||
{
|
||||
var changes = new List<LocalFileTreeAccessor.ChangeRecord>();
|
||||
CollectChanges(changes, LocalChangeSetRaw);
|
||||
|
||||
if (changes.Count == 0)
|
||||
{
|
||||
await UIHelper.SimpleAlert("You haven't choose any changes yet!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(LocalDatabase.CommitMessage))
|
||||
{
|
||||
await UIHelper.SimpleAlert("Commit message can not be empty!");
|
||||
return;
|
||||
}
|
||||
|
||||
var manifest = await RepositoryService.C.CommitWorkspaceAsBaselineAsync(Repository, changes, LocalDatabase.CommitMessage!);
|
||||
if (manifest == null) return;
|
||||
|
||||
LocalDatabase.LocalAccessor.SetBaseline(manifest.Value.FilePaths);
|
||||
LocalDatabase.CommitMessage = string.Empty;
|
||||
await DetectLocalChangesAsyncCommand.Execute();
|
||||
await RendererFileTreeAsync();
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
@ -155,37 +334,28 @@ public partial class RepositoryViewModel : RoutableViewModelBase
|
||||
[ReactiveCommand]
|
||||
private async ValueTask DetectLocalChangesAsync()
|
||||
{
|
||||
var ns = await Task.Run(() =>
|
||||
var ns = await Task.Run(async () =>
|
||||
{
|
||||
LocalDatabase.LocalAccessor.Refresh();
|
||||
|
||||
// Generate a map of all folders
|
||||
var folderMap = new Dictionary<string, LocalChangesNode>();
|
||||
foreach (var k in LocalDatabase.LocalAccessor.Changes.Keys)
|
||||
AddParentToMap(k);
|
||||
|
||||
var nodes = new List<LocalChangesNode>();
|
||||
foreach (var file in LocalDatabase.LocalAccessor.Changes.Values)
|
||||
{
|
||||
var directory = Path.GetDirectoryName(file.File.WorkPath);
|
||||
var n = LocalChangesNode.FromWorkspaceFile(file);
|
||||
if (string.IsNullOrEmpty(directory)) nodes.Add(n);
|
||||
else folderMap[directory].Contents!.Add(n);
|
||||
}
|
||||
|
||||
nodes.AddRange(folderMap.Values);
|
||||
return nodes;
|
||||
|
||||
void AddParentToMap(string path)
|
||||
{
|
||||
var parent = Path.GetDirectoryName(path);
|
||||
if (string.IsNullOrEmpty(parent) || folderMap.ContainsKey(parent)) return;
|
||||
|
||||
folderMap.Add(parent, LocalChangesNode.FromFolder(parent));
|
||||
}
|
||||
return await CalculateFileTreeOfChangesNodeAsync(LocalDatabase.LocalAccessor.Changes.Values);
|
||||
});
|
||||
|
||||
LocalChangeSetRaw.Clear();
|
||||
LocalChangeSetRaw.AddRange(ns);
|
||||
}
|
||||
|
||||
[ReactiveCommand]
|
||||
private void SelectAllChanges()
|
||||
{
|
||||
foreach (var n in LocalChangeSetRaw)
|
||||
n.Included = true;
|
||||
}
|
||||
|
||||
|
||||
[ReactiveCommand]
|
||||
private void DeselectAllChanges()
|
||||
{
|
||||
foreach (var n in LocalChangeSetRaw)
|
||||
n.Included = false;
|
||||
}
|
||||
}
|
||||
@ -14,8 +14,6 @@ public partial class ServerSetupPageViewModel : RoutableViewModelBase
|
||||
|
||||
[Reactive] private string _host = "http://localhost:5256/";
|
||||
|
||||
[Reactive(SetModifier = AccessModifier.Protected)] private string? _issue;
|
||||
|
||||
public IObservable<bool> CanSetHost { get; }
|
||||
|
||||
public ServerSetupPageViewModel(IScreen hostScreen) : base(hostScreen)
|
||||
@ -33,19 +31,18 @@ public partial class ServerSetupPageViewModel : RoutableViewModelBase
|
||||
{
|
||||
try
|
||||
{
|
||||
Issue = string.Empty;
|
||||
await Api.C.SetGatewayAsync(Host);
|
||||
HostScreen.Router.Navigate.Execute(new LoginPageViewModel(HostScreen));
|
||||
}
|
||||
catch (ApiException ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
|
||||
Issue = ex.Content;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
await Console.Error.WriteLineAsync("Can not connect to server: " + ex.ToString());
|
||||
Issue = ex.Message;
|
||||
UIHelper.NotifyError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -20,6 +20,5 @@
|
||||
<Button Content="Login" Command="{Binding LoginCommand}"/>
|
||||
<Button Content="Register" Command="{Binding RegisterCommand}"/>
|
||||
</StackPanel>
|
||||
<Label Content="{Binding Issue}" Foreground="Red"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@ -20,6 +20,5 @@
|
||||
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Spacing="{DynamicResource Semi}">
|
||||
<Button Content="Register" Command="{Binding RegisterCommand}"/>
|
||||
</StackPanel>
|
||||
<Label Content="{Binding Issue}" Foreground="Red"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
@ -16,6 +16,5 @@
|
||||
<StackPanel Spacing="10" HorizontalAlignment="Stretch" VerticalAlignment="Center">
|
||||
<TextBox Watermark="Host" Text="{Binding Host, Mode=TwoWay}"/>
|
||||
<Button Content="Connect" Command="{Binding SetHostCommand}"/>
|
||||
<Label Content="{Binding Issue}" Foreground="Red"/>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@ -21,5 +21,6 @@
|
||||
<Panel>
|
||||
<rxui:RoutedViewHost Router="{Binding Router}"/>
|
||||
<ursa:OverlayDialogHost HostId="Overlay"/>
|
||||
<ursa:WindowNotificationManager/>
|
||||
</Panel>
|
||||
</ursa:UrsaWindow>
|
||||
@ -7,8 +7,7 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoCommitPageView">
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
<TreeDataGrid Grid.Column="0">
|
||||
</TreeDataGrid>
|
||||
<TreeDataGrid Grid.Column="0" Source="{Binding Commits}"/>
|
||||
<Border Grid.Column="1" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<ScrollViewer>
|
||||
<StackPanel Spacing="4">
|
||||
|
||||
@ -10,15 +10,9 @@
|
||||
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
<Border Grid.Column="0" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8"
|
||||
IsVisible="{Binding IsOwnerRole}">
|
||||
<u:IconButton Icon="{StaticResource SemiIconEdit}" Content="Edit"/>
|
||||
</StackPanel>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<SelectableTextBlock Text="{Binding Repository.Description}"/>
|
||||
</ScrollViewer>
|
||||
</Grid>
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<SelectableTextBlock Text="{Binding Repository.Description}"/>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<ScrollViewer Grid.Column="1" Margin="36 20">
|
||||
<StackPanel Orientation="Vertical">
|
||||
|
||||
@ -7,14 +7,14 @@
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoFileTreePageView">
|
||||
<Grid ColumnDefinitions="2*, *">
|
||||
<TreeDataGrid Grid.Column="0">
|
||||
<TreeDataGrid Grid.Column="0" Grid.ColumnSpan="2" Source="{Binding FileTree}">
|
||||
</TreeDataGrid>
|
||||
<Border Grid.Column="1" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
<ScrollViewer>
|
||||
<StackPanel Spacing="4">
|
||||
<Label Content="File History"/>
|
||||
</StackPanel>
|
||||
</ScrollViewer>
|
||||
</Border>
|
||||
<!-- <Border Grid.Column="1" Classes="Shadow" Theme="{StaticResource CardBorder}"> -->
|
||||
<!-- <ScrollViewer> -->
|
||||
<!-- <StackPanel Spacing="4"> -->
|
||||
<!-- <Label Content="File History"/> -->
|
||||
<!-- </StackPanel> -->
|
||||
<!-- </ScrollViewer> -->
|
||||
<!-- </Border> -->
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@ -6,7 +6,26 @@
|
||||
x:DataType="vm:RepositoryViewModel"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Flawless.Client.Views.RepositoryPage.RepoSettingPageView">
|
||||
<StackPanel VerticalAlignment="Center" HorizontalAlignment="Center">
|
||||
<Label Content="Sit down and wait patience."></Label>
|
||||
</StackPanel>
|
||||
<TabControl TabStripPlacement="Left">
|
||||
<TabItem Header="Members">
|
||||
<StackPanel Width="400" HorizontalAlignment="Stretch">
|
||||
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Statics" IsVisible="{Binding IsDeveloperRole}">
|
||||
<StackPanel Width="400" HorizontalAlignment="Stretch">
|
||||
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Admin Area" IsVisible="{Binding IsOwnerRole}">
|
||||
<StackPanel Width="400" HorizontalAlignment="Stretch">
|
||||
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Hooks" IsVisible="{Binding IsOwnerRole}">
|
||||
<StackPanel Width="400" HorizontalAlignment="Stretch">
|
||||
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
</UserControl>
|
||||
|
||||
@ -12,7 +12,9 @@
|
||||
<u:IconButton Icon="{StaticResource SemiIconRefresh}" Content="Detect"
|
||||
Command="{Binding DetectLocalChangesAsyncCommand}"/>
|
||||
<u:IconButton Icon="{StaticResource SemiIconDownload}" Content="Pull"/>
|
||||
<ToggleButton Content="Auto Refresh" IsChecked="{Binding AutoDetectChanges}"/>
|
||||
<u:IconButton Icon="{StaticResource SemiIconCheckList}" Content="Select"/>
|
||||
<u:IconButton Icon="{StaticResource SemiIconList}" Content="Deselect"/>
|
||||
<!-- <ToggleButton Content="Auto Refresh" IsChecked="{Binding AutoDetectChanges}"/> -->
|
||||
</StackPanel>
|
||||
<TreeDataGrid Grid.Row="1" Grid.Column="0" Source="{Binding LocalChange}" CanUserSortColumns="True"/>
|
||||
<Border Grid.Row="1" Grid.Column="2" Classes="Shadow" Theme="{StaticResource CardBorder}">
|
||||
@ -20,10 +22,10 @@
|
||||
<u:Form HorizontalAlignment="Stretch">
|
||||
<TextBox Text="{Binding LocalDatabase.CommitMessage}"
|
||||
Classes="TextArea" MaxHeight="300" Watermark="Description of this commit"/>
|
||||
<SplitButton HorizontalAlignment="Stretch" Content="Commit">
|
||||
<SplitButton HorizontalAlignment="Stretch" Content="Commit" Command="{Binding CommitSelectedChangesCommand}">
|
||||
<SplitButton.Flyout>
|
||||
<MenuFlyout Placement="TopEdgeAlignedRight">
|
||||
<MenuItem Header="Force Commit as Baseline"/>
|
||||
<MenuItem Header="Force Commit as Baseline" Command="{Binding CommitSelectedChangesCommand}"/>
|
||||
</MenuFlyout>
|
||||
</SplitButton.Flyout>
|
||||
</SplitButton>
|
||||
|
||||
@ -19,7 +19,7 @@
|
||||
<TabControl TabStripPlacement="Top" Margin="0 20 0 0">
|
||||
<TabItem>
|
||||
<TabItem.Header>
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<StackPanel Orientation="Horizontal" Spacing="6" VerticalAlignment="Center">
|
||||
<PathIcon MaxHeight="14" MaxWidth="14" Data="{StaticResource SemiIconBox}"/>
|
||||
<Label Content="Dashboard"/>
|
||||
</StackPanel>
|
||||
|
||||
@ -8,9 +8,9 @@ public class CommitRequest
|
||||
|
||||
public required string Message { get; set; }
|
||||
|
||||
public required WorkspaceFile[] WorkspaceSnapshot { get; set; }
|
||||
public required List<string> WorkspaceSnapshot { get; set; }
|
||||
|
||||
public string[]? RequiredDepots { get; set; }
|
||||
public List<string>? RequiredDepots { get; set; }
|
||||
|
||||
public string? MainDepotId { get; set; } // If commit is not modify files, but changes workspace files (Delete) We will not require a main depot id.
|
||||
|
||||
|
||||
@ -1,3 +1,3 @@
|
||||
namespace Flawless.Communication.Response;
|
||||
|
||||
public record CommitSuccessResponse(DateTime CommittedOn, Guid CommitId);
|
||||
public record CommitSuccessResponse(DateTime CommittedOn, Guid CommitId, Guid MainDepotId);
|
||||
@ -17,6 +17,132 @@ public static class DataTransformer
|
||||
return (byte)val;
|
||||
}
|
||||
|
||||
public static void CreateAndInsertStandardDepotFile
|
||||
(Stream depotStream, IEnumerable<WorkspaceFile> workfiles, Func<WorkspaceFile, Stream> payloadLocator)
|
||||
{
|
||||
if (!depotStream.CanWrite || !depotStream.CanRead) throw new IOException("Depot stream is not writable/readable.");
|
||||
if (payloadLocator == null) throw new ArgumentNullException(nameof(payloadLocator));
|
||||
|
||||
long headerStart = depotStream.Position;
|
||||
long payloadStart = 0;
|
||||
long payloadEnd = 0;
|
||||
long fileMapStart = 0;
|
||||
long fileMapEnd = 0;
|
||||
|
||||
try
|
||||
{
|
||||
using var writer = new BinaryWriter(depotStream, Encoding.ASCII, true);
|
||||
|
||||
writer.Write(StandardDepotHeaderV1.FormatMagicNumber);
|
||||
writer.Write((uint) 0);
|
||||
writer.Write((byte) 1); // Crc of header - later
|
||||
writer.Write((byte) CompressType.Raw);
|
||||
writer.Write((ushort) 0); // Preserved
|
||||
writer.Write((uint) 0); // Preserved
|
||||
writer.Write((ulong) 0); // Hash of this file - later
|
||||
writer.Write((ulong) 0);
|
||||
writer.Write(DateTime.UtcNow.ToBinary());
|
||||
writer.Write((ulong) 0); // Filemap Size - later
|
||||
writer.Write((ulong) 0); // Payload Size - later
|
||||
writer.Write((ulong) 0); // Preserved
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
catch (EndOfStreamException e)
|
||||
{
|
||||
throw new InvalidDataException("Stream is too small! Maybe file is broken.", e);
|
||||
}
|
||||
|
||||
|
||||
// Write files into binary
|
||||
List<DepotFileInfo> fileinfos = new List<DepotFileInfo>();
|
||||
try
|
||||
{
|
||||
// Payload start at here
|
||||
payloadStart = depotStream.Position;
|
||||
|
||||
foreach (var wf in workfiles)
|
||||
{
|
||||
var startPos = depotStream.Position;
|
||||
using var rs = payloadLocator(wf);
|
||||
|
||||
rs.CopyTo(depotStream);
|
||||
fileinfos.Add(new DepotFileInfo(
|
||||
(ulong)(startPos - payloadStart),
|
||||
(ulong)(depotStream.Position - startPos),
|
||||
wf.ModifyTime, wf.WorkPath));
|
||||
|
||||
depotStream.Flush();
|
||||
}
|
||||
|
||||
payloadEnd = depotStream.Position;
|
||||
|
||||
// Filemap start at here
|
||||
var splitor = '$';
|
||||
fileMapStart = depotStream.Position;
|
||||
|
||||
using (var writer = new StreamWriter(depotStream, Encoding.UTF8, 1024, true))
|
||||
{
|
||||
// Format: {Path}${Size}${ModifyTime}${Offset}$
|
||||
foreach (var df in fileinfos)
|
||||
{
|
||||
writer.Write(df.Path);
|
||||
writer.Write(splitor);
|
||||
|
||||
writer.Write(df.Size.ToString());
|
||||
writer.Write(splitor);
|
||||
|
||||
writer.Write(df.ModifyTime.ToBinary().ToString());
|
||||
writer.Write(splitor);
|
||||
|
||||
writer.Write(df.Offset.ToString());
|
||||
writer.Write(splitor);
|
||||
}
|
||||
}
|
||||
|
||||
depotStream.Flush();
|
||||
|
||||
fileMapEnd = depotStream.Position;
|
||||
|
||||
}
|
||||
catch (EndOfStreamException e)
|
||||
{
|
||||
throw new InvalidDataException("Stream is too small! Maybe file is broken.", e);
|
||||
}
|
||||
|
||||
// Write rest part of header and calculate crc
|
||||
try
|
||||
{
|
||||
using var writer = new BinaryWriter(depotStream, Encoding.ASCII, true);
|
||||
|
||||
ulong payloadSize = (ulong)(payloadEnd - payloadStart);
|
||||
ulong filemapSize = (ulong)(fileMapEnd - fileMapStart);
|
||||
|
||||
// Write fs size
|
||||
depotStream.Seek(headerStart + 40, SeekOrigin.Begin);
|
||||
writer.Write(filemapSize);
|
||||
writer.Write(payloadSize);
|
||||
|
||||
writer.Flush();
|
||||
|
||||
// Calculate CRC
|
||||
depotStream.Seek(headerStart + 8, SeekOrigin.Begin);
|
||||
Span<byte> crcArea = stackalloc byte[64 - 8];
|
||||
if (depotStream.Read(crcArea) != 64 - 8) throw new InvalidDataException("Stream is too short!");
|
||||
var crc = Crc32.HashToUInt32(crcArea);
|
||||
|
||||
// Write CRC
|
||||
depotStream.Seek(headerStart + 4, SeekOrigin.Begin);
|
||||
writer.Write(crc);
|
||||
|
||||
writer.Flush();
|
||||
}
|
||||
catch (EndOfStreamException e)
|
||||
{
|
||||
throw new InvalidDataException("Stream is too small! Maybe file is broken.", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static StandardDepotHeaderV1 ExtractStandardDepotHeaderV1(Stream depotStream)
|
||||
{
|
||||
@ -76,7 +202,7 @@ public static class DataTransformer
|
||||
public static async IAsyncEnumerable<DepotFileInfo> ExtractDepotFileInfoMapAsync(Stream depotStream, ulong fileMapSize)
|
||||
{
|
||||
var splitor = '$';
|
||||
depotStream.Seek((long) fileMapSize, SeekOrigin.End);
|
||||
depotStream.Seek(-(long)fileMapSize, SeekOrigin.End);
|
||||
|
||||
var state = -1;
|
||||
var buffer = new char[64];
|
||||
@ -91,41 +217,45 @@ public static class DataTransformer
|
||||
// Read loop
|
||||
while (true)
|
||||
{
|
||||
int length = 0;
|
||||
|
||||
try
|
||||
{
|
||||
var length = await reader.ReadBlockAsync(buffer, 0, 64);
|
||||
length = await reader.ReadBlockAsync(buffer, 0, 64);
|
||||
if (length == 0) break;
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var c = buffer[i];
|
||||
if (c != splitor) builder.Append(c);
|
||||
else
|
||||
{
|
||||
switch ((state = (state + 1) % 4))
|
||||
{
|
||||
case 0: path = builder.ToString(); break;
|
||||
case 1: size = ulong.Parse(builder.ToString()); break;
|
||||
case 2: modifyTime = DateTime.FromBinary(long.Parse(builder.ToString())); break;
|
||||
case 3: offset = ulong.Parse(builder.ToString()); break;
|
||||
}
|
||||
|
||||
builder.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (EndOfStreamException e)
|
||||
{
|
||||
throw new InvalidDataException("Stream is too small! Maybe file is broken.", e);
|
||||
}
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var c = buffer[i];
|
||||
if (c != splitor) builder.Append(c);
|
||||
else
|
||||
{
|
||||
switch ((state = (state + 1) % 4))
|
||||
{
|
||||
case 0: path = builder.ToString(); break;
|
||||
case 1: size = ulong.Parse(builder.ToString()); break;
|
||||
case 2: modifyTime = DateTime.FromBinary(long.Parse(builder.ToString())); break;
|
||||
case 3:
|
||||
{
|
||||
offset = ulong.Parse(builder.ToString());
|
||||
yield return new DepotFileInfo(offset, size, modifyTime, path);
|
||||
} break;
|
||||
}
|
||||
|
||||
builder.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
// Do output at here.
|
||||
yield return new DepotFileInfo(offset, size, modifyTime, path);
|
||||
|
||||
}
|
||||
|
||||
// Check is this the real ending
|
||||
if (builder.Length > 0 || state != 0)
|
||||
if (builder.Length > 0 || (state > 0 && state < 3))
|
||||
throw new InvalidDataException("Stream is too small! Maybe file is broken.");
|
||||
}
|
||||
}
|
||||
@ -33,7 +33,7 @@ namespace Flawless.Core.BinaryDataFormat;
|
||||
* 14 : (Preserve)
|
||||
* 15 : (Preserve)
|
||||
* ------------------------------------------------------------
|
||||
* 16 : Depot MD5 Checksum (From 48 to end, uncompressed)
|
||||
* 16 : Depot MD5 Checksum (From 64 to end, uncompressed)
|
||||
* 17 : ~
|
||||
* 18 : ~
|
||||
* 19 : ~
|
||||
|
||||
@ -1,10 +1,17 @@
|
||||
namespace Flawless.Core.Modal;
|
||||
|
||||
[Serializable]
|
||||
public struct WorkspaceFile : IEquatable<WorkspaceFile>
|
||||
{
|
||||
public required DateTime ModifyTime;
|
||||
public DateTime ModifyTime { get; set; }
|
||||
|
||||
public required string WorkPath;
|
||||
public string WorkPath { get; set; }
|
||||
|
||||
public WorkspaceFile(DateTime modifyTime, string workPath)
|
||||
{
|
||||
ModifyTime = modifyTime;
|
||||
WorkPath = workPath;
|
||||
}
|
||||
|
||||
public bool Equals(WorkspaceFile other)
|
||||
{
|
||||
|
||||
@ -1,6 +1,4 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.Json;
|
||||
using Flawless.Communication.Request;
|
||||
using Flawless.Communication.Response;
|
||||
using Flawless.Communication.Shared;
|
||||
@ -9,15 +7,13 @@ using Flawless.Core.Modal;
|
||||
using Flawless.Server.Models;
|
||||
using Flawless.Server.Services;
|
||||
using Flawless.Server.Utility;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.OpenApi.Validations.Rules;
|
||||
|
||||
namespace Flawless.Server.Controllers;
|
||||
|
||||
[ApiController, Authorize, Route("api/repo/{userName}/{repositoryName}")]
|
||||
[ApiController, Microsoft.AspNetCore.Authorization.Authorize, Route("api/repo/{userName}/{repositoryName}")]
|
||||
public class RepositoryInnieController(
|
||||
UserManager<AppUser> userManager,
|
||||
AppDbContext dbContext,
|
||||
@ -223,30 +219,30 @@ public class RepositoryInnieController(
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("fetch_manifest")]
|
||||
[ProducesResponseType<FileStreamResult>(200)]
|
||||
public async Task<IActionResult> DownloadManifestAsync(string userName, string repositoryName, [FromQuery] string commitId)
|
||||
[HttpPost("fetch_manifest")]
|
||||
public async Task<ActionResult<CommitManifest>> DownloadManifestAsync(string userName, string repositoryName, [FromQuery] string commitId)
|
||||
{
|
||||
if (!Guid.TryParse(commitId, out var commitGuid)) return BadRequest(new FailedResponse("Invalid commit id"));
|
||||
var user = (await userManager.GetUserAsync(HttpContext.User))!;
|
||||
var grantIssue = await ValidateRepositoryAsync(userName, repositoryName, user, RepositoryRole.Guest);
|
||||
if (grantIssue is not Repository rp) return (IActionResult) grantIssue;
|
||||
if (grantIssue is not Repository rp) return (ActionResult) grantIssue;
|
||||
|
||||
// Start checkout file.
|
||||
var target = transformer.GetCommitManifestPath(rp.Id, commitGuid);
|
||||
if (System.IO.File.Exists(target)) return File(System.IO.File.OpenRead(target), "application/octet-stream");
|
||||
return NotFound(new FailedResponse($"Could not find commit manifest {target}"));
|
||||
if (!System.IO.File.Exists(target)) return NotFound(new FailedResponse($"Could not find commit manifest {target}"));
|
||||
|
||||
await using var manifest = System.IO.File.OpenRead(target);
|
||||
return await JsonSerializer.DeserializeAsync<CommitManifest>(manifest);
|
||||
}
|
||||
|
||||
|
||||
[HttpGet("fetch_depot")]
|
||||
[ProducesResponseType<FileStreamResult>(200)]
|
||||
public async Task<IActionResult> DownloadDepotAsync(string userName, string repositoryName, [FromQuery] string depotId)
|
||||
[HttpPost("fetch_depot")]
|
||||
public async Task<ActionResult<Stream>> DownloadDepotAsync(string userName, string repositoryName, [FromQuery] string depotId)
|
||||
{
|
||||
if (!Guid.TryParse(depotId, out var depotGuid)) return BadRequest(new FailedResponse("Invalid depot id"));
|
||||
var user = (await userManager.GetUserAsync(HttpContext.User))!;
|
||||
var grantIssue = await ValidateRepositoryAsync(userName, repositoryName, user, RepositoryRole.Guest);
|
||||
if (grantIssue is not Repository rp) return (IActionResult) grantIssue;
|
||||
if (grantIssue is not Repository rp) return (ActionResult) grantIssue;
|
||||
|
||||
// Start checkout file.
|
||||
var target = transformer.GetDepotPath(rp.Id, depotGuid);
|
||||
@ -255,7 +251,7 @@ public class RepositoryInnieController(
|
||||
|
||||
}
|
||||
|
||||
[HttpGet("list_commit")]
|
||||
[HttpPost("list_commit")]
|
||||
public async Task<ActionResult<ListingResponse<RepositoryCommitResponse>>> ListCommitsAsync(string userName, string repositoryName)
|
||||
{
|
||||
var user = (await userManager.GetUserAsync(HttpContext.User))!;
|
||||
@ -277,7 +273,7 @@ public class RepositoryInnieController(
|
||||
return Ok(new ListingResponse<RepositoryCommitResponse>(r.ToArray()));
|
||||
}
|
||||
|
||||
[HttpGet("list_locked_files")]
|
||||
[HttpPost("list_locked_files")]
|
||||
public async Task<ActionResult<ListingResponse<LockFileInfo>>> ListLocksAsync(string userName, string repositoryName)
|
||||
{
|
||||
var user = (await userManager.GetUserAsync(HttpContext.User))!;
|
||||
@ -386,6 +382,7 @@ public class RepositoryInnieController(
|
||||
}
|
||||
|
||||
[HttpPost("create_commit")]
|
||||
[RequestSizeLimit(long.MaxValue)]
|
||||
[ProducesResponseType<CommitSuccessResponse>(200)]
|
||||
public async Task<IActionResult> CommitAsync(string userName, string repositoryName, [FromForm] FormCommitRequest req)
|
||||
{
|
||||
@ -393,6 +390,7 @@ public class RepositoryInnieController(
|
||||
var grantIssue = await ValidateRepositoryAsync(userName, repositoryName, user, RepositoryRole.Developer);
|
||||
if (grantIssue is not Repository rp) return (IActionResult) grantIssue;
|
||||
|
||||
// Appoint or upload a commit - two in one choice.
|
||||
if (req.Depot != null ^ req.MainDepotId != null) return await CommitInternalAsync(rp, user, req);
|
||||
|
||||
// Not valid response
|
||||
@ -402,7 +400,17 @@ public class RepositoryInnieController(
|
||||
|
||||
private async Task<IActionResult> CommitInternalAsync(Repository rp, AppUser user, FormCommitRequest req)
|
||||
{
|
||||
var test = new HashSet<WorkspaceFile>(req.WorkspaceSnapshot);
|
||||
var actualFs = req.WorkspaceSnapshot.Select(s =>
|
||||
{
|
||||
var idx = s.IndexOf('$');
|
||||
if (idx < 0) throw new InvalidDataException($"WorkPath '{s}' is invalid!");
|
||||
var dateTimeStr = s.Substring(0, idx);
|
||||
var pathStr = s.Substring(idx + 1);
|
||||
|
||||
return new WorkspaceFile(DateTime.FromBinary(long.Parse(dateTimeStr)), pathStr);
|
||||
}).ToArray();
|
||||
|
||||
var test = new HashSet<WorkspaceFile>(actualFs);
|
||||
var createNewDepot = false;
|
||||
RepositoryDepot mainDepot;
|
||||
List<DepotLabel> depotLabels = new();
|
||||
@ -481,8 +489,13 @@ public class RepositoryInnieController(
|
||||
.Where(cm => actualRequiredDepots.Contains(cm.DepotId))
|
||||
.ToArrayAsync());
|
||||
|
||||
// Create commit and let it alloc a main key
|
||||
rp.Depots.Add(mainDepot);
|
||||
await dbContext.SaveChangesAsync();
|
||||
|
||||
// Then write depot into disk
|
||||
var depotPath = transformer.GetDepotPath(rp.Id, mainDepot.DepotId);
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(depotPath)!);
|
||||
await using (var depotStream = System.IO.File.Create(depotPath))
|
||||
{
|
||||
cacheStream.Seek(0, SeekOrigin.Begin);
|
||||
@ -492,56 +505,51 @@ public class RepositoryInnieController(
|
||||
// Everything alright, so make response
|
||||
depotLabels.Add(new DepotLabel(mainDepot.DepotId, mainDepot.Length));
|
||||
depotLabels.AddRange(mainDepot.Dependencies.Select(d => new DepotLabel(d.DepotId, d.Length)));
|
||||
rp.Depots.Add(mainDepot);
|
||||
|
||||
createNewDepot = true;
|
||||
}
|
||||
|
||||
// Create manifest file and write to disk
|
||||
var commitId = Guid.NewGuid();
|
||||
var manifestPath = transformer.GetCommitManifestPath(rp.Id, commitId);
|
||||
var manifest = new CommitManifest
|
||||
{
|
||||
ManifestId = commitId,
|
||||
Depot = depotLabels.ToArray(),
|
||||
FilePaths = req.WorkspaceSnapshot
|
||||
};
|
||||
|
||||
await using (var manifestStream = System.IO.File.Create(manifestPath))
|
||||
await JsonSerializer.SerializeAsync(manifestStream, manifest);
|
||||
|
||||
// Create commit info
|
||||
var commit = new RepositoryCommit
|
||||
{
|
||||
Id = commitId,
|
||||
Author = user,
|
||||
CommittedOn = DateTime.UtcNow,
|
||||
MainDepot = mainDepot,
|
||||
Message = manifestPath
|
||||
Message = req.Message,
|
||||
};
|
||||
|
||||
rp.Commits.Add(commit);
|
||||
|
||||
try
|
||||
{
|
||||
// Write changes into db.
|
||||
rp.Commits.Add(commit);
|
||||
await dbContext.SaveChangesAsync();
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Revert manifest create operation
|
||||
if (createNewDepot) System.IO.File.Delete(transformer.GetDepotPath(rp.Id, mainDepot.DepotId));
|
||||
System.IO.File.Delete(manifestPath);
|
||||
|
||||
// Revert depot create operation
|
||||
System.IO.File.Delete(transformer.GetDepotPath(rp.Id, mainDepot.DepotId));
|
||||
throw;
|
||||
}
|
||||
|
||||
return Ok(new CommitSuccessResponse(commit.CommittedOn, commit.Id));
|
||||
// Create manifest file and write to disk
|
||||
var manifestPath = transformer.GetCommitManifestPath(rp.Id, commit.Id);
|
||||
var manifest = new CommitManifest
|
||||
{
|
||||
ManifestId = commit.Id,
|
||||
Depot = depotLabels.ToArray(),
|
||||
FilePaths = actualFs
|
||||
};
|
||||
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(manifestPath)!);
|
||||
await using (var manifestStream = System.IO.File.Create(manifestPath))
|
||||
await JsonSerializer.SerializeAsync(manifestStream, manifest);
|
||||
|
||||
return Ok(new CommitSuccessResponse(commit.CommittedOn, commit.Id, mainDepot.DepotId));
|
||||
}
|
||||
|
||||
private static async ValueTask StencilWorkspaceSnapshotAsync(Stream depotStream, HashSet<WorkspaceFile> unresolved)
|
||||
{
|
||||
// Get version
|
||||
depotStream.Seek(0, SeekOrigin.Begin); // Fix: Get an invalid version code due to offset is bad.
|
||||
var version = DataTransformer.GuessStandardDepotHeaderVersion(depotStream);
|
||||
if (version != 1) throw new InvalidDataException($"Unable to get depot header version, feedback is {version}.");
|
||||
|
||||
|
||||
@ -38,6 +38,8 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="data\development\ff9864da-eac3-41f5-9d0f-99d51e608743\Depots\" />
|
||||
<Folder Include="data\development\ff9864da-eac3-41f5-9d0f-99d51e608743\Manifests\" />
|
||||
<Folder Include="Exceptions\" />
|
||||
</ItemGroup>
|
||||
|
||||
|
||||
@ -7,7 +7,7 @@ public class Repository
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public required AppUser Owner { get; set; }
|
||||
|
||||
@ -5,17 +5,17 @@ namespace Flawless.Server.Models;
|
||||
public class RepositoryCommit
|
||||
{
|
||||
[Required]
|
||||
public required Guid Id { get; set; } = Guid.NewGuid();
|
||||
public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public required AppUser Author { get; set; }
|
||||
public AppUser Author { get; set; }
|
||||
|
||||
[Required]
|
||||
public required DateTime CommittedOn { get; set; }
|
||||
public DateTime CommittedOn { get; set; }
|
||||
|
||||
[Required]
|
||||
public required string Message { get; set; } = String.Empty;
|
||||
public string Message { get; set; } = String.Empty;
|
||||
|
||||
[Required]
|
||||
public required RepositoryDepot MainDepot { get; set; }
|
||||
public RepositoryDepot MainDepot { get; set; }
|
||||
}
|
||||
@ -6,7 +6,7 @@ public class RepositoryDepot
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public Guid DepotId { get; set; } = Guid.NewGuid();
|
||||
public Guid DepotId { get; set; }
|
||||
|
||||
[Required]
|
||||
public long Length { get; set; }
|
||||
|
||||
@ -5,9 +5,7 @@ namespace Flawless.Server.Models;
|
||||
|
||||
public class RepositoryMember
|
||||
{
|
||||
[Key]
|
||||
[Required]
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
[Key] [Required] public Guid Id { get; set; }
|
||||
|
||||
[Required]
|
||||
public required AppUser User { get; set; }
|
||||
|
||||
@ -8,6 +8,7 @@ using Flawless.Server.Services;
|
||||
using Flawless.Server.Utility;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http.Features;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
@ -34,6 +35,20 @@ public static class Program
|
||||
|
||||
private static void ConfigAppService(WebApplicationBuilder builder)
|
||||
{
|
||||
// Set size limit
|
||||
builder.WebHost.ConfigureKestrel(opt =>
|
||||
{
|
||||
opt.Limits.MaxRequestBodySize = long.MaxValue; // As big as possible...
|
||||
opt.Limits.MaxRequestHeaderCount = int.MaxValue; // As big as possible...
|
||||
});
|
||||
|
||||
builder.Services.Configure<FormOptions>(opt =>
|
||||
{
|
||||
opt.MultipartBodyLengthLimit = long.MaxValue;
|
||||
opt.ValueLengthLimit = int.MaxValue;
|
||||
opt.MultipartHeadersLengthLimit = int.MaxValue;
|
||||
});
|
||||
|
||||
// Api related
|
||||
builder.Services.AddSingleton<PathTransformer>();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user