private void Run(Action <BenchmarkIteration, ObjectDB <IFlatbufferObject>, IFlatbufferObject> action, int dataIndex, int dataSize) { var data = InputData[dataIndex]; var factories = new List <Func <ByteBuffer, IFlatbufferObject> > { (bb) => Data_8b.GetRootAsData_8b(bb), (bb) => Data_128b.GetRootAsData_128b(bb), (bb) => Data_1KB.GetRootAsData_1KB(bb), (bb) => Data_1MB.GetRootAsData_1MB(bb), }; var nRecords = dataSize; var buffer = 100_000; using (var db = new ObjectDB <IFlatbufferObject>(FileStorageEngineFactory.Create("benchmark", SIZE_15GB, nRecords + buffer), new FlatBufferSerializer(factories))) { // set up data for (int i = 0; i < nRecords; i++) { db.Insert(data); if (i % 10000 == 0 && i > 0) { Console.WriteLine(i); } } // run benchmark foreach (BenchmarkIteration iter in Benchmark.Iterations) { action(iter, db, data); } } }
/// <summary> /// Internal method for adding a prefab to a specific ObjectDB. /// </summary> /// <param name="objectDB"><see cref="ObjectDB"/> the prefab should be added to</param> /// <param name="prefab"><see cref="GameObject"/> with an <see cref="ItemDrop"/> component to add</param> private void RegisterItemInObjectDB(ObjectDB objectDB, GameObject prefab) { var itemDrop = prefab.GetComponent <ItemDrop>(); if (itemDrop == null) { throw new Exception($"Prefab {prefab.name} has no ItemDrop component attached"); } var hash = prefab.name.GetStableHashCode(); if (objectDB.m_itemByHash.ContainsKey(hash)) { Logger.LogDebug($"Already added item {prefab.name}"); } else { if (!PrefabManager.Instance.Prefabs.ContainsKey(hash)) { PrefabManager.Instance.AddPrefab(prefab); } if (ZNetScene.instance != null && !ZNetScene.instance.m_namedPrefabs.ContainsKey(hash)) { PrefabManager.Instance.RegisterToZNetScene(prefab); } objectDB.m_items.Add(prefab); objectDB.m_itemByHash.Add(hash, prefab); } Logger.LogDebug($"Added item {prefab.name} | Token: {itemDrop.TokenName()}"); }
public static List <ItemDrop.ItemData> GetSetPieces(this ObjectDB objectDB, string setName) { List <ItemDrop.ItemData> list = new List <ItemDrop.ItemData>(); foreach (var itemPrefab in objectDB.m_items) { if (itemPrefab == null) { EpicLoot.LogError("Null Item left in ObjectDB! (This means that a prefab was deleted and not an instance)"); continue; } var itemDrop = itemPrefab.GetComponent <ItemDrop>(); if (itemDrop == null) { EpicLoot.LogError($"Item in ObjectDB missing ItemDrop: ({itemPrefab.name})"); continue; } if (itemDrop.m_itemData.m_shared.m_setName == setName) { list.Add(itemPrefab.GetComponent <ItemDrop>().m_itemData); } } return(list); }
/// <summary> /// Safely invoke the <see cref="OnItemsRegistered"/> event /// </summary> /// <param name="self"></param> private void InvokeOnItemsRegistered(ObjectDB self) { if (SceneManager.GetActiveScene().name == "main") { OnItemsRegistered?.SafeInvoke(); } }
public BenchmarkRelationPartialView() { _fc = new InMemoryFileCollection(); var lowDb = new KeyValueDB(_fc); _db = new ObjectDB(); _db.Open(lowDb, true); using var tr = _db.StartTransaction(); var table = tr.GetRelation <IPersonTable>(); for (var i = 0; i < 10000; i++) { var p = new Person { ParentId = 1, PersonId = i, Age = (ulong)(i / 128), Name = "Lorem ipsum " + i, Children = Enumerable.Range(0, 100).Select(j => new Person { ParentId = i, PersonId = i * 100 + j, Name = "Lorem ipsum child " + j, Age = (ulong)j }).ToList() }; table.Upsert(p); } tr.Commit(); _tr = _db.StartReadOnlyTransaction(); _table = _tr.GetRelation <IPersonTable>(); }
static string DumpRelationContent(string dbDir, string relationName, ulong?openUpToCommitUlong) { using var dfc = new OnDiskFileCollection(dbDir); using var kdb = new KeyValueDB(new KeyValueDBOptions { FileCollection = dfc, ReadOnly = true, OpenUpToCommitUlong = openUpToCommitUlong }); using var odb = new ObjectDB(); odb.Open(kdb, false); using var trkv = kdb.StartReadOnlyTransaction(); using var tr = odb.StartTransaction(); var visitor = new ToStringFastVisitor(); var iterator = new ODBIterator(tr, visitor); iterator.LoadGlobalInfo(); var relationIdInfo = iterator.RelationId2Info.FirstOrDefault(kvp => kvp.Value.Name.EndsWith(relationName)); if (relationIdInfo.Value == null) { return(""); } iterator.IterateRelation(relationIdInfo.Value); return(visitor.ToString()); }
static void ModifyItemStackSizeAndWeight(ObjectDB __instance) { bool stackSizeEnabled = stackSizeEnabledConfig.Value; float stackSizeMultiplier = Mathf.Clamp(stackSizeMultiplierConfig.Value, 0, int.MaxValue); bool weightEnabled = weightEnabledConfig.Value; float weightMultiplier = Mathf.Clamp(weightMultiplierConfig.Value, 0, int.MaxValue); if (!(stackSizeEnabled || weightEnabled)) { return; } foreach (ItemDrop.ItemData.ItemType type in (ItemDrop.ItemData.ItemType[])Enum.GetValues(typeof(ItemDrop.ItemData.ItemType))) { foreach (ItemDrop item in __instance.GetAllItems(type, "")) { if (item.m_itemData.m_shared.m_name.StartsWith("$item_")) { ItemTracker tracker = GetItemTracker(item); if (stackSizeEnabled && (tracker.OriginalStackSize > 1)) { tracker.SetStackSize(stackSizeMultiplier, item); } if (weightEnabled) { tracker.SetWeight(weightMultiplier, item); } } } } }
protected override void Awake() { base.Awake(); SetupConfig(); if (enableLogging != null && enableLogging.Value) { harmonyInst.PatchAll(typeof(DebugStaminaPatches)); } harmonyInst.PatchAll(typeof(GeneralStaminaPatches)); harmonyInst.PatchAll(typeof(ToolsPatches)); harmonyInst.PatchAll(typeof(SkillPatches)); harmonyInst.PatchAll(typeof(StatusEffectPatches)); #if DEBUG // This is to refresh the values on reloading the mod with F6 ObjectDB objectDB = BepInExHelpers.FindObjectDB(); if (objectDB != null) { StatusEffectPatches.UpdateEffects(objectDB); } #endif }
// Token: 0x06000B2C RID: 2860 RVA: 0x00050756 File Offset: 0x0004E956 public void CopyOtherDB(ObjectDB other) { this.m_items = other.m_items; this.m_recipes = other.m_recipes; this.m_StatusEffects = other.m_StatusEffects; this.UpdateItemHashes(); }
IObjectDB CreateObjectDB() { var odb = new ObjectDB(); odb.Open(_kvdb, false); return(odb); }
/// <summary> /// 根据 id 删除对象 /// </summary> /// <param name="t"></param> /// <param name="objId">对象 id</param> /// <returns>返回受影响的行数</returns> public static int delete(Type t, long objId) { int num = ObjectDB.Delete(t, objId); ObjectPool.Delete(t, objId); return(num); }
void Awake() { if (core == null) { core = this; } }
/// <summary> /// 根据查询条件、每页数量,返回分页数据集合 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">查询条件</param> /// <param name="pageSize">每页需要显示的数据量</param> /// <returns>分页数据列表,包括当前页、总记录数、分页条等</returns> public static DataPage <T> findPage <T>(String condition, int pageSize) where T : IEntity { if (pageSize <= 0) { pageSize = 20; } ObjectInfo state = new ObjectInfo(typeof(T)); state.includeAll(); state.Pager.setSize(pageSize); IPageList result = ObjectPool.FindPage(typeof(T), condition, state.Pager); if (result == null) { IList list = ObjectDB.FindPage(state, condition); PageHelper p = state.Pager; ObjectPool.AddPage(typeof(T), condition, p, list); result = new DataPageInfo(); result.Results = list; result.PageCount = p.PageCount; result.RecordCount = p.RecordCount; result.Size = p.getSize(); result.PageBar = p.PageBar; result.Current = p.getCurrent(); } else { result.PageBar = new PageHelper(result.RecordCount, result.Size, result.Current).PageBar; } return(new DataPage <T>(result)); }
private static IList findAllFromChild(IList parents, ObjectInfo state) { ArrayList results = new ArrayList(); foreach (EntityInfo info in state.EntityInfo.ChildEntityList) { ObjectInfo childState = new ObjectInfo(info); childState.includeAll(); IList children = ObjectDB.FindAll(childState); for (int i = 0; i < children.Count; i++) { IEntity child = children[i] as IEntity; // state //child.state.Order = state.Order; results.Add(child); parents.RemoveAt(Query.getIndexOfObject(parents, child)); } } if (parents.Count > 0) { results.AddRange(parents); } results.Sort(); return(results); }
public static String GetSameTypeIds(Type throughType, Type t, int id) { // 1029 ObjectInfo state = new ObjectInfo(throughType); String relationPropertyName = state.EntityInfo.GetRelationPropertyName(t); EntityPropertyInfo info = state.EntityInfo.FindRelationProperty(t); String ids = ObjectDB.Find(state, relationPropertyName + ".Id=" + id).get(info.Name + ".Id"); EntityPropertyInfo property = state.EntityInfo.GetProperty(relationPropertyName); String sql = String.Format("select distinct {0} from {1} where {2} in ({3}) and {0}<>{4}", property.ColumnName, state.EntityInfo.TableName, info.ColumnName, ids, id); IDbCommand command = DataFactory.GetCommand(sql, DbContext.getConnection(state.EntityInfo)); IDataReader rd = null; StringBuilder builder = new StringBuilder(); try { rd = command.ExecuteReader(); while (rd.Read()) { builder.Append(rd[0]); builder.Append(","); } } catch (Exception exception) { logger.Error(exception.Message); throw new OrmException(exception.Message, exception); } finally { OrmHelper.CloseDataReader(rd); } return(builder.ToString().TrimEnd(',')); }
/// <summary> /// 根据查询条件,返回一个查询对象。一般用于参数化查询。 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="condition">查询条件</param> /// <returns>返回查询对象xQuery,可以进一步参数化赋值,并得到结果</returns> public static xQuery <T> find <T>(String condition) where T : IEntity { ObjectInfo state = new ObjectInfo(typeof(T)); Query q = ObjectDB.Find(state, condition); return(new xQuery <T>(q)); }
private static void AddCustomRecipes(this ObjectDB self) { foreach (var customRecipe in CustomRecipes) { var recipe = customRecipe.Recipe; if (customRecipe.FixReference) { recipe.FixReferences(); customRecipe.FixReference = false; } if (customRecipe.FixRequirementReferences) { foreach (var requirement in recipe.m_resources) { requirement.FixReferences(); } customRecipe.FixRequirementReferences = false; } self.m_recipes.Add(recipe); Log.LogInfo($"Added recipe for : {recipe.m_item.TokenName()}"); } }
private void RegisterCustomRecipes(ObjectDB objectDB) { Logger.LogInfo($"---- Adding custom recipes to {objectDB} ----"); foreach (var customRecipe in Recipes) { try { var recipe = customRecipe.Recipe; if (customRecipe.FixReference) { recipe.FixReferences(); customRecipe.FixReference = false; } if (customRecipe.FixRequirementReferences) { foreach (var requirement in recipe.m_resources) { requirement.FixReferences(); } customRecipe.FixRequirementReferences = false; } objectDB.m_recipes.Add(recipe); Logger.LogInfo($"Added recipe for {recipe.m_item.TokenName()}"); } catch (Exception ex) { Logger.LogError($"Error while adding recipe {customRecipe}: {ex}"); } } }
private void RegisterCustomStatusEffects(ObjectDB objectDB) { Logger.LogInfo($"---- Adding custom status effects to {objectDB} ----"); foreach (var customStatusEffect in StatusEffects) { try { var statusEffect = customStatusEffect.StatusEffect; if (customStatusEffect.FixReference) { statusEffect.FixReferences(); customStatusEffect.FixReference = false; } objectDB.m_StatusEffects.Add(statusEffect); Logger.LogInfo($"Added status effect {customStatusEffect}"); } catch (Exception ex) { Logger.LogError($"Error while adding status effect {customStatusEffect}: {ex}"); } } }
void CreateBtdbTestInserts(int count) { var sw = Stopwatch.StartNew(); var rnd = new Random(1234); using var fileCollection = CreateTestFileCollection(); using var db = CreateKeyValueDB(fileCollection); using var odb = new ObjectDB(); odb.Open(db, false); Func <IObjectDBTransaction, IBtdbTestTable> table; using (var tr = odb.StartTransaction()) { table = tr.InitRelation <IBtdbTestTable>("BtdbTest"); tr.Commit(); } for (var i = 0; i < count; i++) { using var tr = odb.StartTransaction(); var tbl = table(tr); tbl.Upsert(new BtdbTest { CompanyId = 123456, TestId = (ulong)i, TestName = "test name " + i, Data1 = "data1 " + i, Data2 = "data2 " + i, Data3 = "data3 " + i }); tr.Commit(); } Console.WriteLine("CreateBtdbTestInserts:" + sw.Elapsed.TotalMilliseconds + " Mem kb:" + Process.GetCurrentProcess().WorkingSet64 / 1024); }
/* * /// <summary> * /// Adds item conversions defined in a JSON file at given path, relative to BepInEx/plugins * /// </summary> * /// <param name="path">JSON file path, relative to BepInEx/plugins folder</param> * public void AddItemConversionsFromJson(string path) * { * string json = AssetUtils.LoadText(path); * * if (string.IsNullOrEmpty(json)) * { * Logger.LogError($"Failed to load item conversions from invalid JSON: {path}"); * return; * } * * List<CustomItemConversion> configs = CustomItemConversion.ListFromJson(json); * * foreach (var config in configs) * { * AddItemConversion(config); * } * }*/ private void RegisterCustomItems(ObjectDB objectDB) { Logger.LogInfo($"---- Adding custom items to {objectDB} ----"); foreach (var customItem in Items) { try { var itemDrop = customItem.ItemDrop; if (customItem.FixReference) { customItem.ItemPrefab.FixReferences(); itemDrop.m_itemData.m_shared.FixReferences(); customItem.FixReference = false; } if (!itemDrop.m_itemData.m_dropPrefab) { itemDrop.m_itemData.m_dropPrefab = customItem.ItemPrefab; } objectDB.m_items.Add(customItem.ItemPrefab); Logger.LogInfo($"Added item {customItem} | Token: {customItem.ItemDrop.TokenName()}"); } catch (Exception ex) { Logger.LogError($"Error while adding item {customItem}: {ex}"); } } Logger.LogInfo("Updating item hashes"); objectDB.UpdateItemHashes(); }
private static void UpdateEffects(ObjectDB __instance) { foreach (StatusEffect se in __instance.m_StatusEffects) { UpdateStatusEffect(se); } }
/// <summary> /// 根据 id 删除数据 /// </summary> /// <typeparam name="T"></typeparam> /// <param name="id">对象的 id</param> /// <returns>返回受影响的行数</returns> public static int delete <T>(int id) where T : IEntity { int num = ObjectDB.Delete(typeof(T), id); ObjectPool.Delete(typeof(T), id); return(num); }
public static List <ItemDrop.ItemData> GetSetPieces(this ObjectDB objectDB, string setName) { return(objectDB.m_items .Where(x => x.GetComponent <ItemDrop>().m_itemData.m_shared.m_setName == setName) .Select(x => x.GetComponent <ItemDrop>().m_itemData) .ToList()); }
static ObjectDB CreateDb(IFileCollection fc) { var lowDb = new KeyValueDB(fc); var db = new ObjectDB(); db.Open(lowDb, true); return(db); }
public RelationPersonTest(ObjectDB db, int count) { _count = count; _db = db; using var tr = _db.StartTransaction(); _creator = tr.InitRelation <IPersonTable>("Job"); tr.Commit(); }
static ObjectDB CreateInMemoryDb() { var lowDb = new InMemoryKeyValueDB(); var db = new ObjectDB(); db.Open(lowDb, true); return(db); }
private void TryRegisterItems(ObjectDB instance, bool createRecipes) { Logger.LogMessage($"Registering custom items in ObjectDB {instance}"); Instance.InitCraftingStations(instance); // Go through all registered Items and try to obtain references // to the actual objects defined as strings in ItemDef foreach (var entry in RegisteredItems) { Logger.LogDebug($"GameObject: {entry.Key.name}"); var prefab = entry.Key; var itemDef = entry.Value; // Add the item prefab to the ObjectDB if not already in there var itemDrop = prefab.GetComponent <ItemDrop>(); if (itemDrop == null) { Logger.LogError($"GameObject {prefab.name} has no ItemDrop attached"); continue; } if (instance.m_itemByHash.ContainsKey(prefab.name.GetStableHashCode())) { Logger.LogWarning("Item already added to ObjectDB"); continue; } itemDrop.m_itemData.m_dropPrefab = prefab; instance.m_items.Add(prefab); Logger.LogInfo($"Registered item {prefab.name}"); if (createRecipes) { // Create the Recipe for this item, defined in ItemDef var recipe = CreateRecipe(instance, prefab, itemDef); // Add the Recipe to the ObjectDB, remove one with the same name first var removed = instance.m_recipes.RemoveAll(x => x.name == recipe.name); if (removed > 0) { Logger.LogDebug($"Removed recipes ({recipe.name}): {removed}"); } instance.m_recipes.Add(recipe); Logger.LogInfo($"Added recipe: {recipe.name}"); } } // If we registered items, update their hashes if (instance.m_items.Count() > instance.m_itemByHash.Count()) { Logger.LogInfo("Updating item hashes"); instance.UpdateItemHashes(); } }
/// <summary> /// /// </summary> /// <param name="objectDB"></param> /// <param name="list"></param> /// <param name="dbPath"></param> /// <returns></returns> private string GenerateClass(ObjectDB objectDB, DataTable list, string dbPath = "") { string fileStr = FileManager.ReadFile(FileManager.GetAppPath + "/Template/TemplateClass.cs"); StringBuilder tmpProperties = new StringBuilder(); StringBuilder tmpRelations = new StringBuilder(); StringBuilder tmpConstructRelations = new StringBuilder(); // Properties TableColumns tableColumns = null; foreach (DataRow row in list.Rows) { tmpProperties.Append("\r\n"); tableColumns = new TableColumns(row); tmpProperties.Append(string.Format(@" public {0}{4} {1} {2} get; set; {3}", GetNetType(tableColumns.type), UppercaseFirst(tableColumns.columnName), "{", "}", tableColumns.isNullable ? "?" : "")); } FkTable[] fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.Direct, dbPath); // Related Properties. foreach (FkTable item in fkList) { tmpRelations.Append("\r\n"); tmpRelations.Append(string.Format(@" public {0} {3} {1} get; set; {2}", item.pkTableName, "{", "}", RemoveLast_S(item.pkTableName))); } // Get Indirect Relationships fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.Indirect, dbPath); foreach (FkTable item in fkList) { tmpRelations.Append("\r\n"); tmpRelations.Append(string.Format(" public virtual IList<{0}> {0} {1} get; set; {2}\r\n", item.fkTableName, "{", "}")); tmpConstructRelations.Append(string.Format(" {0} = new List<{0}>();\r\n", item.fkTableName, "{", "}")); } // Many to Many - Tables related fkList = GetFkRelationShips(objectDB.object_id, TypeSearchRelationship.ManyToMany, dbPath); foreach (FkTable item in fkList) { tmpRelations.Append(string.Format(" public virtual IList<{0}> {0} {1} get; set; {2}\r\n", item.pkTableName, "{", "}")); tmpConstructRelations.Append(string.Format(" {0} = new List<{0}>();\r\n", item.pkTableName, "{", "}")); } //---------------------------------------------------------------------------------------------- // Relationships fileStr = fileStr.Replace("{0}", txtNamespaceClasses.Text); // Namespace fileStr = fileStr.Replace("{1}", objectDB.name); // Class Name fileStr = fileStr.Replace("{2}", tmpProperties.ToString()); // Properties //GetPrimaryKey("",name) fileStr = fileStr.Replace("{3}", tmpRelations.ToString()); // Declaration Relaciones fileStr = fileStr.Replace("{4}", tmpConstructRelations.ToString()); // Inicializacion de las Relaciones return(fileStr); }
private void InvokeOnItemsRegistered(On.ObjectDB.orig_Awake orig, ObjectDB self) { orig(self); if (SceneManager.GetActiveScene().name == "main" && self.IsValid()) { OnItemsRegistered?.SafeInvoke(); } }