////////////////

        private static void CacheAllModTagsAsync()
        {
            ThreadPool.QueueUserWorkItem(_ => {
                lock (GetModTags.MyLock) {
                    var mymod = ModHelpersMod.Instance;
                    var args  = new ModTagsLoadHookArguments {
                        Found = false
                    };

                    GetModTags.RetrieveAllModTagsAsync((success, modTags) => {
                        try {
                            if (success)
                            {
                                args.SetTagMods(modTags);
                            }
                            args.Found = success;

                            CustomLoadHooks.TriggerHook(GetModTags.TagsReceivedHookValidator, GetModTags.TagsReceivedHookValidatorKey, args);
                        } catch (Exception e) {
                            LogHelpers.Alert(e.ToString());
                        }
                    });
                }
            });
        }
        ////////////////

        internal void OnPostModsLoad()
        {
            if (!ModHelpersMod.Config.DisableModTags)
            {
                GetModTags.CacheAllModTagsAsync();
            }
        }
        ////////////////

        internal void OnPostSetupContent()
        {
            if (ModHelpersMod.Instance.Config.IsCheckingModTags)
            {
                GetModTags.CacheAllModTagsAsync();
            }
        }
        ////////////////

        private static void CacheAllModTagsAsync()
        {
            ThreadPool.QueueUserWorkItem(_ => {
                lock (GetModTags.MyLock) {
                    var mymod = ModHelpersMod.Instance;
                    var args  = new ModTagsPromiseArguments {
                        Found = false
                    };

                    GetModTags.RetrieveAllModTagsAsync((modTags, found) => {
                        try {
                            if (found)
                            {
                                args.SetTagMods(modTags);
                            }
                            args.Found = found;

                            Promises.TriggerValidatedPromise(GetModTags.TagsReceivedPromiseValidator, GetModTags.PromiseValidatorKey, args);
                        } catch (Exception e) {
                            LogHelpers.Alert(e.ToString());
                        }
                    });
                }
            });
        }
Beispiel #5
0
        private static void RetrieveAllModTagsAsync(Action <bool, ModTagsDatabase> onCompletion)
        {
            Action <Exception, string> onError = (e, output) => {
                if (e is JsonReaderException)
                {
                    LogHelpers.Alert("Bad JSON: " + output.Trunc(256));
                }
                else if (e is WebException || e is NullReferenceException)
                {
                    LogHelpers.Alert(("'" + output.Trunc(64) + "'" ?? "...") + " - " + e.Message);
                }
                else
                {
                    LogHelpers.Alert(("'" + output.Trunc(64) + "'" ?? "...") + " - " + e.ToString());
                }
            };

            Action <bool, string> onWrappedCompletion = (success, jsonStr) => {
                ModTagsDatabase modTagSet;

                if (success)
                {
                    try {
                        success = GetModTags.HandleModTagsReceipt(jsonStr, out modTagSet);
                    } catch (Exception e) {
                        modTagSet = new ModTagsDatabase();
                        onError(e, jsonStr);
                    }
                }
                else
                {
                    modTagSet = new ModTagsDatabase();
                }

                onCompletion(success, modTagSet);
            };

            WebConnectionHelpers.MakeGetRequestAsync(GetModTags.ModTagsUrl, e => onError(e, ""), onWrappedCompletion);
        }