コード例 #1
0
 private static void LoadColumn(CriteriaPropertyCollection loadProperties)
 {
     foreach (var property in loadProperties)
     {
         property.DbBindColumn.LoadColumn(GeneratorController.Catalog);
     }
 }
コード例 #2
0
        private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var result = new CriteriaPropertyCollection();
            var index  = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                          CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
コード例 #3
0
        private static CriteriaPropertyCollection GetFakeCreateCriteria(CslaObjectInfo info, int createIndex)
        {
            var isCSharp = GeneratorController.Current.CurrentUnit.GenerationParams.OutputLanguage == CodeLanguage.CSharp;
            var result   = new CriteriaPropertyCollection();
            var index    = 0;

            foreach (var crit in info.CriteriaObjects)
            {
                if (crit.IsGetter && !crit.IsCreator)
                {
                    index++;
                    if (index == createIndex)
                    {
                        var criteriaPropertyCollection = CriteriaPropertyCollection.Clone(crit.Properties);
                        foreach (var criteriaProperty in criteriaPropertyCollection)
                        {
                            if (isCSharp)
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperCS.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                            else
                            {
                                criteriaProperty.UnitOfWorkFactoryParameter = "true, " +
                                                                              CslaTemplateHelperVB.GetDataTypeInitExpression(criteriaProperty, criteriaProperty.PropertyType);
                            }
                        }
                        result.AddRange(criteriaPropertyCollection);
                        break;
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        public void Build()
        {
            if (string.IsNullOrEmpty(_validationError))
            {
                // display start up message to the user
                var sb = new StringBuilder();
                sb.AppendFormat("Starting the build of {0} relation.\r\n", ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());

                if (MainLoadingScheme == LoadingScheme.ParentLoad)
                {
                    MainLoadProperties.Clear();
                }
                if (SecondaryLoadingScheme == LoadingScheme.ParentLoad)
                {
                    SecondaryLoadProperties.Clear();
                }

                if (RelationType == ObjectRelationType.OneToMany)
                {
                    var factory = new ObjectRelationsFactory(Parent, this);

                    factory.FacadeObjectInfo             = factory.MainObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.MainRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, MainObject,
                                                                  MainPropertyName, MainCollectionTypeName,
                                                                  MainItemTypeName, MainLoadingScheme,
                                                                  MainLoadProperties, MainLoadParameters, MainLazyLoad));
                    factory.PopulateRelationObjects(MainItemTypeName, factory.MainRootCriteriaProperties);
                }
                else
                {
                    var factory = new ObjectRelationsFactory(Parent, this);

                    factory.FacadeObjectInfo             = factory.MainObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.MainRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, MainObject,
                                                                  MainPropertyName, MainCollectionTypeName,
                                                                  MainItemTypeName, MainLoadingScheme,
                                                                  MainLoadProperties, MainLoadParameters, MainLazyLoad));

                    factory.FacadeObjectInfo             = factory.SecondaryObjectInfo;
                    factory.FacadeRootCriteriaProperties = CriteriaPropertyCollection.Clone(factory.SecondaryRootCriteriaProperties);
                    factory.BuildRelationObjects(new EntityFacade(Parent, RelationType, SecondaryObject,
                                                                  SecondaryPropertyName, SecondaryCollectionTypeName,
                                                                  SecondaryItemTypeName, SecondaryLoadingScheme,
                                                                  SecondaryLoadProperties, SecondaryLoadParameters,
                                                                  SecondaryLazyLoad));

                    factory.PopulateRelationObjects(MainItemTypeName, factory.MainRootCriteriaProperties);
                    factory.PopulateRelationObjects(SecondaryItemTypeName, factory.SecondaryRootCriteriaProperties);
                }

                // display end message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Relation build end.\r\n");
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }
        }
コード例 #5
0
        internal static CriteriaPropertyCollection Clone(CriteriaPropertyCollection masterCritProps)
        {
            var newCritProps = new CriteriaPropertyCollection();

            foreach (var critProp in masterCritProps)
            {
                var newCritProp = new CriteriaProperty();
                newCritProp.DbBindColumn = (DbBindColumn)critProp.DbBindColumn.Clone();
                ((Property)newCritProp).Clone(critProp);
                newCritProp.ParameterValue = critProp.ParameterValue;

                newCritProps.Add(newCritProp);
            }

            return(newCritProps);
        }
コード例 #6
0
        public void PopulateRelationObjects(string itemTypeName, CriteriaPropertyCollection rootCriteriaProperties)
        {
            var currentCslaObject = _cslaObjects.Find(itemTypeName);
            var selectedColumns   = FilterOutSelectedColumns(currentCslaObject, rootCriteriaProperties);

            if (selectedColumns.Count > 0)
            {
                var currentFactory = new ObjectFactory(_currentUnit, currentCslaObject);
                currentFactory.AddProperties(currentCslaObject, _dbObject, _resultSet, selectedColumns, true, true);
            }

            var removeList = FindInvalidProperties(currentCslaObject, BuildParentProperties(currentCslaObject));

            if (removeList.Count > 0)
            {
                // ask user confirmation
                var msg = new StringBuilder();
                msg.Append(
                    "The properties listed below are \"Parent Properties\" and should be removed.\r\n\r\n" +
                    "Do you want to remove the following properties:" +
                    Environment.NewLine);
                foreach (var valueProperty in removeList)
                {
                    msg.AppendFormat(" - {0}.{1}\r\n", currentCslaObject.ObjectName, valueProperty.Name);
                }

                var response = MessageBox.Show(msg.ToString(),
                                               @"Invalid ValueProperty found.",
                                               MessageBoxButtons.YesNo,
                                               MessageBoxIcon.Error);
                if (response == DialogResult.Yes)
                {
                    var sb = new StringBuilder();
                    sb.Append("Successfully removed the following properties:" + Environment.NewLine);

                    foreach (var valueProperty in removeList)
                    {
                        currentCslaObject.ValueProperties.Remove(valueProperty);
                        sb.AppendFormat("\t{0}.{1}\r\n", currentCslaObject.ObjectName, valueProperty.Name);
                    }

                    // display message to the user
                    OutputWindow.Current.AddOutputInfo(sb.ToString());
                }
            }
        }
コード例 #7
0
ファイル: Criteria.cs プロジェクト: rajeshwarn/CslaGenFork
        internal static Criteria Clone(Criteria masterCrit)
        {
            var newCrit = new Criteria(masterCrit.ParentObject);

            newCrit.Name = masterCrit.Name;
            newCrit.CriteriaClassMode = masterCrit.CriteriaClassMode;
            newCrit.NestedClass       = masterCrit.NestedClass;
            newCrit.Summary           = masterCrit.Summary;
            newCrit.Remarks           = masterCrit.Remarks;

            newCrit.CreateOptions = CriteriaUsageParameter.Clone(masterCrit.CreateOptions);
            newCrit.GetOptions    = CriteriaUsageParameter.Clone(masterCrit.GetOptions);
            newCrit.DeleteOptions = CriteriaUsageParameter.Clone(masterCrit.DeleteOptions);
            newCrit.Properties.AddRange(CriteriaPropertyCollection.Clone(masterCrit.Properties));

            return(newCrit);
        }
コード例 #8
0
        /// <summary>
        /// Initializes a new instance of the ObjectFactory class.
        /// </summary>
        /// <param name="currentUnit">The current unit.</param>
        /// <param name="entity">The associative entity.</param>
        public ObjectRelationsFactory(CslaGeneratorUnit currentUnit, AssociativeEntity entity)
        {
            _currentUnit               = currentUnit;
            _cslaObjects               = _currentUnit.CslaObjects;
            _entity                    = entity;
            MainObjectInfo             = _cslaObjects.Find(_entity.MainObject);
            MainRootCriteriaProperties = GetCriteriaProperties(MainObjectInfo);

            if (entity.RelationType == ObjectRelationType.ManyToMany)
            {
                SecondaryObjectInfo             = _cslaObjects.Find(_entity.SecondaryObject);
                SecondaryRootCriteriaProperties = GetCriteriaProperties(SecondaryObjectInfo);

                _associativeTable = FindAssociativeTable(MainObjectInfo, SecondaryObjectInfo);

                _resultSet = new TableResultSet(
                    _associativeTable.ResultIndex,
                    _associativeTable.Columns,
                    _associativeTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associativeTable.ObjectCatalog,
                    _associativeTable.ObjectName,
                    _associativeTable.ObjectSchema,
                    _associativeTable.Catalog);
            }
            else
            {
                var mainItemObjectInfo = _cslaObjects.Find(_entity.MainItemTypeName);

                _associatedTable = FindAssociatedTable(MainObjectInfo, mainItemObjectInfo);

                _resultSet = new TableResultSet(
                    _associatedTable.ResultIndex,
                    _associatedTable.Columns,
                    _associatedTable.Type);

                _dbObject = new TableDataBaseObject(
                    _associatedTable.ObjectCatalog,
                    _associatedTable.ObjectName,
                    _associatedTable.ObjectSchema,
                    _associatedTable.Catalog);
            }
        }
コード例 #9
0
        private static CriteriaPropertyCollection GetCriteriaProperties(CslaObjectInfo objectInfo)
        {
            var criteriaInfo               = typeof(CslaObjectInfo).GetProperty("CriteriaObjects");
            var criteriaObjects            = criteriaInfo.GetValue(objectInfo, null);
            var criteriaPropertyCollection = new CriteriaPropertyCollection();

            foreach (var crit in (CriteriaCollection)criteriaObjects)
            {
                foreach (var prop in crit.Properties)
                {
                    if (crit.GetOptions.Factory)
                    {
                        criteriaPropertyCollection.Add(prop);
                    }
                }
            }

            return(criteriaPropertyCollection);
        }
コード例 #10
0
            public EntityFacade(CslaGeneratorUnit parent, ObjectRelationType relationType, string objectName,
                                string propertyName, string collectionTypeName, string itemTypeName, LoadingScheme loadingScheme,
                                CriteriaPropertyCollection loadProperties, ParameterCollection loadParameters, bool lazyLoad)
                : base(parent)
            {
                RelationType       = relationType;
                ObjectName         = objectName;
                PropertyName       = propertyName;
                CollectionTypeName = collectionTypeName;
                ItemTypeName       = itemTypeName;
                LazyLoad           = lazyLoad;
                LoadingScheme      = loadingScheme;
                LoadProperties     = CriteriaPropertyCollection.Clone(loadProperties);
                LoadParameters     = loadParameters;

                if (parent != null && parent.Params != null)
                {
                    Parent = parent;
                }
            }
コード例 #11
0
        private void BuildCollectionCriteriaGet(CslaObjectInfo info, AssociativeEntity.EntityFacade entity, ChildProperty child)
        {
            const string critName = "CriteriaGet";

            var selfLoad = CslaTemplateHelperCS.IsChildSelfLoaded(info);

            if (!selfLoad)
            {
                DeleteDefaultCollectionCriteria(info, critName);
                return;
            }

            StringBuilder sb;

            // make collection criteria if needed
            var      collCriteria = info.CriteriaObjects;
            Criteria criteria     = null;

            foreach (var crit in collCriteria)
            {
                if (CheckAndSetCollectionCriteriaGet(crit, info, critName))
                {
                    criteria = crit;
                    break;
                }
            }

            if (criteria == null)
            {
                criteria      = new Criteria(info);
                criteria.Name = critName;
                SetCollectionCriteriaGet(criteria, info, critName);
                info.CriteriaObjects.Add(criteria);

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added criteria {0} to {1} collection object.", critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            if (criteria.Name != critName)
            {
                return;
            }

            if (criteria.Properties.Count > 0)
            {
                // clear CriteriaGet properties
                criteria.Properties.Clear();

                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully removed all criteria properties of {0} on {1} collection object.",
                                critName, info.ObjectName);
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // populate collection criteria properties
            var addedProps = new List <string>();

            if (entity.LoadProperties.Count == 0)
            {
                criteria.Properties.AddRange(CriteriaPropertyCollection.Clone(FacadeRootCriteriaProperties));
                foreach (var property in FacadeRootCriteriaProperties)
                {
                    addedProps.Add(property.Name);
                }
            }
            else
            {
                criteria.Properties.AddRange(CriteriaPropertyCollection.Clone(entity.LoadProperties));
                foreach (var property in entity.LoadProperties)
                {
                    addedProps.Add(property.Name);
                }
            }

            if (addedProps.Count > 0)
            {
                // display message to the user
                sb = new StringBuilder();
                sb.AppendFormat("Successfully added the following properties to criteria {0}:" + Environment.NewLine, criteria.Name);
                foreach (var propName in addedProps)
                {
                    sb.AppendFormat("\t{0}.{1}.{2}" + Environment.NewLine, critName, info.ObjectName, propName);
                }
                OutputWindow.Current.AddOutputInfo(sb.ToString());
            }

            // is it non-root?
            var entityCslaObject = _cslaObjects.Find(entity.ObjectName);

            if (entityCslaObject != null)
            {
                if (entityCslaObject.IsNotRootType())
                {
                    // re-fill LoadParameters with child criteria
                    child.LoadParameters.Clear();
                    foreach (var property in criteria.Properties)
                    {
                        child.LoadParameters.Add(new Parameter(criteria.Name, property.Name));
                    }
                }
            }
        }
コード例 #12
0
        private List <IColumnInfo> FilterOutSelectedColumns(CslaObjectInfo currentCslaObject, CriteriaPropertyCollection rootCriteriaProperties)
        {
            ColumnInfoCollection columnInfoCollection;
            var selectedColumns = new List <IColumnInfo>();

            if (_entity.RelationType == ObjectRelationType.OneToMany)
            {
                columnInfoCollection = _associatedTable.Columns;
            }
            else
            {
                columnInfoCollection = _associativeTable.Columns;
            }

            foreach (var column in columnInfoCollection)
            {
                // filter out SoftDelete column
                var filter = GeneratorController.Current.CurrentUnit.Params.SpBoolSoftDeleteColumn == column.ColumnName;

                if (!filter)
                {
                    foreach (var property in rootCriteriaProperties)
                    {
                        // filter out properties the root's Criteria properties (used as Parent Properties)
                        if (column.ColumnName == property.Name)
                        {
                            filter = true;
                            break;
                        }
                    }
                }

                if (!filter)
                {
                    foreach (var valueProperty in currentCslaObject.ValueProperties)
                    {
                        // filter out existing properties
                        if (column.ColumnName == valueProperty.Name)
                        {
                            filter = true;
                            break;
                        }
                    }
                }

                if (!filter)
                {
                    selectedColumns.Add(column);
                }
            }//
            return(selectedColumns);
        }