mirror of
https://github.com/gnh1201/welsonjs.git
synced 2025-11-28 10:31:04 +00:00
ESENT: try 2
This commit is contained in:
parent
7aa70a2eeb
commit
dfef7a622f
|
|
@ -38,6 +38,7 @@ namespace WelsonJS.Launcher
|
||||||
if (!Directory.Exists(instancesRoot))
|
if (!Directory.Exists(instancesRoot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
/*
|
||||||
foreach (string dir in Directory.GetDirectories(instancesRoot))
|
foreach (string dir in Directory.GetDirectories(instancesRoot))
|
||||||
{
|
{
|
||||||
string timestampFile = Path.Combine(dir, ".welsonjs_first_deploy_time");
|
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)
|
private void btnStart_Click(object sender, EventArgs e)
|
||||||
|
|
|
||||||
|
|
@ -140,7 +140,7 @@ namespace WelsonJS.Launcher
|
||||||
ZipFile.ExtractToDirectory(filePath, workingDirectory);
|
ZipFile.ExtractToDirectory(filePath, workingDirectory);
|
||||||
|
|
||||||
// record the first deploy time
|
// record the first deploy time
|
||||||
RecordFirstDeployTime(workingDirectory);
|
RecordFirstDeployTime(workingDirectory, instanceId);
|
||||||
|
|
||||||
// follow the sub-directory
|
// follow the sub-directory
|
||||||
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
workingDirectory = Program.GetWorkingDirectory(instanceId, true);
|
||||||
|
|
@ -157,34 +157,35 @@ namespace WelsonJS.Launcher
|
||||||
SafeInvoke(() => EnableUI());
|
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
|
try
|
||||||
{
|
{
|
||||||
string filePath = Path.Combine(directory, ".welsonjs_first_deploy_time");
|
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);
|
File.WriteAllText(filePath, text);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
throw new Exception($"Failed to record first deploy time: {ex.Message}");
|
Trace.TraceError($"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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@ using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Windows.Forms;
|
||||||
using Microsoft.Isam.Esent.Interop;
|
using Microsoft.Isam.Esent.Interop;
|
||||||
using WelsonJS.Launcher.Storage;
|
using WelsonJS.Launcher.Storage;
|
||||||
|
|
||||||
|
|
@ -104,6 +105,18 @@ namespace WelsonJS.Launcher
|
||||||
Api.JetAddColumn(_session, tableid, col.Name, coldef, null, 0, out _);
|
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.JetCloseTable(_session, tableid);
|
||||||
Api.JetCommitTransaction(_session, CommitTransactionGrbit.None);
|
Api.JetCommitTransaction(_session, CommitTransactionGrbit.None);
|
||||||
}
|
}
|
||||||
|
|
@ -156,6 +169,7 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
Api.JetBeginTransaction(_session);
|
Api.JetBeginTransaction(_session);
|
||||||
|
|
||||||
|
Api.JetSetCurrentIndex(_session, table, null);
|
||||||
MakeKeyByType(keyValue, keyType, _session, table);
|
MakeKeyByType(keyValue, keyType, _session, table);
|
||||||
bool found = Api.TrySeek(_session, table, SeekGrbit.SeekEQ);
|
bool found = Api.TrySeek(_session, table, SeekGrbit.SeekEQ);
|
||||||
|
|
||||||
|
|
@ -180,6 +194,7 @@ namespace WelsonJS.Launcher
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
Trace.TraceError($"[ESENT] Operation failed: {ex.Message}");
|
Trace.TraceError($"[ESENT] Operation failed: {ex.Message}");
|
||||||
|
MessageBox.Show($"[ESENT] Operation failed: {ex.Message}");
|
||||||
Api.JetRollback(_session, RollbackTransactionGrbit.None);
|
Api.JetRollback(_session, RollbackTransactionGrbit.None);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
@ -193,6 +208,7 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.ReadOnly))
|
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.ReadOnly))
|
||||||
{
|
{
|
||||||
|
Api.JetSetCurrentIndex(_session, table, null);
|
||||||
MakeKeyByType(keyValue, keyType, _session, table);
|
MakeKeyByType(keyValue, keyType, _session, table);
|
||||||
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
|
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
|
||||||
return null;
|
return null;
|
||||||
|
|
@ -244,6 +260,7 @@ namespace WelsonJS.Launcher
|
||||||
|
|
||||||
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.Updatable))
|
using (var table = new Table(_session, _dbid, _schema.TableName, OpenTableGrbit.Updatable))
|
||||||
{
|
{
|
||||||
|
Api.JetSetCurrentIndex(_session, table, null);
|
||||||
MakeKeyByType(keyValue, keyType, _session, table);
|
MakeKeyByType(keyValue, keyType, _session, table);
|
||||||
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
|
if (!Api.TrySeek(_session, table, SeekGrbit.SeekEQ))
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ namespace WelsonJS.Launcher
|
||||||
{
|
{
|
||||||
static Mutex mutex;
|
static Mutex mutex;
|
||||||
public static ResourceServer _ResourceServer;
|
public static ResourceServer _ResourceServer;
|
||||||
public static MetadataStore _MetadataStore;
|
public static MetadataStore _InstancesMetadataStore;
|
||||||
|
|
||||||
[STAThread]
|
[STAThread]
|
||||||
static void Main()
|
static void Main()
|
||||||
|
|
@ -39,7 +39,7 @@ namespace WelsonJS.Launcher
|
||||||
new Column("FirstDeployTime", typeof(DateTime), 1)
|
new Column("FirstDeployTime", typeof(DateTime), 1)
|
||||||
});
|
});
|
||||||
schema.SetPrimaryKey("InstanceId");
|
schema.SetPrimaryKey("InstanceId");
|
||||||
_MetadataStore = new MetadataStore(schema);
|
_InstancesMetadataStore = new MetadataStore(schema);
|
||||||
|
|
||||||
// draw the main form
|
// draw the main form
|
||||||
Application.EnableVisualStyles();
|
Application.EnableVisualStyles();
|
||||||
|
|
@ -47,7 +47,7 @@ namespace WelsonJS.Launcher
|
||||||
Application.Run(new MainForm());
|
Application.Run(new MainForm());
|
||||||
|
|
||||||
// close the database
|
// close the database
|
||||||
_MetadataStore.Dispose();
|
_InstancesMetadataStore.Dispose();
|
||||||
|
|
||||||
// destory the mutex
|
// destory the mutex
|
||||||
mutex.ReleaseMutex();
|
mutex.ReleaseMutex();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// Column.cs
|
// Column.cs
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
// https://github.com/gnh1201/welsonjs
|
||||||
//
|
//
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
// TableSchema.cs
|
// TableSchema.cs
|
||||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
// 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
|
// https://github.com/gnh1201/welsonjs
|
||||||
//
|
//
|
||||||
using System;
|
using System;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user