Пример #1
0
        /// <summary>
        /// Event Handler Constructor
        /// </summary>
        private EventHandler()
        {
            IEnumerator<String> events = resourceManager.GetApplicationDescriptor().GetEvents();
            while (events.MoveNext())
            {
                String eventNotifier = events.Current;

                Object model = ClassUtils.CreateClassInstance(eventNotifier);
                if (model is ISiminovEvents)
                {
                    coreEventHandler = (ISiminovEvents)model;
                }
                else if (model is IDatabaseEvents)
                {
                    databaseEventHandler = (IDatabaseEvents)model;
                }
            }
        }
Пример #2
0
        /// <summary>
        /// Event Handler Constructor
        /// </summary>
        private EventHandler()
        {
            IEnumerator <String> events = resourceManager.GetApplicationDescriptor().GetEvents();

            while (events.MoveNext())
            {
                String eventNotifier = events.Current;

                Object model = ClassUtils.CreateClassInstance(eventNotifier);
                if (model is ISiminovEvents)
                {
                    coreEventHandler = (ISiminovEvents)model;
                }
                else if (model is IDatabaseEvents)
                {
                    databaseEventHandler = (IDatabaseEvents)model;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// It process all DatabaseDescriptor.xml and initialize Database and stores in Resource Manager.
        /// </summary>
        protected static void ProcessDatabase()
        {
            ApplicationDescriptor            applicationDescriptor = coreResourceManager.GetApplicationDescriptor();
            IEnumerator <DatabaseDescriptor> databaseDescriptors   = applicationDescriptor.GetDatabaseDescriptors();

            while (databaseDescriptors.MoveNext())
            {
                DatabaseDescriptor databaseDescriptor = databaseDescriptors.Current;

                String         databasePath   = new DatabaseUtils().GetDatabasePath(databaseDescriptor);
                DatabaseBundle databaseBundle = null;

                try
                {
                    databaseBundle = DatabaseHelper.CreateDatabase(databaseDescriptor);
                }
                catch (DatabaseException databaseException)
                {
                    Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while getting database instance from database factory, DATABASE-DESCRIPTOR: " + databaseDescriptor.GetDatabaseName() + ", " + databaseException.GetMessage());
                    throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                }

                IDatabaseImpl database     = databaseBundle.GetDatabase();
                IQueryBuilder queryBuilder = databaseBundle.GetQueryBuilder();



                /*
                 * If Database exists then open and return.
                 * If Database does not exists create the database.
                 */

                String databaseName = databaseDescriptor.GetDatabaseName();
                if (!databaseName.EndsWith(".db"))
                {
                    databaseName = databaseName + ".db";
                }


                bool fileExists = FileUtils.DoesFileExists(databasePath, databaseName, FileUtils.LOCAL_FOLDER);
                if (fileExists)
                {
                    /*
                     * Open Database
                     */
                    try
                    {
                        database.OpenOrCreate(databaseDescriptor);
                    }
                    catch (DatabaseException databaseException)
                    {
                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while opening database, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }


                    /*
                     * Enable Foreign Key Constraints
                     */
                    try
                    {
                        database.ExecuteQuery(databaseDescriptor, null, Constants.SQLITE_DATABASE_QUERY_TO_ENABLE_FOREIGN_KEYS_MAPPING);
                    }
                    catch (DatabaseException databaseException)
                    {
                        FileUtils.DeleteFile(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);

                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while executing query to enable foreign keys, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }


                    /*
                     * Safe MultiThread Transaction
                     */
                    /*try
                     * {
                     *  database.ExecuteMethod(Constants.SQLITE_DATABASE_ENABLE_LOCKING, databaseDescriptor.IsTransactionSafe());
                     * }
                     * catch (DatabaseException databaseException)
                     * {
                     *  FileUtils.DoesFileExists(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);
                     *
                     *  Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while enabling locking on database, " + databaseException.GetMessage());
                     *  throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                     * }*/



                    /*
                     * Upgrade Database
                     */
                    try
                    {
                        DatabaseHelper.UpgradeDatabase(databaseDescriptor);
                    }
                    catch (DatabaseException databaseException)
                    {
                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while upgrading database, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }
                }
                else
                {
                    /*
                     * Create Database Directory
                     */
                    try
                    {
                        FileUtils.GetFolder(databasePath, FileUtils.LOCAL_FOLDER);
                    }
                    catch (System.Exception exception)
                    {
                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "Exception caught while creating database directories, DATABASE-PATH: " + databasePath + ", DATABASE-DESCRIPTOR: " + databaseDescriptor.GetDatabaseName() + ", " + exception.Message);
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", exception.Message);
                    }


                    /*
                     * Create Database File.
                     */
                    try
                    {
                        database.OpenOrCreate(databaseDescriptor);
                    }
                    catch (DatabaseException databaseException)
                    {
                        FileUtils.DeleteFile(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);

                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while creating database, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }


                    /*
                     * Set Database Version
                     */
                    IDictionary <String, Object> parameters = new Dictionary <String, Object>();
                    parameters.Add(IQueryBuilder.FORM_UPDATE_DATABASE_VERSION_QUERY_DATABASE_VERSION_PARAMETER, databaseDescriptor.GetVersion());


                    try
                    {
                        String updateDatabaseVersionQuery = queryBuilder.FormUpdateDatabaseVersionQuery(parameters);
                        database.ExecuteQuery(databaseDescriptor, null, updateDatabaseVersionQuery);
                    }
                    catch (DatabaseException databaseException)
                    {
                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "Database Exception caught while updating database version, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }



                    IDatabaseEvents databaseEventHandler = coreResourceManager.GetDatabaseEventHandler();
                    if (databaseEventHandler != null)
                    {
                        databaseEventHandler.OnDatabaseCreated(databaseDescriptor);
                    }


                    /*
                     * Enable Foreign Key Constraints
                     */
                    try
                    {
                        database.ExecuteQuery(databaseDescriptor, null, Constants.SQLITE_DATABASE_QUERY_TO_ENABLE_FOREIGN_KEYS_MAPPING);
                    }
                    catch (DatabaseException databaseException)
                    {
                        FileUtils.DeleteFile(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);

                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while executing query to enable foreign keys, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }


                    /*
                     * Safe MultiThread Transaction
                     */
                    /*try
                     * {
                     *  database.ExecuteMethod(Constants.SQLITE_DATABASE_ENABLE_LOCKING, databaseDescriptor.IsTransactionSafe());
                     * }
                     * catch (DatabaseException databaseException)
                     * {
                     *  FileUtils.DeleteFile(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);
                     *
                     *  Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while enabling locking on database, " + databaseException.GetMessage());
                     *  throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                     * }*/



                    /*
                     * Create Tables
                     */
                    try
                    {
                        DatabaseHelper.CreateTables(databaseDescriptor.OrderedEntityDescriptors());
                    }
                    catch (DatabaseException databaseException)
                    {
                        FileUtils.DeleteFile(databasePath, databaseDescriptor.GetDatabaseName(), FileUtils.LOCAL_FOLDER);

                        Log.Log.Error(typeof(Siminov).FullName, "ProcessDatabase", "DatabaseException caught while creating tables, " + databaseException.GetMessage());
                        throw new DeploymentException(typeof(Siminov).FullName, "ProcessDatabase", databaseException.GetMessage());
                    }
                }
            }
        }