public List <DatabaseObject> LoadMatchingObjects(string table, string index, List <ValueObject> indexValue, int limit) { if (!this.TableExists(table)) { throw new Exception($"Table '{table}' does not exist."); } var correctTable = this.CorrectTableCase(table); var output = new List <DatabaseObject>(); foreach (var file in Directory.GetFiles(Path.Combine(this.StorageLocation, correctTable), "*.tson", SearchOption.TopDirectoryOnly)) { if (output.Count() >= limit) { return(output); } var dbo = DatabaseObject.LoadFromString(File.ReadAllText(file)); dbo.Key = Path.GetFileNameWithoutExtension(file); if (!dbo.ContainsKey(index)) { continue; } var match = false; foreach (var value in indexValue) { switch (value.ValueType) { case Messages.ValueType.String: if (dbo[index] is string) { if (dbo[index] as string == value.String) { match = true; } } break; case Messages.ValueType.Int: if (dbo[index] is int) { if ((int)dbo[index] == value.Int) { match = true; } } break; case Messages.ValueType.UInt: if (dbo[index] is uint) { if ((uint)dbo[index] == value.UInt) { match = true; } } break; case Messages.ValueType.Long: if (dbo[index] is long) { if ((long)dbo[index] == value.Long) { match = true; } } break; case Messages.ValueType.Bool: if (dbo[index] is bool) { if ((bool)dbo[index] == value.Bool) { match = true; } } break; case Messages.ValueType.Float: if (dbo[index] is float) { if ((float)dbo[index] == value.Float) { match = true; } } break; case Messages.ValueType.Double: if (dbo[index] is double) { if ((double)dbo[index] == value.Double) { match = true; } } break; case Messages.ValueType.ByteArray: if (dbo[index] is byte[]) { if ((byte[])dbo[index] == value.ByteArray) { match = true; } } break; case Messages.ValueType.DateTime: if (dbo[index] is DateTime) { if (((DateTime)dbo[index]).ToUnixTime() == value.DateTime) { match = true; } } break; case Messages.ValueType.Array: case Messages.ValueType.Object: throw new NotImplementedException(); } } if (match) { output.Add(dbo); } output.Add(dbo); } return(output); }
public void CreateObject(string table, string key, DatabaseObject obj) { File.WriteAllText(Path.Combine(this.StorageLocation, table, key + ".tson"), TsonConvert.SerializeObject(DatabaseObjectExtensions.ToDictionary(obj.Properties), Formatting.Indented)); }
public DatabaseObject GetObject(uint index, DatabaseObject defaultValue) => GetObject(index.ToString(), defaultValue);
/// <summary> Add the given object to the array. </summary> public DatabaseArray Add(DatabaseObject value) => Set((uint)this.Properties.Count, value);
public DatabaseObject Set(string property, DatabaseObject value) => this.SetProperty(property, (object)value);