private void AddEntity(BCSModel bcsModel, string name, string display)
        {
            BCSEntity entity = new BCSEntity();

            entity.Name = name;
            entity.DisplayName = display;
            entity.CreateCreateOperation = true;
            entity.CreateDeleteOperation = true;
            entity.CreateReadOperation = true;
            entity.CreateUpdateOperation = true;

            bcsModel.Entities.Add(entity);

            AddField(entity, "Field1", "Field 1", typeof(System.Int32), true, true, false);
            AddField(entity, "Field2", "Field 2", typeof(System.String), false, false, false);
            AddField(entity, "Field3", "Field 3", typeof(System.String), false, false, true);
        }
        public override Dictionary<string, object> GetInitialArguments()
        {
            Dictionary<string, object> arguments = new Dictionary<string, object>();

            arguments.Add("BCSDatabase", "AdventureWorks");

            //add here BCSModel
            BCSModel bcsModel = new BCSModel();

            AddEntity(bcsModel, "Entity1", "Entity 1");
            AddEntity(bcsModel, "Entity2", "Entity 2");
            AddEntity(bcsModel, "Entity3", "Entity 3");

            arguments.Add("BCSModel", bcsModel);

            return arguments;
        }
 void bcsTreeControl1_BCSModelChanged(BCSModel changedModel)
 {
     bcsModel = changedModel;
 }
        public void UpdateResult()
        {
            string warnings = "";
            string errors = "";
            bool dataIsValid = true;

            BCSModel model = new BCSModel();
            model.Entities.Clear();

            foreach (TreeNode tableNode in treeView1.Nodes)
            {
                if (IsNodeChecked(tableNode))
                {
                    BCSEntity generateEntity = tableNode.Tag as BCSEntity;
                    model.Entities.Add(generateEntity);
                    generateEntity.Fields.Clear();

                    foreach (TreeNode fieldNode in tableNode.Nodes)
                    {
                        if (IsNodeChecked(fieldNode))
                        {
                            BCSField generateField = fieldNode.Tag as BCSField;
                            generateEntity.Fields.Add(generateField);
                        }
                    }
                }
            }

            //check the model
            foreach (BCSEntity entity in model.Entities)
            {
                if (string.IsNullOrEmpty(entity.Name) || string.IsNullOrEmpty(entity.DisplayName))
                {
                    errors += "Error: The name or the display name of an entity is empty." + Environment.NewLine;
                    dataIsValid = false;
                }
                if (entity.Name.Contains(" "))
                {
                    errors += "Error: The name of entity '" + entity.Name + "' contains a space. This is not supported by the recipe." + Environment.NewLine;
                    dataIsValid = false;
                }

                bool hasKey = false;
                foreach (BCSField field in entity.Fields)
                {
                    SetAssocationName(field, entity);

                    if (field.IsKey)
                    {
                        hasKey = true;
                    }
                    if (string.IsNullOrEmpty(field.Name) || string.IsNullOrEmpty(field.DisplayName))
                    {
                        errors += "Error: The name or the display name of a field in entity '" + field.Name + "' is empty." + Environment.NewLine;
                        dataIsValid = false;
                    }
                    if (field.Name.Contains(" "))
                    {
                        errors += "Error: The name of field '" + field.Name + "' contains a space. This is not supported by the recipe." + Environment.NewLine;
                        dataIsValid = false;
                    }
                    if ((field.DataType == typeof(Int64)) || (field.DataType == typeof(Byte)) || (field.DataType == typeof(Byte[])))
                    {
                        warnings += "Error: The type of field '" + field.Name + "' is not supported in external lists." + Environment.NewLine;
                    }

                    if (IsDesignMode)
                    {
                        if (!string.IsNullOrEmpty(field.ReferencedEntity))
                        {
                            //check if Reference is valid
                            if (!model.IsValidAssociation(field))
                            {

                                errors += "Error: The association of '" + field.Name + "' to entity '" + field.ReferencedEntity + "' is not valid." + Environment.NewLine;
                                dataIsValid = false;
                            }
                        }
                    }
                }
                if (!hasKey)
                {
                    errors += "Error: The entity '" + entity.Name + "' contains to key field." + Environment.NewLine;
                    dataIsValid = false;
                }
                if (string.IsNullOrEmpty(entity.TitleField))
                {
                    warnings += "Warning: The entity '" + entity.Name + "' has no title field." + Environment.NewLine;
                }
            }

            textBoxInfo.Text = errors + warnings;

            if ((model.Entities.Count == 0) || !dataIsValid)
            {
                //if no elements, then return null
                model = null;
            }

            if (BCSModelChanged != null)
            {
                BCSModelChanged(model);
                // MessageBox.Show("Event raised");
            }
        }