示例#1
0
        public void GetEventDetailsTest(string event_id, bool ignoreCache)
        {
            var actual   = GwApi.GetEventDetails(event_id, ignoreCache);
            var expected = TestData.EventDetailsExpected;

            foreach (var pair in expected)
            {
                var entry = pair.Value;
                Assert.IsTrue(actual.ContainsKey(pair.Key));
                var actualEntry = actual[pair.Key];
                Assert.AreEqual(entry.Name, actualEntry.Name);
                Assert.AreEqual(entry.Level, actualEntry.Level);
                Assert.AreEqual(entry.MapId, actualEntry.MapId);
                Assert.AreEqual(entry.Location.Height, actualEntry.Location.Height);
                Assert.AreEqual(entry.Location.Radius, actualEntry.Location.Radius);
                Assert.AreEqual(entry.Location.Rotation, actualEntry.Location.Rotation);
                Assert.AreEqual(entry.Location.Type, actualEntry.Location.Type);
                if ((entry.Location.Center == null && actualEntry.Location.Center == null) == false)
                {
                    CollectionAssert.AreEquivalent(entry.Location.Center, actualEntry.Location.Center);
                }
                if ((entry.Location.Points == null && actualEntry.Location.Points == null) == false)
                {
                    CollectionAssert.AreEquivalent(entry.Location.Points, actualEntry.Location.Points);
                }
                if ((entry.Location.ZRange == null && actualEntry.Location.ZRange == null) == false)
                {
                    CollectionAssert.AreEquivalent(entry.Location.ZRange, actualEntry.Location.ZRange);
                }
            }
        }
        public void EventsExample()
        {
            GwApi.Network = new NetworkHandler();
            // First lets find out what my world ID is
            var worldNames = GwApi.GetWorldNames();
            int world_id   = worldNames.Values.Single(w => w.Name == "Sorrow's Furnace").Id;

            // now lets get the event names and map names
            // These are lookups keyed on ID value
            var eventNames = GwApi.GetEventNames();
            var maps       = GwApi.GetMapNames();

            // Now lets get a list of events on my world
            // We can use include whatever information we want to query with
            // In this case we want all events where the world id = world_id
            // we could also reduce our search further by providing a map id or event an event id
            var events = GwApi.GetEvents(world_id, -1, null);

            // Lets print all of the active events
            // We can show the map the event is on and it's name
            var activeEvents = events.Where(e => e.State == EventState.Active);

            // Lets get the event details for all events
            // we could request a single event detail by providing the event id as well
            var eventDetails = GwApi.GetEventDetails();

            // we'll use a StringBuilder to compose our print list
            var sb = new StringBuilder("--- Active Event List ---\n");

            foreach (var e in activeEvents)
            {
                // event detail for current e
                var eventDetail = eventDetails[e.EventId];
                sb.AppendFormat("Name: {0}\n", eventDetail.Name);
                sb.AppendFormat("Map: {0}\n", maps[eventDetail.MapId].Name);
                sb.AppendFormat("Level: {0}\n", eventDetail.Level);
                sb.AppendLine("--------");
            }
            // Print the contents
            Console.WriteLine(sb.ToString());

            // We've just downloaded a bunch of data which takes a bit of time
            // Sepcifically the complete event details list
            // If we save this, the next time we need the list it will take very little time
            ResponseCache.Cache.Save();
        }