Example #1
0
        public static T GetLoader <T>() where T : class
        {
            for (int i = 0; i < _loaders.Count; ++i)
            {
                IDBFileLoader loader = _loaders[i];
                if (!(loader is T))
                {
                    continue;
                }

                return((T)loader);
            }

            Console.WriteLine(Resources.Error_unsupported_db_file_loader, typeof(T).Name);
            return(null);
        }
Example #2
0
        public static void Initial()
        {
            _loaders.Clear();

            Type[] types = Assembly.GetCallingAssembly().GetTypes();

            Stopwatch sw = new Stopwatch();

            sw.Start();
            for (int i = 0; i < types.Length; ++i)
            {
                Type type = types[i];
                try
                {
                    if (type.GetInterface(typeof(IDBFileLoader).Name) == null)
                    {
                        continue;
                    }

                    IDBFileLoader loader = Activator.CreateInstance(type) as IDBFileLoader;
                    if (loader == null)
                    {
                        throw new InvalidCastException("IDBFileLoader");
                    }

                    loader.Load();
                    _loaders.Add(loader);
                }
                catch (Exception e)
                {
                    Console.WriteLine(Resources.Error_while_loading_db_file, type.Name);
                    Console.WriteLine(e);
                    continue;
                }
            }
            sw.Stop();
            Console.WriteLine(Resources.Loaded_count_db_files, _loaders.Count, sw.ElapsedMilliseconds);
        }