Beispiel #1
0
 public HookProcessor(Newtonsoft.Json.Linq.JArray hooks)
 {
     if (hooks != null && hooks.Count > 0)
     {
         foreach (var x in hooks)
         {
             HookListener listener = ConstructListener(x as JObject);
             if (listener != null)
             {
                 InstalledHooks.Add(listener);
             }
         }
     }
 }
Beispiel #2
0
        private HookListener ConstructListener(JObject x)
        {
            if (x == null)
            {
                return(null);
            }
            try
            {
                Type   hookType;
                JToken hookName;
                JToken filters;
                if (!x.TryGetValue("Event", out hookName) || hookName.Type != JTokenType.String)
                {
                    throw new Exception("Missing/invalid hook \"Event\" property!");
                }

                if (HookTypeMap.TryGetValue(hookName.ToString(), out hookType))
                {
                    x.TryGetValue("Filters", out filters);
                    List <KeyValuePair <string, IHookFilter> > filterList = ConstructFilters(hookName.ToString(), filters);

                    HookListener listener = new HookListener(filterList)
                    {
                        Event     = hookName.ToString(),
                        EventType = hookType
                    };
                    listener.Action = ConstructHookAction(x.GetValue("Action") as JObject);
                    return(listener);
                }
                else
                {
                    throw new Exception(string.Format("Couldn't find hook type \"{0}\"!", hookName));
                }
            }
            catch (Exception e)
            {
                Printer.PrintWarning("Error installing hook - exception: {0}\n\nHook code:\n{1}", e, x);
            }
            return(null);
        }