Skip to content

Commit

Permalink
Database, remove attributes with NULL
Browse files Browse the repository at this point in the history
  • Loading branch information
veniware committed Jul 6, 2024
1 parent ec05e42 commit 0341f2f
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 31 deletions.
7 changes: 6 additions & 1 deletion Protest/Database/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public bool Save(string file, ConcurrentDictionary<string, Attribute> modificati
//if password is empty-string, keep old value
foreach (KeyValuePair<string, Attribute> pair in modifications) {
if (pair.Key.Contains("password", StringComparison.OrdinalIgnoreCase)
&& String.IsNullOrEmpty(pair.Value.value)
&& pair.Value.value?.Length == 0
&& oldEntry.attributes.TryGetValue(pair.Key, out Attribute oldPassword)) {
modifications[pair.Key] = oldPassword;
}
Expand Down Expand Up @@ -218,6 +218,11 @@ public bool Save(string file, ConcurrentDictionary<string, Attribute> modificati
_ => null
};

string[] attributesWithNull = newEntry.attributes.Where(attr => attr.Value.value is null).Select(attr => attr.Key).ToArray();
foreach (string key in attributesWithNull) {
newEntry.attributes.TryRemove(key, out _);
}

if (newEntry is null) return true;

dictionary.TryAdd(file, newEntry);
Expand Down
4 changes: 2 additions & 2 deletions Protest/Database/GridDataConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public GridDataConverter(string origin) {
}

string file = reader.GetString();
reader.Read(); // Move to the inner object's start
reader.Read();

ConcurrentDictionary<string, Database.Attribute> mod = new ConcurrentDictionary<string, Database.Attribute>();
while (reader.Read()) {
Expand All @@ -42,7 +42,7 @@ public GridDataConverter(string origin) {
}

string key = reader.GetString();
reader.Read(); // Move to the attribute's value
reader.Read();

Database.Attribute attribute = new Database.Attribute {
value = reader.GetString(),
Expand Down
4 changes: 3 additions & 1 deletion Protest/Front/grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,8 +564,10 @@ class Grid extends Window {
let id = element.getAttribute("id");
if (!id) continue;

if (!this.data[id][this.selectedColumn]) continue;

if (!(id in this.mods)) this.mods[id] = {};
this.mods[id][this.selectedColumn] = "";
this.mods[id][this.selectedColumn] = null;
}

this.UpdateTable();
Expand Down
46 changes: 23 additions & 23 deletions Protest/Front/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const UI = {
taskbarPosition: "bottom",

Initialize: ()=> {
for (let i = 0; i < 12; i++) { //clock dots
for (let i=0; i<12; i++) { //clock dots
const newDot = document.createElementNS("http://www.w3.org/2000/svg", "circle");
newDot.setAttribute("r", i % 3 == 0 ? 2.5 : 1.5);
newDot.setAttribute("cx", 48 + Math.sin(i * 30 / 57.29577951) * 36);
Expand Down Expand Up @@ -239,37 +239,37 @@ const UI = {
SizeToString: size=> {
if (size < 8_192) return `${size} bytes`;
if (size < 8_192 * 1024) return `${(size / 1024).toFixed(2)} KB`;
if (size < 8_192 * Math.pow(1024,2)) return `${(size / Math.pow(1024,2)).toFixed(2)}MB`;
if (size < 8_192 * Math.pow(1024,3)) return `${(size / Math.pow(1024,3)).toFixed(2)}GB`;
if (size < 8_192 * Math.pow(1024,4)) return `${(size / Math.pow(1024,4)).toFixed(2)}TB`;
if (size < 8_192 * Math.pow(1024,5)) return `${(size / Math.pow(1024,5)).toFixed(2)}EB`;
if (size < 8_192 * Math.pow(1024,6)) return `${(size / Math.pow(1024,6)).toFixed(2)}ZB`;
if (size < 8_192 * Math.pow(1024,7)) return `${(size / Math.pow(1024,7)).toFixed(2)}YB`;
if (size < 8_192 * Math.pow(1024,8)) return `${(size / Math.pow(1024,8)).toFixed(2)}BB`;
if (size < 8_192 * Math.pow(1024,2)) return `${(size / Math.pow(1024,2)).toFixed(2)} MB`;
if (size < 8_192 * Math.pow(1024,3)) return `${(size / Math.pow(1024,3)).toFixed(2)} GB`;
if (size < 8_192 * Math.pow(1024,4)) return `${(size / Math.pow(1024,4)).toFixed(2)} TB`;
if (size < 8_192 * Math.pow(1024,5)) return `${(size / Math.pow(1024,5)).toFixed(2)} EB`;
if (size < 8_192 * Math.pow(1024,6)) return `${(size / Math.pow(1024,6)).toFixed(2)} ZB`;
if (size < 8_192 * Math.pow(1024,7)) return `${(size / Math.pow(1024,7)).toFixed(2)} YB`;
if (size < 8_192 * Math.pow(1024,8)) return `${(size / Math.pow(1024,8)).toFixed(2)} BB`;
},

BytesPerSecToString: bps=> {
if (bps < 8_192) return `${bps} Bps`;
if (bps < 8_192 * 1024) return `${(bps / 1024).toFixed(2)} KBps`;
if (bps < 8_192 * Math.pow(1024,2)) return `${(bps / Math.pow(1024,2)).toFixed(2)}MBps`;
if (bps < 8_192 * Math.pow(1024,3)) return `${(bps / Math.pow(1024,3)).toFixed(2)}GBps`;
if (bps < 8_192 * Math.pow(1024,4)) return `${(bps / Math.pow(1024,4)).toFixed(2)}TBps`;
if (bps < 8_192 * Math.pow(1024,5)) return `${(bps / Math.pow(1024,5)).toFixed(2)}EBps`;
if (bps < 8_192 * Math.pow(1024,6)) return `${(bps / Math.pow(1024,6)).toFixed(2)}ZBps`;
if (bps < 8_192 * Math.pow(1024,7)) return `${(bps / Math.pow(1024,7)).toFixed(2)}YBps`;
if (bps < 8_192 * Math.pow(1024,8)) return `${(bps / Math.pow(1024,8)).toFixed(2)}BBps`;
if (bps < 8_192 * Math.pow(1024,2)) return `${(bps / Math.pow(1024,2)).toFixed(2)} MBps`;
if (bps < 8_192 * Math.pow(1024,3)) return `${(bps / Math.pow(1024,3)).toFixed(2)} GBps`;
if (bps < 8_192 * Math.pow(1024,4)) return `${(bps / Math.pow(1024,4)).toFixed(2)} TBps`;
if (bps < 8_192 * Math.pow(1024,5)) return `${(bps / Math.pow(1024,5)).toFixed(2)} EBps`;
if (bps < 8_192 * Math.pow(1024,6)) return `${(bps / Math.pow(1024,6)).toFixed(2)} ZBps`;
if (bps < 8_192 * Math.pow(1024,7)) return `${(bps / Math.pow(1024,7)).toFixed(2)} YBps`;
if (bps < 8_192 * Math.pow(1024,8)) return `${(bps / Math.pow(1024,8)).toFixed(2)} BBps`;
},

BitsPerSecToString: bps=> {
if (bps < 8_000) return `${bps} bps`;
if (bps < 8_000 * 1000) return `${Math.floor(bps / 1000)} Kbps`;
if (bps < 8_000 * Math.pow(1000,2)) return `${(bps / Math.pow(1000,2)).toFixed(2)}Mbps`;
if (bps < 8_000 * Math.pow(1000,3)) return `${(bps / Math.pow(1000,3)).toFixed(2)}Gbps`;
if (bps < 8_000 * Math.pow(1000,4)) return `${(bps / Math.pow(1000,4)).toFixed(2)}Tbps`;
if (bps < 8_000 * Math.pow(1000,5)) return `${(bps / Math.pow(1000,5)).toFixed(2)}Ebps`;
if (bps < 8_000 * Math.pow(1000,6)) return `${(bps / Math.pow(1000,6)).toFixed(2)}Zbps`;
if (bps < 8_000 * Math.pow(1000,7)) return `${(bps / Math.pow(1000,7)).toFixed(2)}Ybps`;
if (bps < 8_000 * Math.pow(1000,8)) return `${(bps / Math.pow(1000,8)).toFixed(2)}Bbps`;
if (bps < 8_000 * Math.pow(1000,2)) return `${(bps / Math.pow(1000,2)).toFixed(2)} Mbps`;
if (bps < 8_000 * Math.pow(1000,3)) return `${(bps / Math.pow(1000,3)).toFixed(2)} Gbps`;
if (bps < 8_000 * Math.pow(1000,4)) return `${(bps / Math.pow(1000,4)).toFixed(2)} Tbps`;
if (bps < 8_000 * Math.pow(1000,5)) return `${(bps / Math.pow(1000,5)).toFixed(2)} Ebps`;
if (bps < 8_000 * Math.pow(1000,6)) return `${(bps / Math.pow(1000,6)).toFixed(2)} Zbps`;
if (bps < 8_000 * Math.pow(1000,7)) return `${(bps / Math.pow(1000,7)).toFixed(2)} Ybps`;
if (bps < 8_000 * Math.pow(1000,8)) return `${(bps / Math.pow(1000,8)).toFixed(2)} Bbps`;
},

GenerateUuid: prefix=> {
Expand Down Expand Up @@ -301,7 +301,7 @@ const MENU = {

{ t:"Watchdog", i:"mono/watchdog.svg?light", g:"tools", h:false, f:()=> new Watchdog(), k:"" },
{ t:"Gandalf", i:"mono/gandalf.svg?light", g:"tools", h:false, f:()=> new Gandalf() },
{ t:"Issues", i:"mono/issues.svg?light", g:"tools", h:false, f:()=> new Issues() },
//{ t:"Issues", i:"mono/issues.svg?light", g:"tools", h:false, f:()=> new Issues() },
{ t:"WMI client", i:"mono/wmi.svg?light", g:"tools", h:false, f:args=> new Wmi(args), k:"windows management instrumentation viewer" },
{ t:"SNMP polling", i:"mono/snmp.svg?light", g:"tools", h:false, f:args=> new Snmp(args) },
//{ t:"SNMP traps", i:"mono/trap.svg?light", g:"tools", h:false, f:args=> new Snmp(args) },
Expand Down
7 changes: 3 additions & 4 deletions Protest/Tasks/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,9 @@ public static byte[] SingleDeviceSerialize(Dictionary<string, string> parameters
if (snmp is not null && Guid.TryParse(snmp, out Guid guid)) {
SnmpProfiles.Profile[] profiles = SnmpProfiles.Load();
for (int i = 0; i < profiles.Length; i++) {
if (profiles[i].guid == guid) {
snmpProfile = profiles[i];
break;
}
if (profiles[i].guid != guid) { continue; }
snmpProfile = profiles[i];
break;
}
}

Expand Down

0 comments on commit 0341f2f

Please sign in to comment.