コード例 #1
0
        public static DeleteObjectsCommand Evaluate(IEngine engine, Command command)
        {
            if (command.Parameters.Count < 2)
            {
                return(null);
            }

            if (command.Parameters[0].Name.ToLower() != "delete")
            {
                return(null);
            }
            if (command.Parameters[0].Value != null)
            {
                return(null);
            }

            string name = command.Parameters[1].Name;

            if (string.IsNullOrEmpty(name))
            {
                return(null);
            }

            ISchemaService schemaService = engine.GetService <ISchemaService>();

            if (!schemaService.HasClass(name))
            {
                return(null);
            }

            DeleteObjectsCommand deleteObjectsCommand = new DeleteObjectsCommand(name);

            EvaluateMatch(command.Parameters[1].Value, name, schemaService, deleteObjectsCommand);

            if (command.Parameters.Count > 2)
            {
                switch (command.Parameters[2].Name.ToLower())
                {
                case "match":
                case "where":
                    EvaluateMatch(command.Parameters[2].Value, name, schemaService, deleteObjectsCommand);
                    break;

                case "query":
                    if (command.Parameters[2].Value != null)
                    {
                        deleteObjectsCommand.Where = command.Parameters[2].Value.ToString();
                    }
                    break;
                }
            }
            return(deleteObjectsCommand);
        }
コード例 #2
0
        public static DeleteObjectsCommand Evaluate(IEngine engine, Command command)
        {
            if (command.Parameters.Count < 2)
                return null;

            if (command.Parameters[0].Name.ToLower() != "delete")
                return null;
            if (command.Parameters[0].Value != null)
                return null;

            string name = command.Parameters[1].Name;
            if (string.IsNullOrEmpty(name))
                return null;

            ISchemaService schemaService = engine.GetService<ISchemaService>();
            if (!schemaService.HasClass(name))
                return null;

            DeleteObjectsCommand deleteObjectsCommand = new DeleteObjectsCommand(name);

            EvaluateMatch(command.Parameters[1].Value, name, schemaService, deleteObjectsCommand);

            if (command.Parameters.Count > 2)
            {
                switch (command.Parameters[2].Name.ToLower())
                {
                    case "match":
                    case "where":
                        EvaluateMatch(command.Parameters[2].Value, name, schemaService, deleteObjectsCommand);
                        break;
                    case "query":
                        if (command.Parameters[2].Value != null)
                            deleteObjectsCommand.Where = command.Parameters[2].Value.ToString();
                        break;
                }
            }
            return deleteObjectsCommand;
        }
コード例 #3
0
        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);
                }
            }
        }
コード例 #4
0
 private static void EvaluateMatch(object possibleMatch, string name, ISchemaService schemaService, DeleteObjectsCommand deleteObjectsCommand)
 {
     IList<Parameter> match = possibleMatch as IList<Parameter>;
     if (match != null)
     {
         foreach (Parameter parameter in match)
         {
             if (schemaService.HasProperty(name, parameter.Name))
             {
                 deleteObjectsCommand.Match[parameter.Name] = parameter.Value;
             }
         }
     }
 }
コード例 #5
0
        private static void EvaluateMatch(object possibleMatch, string name, ISchemaService schemaService, DeleteObjectsCommand deleteObjectsCommand)
        {
            IList <Parameter> match = possibleMatch as IList <Parameter>;

            if (match != null)
            {
                foreach (Parameter parameter in match)
                {
                    if (schemaService.HasProperty(name, parameter.Name))
                    {
                        deleteObjectsCommand.Match[parameter.Name] = parameter.Value;
                    }
                }
            }
        }