Example #1
0
        internal static GenericTask FromXML(XElement element)
        {
            GenericTask t =
                new GenericTask()
            {
                Name = element.Name.LocalName
            };

            t.Description      = element.Element("Description").Value.Trim();
            t._lockTime        = int.Parse(element.Element("LockTime").Value.Trim());
            t.OnlyNew          = bool.Parse(element.Element("OnlyNew").Value.Trim());
            t.EventAge         = int.Parse(element.Element("EventAge").Value.Trim());
            t._triggerCount    = int.Parse(element.Element("TriggerCount").Value.Trim());
            t._permaBanTrigger = int.Parse(element.Element("PermaBanCount").Value.Trim());

            t.EventPath.AddRange(element.Element("EventPath").Value.Trim().Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries));
            foreach (XElement e in element.Element("RegexBoosters").Elements("Booster"))
            {
                t._boosters.Add(e.Value.Trim());
            }
            try
            {
                t._regex = new Regex(element.Element("Regex").Value.Trim(), RegexOptions.Compiled);
            }
            catch
            {
                throw new ArgumentException($"Regex not defined or invalid for Task: {t.Name}");
            }
            return(t);
        }
Example #2
0
        private void InitWorkersFromConfig(XDocument d)
        {
            lock (_syncObject)
            {
                string loadedTasks = "";
                string failedTasks = "";

                try
                {
                    HashSet <string> taskNames = new HashSet <string>();
                    foreach (string taskToLoad in from e in d.Root.Element("GenericTaskLoader").Elements("Load") select e.Value)
                    {
                        taskNames.Add(taskToLoad);
                    }
                    foreach (string s in taskNames)
                    {
                        var e = d.Root.Element(s);
                        try
                        {
                            LogTask instance = GenericTask.FromXML(e);

                            loadedTasks += $"\n{instance.Name}\n{ instance.Description}\n";

                            _logTasks.Add(instance);
                        }
                        catch (Exception ex)
                        {
                            failedTasks += $"\n{s}\n Reason: {ex.Message}";
                        }
                    }
                }
                catch
                {
                    Dump("Did not load default tasks. None present, or the XML is corrupted", EventLogEntryType.Warning);
                    throw;
                }

                if (loadedTasks.Length > 0 || failedTasks.Length > 0)
                {
                    Dump($"Generic Tasks loaded, loaded tasks are: \n{loadedTasks}" + (failedTasks.Length > 0 ? $"\nFailing Tasks:\n{failedTasks}" : ""), failedTasks.Length > 0 ? EventLogEntryType.Warning : EventLogEntryType.Information);
                }
                else
                {
                    Dump("No Generic Tasks loaded", EventLogEntryType.Information);
                }
            }
        }