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); }
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); }
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()); } }
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); }
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; } }
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)); } } } }