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(); } } } }
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); } }
private void InitializeItemCtors() { foreach (System.Type current in from x in System.Reflection.Assembly.GetExecutingAssembly().GetTypes() where typeof(BasePlayerItem).IsAssignableFrom(x) select x) { ItemTypeAttribute customAttribute = current.GetCustomAttribute <ItemTypeAttribute>(); if (customAttribute != null) { if (this.m_itemCtorByTypes.ContainsKey(customAttribute.ItemType)) { ItemManager.logger.Error <ItemTypeEnum>("Item Constructor with Type {0} defined twice or more !", customAttribute.ItemType); continue; } this.m_itemCtorByTypes.Add(customAttribute.ItemType, current.GetConstructor(new System.Type[] { typeof(Character), typeof(PlayerItemRecord) }).CreateDelegate <ItemManager.PlayerItemConstructor>()); } ItemHasEffectAttribute customAttribute2 = current.GetCustomAttribute <ItemHasEffectAttribute>(); if (customAttribute2 != null) { if (this.m_itemCtorByEffects.ContainsKey(customAttribute2.Effect)) { ItemManager.logger.Error <EffectsEnum>("Item Constructor with Effect {0} defined twice or more !", customAttribute2.Effect); } else { this.m_itemCtorByEffects.Add(customAttribute2.Effect, current.GetConstructor(new System.Type[] { typeof(Character), typeof(PlayerItemRecord) }).CreateDelegate <ItemManager.PlayerItemConstructor>()); } } } }
private void CreateObject(object parentObject) { FieldInformationAttribute fieldValues = (FieldInformationAttribute)this.PropertyInfo.GetCustomAttribute(typeof(FieldInformationAttribute)); ItemTypeAttribute itemType = (ItemTypeAttribute)this.PropertyInfo.GetCustomAttribute(typeof(ItemTypeAttribute)); this.valuesSource = (ValuesSourceAttribute)this.PropertyInfo.GetCustomAttribute(typeof(ValuesSourceAttribute)); this.HasFieldInformation = true; if (fieldValues == null) { fieldValues = new FieldInformationAttribute(this.PropertyInfo.Name); this.HasFieldInformation = false; } this.ObjectType = itemType == null?ModelItemType.GetItemType(this.PropertyInfo.PropertyType) : itemType.ModelType; this.isComboBoxEdit = itemType == null ? false : itemType.IsComboboxEditable; this.Visibility = fieldValues.IsVisible ? Visibility.Visible : Visibility.Collapsed; this.EitherOrGroupName = fieldValues.EitherOrGroupName; this.IsRequired = fieldValues.IsRequired; this.isSpellCheck = !fieldValues.DisableSpellChecker; this.Caption = fieldValues.FieldCaption; this.Sort = fieldValues.Sort; this.FontWeight = FontWeights.Normal; this.CreateContent(parentObject, fieldValues); this.AddBrowsable(); }
public void AddItemConstructor(System.Type type) { ItemTypeAttribute customAttribute = type.GetCustomAttribute <ItemTypeAttribute>(); if (customAttribute == null) { ItemManager.logger.Error <System.Type>("Item Constructor {0} has no attribute !", type); } else { if (this.m_itemCtorByTypes.ContainsKey(customAttribute.ItemType)) { ItemManager.logger.Error <ItemTypeEnum>("Item Constructor with Type {0} defined twice or more !", customAttribute.ItemType); } else { this.m_itemCtorByTypes.Add(customAttribute.ItemType, type.GetConstructor(new System.Type[] { typeof(Character), typeof(PlayerItemRecord) }).CreateDelegate <ItemManager.PlayerItemConstructor>()); } } }