public static UpdateObjectsCommand Evaluate(IEngine engine, Command command)
        {
            if (command.Parameters.Count < 3)
                return null;

            if (command.Parameters[0].Name.ToLower() != "update")
                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;

            if (command.Parameters[2].Name.ToLower() != "match")
                return null;
            IList<Parameter> match = command.Parameters[2].Value as IList<Parameter>;

            UpdateObjectsCommand updateObjectsCommand = new UpdateObjectsCommand(name);

            IList<Parameter> parameters = command.Parameters[1].Value as IList<Parameter>;
            if (parameters != null)
            {
                foreach (Parameter parameter in parameters)
                {
                    if (schemaService.HasProperty(name, parameter.Name))
                    {
                        updateObjectsCommand.Values[parameter.Name] = parameter.Value;
                    }
                }
            }

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

            return updateObjectsCommand;
        }
        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);
            }
        }
Example #3
0
        public static UpdateObjectsCommand Evaluate(IEngine engine, Command command)
        {
            if (command.Parameters.Count < 3)
            {
                return(null);
            }

            if (command.Parameters[0].Name.ToLower() != "update")
            {
                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);
            }

            if (command.Parameters[2].Name.ToLower() != "match")
            {
                return(null);
            }
            IList <Parameter> match = command.Parameters[2].Value as IList <Parameter>;

            UpdateObjectsCommand updateObjectsCommand = new UpdateObjectsCommand(name);

            IList <Parameter> parameters = command.Parameters[1].Value as IList <Parameter>;

            if (parameters != null)
            {
                foreach (Parameter parameter in parameters)
                {
                    if (schemaService.HasProperty(name, parameter.Name))
                    {
                        updateObjectsCommand.Values[parameter.Name] = parameter.Value;
                    }
                }
            }

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

            return(updateObjectsCommand);
        }