Exemplo n.º 1
0
 public void Connect(string connectionString)
 {
     MRC.GetInstance().ConnectionString = connectionString;
     try
     {
         using (DbConnection cnn = MRC.GetConnection())
         {
             cnn.Open();
             object test = null;
             using (IDbCommand cmd = MRC.GetCommand(cnn))
             {
                 cmd.CommandText = "SELECT Test = 1";
                 test            = cmd.ExecuteScalar();
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception("Cannot connect to database.\n", ex);
     }
 }
Exemplo n.º 2
0
        public void LoadCustomizers()
        {
            Customizers.Clear();

            List <IDlo> customizations = null;

            using (DbConnection cnn = MRC.GetConnection())
            {
                var p = new Persisters.DBCustomizationPersister();
                p.Where = "Active = 1";
                p.CNN   = MRC.GetConnection();
                p.CNN.Open();

                customizations = p.GetData(null);
            }
            var files = Directory.GetFiles(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "*.dll");

            foreach (string fileName in files)
            {
                var ass = Assembly.LoadFile(fileName);
                List <System.Type> types = new List <System.Type>();
                types.AddRange(ass.GetTypes());
                foreach (System.Type typ in types)
                {
                    var customizationAttrib = typ.GetCustomAttribute <Attributes.CustomizationAttribute>();
                    if (customizationAttrib != null && (customizations.Find(dlo => (string)dlo.ColumnValues["CustomizationKey"] == customizationAttrib.CustomizationKey)) != null)
                    {
                        Customizer customizer = (Customizer)System.Activator.CreateInstance(typ);
                        customizer.CustomizationKey = customizationAttrib.CustomizationKey;
                        Customizers.Add(customizer);

                        OnCustomizationLoaded(this, new CustomizationLoadedEventArgs()
                        {
                            Message = "Customizer loaded (CustomizationKey: " + customizationAttrib.CustomizationKey + ").", Customizer = customizer
                        });
                    }
                }
            }
        }
Exemplo n.º 3
0
        public List <IDBModule> LoadModulesFromDB(DBTimeLiner dBTimeLiner)
        {
            //var ret = New List(Of IDBModule);
            var ret = new List <IDBModule>();

            using (DbConnection cnn = MRC.GetConnection())
            {
                try
                {
                    cnn.Open();

                    var per = new Persisters.DBModulePersister();
                    per.Where = "Active = 1";
                    per.CNN   = cnn;
                    List <IDlo> res = per.GetData(null);

                    foreach (IDlo module in res)
                    {
                        string errorMessage      = "";
                        string message           = "";
                        string className         = "";
                        string assemblyName      = "DBTimeLiners.DBModules";
                        string defaultSchemaName = "";
                        string description       = "";
                        try
                        {
                            className         = (string)module.ColumnValues["ClassName"];
                            defaultSchemaName = (string)module.ColumnValues["DefaultSchemaName"];
                            description       = (string)module.ColumnValues["Description"];

                            IDBModule m = (IDBModule)Activator.CreateInstance(assemblyName, assemblyName + "." + className).Unwrap();
                            m.DefaultSchemaName = defaultSchemaName;
                            m.Parent            = dBTimeLiner;

                            message = string.Format(
                                @"Successfully instanced module (ClassName: {0}, AssemblyName: {1}, DefaultSchemaName: {2}, Description: {3}).", className, assemblyName, defaultSchemaName, description);

                            ret.Add(m);
                        }
                        catch (Exception ex)
                        {
                            errorMessage = string.Format(
                                @"Error instancing module from database config (ClassName: {0}, AssemblyName: {1}, DefaultSchemaName: {2}, DefaultSchemaName: {3}),
ErrorMessage: 
{4}", className, assemblyName, defaultSchemaName, description, ex.Message);

                            ret.Clear();
                            break;
                        }
                        finally
                        {
                            OnModuleLoaded(this, new ModuleLoadedEventArgs()
                            {
                                ErrorMessage = errorMessage, Message = message
                            });
                        }
                    }
                }
                catch (Exception)
                {
                    // CONSIDER - do some logging
                    throw;
                }
                foreach (IDBModule m in ret)
                {
                    DBModules.Add(m);
                    dBTimeLiner.DBModules.Add(m);
                }
            }

            return(ret);
        }