Ejemplo n.º 1
0
        public static void GetModProfiles(IEnumerable <int> modIds,
                                          Action <List <ModProfile> > onSuccess,
                                          Action <WebRequestError> onError)
        {
            List <int>        missingModIds = new List <int>(modIds);
            List <ModProfile> modProfiles   = new List <ModProfile>(missingModIds.Count);

            foreach (ModProfile profile in CacheClient.AllModProfiles())
            {
                if (missingModIds.Contains(profile.id))
                {
                    missingModIds.Remove(profile.id);
                    modProfiles.Add(profile);
                }
            }

            if (missingModIds.Count == 0)
            {
                if (onSuccess != null)
                {
                    onSuccess(modProfiles);
                }
            }
            else
            {
                // - Filter -
                RequestFilter modFilter = new RequestFilter();
                modFilter.sortFieldName = GetAllModsFilterFields.id;
                modFilter.fieldFilters[GetAllModsFilterFields.id]
                    = new InArrayFilter <int>()
                    {
                    filterArray = missingModIds.ToArray()
                    };

                Action <List <ModProfile> > onGetMods = (profiles) =>
                {
                    modProfiles.AddRange(profiles);

                    CacheClient.SaveModProfiles(profiles);

                    if (onSuccess != null)
                    {
                        onSuccess(modProfiles);
                    }
                };

                // - Get All Events -
                ModManager.FetchAllResultsForQuery <ModProfile>((p, s, e) => APIClient.GetAllMods(modFilter, p, s, e),
                                                                onGetMods,
                                                                onError);
            }
        }