-
-
Notifications
You must be signed in to change notification settings - Fork 95
Open
Description
Any changes I make in the editor before I hit save are ignored and it just saves what was in the page originally. The file metadata shows that it has been overwritten but the changes I make aren't persisted.
This is the case no matter if I use the Workflow[]
passed into my save method or the one I bound to the RulesEngineEditorPage
with @bind-Workflows
. No matter if I use WorkflowsChanged="Save"
or WorkflowsSaved="Save"
it doesn't work right.
The only way to get your changes to workflows back out of the editor is the download button.
@using Newtonsoft.Json
@using RulesEngine.Models
@using System.Runtime.Serialization
@using System.Security.Cryptography
@using System.Text
@using Azure.Storage.Blobs.Models
@inject AppConfig AppConfig
<p>Last Saved: @lastSaved</p>
<RulesEngineEditorPage @bind-Workflows=Workflows MenuButtons=@menuButtons WorkflowsSaved="Save" />
@code {
DateTime? lastSaved;
private BlobStorageService blobStorageService;
private byte[] startingHash;
private Workflow[] Workflows { get; set; }
private List<MenuButton> menuButtons = new List<MenuButton>()
{
new MenuButton("NewWorkflows"),
new MenuButton("DownloadWorkflows"),
new MenuButton("ImportWorkflows"),
new MenuButton("AddWorkflow"),
new MenuButton("SaveWorkflow")
};
protected override async Task OnInitializedAsync() {
string fileContents;
blobStorageService = new BlobStorageService(Environment.GetEnvironmentVariable("CONNECTION_STRING"));
await using Stream blobStream = await blobStorageService.GetBlobAsync("json", AppConfig.RulesJsonFilename);
using (var streamReader = new StreamReader(blobStream)) {
fileContents = await streamReader.ReadToEndAsync();
}
var workflowList = JsonConvert.DeserializeObject<List<Workflow>>(fileContents);
BlobProperties properties = await blobStorageService.GetBlobPropertiesAsync("json", AppConfig.RulesJsonFilename);
lastSaved = properties.LastModified.LocalDateTime;
startingHash = properties.ContentHash;
Workflows = workflowList.ToArray();
}
protected async Task Save(Workflow[] workflows) {
Workflows = workflows; // I've tried it with this line commented out for no difference
string serializedWorkflows = JsonConvert.SerializeObject(Workflows, Formatting.Indented);
Stream memoryStream = new MemoryStream(Encoding.Default.GetBytes(serializedWorkflows));
byte[] newChecksum = MD5.HashData(memoryStream);
if (newChecksum.SequenceEqual(startingHash)) {
Console.WriteLine("Content is unchanged!!!!");
byte[] paramChecksum = MD5.HashData(new MemoryStream(Encoding.Default.GetBytes(JsonConvert.SerializeObject(workflows, Formatting.Indented))));
Console.WriteLine("is the param also the same? " + paramChecksum.SequenceEqual(startingHash));
throw new TaskCanceledException();
}
Task<BlobContentInfo> saveTask = blobStorageService.UploadBlobAsync("json", AppConfig.RulesJsonFilename, memoryStream);
BlobContentInfo info = await saveTask;
if (saveTask.IsFaulted) {
await Console.Error.WriteLineAsync($"Failed to Save! {saveTask.Exception}");
}
else {
Console.WriteLine($"Save attempt {saveTask.Status}");
lastSaved = info.LastModified.LocalDateTime;
await InvokeAsync(StateHasChanged);
}
}
After saving a few changes, and Console output is :
Content is unchanged!!!!
is the param also the same? True
If you comment out the if block with the checksum code and attempt to save changes, the lastSaved
date updates, but the workflows are unchanged.
Metadata
Metadata
Assignees
Labels
No labels