Ejemplo n.º 1
0
        private static bool LoadDllAndRunDataLoader(Dictionary<string, string> config, ILoaderConfigHandler configHandler, IStatusHandler statusHandler)
        {

            //UGLY CODE BEGINS
            string path = "";
            if (config["PATH"] == "")
            {
                if (Directory.Exists("DataLoaders"))
                {
                    path = Environment.CurrentDirectory + @"\DataLoaders\" + config["DLL"] + ".dll";
                }
                else
                {
                    Console.WriteLine("Folder DataLoaders not found, created folder");
                    Directory.CreateDirectory("DataLoaders");
                    return false;
                }
            }
            else
            {
                path = config["PATH"] + config["DLL"] + ".dll";
            }
            //UGLY CODE ENDS

            //bool oneDataLoader = config["TYPENAME"] != "";
            try
            {
                Assembly plugin = Assembly.LoadFile(path);
                Type[] types = plugin.GetTypes();

                foreach (var type in types)
                {
                    //TODO: Find a cleaner and more readeble solution to this if possible
                    //This terrible implementation is trying to do the following:
                    //If the name parameter in config is specified we only want to create an instance of that class and run the DataLoader
                    //if no name is set then we want to execute RunDataLoader for all classes that implement BaseDataLoader

                    //if (oneDataLoader)
                    //{
                        if (type.Name == config["TYPENAME"])
                        {
                            RunDataLoader(type, configHandler, statusHandler);
                        return true;
                        }
                    //}
                    //else
                    //{
                    //    RunDataLoader(type, propertyHandler, statusHandler);
                    //}
                }

                return false;
            }
            catch (FileNotFoundException ex)
            {
                Console.WriteLine("File: " + path + " exception came up: " + ex.Message);
                return false;
            }
        }
        public SqlLoaderConfigHandlerTester()
        {
            string dbName = "LoaderTestDB";
            LocalDb.CreateLocalDb(dbName, DBCreatorScripts.GetSqlLoaderConfigHandlerTestSqlSetup(), true);

            _connection = LocalDb.GetConnectionString(dbName);  //@"Data Source=localhost\SQLEXPRESS;Database=LoaderDB;Integrated Security=True;";
            _configHandler = new SQLServerLoaderConfigHandler(_connection);

        }
Ejemplo n.º 3
0
        public void InitializeHandlers(ILoaderConfigHandler configHandler, IStatusHandler statusHandler)
        {
            _guid = Guid.NewGuid().ToString();

            //Note: This implementation form is sub-optimal in terms of performance.  Perhaps it is better to find another way to to this
            string dllName = this.GetType().Assembly.GetName().Name; //System.Reflection.Assembly.GetExecutingAssembly().FullName;

            string typeName = this.GetType().Name;
            _config = configHandler.GetLoaderConfig(dllName, typeName);
            _statusHandler = statusHandler;
        }
Ejemplo n.º 4
0
        private static bool SetHandlers(ref ILoaderConfigHandler configStore, ref IStatusHandler statusHandler)
        {
            string reportStoreType = "";
            string reportStoreConnectionString = "";
            string configStoreName = "";
            string configStoreConnectionString = "";

            try
            {
                IniParser ini = new IniParser("conf.ini");
                reportStoreType = ini.GetSetting("STATUS_REPORT", "REPORT_TO");
                reportStoreConnectionString = ini.GetSetting("STATUS_REPORT", "REPORT_CONNECTION");
                configStoreName = ini.GetSetting("CONFIG_STORE", "TYPE");
                configStoreConnectionString = ini.GetSetting("CONFIG_STORE", "CONNECTION");
            }
            catch (System.IO.FileNotFoundException ex)
            {
                Console.WriteLine(ex.Message);
                return false;
            }

            //Setup property store
            //Currently we hardcode this to SQL Server, the infrastructure to reflect on it is in place
            configStore = new Aih.DataLoader.ConfigHandlers.SQLServerLoaderConfigHandler(configStoreConnectionString);


            //Setup where to report status to
            //Currently we hardcode this to SQL Server, the infrastructure to reflect on it is in place
            statusHandler = new Aih.DataLoader.StatusHandlers.SQLServerStatusHandler(reportStoreConnectionString);

            return true;
        }
Ejemplo n.º 5
0
        private static void RunDataLoader(Type type, ILoaderConfigHandler configHandler, IStatusHandler statusHandler)
        {

            if (type.IsSubclassOf(typeof(BaseDataLoader)))
            {
                var loader = (BaseDataLoader)Activator.CreateInstance(type);
                loader.InitializeHandlers(configHandler, statusHandler);
                loader.RunDataLoader();
            }
        }