예제 #1
0
        private void InitExternalWorkerDLLs(XDocument d)
        {
            lock (_syncObject)
            {
                string loadedTasks = "";
                string failedTasks = "";

                //do startup
                foreach (FileInfo fileInfo in new FileInfo(Assembly.GetExecutingAssembly().Location).Directory.GetFiles())
                {
                    if (!fileInfo.FullName.EndsWith(".dll"))
                    {
                        continue;
                    }

                    Assembly a = null;
                    try
                    {
                        a = Assembly.LoadFrom(fileInfo.FullName);
                    }
                    catch
                    {
                        Dump($"Could not load assembly {fileInfo.FullName}", EventLogEntryType.Warning);
                        continue;
                    }

                    foreach (Type t in a.GetTypes())
                    {
                        if (!t.IsAbstract && t.IsSubclassOf(typeof(LogTask)))
                        {
                            try
                            {
                                LogTask instance = (LogTask)Activator.CreateInstance(t);

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

                                _logTasks.Add(instance);
                            }
                            catch (Exception e)
                            {
                                failedTasks += $"\n{t.Name}\n Reason: {e.Message}";
                            }
                        }
                    }
                }
                if (loadedTasks.Length > 0 || failedTasks.Length > 0)
                {
                    Dump($"External DLLs loaded, loaded tasks are: \n{loadedTasks}" + (failedTasks.Length > 0 ? $"\nFailing Tasks:\n{failedTasks}" : ""), failedTasks.Length > 0 ? EventLogEntryType.Warning : EventLogEntryType.Information);
                }
                else
                {
                    Dump("No external DLLs loaded", EventLogEntryType.Information);
                }
            }
        }
예제 #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 = GenericIPBlockingTask.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);
                }
            }
        }