// ---------[ MOD TEAMS ]--------- public static void GetModTeam(int modId, Action <List <ModTeamMember> > onSuccess, Action <WebRequestError> onError) { List <ModTeamMember> cachedModTeam = CacheClient.LoadModTeam(modId); if (cachedModTeam != null) { if (onSuccess != null) { onSuccess(cachedModTeam); } } else { // - Get All Team Members - Action <List <ModTeamMember> > onGetModTeam = (modTeam) => { CacheClient.SaveModTeam(modId, modTeam); if (onSuccess != null) { onSuccess(modTeam); } }; ModManager.FetchAllResultsForQuery <ModTeamMember>((p, s, e) => APIClient.GetAllModTeamMembers(modId, RequestFilter.None, p, s, e), onGetModTeam, onError); } }
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); } }
public static void FetchAndCacheAllModProfiles(Action onSuccess, Action <WebRequestError> onError) { Action <List <ModProfile> > onModProfilesReceived = (modProfiles) => { CacheClient.SaveModProfiles(modProfiles); if (onSuccess != null) { onSuccess(); } }; ModManager.FetchAllResultsForQuery <ModProfile>((p, s, e) => APIClient.GetAllMods(RequestFilter.None, p, s, e), onModProfilesReceived, onError); }
public static void GetAuthenticatedUserMods(Action <List <ModProfile> > onSuccess, Action <WebRequestError> onError) { List <int> cachedModIds = CacheClient.LoadAuthenticatedUserMods(); if (cachedModIds != null) { ModManager.GetModProfiles(cachedModIds, onSuccess, onError); } else { RequestFilter userModsFilter = new RequestFilter(); userModsFilter.fieldFilters[GetUserModFilterFields.gameId] = new EqualToFilter <int>() { filterValue = APIClient.gameId }; Action <List <ModProfile> > onGetMods = (modProfiles) => { CacheClient.SaveModProfiles(modProfiles); List <int> modIds = new List <int>(modProfiles.Count); foreach (ModProfile profile in modProfiles) { modIds.Add(profile.id); } CacheClient.SaveAuthenticatedUserMods(modIds); if (onSuccess != null) { onSuccess(modProfiles); } }; // - Get All Events - ModManager.FetchAllResultsForQuery <ModProfile>((p, s, e) => APIClient.GetUserMods(userModsFilter, p, s, e), onGetMods, onError); } }
public static void FetchAllUserEvents(int fromTimeStamp, int untilTimeStamp, Action <List <UserEvent> > onSuccess, Action <WebRequestError> onError) { // - Filter - RequestFilter userEventFilter = new RequestFilter(); userEventFilter.sortFieldName = GetUserEventsFilterFields.dateAdded; userEventFilter.fieldFilters[GetUserEventsFilterFields.dateAdded] = new RangeFilter <int>() { min = fromTimeStamp, isMinInclusive = false, max = untilTimeStamp, isMaxInclusive = true, }; // - Get All Events - ModManager.FetchAllResultsForQuery <UserEvent>((p, s, e) => APIClient.GetUserEvents(userEventFilter, p, s, e), onSuccess, onError); }
public static void ApplyModEventsToCache(IEnumerable <ModEvent> modEvents, Action <List <ModProfile> > profilesAvailableCallback = null, Action <List <ModProfile> > profilesEditedCallback = null, Action <List <int> > profilesUnavailableCallback = null, Action <List <int> > profilesDeletedCallback = null, Action <List <ModfileStub> > profileBuildsUpdatedCallback = null, Action onSuccess = null, Action <WebRequestError> onError = null) { List <int> addedIds = new List <int>(); List <int> editedIds = new List <int>(); List <int> modfileChangedIds = new List <int>(); List <int> removedIds = new List <int>(); List <int> deletedIds = new List <int>(); // Sort by event type foreach (ModEvent modEvent in modEvents) { switch (modEvent.eventType) { case ModEventType.ModAvailable: { addedIds.Add(modEvent.modId); } break; case ModEventType.ModEdited: { editedIds.Add(modEvent.modId); } break; case ModEventType.ModfileChanged: { modfileChangedIds.Add(modEvent.modId); } break; case ModEventType.ModUnavailable: { removedIds.Add(modEvent.modId); } break; case ModEventType.ModDeleted: { deletedIds.Add(modEvent.modId); } break; } } // --- Process Add/Edit/ModfileChanged --- List <int> modsToFetch = new List <int>(addedIds.Count + editedIds.Count + modfileChangedIds.Count); modsToFetch.AddRange(addedIds); modsToFetch.AddRange(editedIds); modsToFetch.AddRange(modfileChangedIds); if (modsToFetch.Count > 0) { // - Filter & Pagination - RequestFilter modsFilter = new RequestFilter(); modsFilter.fieldFilters[GetAllModsFilterFields.id] = new InArrayFilter <int>() { filterArray = modsToFetch.ToArray(), }; // - Get Mods - Action <List <ModProfile> > onGetMods = (updatedProfiles) => { // - Create Update Lists - List <ModProfile> addedProfiles = new List <ModProfile>(addedIds.Count); List <ModProfile> editedProfiles = new List <ModProfile>(editedIds.Count); List <ModfileStub> modfileChangedStubs = new List <ModfileStub>(modfileChangedIds.Count); foreach (ModProfile profile in updatedProfiles) { int idIndex; // NOTE(@jackson): If added, ignore everything else if ((idIndex = addedIds.IndexOf(profile.id)) >= 0) { addedIds.RemoveAt(idIndex); addedProfiles.Add(profile); } else { if ((idIndex = editedIds.IndexOf(profile.id)) >= 0) { editedIds.RemoveAt(idIndex); editedProfiles.Add(profile); } if ((idIndex = modfileChangedIds.IndexOf(profile.id)) >= 0) { modfileChangedIds.RemoveAt(idIndex); modfileChangedStubs.Add(profile.activeBuild); } } } // - Save changed to cache - CacheClient.SaveModProfiles(updatedProfiles); // --- Notifications --- if (profilesAvailableCallback != null && addedProfiles.Count > 0) { profilesAvailableCallback(addedProfiles); } if (profilesEditedCallback != null && editedProfiles.Count > 0) { profilesEditedCallback(editedProfiles); } if (profileBuildsUpdatedCallback != null && modfileChangedStubs.Count > 0) { profileBuildsUpdatedCallback(modfileChangedStubs); } }; ModManager.FetchAllResultsForQuery <ModProfile>((p, s, e) => APIClient.GetAllMods(modsFilter, p, s, e), onGetMods, null); } // --- Process Removed --- if (removedIds.Count > 0) { // TODO(@jackson): Compare with subscriptions foreach (int modId in removedIds) { CacheClient.DeleteMod(modId); } if (profilesUnavailableCallback != null) { profilesUnavailableCallback(removedIds); } } if (deletedIds.Count > 0) { // TODO(@jackson): Check install state foreach (int modId in deletedIds) { CacheClient.DeleteMod(modId); } if (profilesDeletedCallback != null) { profilesDeletedCallback(deletedIds); } } }