Example #1
0
        internal void CheckDeffered(Type type)
        {
            if (_defferedObjects.IsValueCreated && _defferedObjects.Value.Collection.ContainsKey(type))
            {
                List <ItemBase> items = null;
                lock (_defferedObjects.Value.SyncRoot)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        try
                        {
                            var newCollection = new ConcurrentDictionary <ItemBase, int>();
                            ConcurrentDictionary <ItemBase, int> oldCollection = null;

                            _defferedObjects.Value.Collection.AddOrUpdate(type, newCollection, (key, old) =>
                            {
                                oldCollection = old;
                                return(newCollection);
                            });

                            if (oldCollection != null)
                            {
                                items = oldCollection.Keys.ToList();
                                oldCollection.Clear();
                            }
                            break;
                        }
                        catch
                        {
                            if (i == 2)
                            {
                                throw;
                            }
                        }
                    }
                }

                var IdItemType = ItemTypeAttribute.GetValueFromType(type);

                int             start    = 0;
                List <ItemBase> subItems = null;

                do
                {
                    subItems = items.Skip(start).Take(500).ToList();
                    start   += 500;
                    if (subItems.Count() > 0)
                    {
                        GetForQuery(IdItemType, type, subItems);
                    }
                    else
                    {
                        break;
                    }
                } while (subItems.Count() > 0);
            }
        }
Example #2
0
        internal void CheckDeffered(Type type)
        {
            if (_defferedObjects.IsValueCreated && _defferedObjects.Value.Collection.ContainsKey(type))
            {
                Dictionary <ItemBase, int> items = null;
                lock (_defferedObjects.Value.SyncRoot)
                {
                    for (int i = 0; i < 3; i++)
                    {
                        try
                        {
                            var newCollection = new ConcurrentDictionary <ItemBase, int>();
                            ConcurrentDictionary <ItemBase, int> oldCollection = null;

                            _defferedObjects.Value.Collection.AddOrUpdate(type, newCollection, (key, old) =>
                            {
                                oldCollection = old;
                                return(newCollection);
                            });

                            if (oldCollection != null)
                            {
                                items = oldCollection.ToDictionary(x => x.Key, x => x.Value);
                                oldCollection.Clear();
                            }
                            break;
                        }
                        catch
                        {
                            if (i == 2)
                            {
                                throw;
                            }
                        }
                    }
                }

                var IdItemType   = ItemTypeAttribute.GetValueFromType(type);
                var dataForItems = GetForQuery(IdItemType, type, items.Keys);
                try
                {
                    if (dataForItems != null)
                    {
                        foreach (var p in dataForItems)
                        {
                            p.Key._routingUrlMain           = p.Value?.Item1;
                            p.Key._routingUrlMainSourceType = p.Value?.Item2 ?? UrlSourceType.None;
                        }
                    }
                }
                finally { if (dataForItems != null)
                          {
                              dataForItems.Clear();
                          }
                }
            }
        }