using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Reflection;
using LibraryManager;

namespace Engineer
{
    public class LibraryManager
    {
        public LibraryManagerList Library = new LibraryManagerList();

        public class LibraryManagerList : List<EngineerLibrary>
        {
            public void Add(string libraryPath)
            {
                DirectoryInfo di = new DirectoryInfo(libraryPath);
                if (!di.Exists)
                    di.Create();

                foreach (FileInfo file in di.GetFiles())
                {
                    Assembly asm;
                    try
                    {
                        asm = Assembly.LoadFile(file.FullName);
                    }
                    catch
                    {
                        continue;
                    }
                    foreach (Type type in asm.GetTypes())
                    {
                        if (type.BaseType == typeof(EngineerLibrary))
                        {
                            this.Add((EngineerLibrary)Activator.CreateInstance(type));
                        }
                    }
                }
            }

            public void AddLibrary(EngineerLibrary Library)
            {
                this.Add(Library);
            }
        }

    }
}
