Esempio n. 1
0
        ////////////////

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

                    GetGlobalInbox.RetrieveGlobalInboxAsync((success, globalInbox) => {
                        try {
                            if (success)
                            {
                                args.SetGlobalInbox(globalInbox);
                            }
                            args.Found = success;

                            CustomLoadHooks.TriggerHook(GetGlobalInbox.GlobalInboxReceivedHookValidator, GetGlobalInbox.GlobalInboxReceivedHookValidatorKey, args);
                        } catch (Exception e) {
                            LogHelpers.Alert(e.ToString());
                        }
                    });
                }
            });
        }
Esempio n. 2
0
        private static void RetrieveGlobalInboxAsync(Action <bool, IDictionary <string, string> > onCompletion)
        {
            Action <Exception, string> onError = (e, output) => {
                if (e is JsonReaderException)
                {
                    LogHelpers.Alert("Bad JSON: " + output.Trunc(64));
                }
                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) => {
                IDictionary <string, string> globalInboxSet;

                if (success)
                {
                    try {
                        success = GetGlobalInbox.HandleGlobalInboxReceipt(jsonStr, out globalInboxSet);
                    } catch (Exception e) {
                        globalInboxSet = new Dictionary <string, string>();
                        onError(e, jsonStr);
                    }
                }
                else
                {
                    globalInboxSet = new Dictionary <string, string>();
                }

                onCompletion(success, globalInboxSet);
            };

            WebConnectionHelpers.MakeGetRequestAsync(GetGlobalInbox.GlobalInboxUrl, e => onError(e, ""), onWrappedCompletion);
        }
Esempio n. 3
0
        ////////////////

        internal void OnPostSetupContent()              //TODO
        {
            GetGlobalInbox.CacheAllGlobalInboxAsync();
        }