protected override bool Init() { var bCached = base.Init(); bInited = true; if (!IsMulti) { if (!bCached) { var filter = ADBAccessor.filter_eq(ParamNameDefs.CollectionID, ObjectId.Parse(id)); var res = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname) .FindOneData(cakeType , filter); if (res == null) { var ct = ApiDateTime.SecondsFromBegin(); ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname) .UpdateOneData(cakeType, filter , ADBAccessor.update(ParamNameDefs.CreateTime, ct), true); } else { foreach (var item in res.Names) { if (item == ParamNameDefs.CollectionID) { continue; } SetValue(item, res[item].ToString()); } } } return(bCached); } else if (string.IsNullOrEmpty(iid)) { if (!bCached) { var filter = ADBAccessor.filter_eq(ParamNameDefs.OwnerID, id); var res = ADBManager.Get(InitValueDefs.dbconnect, InitValueDefs.dbname) .FindManyData(cakeType, filter); foreach (var r in res) { var cid = r[ParamNameDefs.ContentID].ToString(); var cakes = new CakeServer(cakeType, id); var cake = cakes.GetSingleItem(cid); foreach (var item in r.Names) { if (item == ParamNameDefs.CollectionID) { continue; } cake.SetValue(item, r[item].ToString()); } subCakes.Add(cid, cake); } } } return(bCached); }
public CakeServer GetSingleItem(string iid) { if (!IsMulti) { throw new Exception($"{cakeType} is not multi!"); } if (subCakes.ContainsKey(iid)) { return(subCakes[iid] as CakeServer); } var cake = new CakeServer(cakeType, id); cake.iid = iid; cake.Init(); cake.SetValue(ParamNameDefs.ContentID, iid); return(cake); }