public void ImportFile() { var npcs = LoadNPCs("data\\_npcs.xml"); ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <NonPlayerEntity> rep = RomViewContainer.Container.GetInstance <IRepository <NonPlayerEntity> >(); INonPlayerEntityRepository repository = new NonPlayerEntityRespository(rep); List <int> addedIdList = new List <int>(); foreach (NPCRecord npc in npcs) { //if (addedIdList.Contains(npc.id)) continue; NonPlayerEntity test = repository.GetByRomId(npc.id, npc.guid); //session.CreateCriteria<NonPlayerEntity>() //.Add(Restrictions.Eq("RomId", npc.id)) //.Add(Restrictions.Eq("UniqueId", npc.guid)) //.UniqueResult<NonPlayerEntity>(); if (test != null) { continue; } test = repository.GetAll().FirstOrDefault(m => ((m.RomId == npc.id) && (m.ZoneId == npc.zoneid))); if (test == null) { NonPlayerEntity entity = new NonPlayerEntity(); entity.RomId = npc.id; entity.UniqueId = npc.guid; entity.Name = npc.name; entity.X = npc.x; entity.Y = npc.y; entity.Z = npc.z; entity.ZoneId = npc.zoneid; repository.Add(entity); } else { test.UniqueId = npc.guid; repository.Update(test); } addedIdList.Add(npc.id); ; } tx.Commit(); } finally { session.Close(); } }
public void TestCanUpdateRemedial() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { ICharacterRepository rep = RomViewContainer.Container.GetInstance <ICharacterRepository>(); CharacterDefinition def = rep.FindByName("Remedial"); def.PrimaryClass = CharacterClass.Scout; def.PrimaryLevel = 56; def.SecondaryLevel = 55; def.SecondayClass = CharacterClass.Mage; def.Race = "Human"; def.Sex = Sex.Female; rep.Update(def); tx.Commit(); } finally { session.Close(); } }
public void TestCanAddItem() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <CharacterDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <CharacterDefinition> >(); CharacterDefinition def = new CharacterDefinition { Name = "Remedial", Race = "Human" }; IRepository <QuestDefinition> qRep = RomViewContainer.Container.GetInstance <IRepository <QuestDefinition> >(); QuestDefinition dummy = new QuestDefinition() { RomId = -1, Name = "TestQuest" }; session.Save(dummy); def.CompletedQuests.Add(dummy); session.Save(def); } finally { tx.Rollback(); session.Close(); } }
public void CanLocate() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { MapBuilder mb = RomViewContainer.Container.GetInstance <MapBuilder>(); Map map = mb.BuildMap(100); Vector3 loc = new Vector3(-4574, 81, 7477); int zoneId = 15; var result = map.BuildRoute(loc, zoneId, 110245); for (int i = 0; i < result.Count; i++) { string link = result[i].Start.Id.ToString() + "->" + result[i].End.Id.ToString(); Console.WriteLine(link); } } finally { tx.Rollback(); } }
public NhibernateRegistry() { Scan(x => { x.AssemblyContainingType <IdConvention>(); x.AddAllTypesOf <IConvention>(); x.Exclude(type => !typeof(IConvention).IsAssignableFrom(type)); }); For <IEnumerable <IConvention> >().Use(ctx => ctx.GetAllInstances <IConvention>()); ForSingletonOf <ISessionFactoryGenerator>().Use <SessionFactoryGenerator>(); ForSingletonOf <ISessionFactory>().Use( ctx => ctx.GetInstance <ISessionFactoryGenerator>().CreateSessionFactory()); For <ISession>().Use((ctx) => { var sessionFactory = ctx.GetInstance <ISessionFactory>(); ISession session; if (CallSessionContext.HasBind(sessionFactory)) { session = sessionFactory.GetCurrentSession(); } else { session = sessionFactory.OpenSession(); CallSessionContext.Bind(session); } return(session); }); }
public void ImportFromQuestListXML() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); //LazySessionContext.Bind(new Lazy<ISession>(() => session), fac); try { IRepository <QuestDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <QuestDefinition> >(); IQuestRepository repository = new QuestRepository(rep); IList <QuestDefinition> items = repository.GetAll(); string filename = "Data\\questlist.xml"; if (!File.Exists(filename)) { throw new Exception("File missing"); } list data = new list(); data = list.LoadFromFile(filename); XmlDocument doc = new XmlDocument(); doc.Load(filename); XmlNodeList quests = doc.SelectNodes("//romquest"); foreach (XmlNode romquest in quests) { int id = Convert.ToInt32(romquest.Attributes["id"].Value); string name = romquest.Attributes["name"].Value; QuestDefinition quest = items.FirstOrDefault(definition => definition.RomId == id); if (quest == null) { quest = new QuestDefinition() { RomId = id, Name = name }; repository.Add(quest); } else { quest.RomId = id; quest.Name = name; repository.Update(quest); } } tx.Commit(); } finally { session.Close(); } }
public static void Init() { RomViewContainer.Initialize(); SessionFactory = RomViewContainer.Container.GetInstance <ISessionFactory>(); Session = SessionFactory.OpenSession(); CallSessionContext.Bind(Session); NpeRepository = RomViewContainer.Container.GetInstance <INonPlayerEntityRepository>(); MapPointRepository = RomViewContainer.Container.GetInstance <IRepository <MapPoint> >(); ZoneRepository = RomViewContainer.Container.GetInstance <IRepository <MapZone> >(); }
private void button1_Click(object sender, EventArgs e) { _logger.Info("Starting"); SetButtonState(true); try { RomViewContainer.Initialize(); ISessionFactory _factory = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = _factory.OpenSession(); CallSessionContext.Bind(session); //ITransaction tx = session.BeginTransaction(); INonPlayerEntityRepository npeRepo = RomViewContainer.Container.GetInstance <INonPlayerEntityRepository>(); IRepository <MapPoint> pointRepo = RomViewContainer.Container.GetInstance <IRepository <MapPoint> >(); IRepository <MapZone> zoneRepo = RomViewContainer.Container.GetInstance <IRepository <MapZone> >(); MapBuilder mb = new MapBuilder(npeRepo, pointRepo, zoneRepo); Map map = mb.BuildMap(100); RomViewContainer.Container.Inject(typeof(Map), map); _server = new TCPServer(31001); _server.StartServer(); _logger.Info("Started"); /* * _client = new TcpClient("127.0.0.1", 31001); * int itemId = 228216; * string source = string.Format("ITEM{0}GET{0}{1}{2}", (char)1, itemId, (char)0); * NetworkStream ns = _client.GetStream(); * byte[] data = Encoding.ASCII.GetBytes(source); * ns.Write(data, 0, data.Length); * * byte[] byteBuffer = new byte[1024]; * int size = ns.Read(byteBuffer, 0, byteBuffer.Length); * string result = Encoding.ASCII.GetString(byteBuffer, 0, size); * * _client.Close(); * _server.StopServer(); * */ } catch (Exception ex) { _logger.Error(ex.ToString()); SetButtonState(false); } }
public void CanImportItems() { string filename = "Items.txt"; if (File.Exists(filename)) { string[] data = File.ReadAllLines(filename); ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); //CallSessionContext.Bind(); //LazySessionContext.Bind(new Lazy<ISession>(() => session), fac); try { IRepository <ItemDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); IItemRepository repository = new ItemRepository(rep); foreach (string s in data) { string[] detail = s.Split('|'); int romId = Convert.ToInt32(detail[0]); ItemDefinition def = repository.Get(romId); if (def == null) { def = new ItemDefinition(); } def.RomId = romId; def.Name = detail[1]; repository.AddItem(def); } tx.Commit(); } finally { session.Close(); } } }
public void TestFindQuest() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); //ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); GoalSetter gs = RomViewContainer.Container.GetInstance <GoalSetter>(); ICharacterRepository charRep = RomViewContainer.Container.GetInstance <ICharacterRepository>(); CharacterDefinition toon = charRep.FindByName("Remedial"); gs.Character = toon; gs.State = new CharacterState(); gs.State.Location = new Vector3(6130, 137, 23169); var a = gs.DetermineNearestQuest(); CallSessionContext.Unbind(fac); }
public void CanRunFromTo() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { MapBuilder mb = RomViewContainer.Container.GetInstance <MapBuilder>(); Map map = mb.BuildMap(100); Vector3 loc = new Vector3(-1169, 38, -5527); //logar snoop int zoneId = 1; Vector3 dV = new Vector3(-20460, -190, 6507); PlottedMapPoint dest = map.FindNearest(dV, 6); var result = map.BuildRoute(loc, zoneId, dest.MapPoint); StringBuilder sb = new StringBuilder(); sb.AppendLine("<?xml version=\"1.0\" encoding=\"utf-8\"?><waypoints>"); for (int i = 0; i < result.Count; i++) { string script = ""; //if (i < path.Count - 1) script = path[i + 1].Script; sb.AppendLine(result[i].Start.ToRomBotXML(i + 1, result[i].Script)); } if (result.Count > 0) { sb.AppendLine(result[result.Count - 1].End.ToRomBotXML(result.Count, "")); } Console.WriteLine(sb.ToString()); } finally { tx.Rollback(); } }
public void TestHandlesInvalidFetchByName() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <ItemDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); IItemRepository repository = new ItemRepository(rep); ItemDefinition result = repository.Get("asdfasdas"); Assert.IsNull(result); } finally { tx.Rollback(); session.Close(); } }
public void CanMap() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { MapBuilder mb = RomViewContainer.Container.GetInstance <MapBuilder>(); Map map = mb.BuildMap(100); MapPoint start = (MapPoint)map.MapPoints[1]; MapPoint end = (MapPoint)map.MapPoints[5]; var result = map.BuildRoute(start, end); for (int i = 0; i < result.Count; i++) { string link = result[i].Start.Id.ToString() + "->" + result[i].End.Id.ToString(); Console.WriteLine(link); } start = (MapPoint)map.MapPoints[735]; end = (MapPoint)map.MapPoints[1565]; result = map.BuildRoute(start, end); for (int i = 0; i < result.Count; i++) { string link = result[i].Start.Id.ToString() + "->" + result[i].End.Id.ToString(); Console.WriteLine(link); } } finally { tx.Rollback(); } }
public void TestCanFetchByName() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <ItemDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); IItemRepository repository = new ItemRepository(rep); ItemDefinition def = new ItemDefinition { RomId = 999999, Name = "Augury Cloth Bootses", ItemType = "Armor", ItemSubType = "Boots", ItemSubSubType = "Cloth", Value = 100 }; string expected = def.ToDelimitedString(1); repository.AddItem(def); ItemDefinition result = repository.Get(def.Name); Assert.AreEqual(expected, result.ToDelimitedString(1)); } finally { tx.Rollback(); session.Close(); } }
public string HandleMessage(String oneLine) { _logger.InfoFormat("HandleMessage: {0}", oneLine); ISession session = _factory.OpenSession(); CallSessionContext.Bind(session); ITransaction tx = session.BeginTransaction(); try { string response = null; //log!!! if (oneLine == null) { return(null); } string[] sections = oneLine.Split((char)1); if (sections.Length < 2) { return(null); } switch (sections[0]) { case "ITEM": response = _handleItemMessage(sections); break; case "QUEST": response = _handleQuestMessage(sections); break; case "NPC": response = _handleNPEMessage(sections); break; case "TOON": response = _handleToonMessage(sections); break; case "MAP": response = _handleMapMessage(sections); break; default: //log break; } tx.Commit(); if (!string.IsNullOrEmpty(response)) { response += GetDelimiter(); } return(response); } catch (Exception ex) { tx.Rollback(); LogManager.GetLogger(typeof(RomMessageProcessor)).Error(ex.ToString()); return(ex.Message); } finally { CallSessionContext.Unbind(_factory); } }
public void CanUpdateItemsFromRomDB() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); //LazySessionContext.Bind(new Lazy<ISession>(() => session), fac); try { List <string> itemTypes = new List <string>(_itemTypes); List <string> itemSubTypes = new List <string>(_itemSubTypes); List <string> itemSubSubTypes = new List <string>(_itemSubSubTypes); Hashtable _typeFromSubTypeMap = new Hashtable(_itemSubTypeToTypeMap.Length); Hashtable _customTypeMap = new Hashtable(_subTypeTx.Length); Hashtable _subTypeFix = new Hashtable(_itemSubTypeFixes.Length); Hashtable _subSubTypeFix = new Hashtable(_itemSubSubTypeFixes.Length); foreach (string s in _itemSubTypeToTypeMap) { string[] map = s.Split('='); _typeFromSubTypeMap[map[0]] = map[1]; } foreach (string s in _subTypeTx) { string[] map = s.Split('='); _customTypeMap[map[0]] = map[1]; } foreach (string s in _itemSubTypeFixes) { string[] map = s.Split('='); _subTypeFix[map[0]] = map[1]; } foreach (string s in _itemSubSubTypeFixes) { string[] map = s.Split('='); _subSubTypeFix[map[0]] = map[1]; } IRepository <ItemDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); IItemRepository repository = new ItemRepository(rep); var src = repository.GetAll().Where(definition => String.IsNullOrEmpty(definition.ItemType) && (definition.Value < 1)); IList <ItemDefinition> items = new List <ItemDefinition>(src); string url = "http://www.runesdatabase.com/xml/en_US/items/xmls/{0}.xml"; Regex _goldMatch = new Regex(@"Worth: (\d+) Gold", RegexOptions.IgnoreCase); Regex _reqLevelMatch = new Regex(@"Required level (\d+)", RegexOptions.IgnoreCase); Regex _cardMatch = new Regex(@"Card - ", RegexOptions.IgnoreCase); Regex _questMatch = new Regex(@"Daily quest", RegexOptions.IgnoreCase); int tCount = 0; for (int i = 0; i < items.Count; i++) //int i = 207141; { if (!string.IsNullOrEmpty(items[i].ItemType)) { //Debug.WriteLine("Ignoring "+items[i].RomId); continue; } if (tCount > 10) { tx.Commit(); tx = session.BeginTransaction(); tCount = 0; Debug.WriteLine("Committed 10"); } //} //foreach (ItemDefinition item in items) //{ string xml; ItemDefinition item = items[i]; if ((item.RomId > 550001) && (item.RomId < 770000)) { continue; } Debug.WriteLine("Working on item " + item.RomId); //if (item.RomId < 204499) continue; try { string filename = "data\\" + item.RomId.ToString() + ".xml"; if (File.Exists(filename)) { xml = File.ReadAllText(filename); Debug.WriteLine("Data fetched from disk."); } else { using (var webClient = new WebClient()) { xml = webClient.DownloadString(string.Format(url, item.RomId)); File.WriteAllText(filename, xml); } } romitem rItem = new romitem(); romitem.Deserialize(xml, out rItem); /* * bool isArmour = rItem.tooltip.Contains("Physical Defense"); * bool isWeapon = rItem.tooltip.Contains("Physical Damage"); * bool isItemShopItem = rItem.tooltip.Contains("Item Shop Item"); * bool isQuestItem = rItem.tooltip.Contains("Quest Item"); * bool isQuestStartItem = rItem.tooltip.Contains("(Daily Quest)"); * bool isMaterial = rItem.tooltip.Contains("Production Rune"); * bool isEqEnhancement = rItem.tooltip.Contains("Rune"); * if (isQuestStartItem) isQuestItem = true; */ bool changed = false; HtmlDocument doc = new HtmlDocument(); string html = string.Format("<html><body>{0}</body></html>", rItem.tooltip); //File.AppendAllText("itemHtml.xml", html); doc.LoadHtml(html); foreach (HtmlNode table in doc.DocumentNode.SelectNodes("//table")) { var rows = table.SelectNodes("tr"); bool typeFound = false; foreach (HtmlNode row in rows) { var cells = row.SelectNodes("td"); string firstCell = ""; string secondCell = ""; if (cells.Count > 0) { firstCell = cells[0].InnerText; } if (cells.Count > 1) { secondCell = cells[1].InnerText; } if (Regex.IsMatch(firstCell, "Not dropped on PK")) { continue; } if (Regex.IsMatch(firstCell, "Tier ")) { continue; } if (Regex.IsMatch(firstCell, "Durability ")) { continue; } if (Regex.IsMatch(firstCell, "Physical ")) { continue; } if (Regex.IsMatch(firstCell, "Magical ")) { continue; } if (Regex.IsMatch(firstCell, "Binds ")) { continue; } Match match = _goldMatch.Match(firstCell); if (match.Success) { item.Value = Convert.ToInt32(match.Groups[1].Value); changed = true; } match = _reqLevelMatch.Match(firstCell); if (match.Success) { item.RequiredLevel = Convert.ToInt32(match.Groups[1].Value); changed = true; } if (!string.IsNullOrEmpty(firstCell) && (itemSubTypes.Contains(firstCell))) { if (_subTypeFix.Contains(firstCell)) { firstCell = _subTypeFix[firstCell].ToString(); } item.ItemSubType = firstCell; changed = true; typeFound = true; } if (!string.IsNullOrEmpty(secondCell) && (itemSubSubTypes.Contains(secondCell))) { if (_subTypeFix.Contains(secondCell)) { secondCell = _subTypeFix[secondCell].ToString(); } item.ItemSubSubType = secondCell; changed = true; } if (!typeFound) { if (_cardMatch.IsMatch(firstCell)) { item.ItemSubType = "Card"; changed = true; } else if (_questMatch.IsMatch(firstCell)) { item.ItemSubType = "Daily quest Item"; changed = true; } else if (_customTypeMap.ContainsKey(firstCell)) { string[] data = _customTypeMap[firstCell].ToString().Split(','); item.ItemType = data[0]; item.ItemSubType = data[1]; item.ItemSubSubType = data[2]; } } } } if ((changed) && (!string.IsNullOrEmpty(item.ItemSubType))) { if (_typeFromSubTypeMap.ContainsKey(item.ItemSubType)) { item.ItemType = (string)_typeFromSubTypeMap[item.ItemSubType]; changed = true; } } if (changed) { repository.UpdateItem(item); tCount++; } } catch { } } tx.Commit(); } finally { session.Close(); } }
public void TestCanAddSingleItem() { ISessionFactory fac = RomViewContainer.Container.GetInstance <ISessionFactory>(); ISession session = fac.OpenSession(); ITransaction tx = session.BeginTransaction(); CallSessionContext.Bind(session); try { IRepository <QuestDefinition> rep = RomViewContainer.Container.GetInstance <IRepository <QuestDefinition> >(); IQuestRepository repository = new QuestRepository(rep); QuestChain chain = new QuestChain() { Name = "Saving a Marriage" }; IRepository <QuestChain> chainRep = RomViewContainer.Container.GetInstance <IRepository <QuestChain> >(); try { chain = chainRep.SaveOrUpdate(chain); } catch { } QuestDefinition def = new QuestDefinition() { RomId = 423924, Name = "Act First and Report Later", MinLevel = 25, Level = 27, StarterId = 117396, EnderId = 117396, Gold = 1515, XP = 17301, TP = 1730, RewardCategory = RewardCategory.Armor, RewardSubCategory = RewardSubCategory.Head, ChainIndex = 4, QuestChain = chain }; IRepository <ItemDefinition> idef = RomViewContainer.Container.GetInstance <IRepository <ItemDefinition> >(); ItemRepository irep = new ItemRepository(idef); ItemDefinition item = irep.GetByRomId(228250); item.ItemType = "armor"; item.ItemSubType = "cloth"; item.ItemSubSubType = "head"; item.Value = 196; irep.UpdateItem(item); QuestReward reward = new QuestReward() { Item = item, RewardIndex = 1, RewardType = "Cloth", Quest = def }; def.Rewards.Add(reward); item = irep.GetByRomId(228251); item.ItemType = "armor"; item.ItemSubType = "leather"; item.ItemSubSubType = "head"; item.Value = 261; irep.UpdateItem(item); reward = new QuestReward() { Item = item, RewardIndex = 2, RewardType = "Leather", Quest = def }; def.Rewards.Add(reward); repository.Add(def); } finally { tx.Rollback(); session.Close(); } }