Example #1
0
        static Dictionary <PrimaryKey, string> GetStrings <T>(List <PrimaryKey> ids) where T : Entity
        {
            ICacheController cc = Schema.Current.CacheController(typeof(T));

            if (cc != null && cc.Enabled)
            {
                cc.Load();
                return(ids.ToDictionary(a => a, a => cc.TryGetToString(a)));
            }
            else
            {
                return(ids.GroupsOf(Schema.Current.Settings.MaxNumberOfParameters)
                       .SelectMany(gr =>
                                   Database.Query <T>().Where(e => gr.Contains(e.Id)).Select(a => KVP.Create(a.Id, a.ToString())))
                       .ToDictionary());
            }
        }
Example #2
0
        public void Deserialize_Load_Model(ICacheController cacheController)
        {
            var model = cacheController.Load <AbstractList>();

            ValidateModel(model);
        }
Example #3
0
        public void Deserialize_Load_Model(ICacheController cacheController)
        {
            var model = cacheController.Load <ModelWithReadOnly>();

            ValidateModel(model);
        }
Example #4
0
        public void Dispose()
        {
retry:
            if (requests != null)
            {
                while (requests.Count > 0)
                {
                    var group = requests.WithMax(a => a.Value.Count);

                    var dic             = group.Value;
                    ICacheController cc = Schema.Current.CacheController(group.Key);

                    if (cc != null && cc.Enabled)
                    {
                        cc.Load();

                        while (dic.Count > 0)
                        {
                            Entity ident = dic.Values.FirstEx();

                            cc.Complete(ident, this);

                            retrieved.Add(new IdentityTuple(ident), ident);
                            dic.Remove(ident.Id);
                        }
                    }
                    else
                    {
                        Database.RetrieveList(group.Key, dic.Keys.ToList());
                    }

                    if (dic.Count == 0)
                    {
                        requests.Remove(group.Key);
                    }
                }
            }

            if (liteRequests != null)
            {
                {
                    List <IdentityTuple> toRemove = null;
                    foreach (var item in liteRequests)
                    {
                        var entity = retrieved.TryGetC(item.Key);
                        if (entity != null)
                        {
                            var toStr = entity.ToString();

                            foreach (var lite in item.Value)
                            {
                                lite.SetToString(toStr);
                            }

                            if (toRemove == null)
                            {
                                toRemove = new List <IdentityTuple>();
                            }

                            toRemove.Add(item.Key);
                        }
                    }

                    if (toRemove != null)
                    {
                        liteRequests.RemoveRange(toRemove);
                    }
                }

                while (liteRequests.Count > 0)
                {
                    var group = liteRequests.GroupBy(a => a.Key.Type).FirstEx();

                    var dic = giGetStrings.GetInvoker(group.Key)(group.Select(a => a.Key.Id).ToList());

                    foreach (var item in group)
                    {
                        var toStr = dic.TryGetC(item.Key.Id) ?? ("[" + EngineMessage.EntityWithType0AndId1NotFound.NiceToString().FormatWith(item.Key.Type.NiceName(), item.Key.Id) + "]");
                        foreach (var lite in item.Value)
                        {
                            lite.SetToString(toStr);
                        }
                    }

                    liteRequests.RemoveRange(group.Select(a => a.Key));
                }
            }

            foreach (var entity in retrieved.Values)
            {
                entity.PostRetrieving();
                Schema.Current.OnRetrieved(entity);
                entityCache.Add(entity);
            }

            foreach (var embedded in modifiablePostRetrieving)
            {
                embedded.PostRetrieving();
            }

            ModifiedState ms = ModifiedState;

            foreach (var entity in retrieved.Values)
            {
                entity.Modified = ms;
                entity.IsNew    = false;
            }

            foreach (var embedded in modifiablePostRetrieving)
            {
                embedded.Modified = ms;
            }

            if (liteRequests != null && liteRequests.Count > 0 ||
                requests != null && requests.Count > 0) // PostRetrieving could retrieve as well
            {
                retrieved.Clear();
                modifiablePostRetrieving.Clear();
                goto retry;
            }

            entityCache.ReleaseRetriever(this);
        }
Example #5
0
        public void Deserialize_Load_Model(ICacheController cacheController)
        {
            var model = cacheController.Load <Models.V2.ModelV2>();

            ValidateModel(model);
        }