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

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

            CreateObjectCommand createObjectCommand = new CreateObjectCommand(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))
                    {
                        createObjectCommand.Values[parameter.Name] = parameter.Value;
                    }
                }
            }

            return createObjectCommand;
        }
Esempio n. 2
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]);
                    }
                }
            }
        }
Esempio n. 3
0
        public static CreateObjectCommand Evaluate(IEngine engine, Command command)
        {
            if (command.Parameters.Count < 2)
            {
                return(null);
            }

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

            CreateObjectCommand createObjectCommand = new CreateObjectCommand(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))
                    {
                        createObjectCommand.Values[parameter.Name] = parameter.Value;
                    }
                }
            }

            return(createObjectCommand);
        }