Skip to content

Commit

Permalink
Only the generation function of the last words function is retained
Browse files Browse the repository at this point in the history
  • Loading branch information
JusterZhu committed Sep 23, 2023
1 parent 24ad0da commit 653b856
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 32 deletions.
24 changes: 14 additions & 10 deletions src/c#/GeneralUpdate.Core/Domain/PO/TestamentPO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,24 @@ namespace GeneralUpdate.Core.Domain.PO
{
public class TestamentPO
{
public TestamentPO()
{
UUID = Guid.NewGuid().ToString();
CreateTime = DateTime.Now;
}

public string UUID { get; private set; }
/// <summary>
/// The tracking id of this update request
/// </summary>
public string TrackID { get; set; }

/// <summary>
/// dump files everywhere after an exception occurs.
/// </summary>
public string DumpPath { get; set; }

public DateTime CreateTime { get; private set; }
/// <summary>
/// Backup the file path that needs to be updated before updating.
/// </summary>
public string BackupPath { get; set; }

/// <summary>
/// Exception information that occurs when updating fails.
/// </summary>
public Exception Exception { get; set; }

public VersionPO Version { get; set; }
}
}
31 changes: 9 additions & 22 deletions src/c#/GeneralUpdate.Core/Testament/GeneralTestamentProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Diagnostics;
using Microsoft.Diagnostics.NETCore.Client;
using System.Threading.Tasks;
using System.Collections.Generic;

namespace GeneralUpdate.Core.Testament
{
Expand All @@ -22,38 +23,24 @@ public GeneralTestamentProvider(string url, string path)
_dumpPath = Path.Combine(path, DUMP_FILE);
}

/// <summary>
/// When the program is started, the contents of the last note will be analyzed to restore the backup or continue to update the last note.
/// </summary>
public void Demolish()
{
//TODO: If the backup file is rolled back to the current process, the restoration file will fail...
var testamentPO = FileUtil.ReadJsonFile<TestamentPO>(_testamentPath);
File.Delete(_testamentPath);
}

/// <summary>
/// Generate the contents of the last word, read the last word when the next program starts for backup restoration or re-update.
/// </summary>
/// <param name="testament"></param>
public void Build(VersionPO version,Exception exception)
public void Build(TestamentPO testament)
{
if (version == null) return;
if (testament == null) return;

Task.Run(async () =>
{
//Generate last words locally.
var testament = new TestamentPO();
testament.Exception = exception;
testament.Version = version;
testament.DumpPath = _dumpPath;
FileUtil.CreateJsonFile(_testamentPath, TESTAMENT_FILE, testament);

//dump files locally everywhere.
CreateDump();

//Report the current update failure to the server.
await HttpUtil.GetTaskAsync<string>(_url);
var parameters = new Dictionary<string, string>
{
{ "TrackID", testament.TrackID },
{ "Exception", testament.Exception.ToString() }
};
await HttpUtil.PostFileTaskAsync<string>(_url, parameters, _dumpPath);
});
}

Expand Down

0 comments on commit 653b856

Please sign in to comment.