Пример #1
0
        public void AddProvider <T>() where T : IJournalProvider, new()
        {
            T obj = new T();

            obj.Load();

            RegisteredJournalProviders.Add(obj);
        }
Пример #2
0
        private void ReadAllProviders(bool readFromOnlyCurrentAssembly = false)
        {
            RegisteredJournalProviders = Assembly
                                         .GetExecutingAssembly()
                                         .GetTypes()
                                         .Where(m => m.GetInterfaces().Contains(typeof(IJournalProvider)))
                                         .Select(m => m.GetConstructor(Type.EmptyTypes).Invoke(null) as IJournalProvider)
                                         .ToList();

            if (!readFromOnlyCurrentAssembly)
            {
                var files = Directory.GetFiles("plugins\\log\\providers\\", "*.dll");
                if (files.Length <= 0)
                {
                    return;
                }

                foreach (var file in files)
                {
                    try
                    {
                        var assembly = Assembly.LoadFile(file);
                        if (assembly != null)
                        {
                            var providers = assembly.GetTypes().Where((x) => x.GetInterfaces().Contains(typeof(IJournalProvider)))
                                            .Select((x) => x.GetConstructor(Type.EmptyTypes)?.Invoke(null) as IJournalProvider)
                                            .ToList();

                            foreach (var provider in providers)
                            {
                                RegisteredJournalProviders.Add(provider);
                            }
                        }
                    }
                    catch
                    { } // ignore
                }
            }

            foreach (var item in RegisteredJournalProviders)
            {
                item.Load();
            }
        }