public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            CreateObjectCommand createObjectCommand = CreateObjectCommand.Evaluate(engine, e.Command);
            if (createObjectCommand == null)
                return;

            IObjectService objectService = engine.GetService<IObjectService>();
            ISchemaService schemaService = engine.GetService<ISchemaService>();
            IDatabaseService databaseService = engine.GetService<IDatabaseService>();

            databaseService.EnsureTransaction();

            Type type = objectService.GetTypeByName(createObjectCommand.ClassName);

            //Create a new object of the class
            object obj = objectService.CreateObject(type);

            //Set the properties of the new object
            if (createObjectCommand.Values != null)
            {
                foreach (string propertyName in createObjectCommand.Values.Keys)
                {
                    if (schemaService.HasProperty(createObjectCommand.ClassName, propertyName))
                    {
                        objectService.SetProperty(obj, propertyName, createObjectCommand.Values[propertyName]);
                    }
                }
            }
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            DeleteObjectsCommand deleteObjectsCommand = DeleteObjectsCommand.Evaluate(engine, e.Command);
            if (deleteObjectsCommand == null)
                return;

            IObjectService objectService = engine.GetService<IObjectService>();
            IDatabaseService databaseService = engine.GetService<IDatabaseService>();

            databaseService.EnsureTransaction();

            Type type = objectService.GetTypeByName(deleteObjectsCommand.ClassName);

            IList objects = null;
            if (!string.IsNullOrEmpty(deleteObjectsCommand.Where))
                objects = objectService.GetObjects(type, deleteObjectsCommand.Where);
            else
                objects = objectService.GetObjects(type, deleteObjectsCommand.Match);

            if (objects != null)
            {
                foreach (object obj in objects)
                {
                    objectService.DeleteObject(obj);
                }
            }
        }
示例#3
0
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            CreateObjectCommand createObjectCommand = CreateObjectCommand.Evaluate(engine, e.Command);

            if (createObjectCommand == null)
            {
                return;
            }

            IObjectService   objectService   = engine.GetService <IObjectService>();
            ISchemaService   schemaService   = engine.GetService <ISchemaService>();
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();

            databaseService.EnsureTransaction();

            Type type = objectService.GetTypeByName(createObjectCommand.ClassName);

            //Create a new object of the class
            object obj = objectService.CreateObject(type);

            //Set the properties of the new object
            if (createObjectCommand.Values != null)
            {
                foreach (string propertyName in createObjectCommand.Values.Keys)
                {
                    if (schemaService.HasProperty(createObjectCommand.ClassName, propertyName))
                    {
                        objectService.SetProperty(obj, propertyName, createObjectCommand.Values[propertyName]);
                    }
                }
            }
        }
示例#4
0
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine         engine         = sender as IEngine;
            ILoggingService loggingService = engine.GetService <ILoggingService>();

            loggingService.WriteToLog(e.Command.ToString());
        }
        public void CreateProperty(CreatePropertyCommand createPropertyCommand, object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;
            ISchemaService schemaService = engine.GetService<ISchemaService>();
            IDatabaseService databaseService = engine.GetService<IDatabaseService>();

            string className = createPropertyCommand.ClassName;
            string propertyName = createPropertyCommand.Name;

            string propertyType = createPropertyCommand.Type.ToString();

            string columnName = createPropertyCommand.ColumnName;
            DbType columnType = databaseService.GetDbType(createPropertyCommand.Type, createPropertyCommand.StringLength); ;

            string tableName = schemaService.GetTableForClass(className);

            //Add a property to the class
            schemaService.CreateProperty(className, propertyName, propertyType);

            //Set the nullability of the property
            schemaService.SetPropertyMetaData(className, propertyName, PropertyMetaData.Nullable, createPropertyCommand.Nullable);

            //Add a column to the table
            schemaService.CreateColumn(tableName, columnName, columnType);

            //Set the nullability of the column
            schemaService.SetColumnMetaData(tableName, columnName, ColumnMetaData.Nullable, createPropertyCommand.Nullable);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(className, propertyName, tableName, columnName);
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            CreateClassCommand createClassCommand = CreateClassCommand.Evaluate(e.Command);

            if (createClassCommand == null)
            {
                return;
            }
            IEngine        engine        = sender as IEngine;
            ISchemaService schemaService = engine.GetService <ISchemaService>();

            string name         = createClassCommand.Name;
            string propertyName = "Id";
            string propertyType = "System.Int32";
            string columnName   = name + "Id";
            DbType columnType   = DbType.Int32;

            //Add the class to the schema
            schemaService.CreateClass(name);

            //Add a property to the class
            schemaService.CreateProperty(name, propertyName, propertyType);

            //Mark the property as an identity property
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Identity, true);

            //Mark the property as not nullable
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Nullable, false);

            //Mark the property as assigned by the data source
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.SourceAssigned, true);

            //Add the table to the schema
            schemaService.CreateTable(createClassCommand.TableName);

            //Add a column to the table
            schemaService.CreateColumn(createClassCommand.TableName, columnName, columnType);

            //Mark the column as a primary key column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.PrimaryKey, true);

            //Mark the column as not nullable
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.Nullable, false);

            //Mark the column as an auto increasing column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.AutoIncreaser, true);

            //Map the class to the table in the schema
            schemaService.MapClassToTable(name, createClassCommand.TableName);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(name, propertyName, createClassCommand.TableName, columnName);
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            CreatePropertyCommand createPropertyCommand = CreatePropertyCommand.Evaluate(engine, e.Command);
            if (createPropertyCommand == null)
                return;

            if (createPropertyCommand.Multiplicity == Multiplicity.None)
                CreateProperty(createPropertyCommand, sender, e);
            else
                CreateRelationship(createPropertyCommand, sender, e);
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            CreateClassCommand createClassCommand = CreateClassCommand.Evaluate(e.Command);
            if (createClassCommand == null)
                return;
            IEngine engine = sender as IEngine;
            ISchemaService schemaService = engine.GetService<ISchemaService>();

            string name = createClassCommand.Name;
            string propertyName = "Id";
            string propertyType = "System.Int32";
            string columnName = name + "Id";
            DbType columnType = DbType.Int32;

            //Add the class to the schema
            schemaService.CreateClass(name);

            //Add a property to the class
            schemaService.CreateProperty(name, propertyName, propertyType);

            //Mark the property as an identity property
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Identity, true);

            //Mark the property as not nullable
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.Nullable, false);

            //Mark the property as assigned by the data source
            schemaService.SetPropertyMetaData(name, propertyName, PropertyMetaData.SourceAssigned, true);

            //Add the table to the schema
            schemaService.CreateTable(createClassCommand.TableName);

            //Add a column to the table
            schemaService.CreateColumn(createClassCommand.TableName, columnName, columnType);

            //Mark the column as a primary key column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.PrimaryKey, true);

            //Mark the column as not nullable
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.Nullable, false);

            //Mark the column as an auto increasing column
            schemaService.SetColumnMetaData(createClassCommand.TableName, columnName, ColumnMetaData.AutoIncreaser, true);

            //Map the class to the table in the schema
            schemaService.MapClassToTable(name, createClassCommand.TableName);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(name, propertyName, createClassCommand.TableName, columnName);
        }
        public void CreateRelationship(CreatePropertyCommand createPropertyCommand, object sender, ExecutionCancelEventArgs e)
        {
            //IDatabaseService databaseService = engine.GetService<IDatabaseService>();
            //ISqlService sqlService = engine.GetService<ISqlService>();
            //ISchemaService schemaService = engine.GetService<ISchemaService>();

            ////Begins a new transaction or gets the current transaction
            //IDbTransaction transaction = databaseService.EnsureTransaction();

            //string tableName = schemaService.GetTableForClass(createPropertyCommand.ClassName);
            //DbType dbType = databaseService.GetDbType(createPropertyCommand.Type, createPropertyCommand.StringLength);

            ////Create the database table with the primary key column
            //sqlService.CreateColumn(transaction, tableName, createPropertyCommand.ColumnName, dbType, createPropertyCommand.Nullable);
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            CreateClassCommand createClassCommand = CreateClassCommand.Evaluate(e.Command);
            if (createClassCommand == null)
                return;

            IEngine engine = sender as IEngine;
            IDatabaseService databaseService = engine.GetService<IDatabaseService>();
            ISqlService sqlService = engine.GetService<ISqlService>();

            //Begins a new transaction or gets the current transaction
            IDbTransaction transaction = databaseService.EnsureTransaction();

            //Create the database table with the primary key column
            sqlService.CreateTableWithPrimaryKeyColumn(transaction, createClassCommand.TableName, createClassCommand.Name + "Id");
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            UpdateObjectsCommand updateObjectsCommand = UpdateObjectsCommand.Evaluate(engine, e.Command);
            if (updateObjectsCommand == null)
                return;

            IObjectService objectService = engine.GetService<IObjectService>();
            IDisplayService displayService = engine.GetService<IDisplayService>();

            Type type = objectService.GetTypeByName(updateObjectsCommand.ClassName);

            IList objects = objectService.GetObjects(type, updateObjectsCommand.Match);

            foreach (object obj in objects)
                displayService.Display(obj);
        }
示例#12
0
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            CreateClassCommand createClassCommand = CreateClassCommand.Evaluate(e.Command);

            if (createClassCommand == null)
            {
                return;
            }

            IEngine          engine          = sender as IEngine;
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();
            ISqlService      sqlService      = engine.GetService <ISqlService>();

            //Begins a new transaction or gets the current transaction
            IDbTransaction transaction = databaseService.EnsureTransaction();

            //Create the database table with the primary key column
            sqlService.CreateTableWithPrimaryKeyColumn(transaction, createClassCommand.TableName, createClassCommand.Name + "Id");
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;
            CreatePropertyCommand createPropertyCommand = CreatePropertyCommand.Evaluate(engine, e.Command);

            if (createPropertyCommand == null)
            {
                return;
            }

            if (createPropertyCommand.Multiplicity == Multiplicity.None)
            {
                CreateProperty(createPropertyCommand, sender, e);
            }
            else
            {
                CreateRelationship(createPropertyCommand, sender, e);
            }
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            UpdateObjectsCommand updateObjectsCommand = UpdateObjectsCommand.Evaluate(engine, e.Command);

            if (updateObjectsCommand == null)
            {
                return;
            }

            IObjectService  objectService  = engine.GetService <IObjectService>();
            IDisplayService displayService = engine.GetService <IDisplayService>();

            Type type = objectService.GetTypeByName(updateObjectsCommand.ClassName);

            IList objects = objectService.GetObjects(type, updateObjectsCommand.Match);

            foreach (object obj in objects)
            {
                displayService.Display(obj);
            }
        }
        public void OnExecuting(object sender, ExecutionCancelEventArgs e)
        {
            IEngine engine = sender as IEngine;

            DeleteObjectsCommand deleteObjectsCommand = DeleteObjectsCommand.Evaluate(engine, e.Command);

            if (deleteObjectsCommand == null)
            {
                return;
            }

            IObjectService   objectService   = engine.GetService <IObjectService>();
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();

            databaseService.EnsureTransaction();

            Type type = objectService.GetTypeByName(deleteObjectsCommand.ClassName);

            IList objects = null;

            if (!string.IsNullOrEmpty(deleteObjectsCommand.Where))
            {
                objects = objectService.GetObjects(type, deleteObjectsCommand.Where);
            }
            else
            {
                objects = objectService.GetObjects(type, deleteObjectsCommand.Match);
            }

            if (objects != null)
            {
                foreach (object obj in objects)
                {
                    objectService.DeleteObject(obj);
                }
            }
        }
示例#16
0
        //void Execute(ITypedCommand typedCommand)
        //{
        //    IList<ITypedCommand> typedCommands = new List<ITypedCommand>();
        //    typedCommands.Add(typedCommand);
        //    Execute(typedCommands);
        //}

        //void Execute(IList<ITypedCommand> typedCommands)
        //{
        //    IList<Command> commands = new List<Command>();

        //    foreach (ITypedCommand typedCommand in typedCommands)
        //        commands.Add(typedCommand.ToCommand());

        //    Execute(commands);
        //}

        public void Execute(string text)
        {
            //    Execute(Parser.Parse(text));
            //}

            //public void Execute(IList<Command> commands)
            //{
            IList <Command> commands   = Parser.Parse(text);
            EngineEventArgs engineArgs = new EngineEventArgs();

            foreach (IExecutor executor in executors)
            {
                executor.OnBeginning(this, engineArgs);
            }

            try
            {
                IDictionary <Command, ExecutionCancelEventArgs> commandArgs = new Dictionary <Command, ExecutionCancelEventArgs>();
                foreach (Command command in commands)
                {
                    ExecutionCancelEventArgs args = new ExecutionCancelEventArgs(command);
                    commandArgs[command] = args;
                    foreach (IExecutor executor in executors)
                    {
                        executor.OnExecuting(this, args);
                        //If one executor raises the cancel flag,
                        //the rest of the execution for the command is canceled
                        if (args.Cancel)
                        {
                            break;
                        }
                    }
                }

                foreach (Command command in commands)
                {
                    ExecutionCancelEventArgs cancelArgs = commandArgs[command];
                    if (!cancelArgs.Cancel)
                    {
                        ExecutionEventArgs args = new ExecutionEventArgs(command);
                        foreach (IExecutor executor in executors)
                        {
                            executor.OnExecuted(this, args);
                        }
                    }
                }

                //this is really not satisfactory:
                //should be replaced with elevating two-phase commits, i.e tx scopes
                foreach (IExecutor executor in executors)
                {
                    executor.OnCommitting(this, engineArgs);
                }
            }
            catch (Exception ex)
            {
                foreach (IExecutor executor in executors)
                {
                    executor.OnAborting(this, engineArgs);
                }
            }
        }
        public void CreateRelationship(CreatePropertyCommand createPropertyCommand, object sender, ExecutionCancelEventArgs e)
        {
            //IDatabaseService databaseService = engine.GetService<IDatabaseService>();
            //ISqlService sqlService = engine.GetService<ISqlService>();
            //ISchemaService schemaService = engine.GetService<ISchemaService>();

            ////Begins a new transaction or gets the current transaction
            //IDbTransaction transaction = databaseService.EnsureTransaction();

            //string tableName = schemaService.GetTableForClass(createPropertyCommand.ClassName);
            //DbType dbType = databaseService.GetDbType(createPropertyCommand.Type, createPropertyCommand.StringLength);

            ////Create the database table with the primary key column
            //sqlService.CreateColumn(transaction, tableName, createPropertyCommand.ColumnName, dbType, createPropertyCommand.Nullable);
        }
        public void CreateProperty(CreatePropertyCommand createPropertyCommand, object sender, ExecutionCancelEventArgs e)
        {
            IEngine          engine          = sender as IEngine;
            ISchemaService   schemaService   = engine.GetService <ISchemaService>();
            IDatabaseService databaseService = engine.GetService <IDatabaseService>();

            string className    = createPropertyCommand.ClassName;
            string propertyName = createPropertyCommand.Name;

            string propertyType = createPropertyCommand.Type.ToString();

            string columnName = createPropertyCommand.ColumnName;
            DbType columnType = databaseService.GetDbType(createPropertyCommand.Type, createPropertyCommand.StringLength);;

            string tableName = schemaService.GetTableForClass(className);

            //Add a property to the class
            schemaService.CreateProperty(className, propertyName, propertyType);

            //Set the nullability of the property
            schemaService.SetPropertyMetaData(className, propertyName, PropertyMetaData.Nullable, createPropertyCommand.Nullable);

            //Add a column to the table
            schemaService.CreateColumn(tableName, columnName, columnType);

            //Set the nullability of the column
            schemaService.SetColumnMetaData(tableName, columnName, ColumnMetaData.Nullable, createPropertyCommand.Nullable);

            //Map the property to the column in the schema
            schemaService.MapPropertyToColumn(className, propertyName, tableName, columnName);
        }