ESENT: try 2

This commit is contained in:
Namhyeon Go 2025-06-22 22:27:42 +09:00
parent 7aa70a2eeb
commit dfef7a622f
6 changed files with 64 additions and 26 deletions

View File

@ -38,6 +38,7 @@ namespace WelsonJS.Launcher
if (!Directory.Exists(instancesRoot))
return;
/*
foreach (string dir in Directory.GetDirectories(instancesRoot))
{
string timestampFile = Path.Combine(dir, ".welsonjs_first_deploy_time");
@ -66,6 +67,25 @@ namespace WelsonJS.Launcher
});
}
}
*/
var instances = Program._InstancesMetadataStore.FindAll();
foreach (var instance in instances)
{
string instanceId = instance["InstanceId"].ToString();
string firstDeployTime = instance.ContainsKey("FirstDeployTime")
? ((DateTime)instance["FirstDeployTime"]).ToString(timestampFormat)
: "Unknown";
lvInstances.Items.Add(new ListViewItem(new[]
{
instanceId,
firstDeployTime
})
{
Tag = Path.Combine(instancesRoot, instanceId)
});
}
}
private void btnStart_Click(object sender, EventArgs e)

View File

@ -140,7 +140,7 @@ namespace WelsonJS.Launcher
ZipFile.ExtractToDirectory(filePath, workingDirectory);
// record the first deploy time
RecordFirstDeployTime(workingDirectory);
RecordFirstDeployTime(workingDirectory, instanceId);
// follow the sub-directory
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
@ -157,34 +157,35 @@ namespace WelsonJS.Launcher
SafeInvoke(() => EnableUI());
}
private void RecordFirstDeployTime(string directory)
private void RecordFirstDeployTime(string directory, string instanceId)
{
/*
// get current time
DateTime now = DateTime.Now;
// record to the metadata database
try
{
Program._InstancesMetadataStore.Insert(new Dictionary<string, object>
{
["InstanceId"] = instanceId,
["FirstDeployTime"] = now
}, out _);
}
catch (Exception ex)
{
Trace.TraceError($"Failed to record first deploy time: {ex.Message}");
}
// record to the instance directory
try
{
string filePath = Path.Combine(directory, ".welsonjs_first_deploy_time");
string text = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string text = now.ToString("yyyy-MM-dd HH:mm:ss");
File.WriteAllText(filePath, text);
}
catch (Exception ex)
{
throw new Exception($"Failed to record first deploy time: {ex.Message}");
}
*/
try
{
object key;
Program._MetadataStore.Insert(new Dictionary<string, object>
{
["InstanceId"] = "abc123",
["FirstDeployTime"] = "2025-06-19 10:00:00"
}, out key);
}
catch (Exception ex)
{
Trace.TraceWarning(ex.Message);
Trace.TraceError($"Failed to record first deploy time: {ex.Message}");
}
}

View File

@ -9,6 +9,7 @@ using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Isam.Esent.Interop;
using WelsonJS.Launcher.Storage;
@ -104,6 +105,18 @@ namespace WelsonJS.Launcher
Api.JetAddColumn(_session, tableid, col.Name, coldef, null, 0, out _);
}
string indexName = "primary";
string indexKey = $"+{_primaryKey}\0\0"; // Primary key ASC
Api.JetCreateIndex(
_session,
tableid,
indexName,
CreateIndexGrbit.IndexPrimary | CreateIndexGrbit.IndexUnique,
indexKey,
indexKey.Length,
100);
Api.JetCloseTable(_session, tableid);
Api.JetCommitTransaction(_session, CommitTransactionGrbit.None);
}
@ -156,6 +169,7 @@ namespace WelsonJS.Launcher
{
Api.JetBeginTransaction(_session);
Api.JetSetCurrentIndex(_session, table, null);
MakeKeyByType(keyValue, keyType, _session, table);
bool found = Api.TrySeek(_session, table, SeekGrbit.SeekEQ);
@ -180,6 +194,7 @@ namespace WelsonJS.Launcher
catch (Exception ex)
{
Trace.TraceError($"[ESENT] Operation failed: {ex.Message}");
MessageBox.Show($"[ESENT] Operation failed: {ex.Message}");
Api.JetRollback(_session, RollbackTransactionGrbit.None);
return false;
}
@ -193,6 +208,7 @@ namespace WelsonJS.Launcher
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.ReadOnly))
{
Api.JetSetCurrentIndex(_session, table, null);
MakeKeyByType(keyValue, keyType, _session, table);
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
return null;
@ -244,6 +260,7 @@ namespace WelsonJS.Launcher
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.Updatable))
{
Api.JetSetCurrentIndex(_session, table, null);
MakeKeyByType(keyValue, keyType, _session, table);
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
return false;

View File

@ -19,7 +19,7 @@ namespace WelsonJS.Launcher
{
static Mutex mutex;
public static ResourceServer _ResourceServer;
public static MetadataStore _MetadataStore;
public static MetadataStore _InstancesMetadataStore;
[STAThread]
static void Main()
@ -39,7 +39,7 @@ namespace WelsonJS.Launcher
new Column("FirstDeployTime", typeof(DateTime), 1)
});
schema.SetPrimaryKey("InstanceId");
_MetadataStore = new MetadataStore(schema);
_InstancesMetadataStore = new MetadataStore(schema);
// draw the main form
Application.EnableVisualStyles();
@ -47,7 +47,7 @@ namespace WelsonJS.Launcher
Application.Run(new MainForm());
// close the database
_MetadataStore.Dispose();
_InstancesMetadataStore.Dispose();
// destory the mutex
mutex.ReleaseMutex();

View File

@ -1,6 +1,6 @@
// Column.cs
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2025 Catswords OSS and WelsonJS Contributors
// SPDX-FileCopyrightText: 2025 Namhyeon Go, Catswords OSS and WelsonJS Contributors
// https://github.com/gnh1201/welsonjs
//
using System;

View File

@ -1,6 +1,6 @@
// TableSchema.cs
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2025 Catswords OSS and WelsonJS Contributors
// SPDX-FileCopyrightText: 2025 Namhyeon Go, Catswords OSS and WelsonJS Contributors
// https://github.com/gnh1201/welsonjs
//
using System;