/// <summary> /// Initializes the object with the provided entityname and additionaldatakey /// </summary> /// <param name="entityName">Name of the entity.</param> /// <param name="additionalDataKey">The additional data key.</param> public void Initialize(string entityName, string additionalDataKey) { Check.Require(string.IsNullOrEmpty(entityName) == false); Check.Require(additionalDataKey != null); _Entity = EntityFactory.GetEntityInfoByName(entityName, additionalDataKey); Initialize(_Entity); }
private void CreateTest(string entityName, string additionalDataKey) { EntityInfoBase en = EntityFactory.GetEntityInfoByName(entityName, additionalDataKey); Assert.IsTrue(en != null); //Assert.IsTrue(string.IsNullOrEmpty(en.TitleFieldName) == false); //Assert.IsTrue(string.IsNullOrEmpty(en.CodeFieldName) == false); }
/// <summary> /// Gets the name of the entity info by. /// </summary> /// <param name="entityName">Name of the entity.</param> /// <param name="additionalDataKey">The additional data key.</param> /// <returns></returns> public EntityInfoBase GetEntityInfoByName(string entityName, string additionalDataKey) { ApplicationSetting appSetting = FWUtils.ConfigUtils.GetAppSettings(); EntityInfoBase ef = (EntityInfoBase)FWUtils.ReflectionUtils.CreateInstance(appSetting.Project.NamespacePrefix + ".Common.EntityInfos", entityName + "EN", appSetting.Project.NamespacePrefix + ".Common", null); ef.Initialize(entityName, additionalDataKey); return(ef); }
/// <summary> ///A test for Initialize ///</summary> public void InitializeTest1Helper <T, V>() { ServiceBase <T, V> target = (ServiceBase <T, V>)(object) new UTD.Tricorder.Service.TestCaseTesterService(); EntityInfoBase entity = EntityFactory.GetEntityInfoByName(vTestCaseTester.EntityName, ""); target.Initialize(entity); bool exptected = true; Assert.AreEqual(exptected, target.IsInitialized); }
public void GetEntityInfoByNameTest() { ProjectEntityFactory target = new ProjectEntityFactory(); string entityName = vTestCaseTester.EntityName; string additionalDataKey = ""; EntityInfoBase expected = null; EntityInfoBase actual; actual = target.GetEntityInfoByName(entityName, additionalDataKey); Assert.AreNotEqual(expected, actual); }
/// <summary> /// Initializes the object with the provided entity class. It is fast when entity class is already created. /// </summary> /// <param name="entity">The entity.</param> public void Initialize(EntityInfoBase entity) { Check.Require(_IsInitialized == false, "This class is already initialized."); Check.Require(entity != null); #if DEBUG // Checking the class refelection name with the provided name Check.Require(entity.EntityName == FWUtils.ReflectionUtils.GetEntityNameFromType(this.GetType().FullName, ClassPostFix), "EntityName provided is not match the class. Please make sure that the class is located in an appropriate location and EntityFactory class works correctly."); #endif _EntityName = entity.EntityName; _AdditionalDataKey = entity.AdditionalDataKey; _Entity = entity; this.AutoSave = true; _IsInitialized = true; }
/// <summary> /// Initializes the object with the provided entity class. It is fast when entity class is already created. /// </summary> /// <param name="entity">The entity.</param> public void Initialize(EntityInfoBase entity) { Check.Require(_IsInitialized == false, "This class is already initialized."); Check.Require(entity != null); #if DEBUG // Checking the class refelection name with the provided name Check.Require(entity.EntityName == FWUtils.ReflectionUtils.GetEntityNameFromType(this.GetType().FullName, ClassPostFix), "EntityName provided is not match the class. Please make sure that the class is located in an appropriate location and EntityFactory class works correctly."); #endif _EntityName = entity.EntityName; _AdditionalDataKey = entity.AdditionalDataKey; _Entity = entity; _DataAccessObject = EntityFactory.GetEntityDataAccessByName(this.EntityName, this.AdditionalDataKey); _BusinessLogicObject = EntityFactory.GetEntityBusinessRuleByName(this.EntityName, this.AdditionalDataKey); this.SecurityCheckers = new List <EntitySecurityBase>(); this.SecurityCheckers.Add(new ResourceCheckEntitySecurity(this)); _IsInitialized = true; OnAfterInitialize(); }
/// <summary> /// Gets the entity field value string. /// </summary> /// <param name="entity">The entity.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="dataTransferObject">The data transfer object.</param> /// <returns></returns> public string GetEntityFieldValueString(object dataTransferObject, string fieldName, EntityInfoBase entity) { // we defined the separate function to support CustomFields later in the framework return(GetObjectFieldValueString(dataTransferObject, fieldName)); }
/// <summary> /// Sets the entity field value string. /// </summary> /// <param name="entity">The entity.</param> /// <param name="fieldName">Name of the field.</param> /// <param name="dataTransferObject">The data transfer object.</param> /// <param name="value">The value.</param> public void SetEntityFieldValue(EntityInfoBase entity, string fieldName, object dataTransferObject, object value) { SetObjectFieldValue(fieldName, dataTransferObject, value); }
/// <summary> /// Converts the class to the GetByFilter class used in Framework /// </summary> /// <returns>GetByFilter parameters</returns> public GetByFilterParameters ConvertToGetByFilterParameters(EntityInfoBase entity) { // logic is like this: The deserializer deserialize JSON on this object // we need to read from this.PropertyName and create new GetByFilterObject FilterExpression filterFinal = new FilterExpression(); if (this.Filter != null) { if (this.Filter.LogicalOperator.HasValue == false) // default value for logical operator { this.Filter.LogicalOperator = FilterLogicalOperatorEnum.AND; } filterFinal.LogicalOperator = this.Filter.LogicalOperator.Value; if (this.Filter.FiltersList != null) { foreach (var item in this.Filter.FiltersList) { //TODO: It doesn't support advanced filter by now. // Add advanced filter later if (item.LogicalOperator.HasValue) { throw new NotImplementedException("Nested filters are not supported by now"); // FilterExpression f2 = new FilterExpression(); // f2.AddFilter() } if (item.Operator.HasValue == false) // default value for filter operator { item.Operator = FilterOperatorEnum.EqualTo; } // some security check for column names if (entity.EntityColumns.ContainsKey(item.ColumnName)) { // type casting for columns if (item.Value is string) { item.Value = FWUtils.EntityUtils.ConvertStringToObject((string)item.Value, entity.EntityColumns[item.ColumnName].DataTypeDotNet); } } else { throw new Exception("Filter column name : " + item.ColumnName + " is not exists in the entity: " + entity.EntityName); } filterFinal.AddFilter(new Filter(item.ColumnName, item.Value, item.Operator.Value)); } } } // Check sort experssion columns if (this.Sort != null) { foreach (var item in this.Sort.SortInfoList) { if (entity.EntityColumns.ContainsKey(item.ColumnName) == false) { throw new Exception("Sort column name : " + item.ColumnName + " is not exists in the entity: " + entity.EntityName); } } } // fix page size // if the page size is greater than 100, then we need to decrease it. if (this.PageSize > 100) { this.PageSize = 100; } if (this.PageSize == 0) { this.PageSize = -1; } GetByFilterParameters getByFilter = new GetByFilterParameters(filterFinal, this.Sort, this.PageIndex, this.PageSize, this.SelectColumns, this.SourceType); return(getByFilter); }