Пример #1
0
        public void RequestItem(ItemKey itemKey)
        {
            if (itemKey.TypeId == 0)
            {
                return;
            }
            if (!typesAccessed.ContainsKey(itemKey.TypeId))
            {
                // We need to make sure that the application is loaded
                if (itemKey.GetType(core).ApplicationId > 0)
                {
                    core.ItemCache.RegisterType(typeof(ApplicationEntry));

                    ItemKey applicationKey = new ItemKey(itemKey.GetType(core).ApplicationId, ItemType.GetTypeId(core, typeof(ApplicationEntry)));
                    core.ItemCache.RequestItem(applicationKey);

                    ApplicationEntry ae = (ApplicationEntry)core.ItemCache[applicationKey];

                    typesAccessed.Add(itemKey.TypeId, ae.Assembly.GetType(itemKey.GetType(core).TypeNamespace));
                }
                else
                {
                    try
                    {
                        typesAccessed.Add(itemKey.TypeId, Type.GetType(itemKey.GetType(core).TypeNamespace));
                    }
                    catch
                    {
                        HttpContext.Current.Response.Write(itemKey.ToString());
                        HttpContext.Current.Response.End();
                    }
                }
            }
            NumberedItemId loadedId = new NumberedItemId(itemKey.Id, itemKey.TypeId);
            if (!(batchedItemIds.Contains(loadedId) || itemsCached.ContainsKey(loadedId)))
            {
                batchedItemIds.Add(loadedId);
            }
        }
Пример #2
0
        private void loadItems(long typeId, List<NumberedItemId> itemIds)
        {
            List<long> itemId = new List<long>(20);

            foreach (NumberedItemId id in itemIds)
            {
                if (id.TypeId == typeId)
                {
                    itemId.Add(id.Id);
                }
            }

            Type typeToGet;

            typeToGet = typesAccessed[typeId];

            if (typeToGet != null)
            {
                SelectQuery query;

            #if DEBUG
                Stopwatch timer = new Stopwatch();
                timer.Start();
            #endif
                bool dataReader = false;

                ConstructorInfo[] constructors = typeToGet.GetConstructors();

                // temporary
                foreach (ConstructorInfo constructor in constructors)
                {
                    ParameterInfo[] parameters = constructor.GetParameters();
                    if (parameters.Length >= 2)
                    {
                        if (parameters[1].ParameterType == typeof(System.Data.Common.DbDataReader))
                        {
                            dataReader = true;
                            break;
                        }
                    }
                }
                // end temporary
            #if DEBUG
                timer.Stop();
                if (HttpContext.Current != null)
                {
                    //HttpContext.Current.Response.Write(string.Format("<!-- Constructor {1} found in {0} -->\r\n", timer.ElapsedTicks / 10000000.0, typeToGet.Name));
                }
            #endif

                if (typeToGet.GetMethod(typeToGet.Name + "_GetSelectQueryStub", new Type[] { typeof(Core) }) != null)
                {
                    query = (SelectQuery)typeToGet.InvokeMember(typeToGet.Name + "_GetSelectQueryStub", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] { core }); //GetSelectQueryStub(typeToGet);
                }
                else if (typeToGet.GetMethod(typeToGet.Name + "_GetSelectQueryStub", Type.EmptyTypes) != null)
                {
                    query = (SelectQuery)typeToGet.InvokeMember(typeToGet.Name + "_GetSelectQueryStub", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, null, new object[] { }); //GetSelectQueryStub(typeToGet);
                }
                else
                {
                    query = Item.GetSelectQueryStub(core, typeToGet);
                }

                query.AddCondition(Item.GetTable(typeToGet) + "." + Item.GetPrimaryKey(core, typeToGet), ConditionEquality.In, itemId);

                if (dataReader)
                {
                    System.Data.Common.DbDataReader reader = core.Db.ReaderQuery(query);

                    while (reader.Read())
                    {
                        // this may seem counter intuitive, but the items self-cache through the RegisterItem(NumberedItem) method
                        NumberedItem item = Activator.CreateInstance(typeToGet, new object[] { core, reader }) as NumberedItem;

                        NumberedItemId loadedId = new NumberedItemId(item.Id, ItemType.GetTypeId(core, typeToGet));
                        batchedItemIds.Remove(loadedId);
                    }

                    reader.Close();
                    reader.Dispose();
                }
                else
                {
                    DataTable itemsTable = db.Query(query);

                    foreach (DataRow dr in itemsTable.Rows)
                    {
                        // this may seem counter intuitive, but the items self-cache through the RegisterItem(NumberedItem) method
                        NumberedItem item = Activator.CreateInstance(typeToGet, new object[] { core, dr }) as NumberedItem;

                        NumberedItemId loadedId = new NumberedItemId(item.Id, ItemType.GetTypeId(core, typeToGet));
                        batchedItemIds.Remove(loadedId);
                    }
                }

                if (itemsPersisted != null)
                {
                    core.Cache.SetCached("NumberedItems", itemsPersisted, new TimeSpan(1, 0, 0), CacheItemPriority.Default);
                }
            }
        }
Пример #3
0
        public void RegisterItem(NumberedItem item)
        {
            try
            {
                long id = item.Id;
            }
            catch (NotImplementedException)
            {
                // Cannot cache this item
            }
            NumberedItemId itemKey = new NumberedItemId(item.Id, item.ItemKey.TypeId);

            if (itemKey.TypeId == 0)
            {
                return;
            }
            if (!typesAccessed.ContainsKey(itemKey.TypeId))
            {
                typesAccessed.Add(itemKey.TypeId, item.GetType());
            }

            if (!(itemsCached.ContainsKey(itemKey)))
            {
                itemsCached.Add(itemKey, item);
            }

            /*Type typeToGet;

            typeToGet = typesAccessed[itemKey.TypeId];

            if (typeToGet != null && itemsPersisted != null && typeToGet.GetCustomAttributes(typeof(CacheableAttribute), false).Length > 0)
            {
                lock (itemsPersistedLock)
                {
                    if (!(itemsPersisted.ContainsKey(itemKey)))
                    {
                        itemsPersisted.Add(itemKey, item);
                    }
                }
            }*/
            batchedItemIds.Remove(itemKey);
        }