示例#1
0
        /// <summary>
        /// 加载单个Model,用于运行时或设计时重新加载
        /// </summary>
        internal static async ValueTask <ModelBase> LoadModelAsync(ulong modelId)
        {
            IntPtr keyPtr;

            unsafe
            {
                byte *pk = stackalloc byte[KeyUtil.MODEL_KEY_SIZE];
                KeyUtil.WriteModelKey(pk, modelId);
                keyPtr = new IntPtr(pk);
            }

            var res = await StoreApi.Api.ReadIndexByGetAsync(KeyUtil.META_RAFTGROUP_ID, keyPtr, KeyUtil.MODEL_KEY_SIZE);

            if (res == null)
            {
                return(null);
            }

            ModelBase model = null;

            try { model = (ModelBase)DeserializeModel(res.DataPtr, (int)res.Size); } //TODO: change to runtime mode
            catch (Exception) { throw; }
            finally { res.Dispose(); }

            model.AcceptChanges(); //TODO:同上
            return(model);
        }
 public void AddModelCache(ModelBase model)
 {
     model.AcceptChanges();
     models.TryAdd(model.Id, model);
 }