private static void RetrieveAllModInfoAsync(Action <bool, BasicModInfoDatabase> onCompletion)
        {
            Action <Exception, string> onError = (e, jsonStr) => {
                if (e == null)
                {
                    LogHelpers.Alert((jsonStr.Trunc(64) ?? "") + " - Invalid exception?");
                }
                else if (e is JsonReaderException)
                {
                    LogHelpers.Alert("Bad JSON: " + jsonStr.Trunc(256));
                }
                else if (e is WebException || e is NullReferenceException)
                {
                    LogHelpers.Alert(("'" + jsonStr.Trunc(64) + "'" ?? "...") + " - " + e.Message);
                }
                else
                {
                    LogHelpers.Alert(("'" + jsonStr.Trunc(64) + "'" ?? "...") + " - " + e.ToString());
                }
            };

            Action <bool, string> onWrappedCompletion = (success, jsonStr) => {
                BasicModInfoDatabase modInfoDb;

                if (success)
                {
                    try {
                        success = GetModInfo.HandleModInfoReceipt(jsonStr, out modInfoDb);
                    } catch (Exception e) {
                        modInfoDb = new BasicModInfoDatabase();
                        onError(e, jsonStr);
                    }
                }
                else
                {
                    modInfoDb = new BasicModInfoDatabase();
                }

                onCompletion(success, modInfoDb);
            };

            WebConnectionHelpers.MakeGetRequestAsync(GetModInfo.ModInfoUrl, e => onError(e, ""), onWrappedCompletion);
        }
Beispiel #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);
        }
Beispiel #3
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);
        }