Exemple #1
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);
        }
        public Task <EntryDictionary <int, ColorEntry> > ParseAsync(object apiResponse)
        {
            string json = ParserResponseHelper.GetResponseString(apiResponse);

            return(Task.Run(async() =>
            {
                var temp = await ParserHelper <Dictionary <string, EntryDictionary <int, ColorEntry> > > .ParseAsync(json).ConfigureAwait(false);
                EntryDictionary <int, ColorEntry> colors = temp["colors"];
                foreach (var pair in colors)
                {
                    pair.Value.Id = pair.Key;
                    pair.Value.Cloth.Type = ColorItemType.Cloth;
                    pair.Value.Leather.Type = ColorItemType.Leather;
                    pair.Value.Metal.Type = ColorItemType.Metal;
                }
                if (colors == null)
                {
                    GwApi.Logger.Error("Failed parsing colors - {0}", Thread.CurrentContext.ContextID);
                }
                else
                {
                    GwApi.Logger.Info("Parsed {0} Colors - {1}", colors.Values.Count, Thread.CurrentContext.ContextID);
                }
                return colors;
            }));
        }
Exemple #3
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);
        }
Exemple #4
0
        /// <summary>
        /// Downloads and updates <seealso cref="Recipes"/> with any unknown recipes.
        /// <remarks><code>
        /// 1. Downloads a complete list of available recipe ids.
        /// 2. Compiles a list of unknown recipe ids.
        /// 3. Downloads the unknown recipes
        /// 4. Adds the new recipes to <seealso cref="Recipes"/>
        /// 5. Updates ResponseCache</code></remarks>
        /// </summary>
        /// <returns></returns>
        public async Task DownloadRecipesAsync()
        {
            // Load recipes from cache.
            // We can do this at the same time as some other operations so don't await
            Task <EntryDictionary <int, RecipeDetailsEntry> > loadCacheTask = GetCachedRecipesAsync();

            Status = "Downloading ID List";
            // get list of available recipes (id list)
            IdList idList = await DownloadCompleteIdListAsync().ConfigureAwait(false);

            // make sure the cache is finished loading.  The next task requires our loadCacheTask to be finished
            Recipes = await loadCacheTask.ConfigureAwait(false) ?? new EntryDictionary <int, RecipeDetailsEntry>();

            // get unknown id list;
            Status = "Determining unknown ids";
            IList <int> unknownIds = await GetUnknownIdsAsync(idList).ConfigureAwait(false);

            // download unknown ids;
            Status = "Downloading Unknown Recipes";
            EntryDictionary <int, RecipeDetailsEntry> recipes = await DownloadRecipesAsync(unknownIds).ConfigureAwait(false);

            // add new recipes to .Recipes
            Status = "Merging Unknown Recipes into Recipe Dictionary";
            await MergeRecipesAsync(recipes).ConfigureAwait(false);

            Status = "Recipe Dicitonary Updated";
            CacheRecipesAsync();
        }
Exemple #5
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);
        }
        /// <summary>
        /// Open the Dictionary OWLReact.
        ///
        /// <returns>The dictionary reaction-processes</returns>
        /// </summary>
        private EntryDictionary OpeningDictionary()
        {
            DictionaryDatabase db   = new DictionaryDatabase();
            EntryDictionary    dict = db.GetDictionary("reaction-processes");

            return(dict);
        }
 private async void LoadAsyncData()
 {
     InfoText = "Loading Data";
     _worldData = await _worldFetch.GetWorldNamesAsync();
     var worlds = _worldData.Values.Select(x => x.Name).ToList();
     worlds.Sort();
     Worlds = worlds.ToArray<String>();
     InfoText = "Load Complete";
 }
Exemple #10
0
        private Task MergeRecipesAsync(EntryDictionary <int, RecipeDetailsEntry> recipes)
        {
            Action <object> act = r =>
            {
                Recipes.AddRange(r as EntryDictionary <int, RecipeDetailsEntry>);
            };
            var task = Task.Factory.StartNew(act, recipes);

            return(task);
        }
Exemple #11
0
        private async void LoadAsyncData()
        {
            InfoText   = "Loading Data";
            _worldData = await _worldFetch.GetWorldNamesAsync();

            var worlds = _worldData.Values.Select(x => x.Name).ToList();

            worlds.Sort();
            Worlds   = worlds.ToArray <String>();
            InfoText = "Load Complete";
        }
Exemple #12
0
        /// <summary>
        /// Open the Dictionary OWLReact.
        /// </summary>
        /// <param name="nameDict">Name of the Dictionary</param>
        /// <param name="reaction">The IReactionProcess</param>
        /// <returns>The entry for this reaction</returns>
        private EntryReact InitiateDictionary(string nameDict, IReactionProcess reaction)
        {
            DictionaryDatabase db = new DictionaryDatabase();

            dictionary = db.GetDictionary(nameDict);
            string entryString = reaction.Specification.SpecificationReference;

            entryString = entryString.Substring(entryString.IndexOf('#') + 1);

            return((EntryReact)dictionary[entryString.ToLowerInvariant()]);
        }
Exemple #13
0
 private ItemManager()
 {
     _worker = new BackgroundWorker()
     {
         WorkerReportsProgress = true,
     };
     _worker.DoWork             += _worker_DoWork;
     _worker.ProgressChanged    += _worker_ProgressChanged;
     _worker.RunWorkerCompleted += _worker_RunWorkerCompleted;
     Items   = new EntryDictionary <int, ItemDetailsEntry>();
     ItemIds = new IdList();
 }
/*
 *      public static EntryDictionary<TKey, TElement> ToEntryDictionary<TSource, TKey, TElement>(
 *          this IEnumerable<TSource> source, Func<TSource, TKey> keySelector, Func<TSource, TElement> elementSelector,
 *          IEqualityComparer<TKey> comparer)
 *      {
 *          ExceptionHelper.ThrowOnNull(source, "source");
 *          ExceptionHelper.ThrowOnNull(keySelector, "keySelector");
 *          ExceptionHelper.ThrowOnNull(elementSelector, "elementSelector");
 *          EntryDictionary<TKey, TElement> dictionary = new EntryDictionary<TKey, TElement>(comparer);
 *          foreach (TSource source1 in source)
 *              dictionary.Add(keySelector(source1), elementSelector(source1));
 *          return dictionary;
 *      }
 */

        public static EntryDictionary <TKey, TSource> ToEntryDictionary <TKey, TSource>(this IEnumerable <TSource> enumerable,
                                                                                        Func <TSource, TKey> keyselector)
        {
            ExceptionHelper.ThrowOnNull(keyselector, "keyselector");
            EntryDictionary <TKey, TSource> dictionary = new EntryDictionary <TKey, TSource>();

            foreach (TSource element in enumerable)
            {
                dictionary.Add(keyselector(element), element);
            }
            return(dictionary);
        }
        public bool DictionaryBuildCacheStrategyExpiredTest(int buildOffset)
        {
            var            strat      = new DictionaryCacheStrategy <EntryDictionary <int, ResponseObject>, int, ResponseObject>();
            var            buildStrat = new BuildVersionCacheStrategy();
            ResponseObject ro         = new ResponseObject();

            ro.CacheStrategy = buildStrat;
            EntryDictionary <int, ResponseObject> responses = new EntryDictionary <int, ResponseObject>();

            responses.Add(1, ro);
            responses.LastUpdateBuild = GwApi.Build - buildOffset;
            return(strat.Expired(responses));
        }
 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;
 }
Exemple #17
0
        public void Refresh(bool forceUpdate = false)
        {
            EntryDictionary <int, ColorEntry> colors = null;

            lock (Colors)
            {
                Status = "Updating";
                colors = GwApi.GetColors(forceUpdate);
                Status = "Done";
                Colors = colors;
            }
            OnColorsUpdated(colors);
        }
        public void Append(FeatureCWPAnalysisSiteMetrics metrics, Boolean SubLevelCall)
        {
            AddEntry(metrics);

            if (purpose != FeatureCWPAnalysisSettings.AnalysisPurpose.application)
            {
                featuresByClass.Add(metrics.featureClass, metrics.term);

                List <Double> scores = metrics.GetVectors(true, true);

                EntryDictionary.AddEntry(metrics.term, scores.ToArray(), false);
            }
        }
Exemple #19
0
        /// <summary>
        /// Compiles a list of unknown ids
        /// </summary>
        /// <param name="knownRecipes">known recipes</param>
        /// <param name="idList">a list of recipe ids</param>
        /// <returns>list of recipe ids.  This is any id that is in <paramref name="idList"/> but not in <paramref name="knownRecipes"/></returns>
        private IList <int> _getUnknownIds(EntryDictionary <int, RecipeDetailsEntry> knownRecipes, IList <int> idList)
        {
            List <int> unknownIds = new List <int>();

            foreach (int id in idList)
            {
                if (knownRecipes.ContainsKey(id) == false)
                {
                    unknownIds.Add(id);
                }
            }
            return(unknownIds);
        }
        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);
        }
        public async Task <EntryDictionary <int, MapEntry> > ParseAsync(object apiResponse)
        {
            string json  = ParserResponseHelper.GetResponseString(apiResponse);
            var    maps2 = await ParserHelper <Dictionary <string, EntryDictionary <int, MapEntry> > > .ParseAsync(json).ConfigureAwait(false);

            EntryDictionary <int, MapEntry> maps = null;

            if (maps2 != null)
            {
                maps = maps2["maps"];
                foreach (var map in maps)
                {
                    map.Value.Id = map.Key;
                }
            }
            return(maps ?? new EntryDictionary <int, MapEntry>());
        }
        public EntryDictionary <string, Gw2StatsStatusEntry> Parse(object apiResponse)
        {
            IRestResponse response = apiResponse as IRestResponse;

            if (response == null)
            {
                return(null);
            }
            string json = response.Content;
            var    temp = ParserHelper <Dictionary <string, EntryDictionary <string, Gw2StatsStatusEntry> > > .Parse(json);

            EntryDictionary <string, Gw2StatsStatusEntry> apiStatuses = temp["api"];

            foreach (var status in apiStatuses)
            {
                status.Value.Id = status.Key;
            }
            return(apiStatuses);
        }
        private async void LoadAsync()
        {
            LoadingMsg  = "Loading Data";
            _eventNames = await _em.GetEventNamesAsync();

            _eventDetails = await _em.GetEventDetailsAsync();

            _mapNames = await _mf.GetMapNamesAsync();

            Events = _eventNames.Select(x => x.Value.Name).ToList();
            Events.Sort();

            _mapToEvents = _eventDetails.GroupBy(x => x.MapId, y => _eventNames[y.EventId]).ToDictionary(k => _mapNames[k.Key], v => v.ToList <EventNameEntry>());

            _eventsWithNames = _eventDetails.Select(x => new KeyValuePair <MapNameEntry, EventNameEntry>(_mapNames[x.MapId], _eventNames[x.EventId])).ToList();
            _eventsWithNames.OrderBy(x => x.Key.Name).ThenBy(y => y.Value.Name);
            //NOTE: build add just for testing
            //Events.ForEach(c => WatchedEvents.Add(c));
            LoadingMsg = "Load Complete";
        }
        /// <summary>
        /// Set the IReactionProcess to analyzed
        ///
        /// <param name="reactionClass">The IReactionProcess class</param>
        // @throws Exception
        /// </summary>
        public void SetReaction(Type reactionClass)
        {
            if (dictionary == null)
            {
                dictionary = OpeningDictionary();
            }

            var obj = reactionClass.GetConstructor(Type.EmptyTypes).Invoke(Array.Empty <object>());

            if (!(obj is IReactionProcess))
            {
                throw new CDKException("The passed reaction class must be a IReactionProcess");
            }
            else if (reaction == null)
            {
                reaction = (IReactionProcess)obj;

                entryString = reaction.Specification.SpecificationReference;
                entryString = entryString.Substring(entryString.IndexOf("#") + 1);
            }
        }
Exemple #25
0
        public void DownloadRecipes()
        {
            ResponseCache.Cache.Load("RecipeDetailsDictionary.bin");
            EntryDictionary <int, RecipeDetailsEntry> recipes =
                ResponseCache.Cache.Get("RecipeDetailsDictionary") as EntryDictionary <int, RecipeDetailsEntry> ??
                new EntryDictionary <int, RecipeDetailsEntry>();
            MockNetHandler handler = new MockNetHandler();
            var            ids     = GwApi.GetRecipeIds(true);

            ResponseCache.Cache.Save("RecipeDetailsDictionary.bin");
            GwApi.Network = handler;
            recipes.Url   = "RecipeDetailsDictionary";
            foreach (var id in ids)
            {
                if (recipes.ContainsKey(id) == false)
                {
                    var recipe = GwApi.GetRecipeDetails(id);
                    recipes[recipe.RecipeId] = recipe;
                }
            }
            ResponseCache.Cache.Add("RecipeDetailsDictionary", recipes);
            ResponseCache.Cache.Save("RecipeDetailsDictionary.bin");
        }
        public EntryDictionary <int, ColorEntry> Parse(object apiResponse)
        {
            string json = ParserResponseHelper.GetResponseString(apiResponse);
            var    temp = ParserHelper <Dictionary <string, EntryDictionary <int, ColorEntry> > > .Parse(json);

            EntryDictionary <int, ColorEntry> colors = temp["colors"];

            foreach (var pair in colors)
            {
                pair.Value.Id           = pair.Key;
                pair.Value.Cloth.Type   = ColorItemType.Cloth;
                pair.Value.Leather.Type = ColorItemType.Leather;
                pair.Value.Metal.Type   = ColorItemType.Metal;
            }
            if (colors == null)
            {
                GwApi.Logger.Error("Failed parsing colors");
            }
            else
            {
                GwApi.Logger.Info("Parsed {0} Colors", colors.Values.Count);
            }
            return(colors);
        }
        public async Task <EntryDictionary <int, ContinentEntry> > ParseAsync(object apiResponse)
        {
            string json       = ParserResponseHelper.GetResponseString(apiResponse);
            var    dictionary = await ParserHelper <Dictionary <string, EntryDictionary <int, ContinentEntry> > > .ParseAsync(json).ConfigureAwait(false);

            EntryDictionary <int, ContinentEntry> continents = null;

            try
            {
                continents = dictionary["continents"];

                foreach (var pair in continents)
                {
                    pair.Value.Id = pair.Key;
                }
                GwApi.Logger.Info("Parsed {0} Colors - {1}",
                                  "ID:" + string.Join(",", continents.Keys), Thread.CurrentContext.ContextID);
            }
            catch (Exception e)
            {
                GwApi.Logger.Error(e);
            }
            return(continents ?? new EntryDictionary <int, ContinentEntry>());
        }
Exemple #28
0
 private ColorsManager()
 {
     Colors = new EntryDictionary <int, ColorEntry>();
 }
        private async void LoadAsync()
        {
            LoadingMsg = "Loading Data";
            _eventNames = await _em.GetEventNamesAsync();
            _eventDetails = await _em.GetEventDetailsAsync();
            _mapNames = await _mf.GetMapNamesAsync();
            Events = _eventNames.Select(x => x.Value.Name).ToList();
            Events.Sort();

            _mapToEvents = _eventDetails.GroupBy(x => x.MapId, y => _eventNames[y.EventId]).ToDictionary(k => _mapNames[k.Key], v => v.ToList<EventNameEntry>());

            _eventsWithNames = _eventDetails.Select(x => new KeyValuePair<MapNameEntry, EventNameEntry>(_mapNames[x.MapId], _eventNames[x.EventId])).ToList();
            _eventsWithNames.OrderBy(x => x.Key.Name).ThenBy(y => y.Value.Name);
            //NOTE: build add just for testing
            //Events.ForEach(c => WatchedEvents.Add(c));
            LoadingMsg = "Load Complete";
        }
Exemple #30
0
        public async Task <String> GetMapNameAsync(int mapID)
        {
            EntryDictionary <int, MapNameEntry> retVal = await GwApi.GetMapNamesAsync();

            return(retVal[mapID].Name);
        }
Exemple #31
0
        public async Task <EntryDictionary <int, MapNameEntry> > GetMapNamesAsync()
        {
            EntryDictionary <int, MapNameEntry> retVal = await GwApi.GetMapNamesAsync();

            return(retVal);
        }
        public async Task <EntryDictionary <int, WorldNameEntry> > GetWorldNamesAsync()
        {
            EntryDictionary <int, WorldNameEntry> x = await GwApi.GetWorldNamesAsync();

            return(x);
        }
        public void DownloadAllItemDetails()
        {
            // Warning this will take quite a long time.
            // It is highly recommended that you save this information as it is not expected to change often if at all
            // Luckily we can use the ResponseCache to do this for us.
            // Here is an example to download the data/save it, and allow for updates later

            {
                // lets obtain all the currently known item ids
                var itemIds = GwApi.GetItemIds();
                var itemDetailsDictionary = new EntryDictionary <int, ItemDetailsEntry>(itemIds.Count);
                // This could take 20-30 minutes
                // keep in mind there are currently 27,000+ items at the time of writting this
                foreach (var id in itemIds)
                {
                    var item = GwApi.GetItemDetails(id);
                    itemDetailsDictionary.Add(id, item);
                }

                // This is important, We should save this for nice and fast retrival
                // While our individual items are already stored in the ResponseCache
                // The dictionary is not, and it is much more convenient to just grab the entire dictionary
                // This will allow us easy access to search for items
                // We are going to store it using ItemDetailsDictionary
                ResponseCache.Cache.Add("ItemDetailsDictionary", itemDetailsDictionary);
            }

            {
                // lets update our complete dictionary of items we've already downloaded earlier
                // first lets obtain the complete list of item ids
                // notice how we passed (true) this time.  This will skip our response cache and for an update.
                // We want to make sure we have a complete list as of right now, not yesterday
                var itemIds = GwApi.GetItemIds(true);
                // Lets get the item dictionary we already have (Remember we stored it in cache)
                var itemDetailsDictionary =
                    ResponseCache.Cache.Get("ItemDetailsDictionary") as EntryDictionary <int, ItemDetailsEntry> ?? new EntryDictionary <int, ItemDetailsEntry>();
                // This could take 20-30 minutes
                // keep in mind there are currently 27,000+ items at the time of writting this
                foreach (var id in itemIds)
                {
                    if (itemDetailsDictionary.ContainsKey(id) == false)
                    {
                        var item = GwApi.GetItemDetails(id);
                        itemDetailsDictionary.Add(id, item);
                    }
                }

                // Lets update our ResponseCache with our updated item dictionary
                ResponseCache.Cache.Add("ItemDetailsDictionary", itemDetailsDictionary);
            }

            {
                // We have this big dictionary that took a really long time to download
                // What can we do with it?
                // Store it in a DataBase? sure that's not a bad idea.  Could make searching through it easy and quick.
                // We can also use LINQ - this is a great idea for those non-repeated retrival instances
                // First lets get our item dictionary
                var itemDetailsDictionary =
                    ResponseCache.Cache.Get("ItemDetailsDictionary") as EntryDictionary <int, ItemDetailsEntry> ?? new EntryDictionary <int, ItemDetailsEntry>();

                // Search for an item by name
                var item = itemDetailsDictionary.Values.SingleOrDefault(i => i.Name == "Godrock Amulet");
                // Get all lvl 80 items
                var itemsByLevel = itemDetailsDictionary.Values.Where(i => i.Level == 80);
                // What about all lvl 80 weapons
                itemsByLevel = itemDetailsDictionary.Values.Where(i => i.Level == 80 && i.ItemType == ItemType.Weapon);
                // Lets reduce the previous query to all swords; then we'll have all lvl 80 swords
                var swords =
                    itemsByLevel.Where(i => i.WeaponDetails.Type == ItemDetailsEntry.WeaponInfo.WeaponType.Sword);

                // Lets get all swords within 2 levels of 40
                itemsByLevel = itemDetailsDictionary.Values.Where(i => i.ItemType == ItemType.Weapon && i.WeaponDetails.Type == ItemDetailsEntry.WeaponInfo.WeaponType.Sword && i.Level >= 38 && i.Level <= 42);
            }
        }