Пример #1
0
        public void ResponseObjectExpirationTest(int world_id, int map_id, Guid?event_id, bool ignoreCache, int expiresAfter, int nowOffset)
        {
            EntryCollection <EventEntry> expected = GwApi.GetEvents(world_id, map_id, event_id, true);

            expected.CacheStrategy = new AgeCacheStrategy(TimeSpan.FromMilliseconds(expiresAfter));
            expected.LastUpdated   = expected.LastUpdated.Subtract(TimeSpan.FromMilliseconds(nowOffset));
            ResponseCache.Cache.Add(expected);
            Assert.IsFalse(expected.FromCache);

            var actual = GwApi.GetEvents(world_id, map_id, event_id, ignoreCache);

            if (ignoreCache || nowOffset >= expiresAfter)
            {
                // forced update, or has expired
                Assert.LessOrEqual(expected.LastUpdated, actual.LastUpdated);
                Assert.Greater(expected.Age, actual.Age);
                Assert.IsFalse(actual.Expired);   // If it was just updated, it shouldn't expire so soon
                Assert.IsFalse(actual.FromCache); // must always be false if cache was ignored
            }
            else
            {
                // Not expired and therefore from cache
                Assert.AreEqual(expected.LastUpdated, actual.LastUpdated);
                Assert.AreEqual(expected.Age, actual.Age);
                Assert.IsFalse(actual.Expired);
                Assert.IsTrue(actual.FromCache);
            }
        }
Пример #2
0
        public void GetEventsTest(bool ignoreCache)
        {
            var actuals     = GwApi.GetEvents(-1, -1, null, ignoreCache);
            var expectedCol = TestData.EventEntriesExpected;

            VerifyEvents(expectedCol, actuals);
        }
Пример #3
0
        public bool EntryCollectionAgeCacheStrategyExpiredTest(string maxAgeStr, string offsetStr)
        {
            var items  = GwApi.GetEvents(-1, -1, null, true);
            var maxAge = TimeSpan.Parse(maxAgeStr);
            var offset = TimeSpan.Parse(offsetStr);

            items.LastUpdated = DateTime.Now.Add(offset);
            var strat1 = new AgeCacheStrategy(maxAge);
            var strat2 = new CollectionCacheStrategy <EntryCollection <EventEntry>, EventEntry>();

            return(strat2.Expired(items, strat1));
        }
Пример #4
0
        public EntryDictionary <Guid, EventNameEntry> GetEventNames(int mapID)
        {
            EntryCollection <EventEntry> x = GwApi.GetEvents(_bs.WorldID, mapID, null);
            HashSet <Guid> z = new HashSet <Guid>();

            foreach (EventEntry p in x)
            {
                z.Add(p.EventId);
            }
            var y = GwApi.GetEventNames();
            EntryDictionary <Guid, EventNameEntry> ret = new EntryDictionary <Guid, EventNameEntry>();

            y.Where(j => z.Contains(j.Value.Id)).ToList().ForEach(k => ret.Add(k.Key, k.Value));
            return(ret);
        }
Пример #5
0
        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();
        }
Пример #6
0
        public EntryCollection <EventEntry> GetEventDetails()
        {
            EntryCollection <EventEntry> eventDetails = GwApi.GetEvents(_bs.WorldID, -1, null);

            return(eventDetails);
        }