protected override void RefreshData(IDictionary <string, string> _get) { string html; using (WebClient client = new WebClient()) { html = client.DownloadString(WIKI_URL); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); XPathNavigator nav = doc.CreateNavigator(); XPathNodeIterator i = nav.Select("//table/tr/td[position()=6]"); IList <string> champ_list = new List <string>(); while (i.MoveNext()) { XPathNavigator node = i.Current.SelectSingleNode("./a"); if (node != null) { champ_list.Add(WIKI_NAME_CLEAN.Replace(node.Value.ToLower(), string.Empty)); } } EventNamesResponse names = new EventNamesRequest(LanguageCode.EN).Execute(); IDbTransaction tx = m_DbConn.BeginTransaction(); try { foreach (Event ev in names) { if (champ_list.Contains(WIKI_NAME_CLEAN.Replace(ev.Name.ToLower(), string.Empty))) { DbAddEvent(ev.Id, tx); } } tx.Commit(); } catch (Exception e) { LOGGER.Error("Exception thrown when attempting to update event status", e); try { tx.Rollback(); } catch (Exception ex) { LOGGER.Error("Exception thrown when attempting to roll back event status update", ex); } } }
public void Execute() { // act var response = new EventNamesRequest().Execute(); // assert Assert.IsTrue(response.Count > 0); foreach (var ev in response) { Assert.IsNotNull(ev.Id); Assert.IsNotNull(ev.Name); } }
public void ExecuteTranslated() { // arrange var eventId = new Guid("F479B4CF-2E11-457A-B279-90822511B53B"); // Defeat the Karka Queen threatening the settlements. var translatedNames = new Dictionary <LanguageCode, string>() { { LanguageCode.DE, "Besiegt die Karka-Königin, die die Siedlungen bedroht." }, { LanguageCode.EN, "Defeat the Karka Queen threatening the settlements." }, { LanguageCode.ES, "Derrota a la reina karka que amenaza a los asentamientos." }, { LanguageCode.FR, "Vaincre la reine karka qui menace les colonies." }, }; foreach (var pair in translatedNames) { // act var response = new EventNamesRequest(pair.Key).Execute(); // assert var ev = response.Where(e => e.Id == eventId).First(); Assert.AreEqual(pair.Value, ev.Name); } }
public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage:"); Console.WriteLine(" GuildWars2.ArenaNet.EventTimer.Test.exe [meta_id] [file]"); Console.WriteLine(); return; } FileInfo csv = new FileInfo(args[1]); MetaEvent meta = MetaEventDefinitions.MetaEvents.Where(m => m.Id == args[0]).Single(); if (meta == null) { Console.WriteLine("Could not find meta-event {0}", args[0]); return; } IList <Guid> events = meta.Stages.SelectMany(s => s.EventStates).Select(s => s.Event).Distinct().ToList(); EventNamesResponse namesResponse = new EventNamesRequest().Execute(); if (namesResponse == null) { Console.WriteLine("Could not retrieve event names"); return; } IDictionary <Guid, string> names = namesResponse.ToDictionary(n => n.Id, n => n.Name); DataTable table = new DataTable(); table.Columns.Add("Timestamp"); foreach (Guid ev in events) { table.Columns.Add(ev.ToString()); } table.Columns.Add("MetaState"); Console.WriteLine("Beginning status tracking. Please press any key to exit."); while (!Console.KeyAvailable) { EventsResponse response = new EventsRequest(1007).Execute(); if (response != null) { HashSet <EventState> states = new HashSet <EventState>(response.Events.Where(e => events.Contains(e.EventId))); int stageId = meta.GetStageId(states); DateTime timestamp = DateTime.Now; DataRow row = table.NewRow(); foreach (DataColumn column in table.Columns) { if (column.ColumnName == "Timestamp") { row[column] = timestamp.ToString("yyyy-MM-dd HH:mm:ss"); } else if (column.ColumnName == "MetaState") { row[column] = (stageId >= 0 ? meta.Stages.ElementAt(stageId).Name : "Inactive"); } else { Guid eventId = new Guid(column.ColumnName); row[column] = states.Where(e => e.EventId == eventId).Select(e => e.State).Single(); } } DataRow lastRow = (table.Rows.Count == 0 ? table.NewRow() : table.Rows[table.Rows.Count - 1]); bool stateChanged = false; foreach (DataColumn column in table.Columns) { if (column.ColumnName == "Timestamp") { continue; } if (!lastRow[column].Equals(row[column])) { stateChanged = true; break; } } if (stateChanged) { Console.WriteLine("Recording state change..."); table.Rows.Add(row); } } Thread.Sleep(5000); } Console.ReadKey(true); try { using (FileStream stream = csv.Open(FileMode.Create)) { StreamWriter writer = new StreamWriter(stream); foreach (DataColumn column in table.Columns) { IList <string> values = new List <string>(); if (column.ColumnName != "Timestamp" && column.ColumnName != "MetaState") { Guid ev = new Guid(column.ColumnName); values.Add(names[ev]); } else { values.Add(string.Empty); } foreach (DataRow row in table.Rows) { values.Add(row[column].ToString()); } string data = string.Join(",", values.Select(s => (s.Contains(",") ? string.Format("\"{0}\"", s) : s))); writer.WriteLine(data); } writer.Close(); } } catch { } }
public static void Main(string[] args) { if (args.Length != 2) { Console.WriteLine("Usage:"); Console.WriteLine(" GuildWars2.ArenaNet.EventTimer.Test.exe [meta_id] [file]"); Console.WriteLine(); return; } FileInfo csv = new FileInfo(args[1]); MetaEvent meta = MetaEventDefinitions.MetaEvents.Where(m => m.Id == args[0]).Single(); if (meta == null) { Console.WriteLine("Could not find meta-event {0}", args[0]); return; } IList<Guid> events = meta.Stages.SelectMany(s => s.EventStates).Select(s => s.Event).Distinct().ToList(); EventNamesResponse namesResponse = new EventNamesRequest().Execute(); if (namesResponse == null) { Console.WriteLine("Could not retrieve event names"); return; } IDictionary<Guid, string> names = namesResponse.ToDictionary(n => n.Id, n => n.Name); DataTable table = new DataTable(); table.Columns.Add("Timestamp"); foreach (Guid ev in events) { table.Columns.Add(ev.ToString()); } table.Columns.Add("MetaState"); Console.WriteLine("Beginning status tracking. Please press any key to exit."); while (!Console.KeyAvailable) { EventsResponse response = new EventsRequest(1007).Execute(); if (response != null) { HashSet<EventState> states = new HashSet<EventState>(response.Events.Where(e => events.Contains(e.EventId))); int stageId = meta.GetStageId(states); DateTime timestamp = DateTime.Now; DataRow row = table.NewRow(); foreach (DataColumn column in table.Columns) { if (column.ColumnName == "Timestamp") row[column] = timestamp.ToString("yyyy-MM-dd HH:mm:ss"); else if (column.ColumnName == "MetaState") row[column] = (stageId >= 0 ? meta.Stages.ElementAt(stageId).Name : "Inactive"); else { Guid eventId = new Guid(column.ColumnName); row[column] = states.Where(e => e.EventId == eventId).Select(e => e.State).Single(); } } DataRow lastRow = (table.Rows.Count == 0 ? table.NewRow() : table.Rows[table.Rows.Count - 1]); bool stateChanged = false; foreach (DataColumn column in table.Columns) { if (column.ColumnName == "Timestamp") continue; if (!lastRow[column].Equals(row[column])) { stateChanged = true; break; } } if (stateChanged) { Console.WriteLine("Recording state change..."); table.Rows.Add(row); } } Thread.Sleep(5000); } Console.ReadKey(true); try { using (FileStream stream = csv.Open(FileMode.Create)) { StreamWriter writer = new StreamWriter(stream); foreach (DataColumn column in table.Columns) { IList<string> values = new List<string>(); if (column.ColumnName != "Timestamp" && column.ColumnName != "MetaState") { Guid ev = new Guid(column.ColumnName); values.Add(names[ev]); } else { values.Add(string.Empty); } foreach (DataRow row in table.Rows) { values.Add(row[column].ToString()); } string data = string.Join(",", values.Select(s => (s.Contains(",") ? string.Format("\"{0}\"", s) : s))); writer.WriteLine(data); } writer.Close(); } } catch { } }