public void TypeEquality() { var entry1 = new ProxyCacheEntry(typeof(Entity1), null); var entry2 = new ProxyCacheEntry(typeof(Entity1), new System.Type[0]); Assert.IsTrue(entry1.Equals(entry2)); Assert.IsTrue(entry2.Equals(entry1)); }
public void InterfaceInequality() { var entry1 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(INHibernateProxy), typeof(ISerializable) }); var entry2 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(ISerializable) }); TweakEntry(entry2, entry1.GetHashCode()); Assert.IsFalse(entry1.Equals(entry2)); Assert.IsFalse(entry2.Equals(entry1)); }
public void InterfaceEqualityWithLotOfUnordererdAndDupInterfaces() { var entry1 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(INHibernateProxy), typeof(ISerializable), typeof(IType), typeof(IDisposable), typeof(IFilter) }); // Interfaces order inverted and duplicated on purpose: must be supported. var entry2 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(IType), typeof(ISerializable), typeof(IFilter), typeof(IDisposable), typeof(IType), typeof(IFilter), typeof(INHibernateProxy) }); Assert.IsTrue(entry1.Equals(entry2)); Assert.IsTrue(entry2.Equals(entry1)); }
public void InterfaceEquality() { var entry1 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(INHibernateProxy), typeof(ISerializable) }); // Interfaces order inverted on purpose: must be supported. var entry2 = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(ISerializable), typeof(INHibernateProxy) }); Assert.IsTrue(entry1.Equals(entry2)); Assert.IsTrue(entry2.Equals(entry1)); }
public void TypeInequality() { var entry1 = new ProxyCacheEntry(typeof(Entity1), null); var entry2 = new ProxyCacheEntry(typeof(Entity2), null); TweakEntry(entry2, entry1.GetHashCode()); Assert.IsFalse(entry1.Equals(entry2)); Assert.IsFalse(entry2.Equals(entry1)); }
public void ProxyCacheEntity1FakeProxy2() { var entry = new ProxyCacheEntry(typeof(Entity1), new[] { typeof(INHibernateProxy) }); TweakEntry(entry, _hashCode1); var result = _internalCache[entry]; Assert.AreEqual(typeof(Entity1FakeProxy2), result); }
public void ProxyCacheEntity2FakeProxy2() { var entry = new ProxyCacheEntry(typeof(Entity2), null); TweakEntry(entry, _hashCode2); var result = _internalCache[entry]; Assert.AreEqual(typeof(Entity2FakeProxy2), result); }
/// <summary> /// Stores a proxy type in the cache. /// </summary> /// <param name="result">The proxy type to be stored.</param> /// <param name="baseType">The base type of the dynamically-generated proxy type.</param> /// <param name="baseInterfaces">The list of interfaces that the generated proxy type must implement.</param> public void Store(Type result, Type baseType, params Type[] baseInterfaces) { var entry = new ProxyCacheEntry(baseType, baseInterfaces); lock (_cache) { _cache[entry] = result; } }
public void ProxyCacheEntity4FakeProxy2() { var entry = new ProxyCacheEntry(typeof(Entity4), new[] { typeof(ISerializable) }); TweakEntry(entry, _hashCode2); var result = _internalCache[entry]; Assert.AreEqual(typeof(Entity4FakeProxy2), result); }
public void ProxyCacheEntity5FakeProxy2() { // Interfaces order inverted on purpose: must be supported. var entry = new ProxyCacheEntry(typeof(Entity5), new[] { typeof(IProxy), typeof(INHibernateProxy) }); TweakEntry(entry, _hashCode2); var result = _internalCache[entry]; Assert.AreEqual(typeof(Entity5FakeProxy2), result); }
/// <summary> /// Allows to simulate a hashcode collision. Issue would be unpractical to test otherwise. /// Hashcode collision must be supported for avoiding unexpected and hard to reproduce failures. /// </summary> private void TweakEntry(ProxyCacheEntry entryToTweak, int hashcode) { // Though hashCode is a readonly field, this works at the time of this writing. If it starts breaking and cannot be fixed, // ignore those tests or throw them away. HashCodeField.SetValue(entryToTweak, hashcode); }
public SimcraftImpl() { //Write("go!"); try { dbc = Serializer.DeSerializeObject(FindDatabase()); } catch (Exception e) { Write(e.ToString()); } spell_data_t[] a = new spell_data_t[dbc.Spells.Values.Count]; dbc.Spells.Values.CopyTo(a, 0); foreach (var v in a) { dbc.Spells[v.id, v.token] = v; } Write("Count "+dbc.Spells.Count); Directory.CreateDirectory(SimcraftProfilePath); try { RoutineManager.Current = null; SimcNames.Populate(); MainCache = new ProxyCacheEntry(); inst = this; active_dot = new ActiveDot(); //trinket = new TrinketProxy(() => StyxWoW.Me.ToUnit(), this); health = new HealthProxy(() => StyxWoW.Me.ToUnit()); energy = new EnergyProxy(() => StyxWoW.Me.ToUnit()); focus = new FocusProxy(() => StyxWoW.Me.ToUnit()); chi = new ChiProxy(() => StyxWoW.Me.ToUnit()); rage = new RageProxy(() => StyxWoW.Me.ToUnit()); buff = new BuffProxy(() => StyxWoW.Me.ToUnit(), PlayerAuras); debuff = new DebuffProxy(() => conditionUnit); talent = new TalentProxy(() => StyxWoW.Me.ToUnit()); cooldown = new CooldownProxy(() => StyxWoW.Me.ToUnit()); spell = new SpellProxy(() => StyxWoW.Me.ToUnit()); combo_points = new ComboPointProxy(() => StyxWoW.Me.ToUnit()); target = new TargetProxy(() => conditionUnit); runic_power = new RunicPowerProxy(() => StyxWoW.Me.ToUnit()); disease = new DiseaseProxy(this); blood = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Blood); unholy = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Unholy); frost = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Frost); death = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Death); glyph = new GlyphProxy(() => StyxWoW.Me.ToUnit()); set_bonus = new SetBonusProxy(); prev_gcd = new PrevGcdProxy(); prev = new PrevGcdProxy(); pet = new PetProxy("def"); eclipse_energy = new EclipseProxy(() => StyxWoW.Me.ToUnit()); mana = new ManaProxy(() => StyxWoW.Me.ToUnit()); holy_power = new HolyPowerProxy(() => StyxWoW.Me.ToUnit()); seal = new SealProxy(); actions = new ActionProxy(); stat = new StatProxy(); obliterate = new ObliterateProxy(); MainCache["gcd"].SetRetrievalDelegate(() => { var rem = (Decimal)SpellManager.GlobalCooldownLeft.TotalSeconds; var g = BaseGcd(); g = g / ((100+spell_haste)/ 100); return new Gcd((Decimal)_conditionSpell.gcd, Math.Max(g, 1), rem); }); MainCache["GlobalCooldown"].SetRetrievalDelegate(() => { return SpellManager.GlobalCooldownLeft.TotalMilliseconds > 1000/15; }); MainCache["WoWTime"].SetRetrievalDelegate(() => { return Lua.GetReturnVal<double>("return GetTime()",0); }); var s = new spell_data_t(); s.name = "Storm, Earth, and Fire"; s.token = "storm_earth_and_fire"; s.id = 138130; dbc.Spells.Add(138130, s); GenerateApls(SimcraftProfilePath); var settings = SimCSettings.currentSettings; if (settings.Specs.ContainsKey(Me.Specialization)) { var aplFileName = settings.Specs[Me.Specialization]; try { var apl = apls[aplFileName]; apl.CreateBehavior(); apl.PrintResolutionTable(); current_action_list = apl; } catch (KeyNotFoundException) { throw new ApplicationException( string.Format("settings are incorrect for current spec {0}, it reference unexistent file {1}", Me.Specialization, aplFileName)); } } else { try { var apl = apls.Values.First(o => o.Class == Me.Class); var filename = apls.Keys.First(k => apls[k] == apl); settings.Specs[Me.Specialization] = filename; SimCSettings.Save(); Write(string.Format("Settings does not tell which *.simc " + "use for current spec({0}) so picking most appropriate: {1}", Me.Specialization, filename)); apl.CreateBehavior(); apl.PrintResolutionTable(); current_action_list = apl; } catch (Exception) { throw new ApplicationException( string.Format("There's not *.simc for current spec({0})", Me.Specialization)); } } } catch (Exception e) { Write(e.ToString()); } }
private void Inject(ProxyCacheEntry entryToTweak, int hashcode, System.Type result) { TweakEntry(entryToTweak, hashcode); _internalCache[entryToTweak] = result; }
public SimcraftImpl() { //Write("go!"); try { dbc = Serializer.DeSerializeObject(FindDatabase()); } catch (Exception e) { Write(e.ToString()); } spell_data_t[] a = new spell_data_t[dbc.Spells.Values.Count]; dbc.Spells.Values.CopyTo(a, 0); foreach (var v in a) { dbc.Spells[v.id, v.token] = v; } Write("Count "+dbc.Spells.Count); Directory.CreateDirectory(SimcraftProfilePath); try { RoutineManager.Current = null; SimcNames.Populate(); MainCache = new ProxyCacheEntry(); inst = this; active_dot = new ActiveDot(); //trinket = new TrinketProxy(() => StyxWoW.Me.ToUnit(), this); health = new HealthProxy(() => StyxWoW.Me.ToUnit()); energy = new EnergyProxy(() => StyxWoW.Me.ToUnit()); focus = new FocusProxy(() => StyxWoW.Me.ToUnit()); chi = new ChiProxy(() => StyxWoW.Me.ToUnit()); rage = new RageProxy(() => StyxWoW.Me.ToUnit()); buff = new BuffProxy(() => StyxWoW.Me.ToUnit(), PlayerAuras); debuff = new DebuffProxy(() => conditionUnit); talent = new TalentProxy(() => StyxWoW.Me.ToUnit()); cooldown = new CooldownProxy(() => StyxWoW.Me.ToUnit()); spell = new SpellProxy(() => StyxWoW.Me.ToUnit()); combo_points = new ComboPointProxy(() => StyxWoW.Me.ToUnit()); target = new TargetProxy(() => conditionUnit); runic_power = new RunicPowerProxy(() => StyxWoW.Me.ToUnit()); disease = new DiseaseProxy(this); blood = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Blood); unholy = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Unholy); frost = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Frost); death = new RuneProxy(() => StyxWoW.Me.ToUnit(), RuneType.Death); glyph = new GlyphProxy(() => StyxWoW.Me.ToUnit()); set_bonus = new SetBonusProxy(); prev_gcd = new PrevGcdProxy(); prev = new PrevGcdProxy(); pet = new PetProxy("def"); eclipse_energy = new EclipseProxy(() => StyxWoW.Me.ToUnit()); mana = new ManaProxy(() => StyxWoW.Me.ToUnit()); holy_power = new HolyPowerProxy(() => StyxWoW.Me.ToUnit()); seal = new SealProxy(); actions = new ActionProxy(); stat = new StatProxy(); obliterate = new ObliterateProxy(); MainCache["gcd"].SetRetrievalDelegate(() => { var rem = (Decimal)SpellManager.GlobalCooldownLeft.TotalSeconds; var g = BaseGcd(); g = g / ((100+spell_haste)/ 100); return new Gcd((Decimal)_conditionSpell.gcd, Math.Max(g, 1), rem); }); MainCache["GlobalCooldown"].SetRetrievalDelegate(() => { return SpellManager.GlobalCooldownLeft.TotalMilliseconds > 1000/15; }); MainCache["WoWTime"].SetRetrievalDelegate(() => { return Lua.GetReturnVal<double>("return GetTime()",0); }); var s = new spell_data_t(); s.name = "Storm, Earth, and Fire"; s.token = "storm_earth_and_fire"; s.id = 138130; dbc.Spells.Add(138130, s); } catch (Exception e) { Write(e.ToString()); } }
/// <summary> /// Retrieves an existing proxy type from the cache. /// </summary> /// <param name="baseType">The base type of the dynamically-generated proxy type.</param> /// <param name="baseInterfaces">The list of interfaces that the generated proxy type must implement.</param> /// <returns>Returns a valid <see cref="Type"/> if the type already exists; otherwise, it might return <c>null</c> or opt to throw an exception.</returns> public Type Get(Type baseType, params Type[] baseInterfaces) { var entry = new ProxyCacheEntry(baseType, baseInterfaces); return _cache[entry]; }
/// <summary> /// Determines whether or not the cache contains an existing proxy type /// that is derived from the <paramref name="baseType"/> and implements /// the given <paramref name="baseInterfaces"/>. /// </summary> /// <param name="baseType">The base type of the dynamically-generated proxy type.</param> /// <param name="baseInterfaces">The list of interfaces that the generated proxy type must implement.</param> /// <returns>Returns <c>true</c> if the proxy type already exists; otherwise, it will return <c>false.</c></returns> public bool Contains(Type baseType, params Type[] baseInterfaces) { var entry = new ProxyCacheEntry(baseType, baseInterfaces); return _cache.ContainsKey(entry); }