예제 #1
0
        public void GetFilesTest(bool ignoreCache)
        {
            var actual   = GwApi.GetFiles(ignoreCache);
            var expected = TestData.FileEntriesExpected;

            VerifyFiles(expected, actual);
        }
예제 #2
0
        public void GetMapFloorTest(int continent_id, int floor, bool ignoreCache)
        {
            var actual   = GwApi.GetMapFloor(continent_id, floor, ignoreCache);
            var expected = TestData.MapFloorEntriesExpected;

            VerifyMapFloor(expected, actual);
        }
예제 #3
0
        public void GetColorsTest(bool ignoreCache)
        {
            var actual   = GwApi.GetColors(ignoreCache);
            var expected = TestData.ColorEntriesExpected;

            VerifyColors(expected, actual);
        }
예제 #4
0
        public void GetObjectiveNamesTest(bool ignoreCache)
        {
            var actual   = GwApi.GetObjectiveNames(ignoreCache);
            var expected = TestData.ObjectiveNamesExpected;

            VerifyObjectiveNames(expected, actual);
        }
예제 #5
0
        public void GetMapTest(bool ignoreCache)
        {
            var actual   = GwApi.GetMap(ignoreCache);
            var expected = TestData.MapEntriesExpected;

            VerifyMaps(expected, actual);
        }
예제 #6
0
        public void GetGuildDetailsByIdTest(string guild_id, bool ignoreCache)
        {
            var actual   = GwApi.GetGuildDetailsById(guild_id, ignoreCache);
            var expected = TestData.GuildDetailsExpected.Single(g => g.GuildId == g.GuildId);

            VerifyGuildDetailsEntry(expected, actual);
        }
예제 #7
0
        public void GetMatchDetailsTest(string match_id, bool ignoreCache)
        {
            var actual   = GwApi.GetMatchDetails(match_id, ignoreCache);
            var expected = TestData.MatchDetailsExpected.Single(g => g.Id == match_id);

            VerifyMatchDetails(expected, actual);
        }
예제 #8
0
        public void GetRecipeIdsTest(bool ignoreCache)
        {
            var actual   = GwApi.GetRecipeIds(ignoreCache);
            var expected = TestData.RecipeIdListExpected;

            CollectionAssert.AreEquivalent(expected, actual);
        }
예제 #9
0
        public void GetGuildDetailsByNameTest(string guild_name, bool ignoreCache)
        {
            var actual   = GwApi.GetGuildDetailsByName(guild_name, ignoreCache);
            var expected = TestData.GuildDetailsExpected.Single(g => g.GuildName == guild_name);

            VerifyGuildDetailsEntry(expected, actual);
        }
예제 #10
0
        public void GetRecipeDetailsTest(int recipe_id, bool ignoreCache)
        {
            var actual   = GwApi.GetRecipeDetails(recipe_id, ignoreCache);
            var expected = TestData.RecipeDetailsExpected.Single(r => r.RecipeId == recipe_id);

            VerifyRecipeDetails(expected, actual);
        }
예제 #11
0
        public void GetItemDetailsTest(int item_id, bool ignoreCache)
        {
            var actual   = GwApi.GetItemDetails(item_id, ignoreCache);
            var expected = TestData.ItemDetailsExpected.Single(i => i.ItemId == item_id);

            VerifyItemDetails(expected, actual);
        }
예제 #12
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);
                }
            }
        }
예제 #13
0
        public void GetEventsTest(bool ignoreCache)
        {
            var actuals     = GwApi.GetEvents(-1, -1, null, ignoreCache);
            var expectedCol = TestData.EventEntriesExpected;

            VerifyEvents(expectedCol, actuals);
        }
예제 #14
0
        public static string GetTileUrlFromWorldPos(MapEntryBase map, int floor, int zoomLevel, Gw2Point worldPosition, string errorTileUrl)
        {
            MapEntry mapEntry    = map is MapEntry ? (map as MapEntry) : GwApi.GetMap()[map.Id];
            int      continentId = mapEntry.ContinentId;

            return(GetTileUrl(continentId, floor, zoomLevel, WorldPosToTile(map, worldPosition, zoomLevel), errorTileUrl));
        }
예제 #15
0
        public void CachePerformanceLoadTest()
        {
            Stopwatch watch = new Stopwatch();
            var       items = ResponseCache.Cache.Get("ItemsDictionary") as EntryDictionary <int, ItemDetailsEntry>;

            if (items == null)
            {
                return;
            }
            int count = 0;

            Console.WriteLine("Time to complete {0} {1}", count, watch.Elapsed.TotalSeconds.ToString("0.0000000"));
            List <Task <ItemDetailsEntry> > addTask = new List <Task <ItemDetailsEntry> >();

            watch.Start();
            var items2 = new EntryDictionary <int, ItemDetailsEntry>();

            foreach (var item in items)
            {
                var i = GwApi.GetItemDetails(item.Key);
                items2.Add(i.ItemId, i);
                count++;
            }
            watch.Stop();
            string output = string.Format("Time to complete {0} {1}", items2.Count,
                                          watch.Elapsed.TotalSeconds.ToString("0.0000000"));

            Console.WriteLine(output);
        }
예제 #16
0
        public void LangTest()
        {
            NetworkHandler handler = new NetworkHandler();

            GwApi.Network = handler;
            var evennames = GwApi.GetEventNames(false, Language.German);
        }
예제 #17
0
        private void _worker_DoWork(object sender, DoWorkEventArgs e)
        {
            var idList = e.Argument as IList <int>;
            var items  = Items ?? new EntryDictionary <int, ItemDetailsEntry>();

            e.Result = items;
            lock (_downloadLock)
            {
                e.Result      = items;
                DownloadTotal = idList.Count;
                for (int i = 0; i < idList.Count; i++)
                {
                    var item = GwApi.GetItemDetails(idList[i]);
                    try
                    {
                        items.Add(item.ItemId, item);
                    }
                    catch (Exception)
                    {
                    }
                    DownloadCount    = i;
                    DownloadProgress = (int)(100 * ((double)i / idList.Count));
                    //_worker.ReportProgress((int) (100*((double) i/idList.Count)));
                    if (e.Cancel)
                    {
                        return;
                    }
                }
            }
        }
예제 #18
0
        public void examples()
        {
            GwApi.Network = new NetworkHandler();
            IdList list = GwApi.GetItemIds(true);

            Console.WriteLine("Total Items: {0}", list.Count);
        }
예제 #19
0
        public static Gw2StatsRatingsObject Gw2StatsRatingsObject(bool ignoreCache = true)
        {
            var        parser  = new Gw2StatsRatingsObjectParser();
            ApiRequest request = new ApiRequest(Constants.gw2_ratings);

            return(GwApi.HandleRequest(request, parser, Network, ignoreCache));
        }
예제 #20
0
        public void CachePerformanceLoadTest2()
        {
            Stopwatch watch = new Stopwatch();
            var       items = ResponseCache.Cache.Get("ItemsDictionary") as EntryDictionary <int, ItemDetailsEntry>;

            if (items == null)
            {
                return;
            }
            int count = 0;

            Console.WriteLine("Time to complete {0} {1}", count, watch.Elapsed.TotalSeconds.ToString("0.0000000"));
            List <Task <ItemDetailsEntry> > addTask = new List <Task <ItemDetailsEntry> >();
            var             items2 = new EntryDictionary <int, ItemDetailsEntry>();
            List <TimeSpan> times  = new List <TimeSpan>();

            watch.Start();
            foreach (var item in items)
            {
                addTask.Add(GwApi.GetItemDetailsAsync(item.Key));
                count++;
            }
            var time = watch.Elapsed;

            Task.WaitAll(addTask.ToArray());
            foreach (var task in addTask)
            {
                items2.Add(task.Result.ItemId, task.Result);
            }
            watch.Stop();
            string output = string.Format("Time to complete {0} {1} {2}", items2.Count,
                                          watch.Elapsed.TotalSeconds.ToString("0.0000000"), time.TotalSeconds.ToString("0.0000000"));

            Console.WriteLine(output);
        }
예제 #21
0
        public static EntryDictionary <string, Gw2StatsStatusEntry> GetGw2StatsStatus(bool ignoreCache = true)
        {
            var        parser  = new Ge2StatsStatusEntryParser();
            ApiRequest request = new ApiRequest(Constants.gw2_status);

            return(GwApi.HandleRequest(request, parser, Network, ignoreCache));
        }
예제 #22
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);
            }
        }
예제 #23
0
        public void ItemDetailsExample()
        {
            GwApi.Network = new NetworkHandler();

            // Lets get the details of my awesome item.
            var           item = GwApi.GetItemDetails(39276);
            StringBuilder sb   = new StringBuilder(string.Format("{0} - Item Detail\n", item.ItemId));

            sb.AppendFormat("Name: {0}\n", item.Name);
            sb.AppendFormat("{0}\n", item.Description);
            sb.AppendFormat("Level: {0}\n", item.Level);
            sb.AppendFormat("Rarity: {0}\n", item.Rarity);
            sb.AppendFormat("Type: {0}\n", item.ItemType);
            sb.AppendFormat("Value: {0}\n", item.VendorValue);
            sb.AppendFormat("Buffs:\n");
            sb.AppendFormat("{0}\n", item.TrinketDetails.InfixUpgrade.Buff.Description);
            sb.AppendFormat("Attributes:\n");
            foreach (var attr in item.TrinketDetails.InfixUpgrade.Attributes)
            {
                sb.AppendFormat("\t{0}:{1}\n", attr.Attribute, attr.Modifier);
            }
            sb.AppendFormat("Infusion Slots ({0}):\n", item.TrinketDetails.InfusionSlots.Count);
            for (int i = 0; i < item.TrinketDetails.InfusionSlots.Count; i++)
            {
                sb.AppendFormat("\tType: {1} - {0}\n", item.TrinketDetails.InfusionSlots[i].Item ?? "Unused", string.Join(",", item.TrinketDetails.InfusionSlots[i].Flags));
            }

            Console.WriteLine(sb.ToString());
        }
예제 #24
0
        /// <summary>
        /// Download Recipes
        /// </summary>
        /// <param name="idlist">list of recipe ids to download</param>
        /// <returns>Dictionary of Recipes downloaded, keyed by the recipe id</returns>
        public Task <EntryDictionary <int, RecipeDetailsEntry> > DownloadRecipesAsync(IList <int> idlist)
        {
            var tsk     = new TaskCompletionSource <EntryDictionary <int, RecipeDetailsEntry> >();
            var recipes = new EntryDictionary <int, RecipeDetailsEntry>();
            List <Exception> exceptions = new List <Exception>();

            ThreadPool.QueueUserWorkItem(o =>
            {
                try
                {
                    TotalDownloadCount = idlist.Count;
                    DownloadCount      = 0;
                    foreach (var id in idlist)
                    {
                        try
                        {
                            var recipe = GwApi.GetRecipeDetails(id);
                            recipes.Add(id, recipe);
                            DownloadCount++;
                        }
                        catch (Exception e)
                        {
                            exceptions.Add(e);
                        }
                    }
                    tsk.TrySetResult(recipes);
                }
                catch (Exception e)
                {
                    exceptions.Add(e);
                    tsk.TrySetException(e);
                }
            });
            return(tsk.Task);
        }
예제 #25
0
        public void Test()
        {
            int build = GwApi.GetBuildNumber();

            GwApi.Network = new NetworkHandler();
            GwApi.GetColors(true);
            ResponseCache.Cache.Save();
        }
예제 #26
0
        public override string ToString()
        {
            var sb   = new StringBuilder();
            var item = GwApi.GetItemDetails(ItemId);

            sb.AppendFormat("{0} x{1}", item.Name, Count);
            return(sb.ToString());
        }
예제 #27
0
        private static async Task <ItemDetailsEntry> DownloadItemDetails(int id, bool ignoreCache = false)
        {
            var item = await Task.Run(
                () => GwApi.GetItemDetails(id, ignoreCache));

            Items[id] = item;
            return(item);
        }
예제 #28
0
        public static Gw2StatsMatchEntry GetGw2StatsMatchEntry(bool objectives = false, bool ratings = false, bool ignoreCache = true)
        {
            var        parser  = new Gw2StatsMatchEntryParser();
            ApiRequest request = new ApiRequest(Constants.gw2_matches);

            request.AddParameter("objectives", objectives ? "true" : "false");
            request.AddParameter("ratings", ratings ? "true" : "false");
            return(GwApi.HandleRequest(request, parser, Network, ignoreCache));
        }
예제 #29
0
        /// <summary>
        /// Downloads a complete list of available recipe ids.
        /// This is a full list of known recipe ids available via the GW2 API.
        /// </summary>
        /// <returns>IdList containing the ids</returns>
        public Task <IdList> DownloadCompleteIdListAsync()
        {
            TaskCompletionSource <IdList> tsk = new TaskCompletionSource <IdList>();

            ThreadPool.QueueUserWorkItem(o =>
            {
                tsk.TrySetResult(GwApi.GetRecipeIds());
            });
            return(tsk.Task);
        }
예제 #30
0
 private void _initAll()
 {
     GwApi.RegisterErrorHandler <ResponseException>(_exceptionHandler);
     BuildLabel.Text = GwApi.Build.ToString();
     _initItemsTab();
     _initGuildDetailsTab();
     _initColorsTab();
     _initMapTab();
     _initRecipeTab();
 }