//public static Dictionary<string, Type> GetExpressionBuiltinVariables() //{ // return GetExpressionHandler.GetExpressionBuiltinVariables(); //} public static I_ExpressionEvaluator GetExpressionEvaluator(DP_DataRepository mainDataItem, DR_Requester requester, bool definition, List <int> usedFormulaIDs) { var entity = bizTableDrivedEntity.GetPermissionedEntity(requester, mainDataItem.TargetEntityID); var properties = GetProperties(requester, entity, null, definition); MyCustomSingleData formulaObject = new MyCustomSingleData(mainDataItem, requester, definition, properties, usedFormulaIDs); var refTypes = GetRefTypes(); var variables = GetRefObjects(entity, requester); var expressionEcaluator = GetExpressionHandler.GetExpressionEvaluator(formulaObject, refTypes, variables); formulaObject.PropertyCalled += (sender, e) => FormulaObject_PropertyCalled(sender, e, expressionEcaluator); return(expressionEcaluator); }
public FormulaObject(DP_DataRepository dataItem, DR_Requester requester, bool isDefinitionFormulaObject = false) { Requester = requester; bool getFromDB = false; if (isDefinitionFormulaObject == false) { if (!dataItem.IsNewItem && MyDataHelper.DataItemPrimaryKeysHaveValue(dataItem) && !MyDataHelper.DataItemNonPrimaryKeysHaveValues(dataItem)) { getFromDB = true; } } if (getFromDB) { SearchRequestManager searchProcessor = new SearchRequestManager(); DP_SearchRepository searchDataItem = new DP_SearchRepository(dataItem.TargetEntityID); foreach (var property in dataItem.GetProperties()) { searchDataItem.Phrases.Add(new SearchProperty() { ColumnID = property.ColumnID, Value = property.Value }); } //سکوریتی داده اعمال میشود //یعنی ممکن است به خود داده دسترسی نداشته باشد و یا حتی به بعضی از فیلدها و روابط DR_SearchFullDataRequest request = new DR_SearchFullDataRequest(Requester, searchDataItem); var result = searchProcessor.Process(request); if (result.Result == Enum_DR_ResultType.SeccessfullyDone) { dataItem = result.ResultDataItems.FirstOrDefault(); // searchProcessor.GetDataItemsByListOFSearchProperties(Requester, searchDataItem).FirstOrDefault(); } else if (result.Result == Enum_DR_ResultType.ExceptionThrown) { throw (new Exception(result.Message)); } } DataItem = dataItem; this.PropertyGetCalled += FormulaObject_PropertyGetCalled; IsDefinitionFormulaObject = isDefinitionFormulaObject; var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, DataItem.TargetEntityID); var properties = FormulaInstanceInternalHelper.GetProperties(entity, null, false, true); SetProperties(properties); }
public frmPropertySelector(int entityID) { InitializeComponent(); dtgFormulaItems.MouseDoubleClick += DtgFormulaItems_MouseDoubleClick; var entity = bizTableDrivedEntity.GetPermissionedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), entityID); var properties = FormulaInstanceInternalHelper.GetProperties(MyProjectManager.GetMyProjectManager.GetRequester(), entity, null, true).Select(x => x.Value).ToList(); dtgFormulaItems.ItemsSource = properties; }
private void BindableTypeDescriptor_PropertyGetCalled(object sender, PropertyGetArg e) { if (e.PropertyInfo.ValueSearched == false) { if (e.PropertyInfo.PropertyType == PropertyType.Relationship) { //روابط به طور پیش فرض موقع ساخته شدن چه تعریف فرمول و چه محاسبه مقدار نمیگیرند و اینجا مقدار میگیرند e.PropertyInfo.ValueSearched = true; var newObject = FormulaInstanceInternalHelper.GetNewFormulaObject(e.PropertyInfo); newObject.DataItem = new DP_DataRepository(e.PropertyInfo.PropertyRelationship.EntityID2, e.PropertyInfo.PropertyRelationship.Entity2); newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //newObject.PropertySetChanged += FormulaObject_PropertySetChanged; //newObject.PropertyChanged += FormulaObject_PropertyChanged; var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, newObject.DataItem.TargetEntityID); if (e.PropertyInfo.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany) { var list = FormulaInstanceInternalHelper.GetNewFormulaObjectList(e.PropertyInfo); list.Add(newObject); e.PropertyInfo.Value = list; foreach (CustomObject item in (e.PropertyInfo.Value as IList)) { //بهتر نوشته شود.برای لیست لازم نیست هر دفعه خصوصیات خوانده شوند if (item.PropertiesLoaded == false) { var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, true, false); item.SetProperties(properties); } } } else { e.PropertyInfo.Value = newObject; if ((e.PropertyInfo.Value as CustomObject).PropertiesLoaded == false) { var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, true, false); (e.PropertyInfo.Value as CustomObject).SetProperties(properties); } } } else { throw new Exception("Sfsdf"); } } //برای همه پراپرتی ها صدا زده میشود که در قسمت ساختن درخت خصوصیات استفاده میشود if (PropertyGetCalled != null) { PropertyGetCalled(sender, e); } }
//TableDrivedEntityDTO Entity { set; get; } public frmFormulaDefinition(string formula, int entityID) { InitializeComponent(); EntityID = entityID; var entity = bizTableDrivedEntity.GetPermissionedEntity(MyProjectManager.GetMyProjectManager.GetRequester(), entityID); formulaAutoComplete = new FormulaAutoComplete(MyProjectManager.GetMyProjectManager.GetRequester(), entity); formulaAutoComplete.NodeSelected += FormulaAutoComplete_NodeSelected; FormulaString = formula; ExpressionEditor.ExpressionText = FormulaString; //ExpressionEditor. SetTimers(); PrepareFormulaInstance(entity); SetParametersTree(); ExpressionEditor.Loaded += ExpressionEditor_Loaded; SetEditEntityArea(); }
public EntitySearchDTO GetDefaultEntitySearch(DR_Requester requester, int entityID) { EntitySearchDTO result = null; using (var projectContext = new DataAccess.MyProjectEntities()) { var entity = projectContext.TableDrivedEntity.First(x => x.ID == entityID); if (entity.EntitySearch != null) { if (DataIsAccessable(requester, entity.EntitySearch)) { result = ToEntitySearchDTO(requester, entity.EntitySearch, true); } else { return(null); } } else { var defaultListView = entity.EntitySearch1.FirstOrDefault(); if (defaultListView != null) { if (DataIsAccessable(requester, defaultListView)) { result = ToEntitySearchDTO(requester, defaultListView, true); } else { return(null); } } else { //باید یک دیفالت ساخته و فرستاده شه BizTableDrivedEntity bizTableDrivedEntity = new BizTableDrivedEntity(); var entityDTO = bizTableDrivedEntity.GetPermissionedEntity(requester, entityID); result = ToEntitySimpleSearch(entityDTO); } } } return(result); }
public TableDrivedEntityDTO GetPermissionedEntity(DR_Requester requester, int entityID) { return(bizTableDrivedEntity.GetPermissionedEntity(requester, entityID)); }
private void BindableTypeDescriptor_PropertyGetCalled(object sender, PropertyGetArg e) { if (e.PropertyInfo.ValueSearched == false) { if (e.PropertyInfo.PropertyType == PropertyType.Relationship) { List <DP_DataRepository> relatedDataItems = GetRelatedDataItems((sender as CustomObject).DataItem, e.PropertyInfo.PropertyRelationship, e.PropertyInfo.PropertyRelationshipProperties); if (e.PropertyInfo.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany) { var list = FormulaInstanceInternalHelper.GetNewFormulaObjectList(e.PropertyInfo); var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, e.PropertyInfo.PropertyRelationship.EntityID2); foreach (var relatedDataItem in relatedDataItems) { var newObject = FormulaInstanceInternalHelper.GetNewFormulaObject(e.PropertyInfo); newObject.DataItem = relatedDataItem; list.Add(newObject); newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //newObject.PropertySetChanged += FormulaObject_PropertySetChanged; //newObject.PropertyChanged += FormulaObject_PropertyChanged; //////newObject.PropertySetChanged += (sender1, e1) => NewObject_PropertySetChanged(sender1, e1, sender as FormulaObject); //////newObject.PropertyGetCalled += (sender1, e1) => NewObject_PropertyGetCalled(sender1, e1, sender as FormulaObject); } e.PropertyInfo.Value = list; var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, false); foreach (CustomObject item in (e.PropertyInfo.Value as IList)) { //بهتر نوشته شود.برای لیست لازم نیست هر دفعه خصوصیات خوانده شوند if (item.PropertiesLoaded == false) { item.SetProperties(properties); } } } else if (relatedDataItems.Any()) { var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, e.PropertyInfo.PropertyRelationship.EntityID2); var properties = FormulaInstanceInternalHelper.GetProperties(entity, e.PropertyInfo, false); var newObject = FormulaInstanceInternalHelper.GetNewFormulaObject(e.PropertyInfo); newObject.DataItem = relatedDataItems.First(); newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //newObject.PropertySetChanged += FormulaObject_PropertySetChanged; //newObject.PropertyChanged += FormulaObject_PropertyChanged; e.PropertyInfo.Value = newObject; if ((e.PropertyInfo.Value as CustomObject).PropertiesLoaded == false) { (e.PropertyInfo.Value as CustomObject).SetProperties(properties); } } e.PropertyInfo.ValueSearched = true; } else if (e.PropertyInfo.PropertyType == PropertyType.Column) { e.PropertyInfo.ValueSearched = true; EntityInstanceProperty property = (sender as CustomObject).DataItem.GetProperty(e.PropertyInfo.ID); if (property != null) { e.PropertyInfo.Value = property.Value; } } else if (e.PropertyInfo.PropertyType == PropertyType.FormulaParameter) { if (UsedFormulaIDs != null && UsedFormulaIDs.Contains(e.PropertyInfo.ParameterFormulaID)) { AddException("Loop"); } UsedFormulaIDs.Add(e.PropertyInfo.ParameterFormulaID); Application.Current.Dispatcher.Invoke((Action) delegate { e.PropertyInfo.ValueSearched = true; var value = FormulaFunctionHandler.CalculateFormula(e.PropertyInfo.ParameterFormulaID, (sender as CustomObject).DataItem, Requester, false, UsedFormulaIDs); if (string.IsNullOrEmpty(value.Exception)) { //if ((e.PropertyInfo.Context is FormulaDTO) && (e.PropertyInfo.Context as FormulaDTO).ValueCustomType != ValueCustomType.None) // e.PropertyInfo.Value = GetCustomTypePropertyValue(e.PropertyInfo, (e.PropertyInfo.Context as FormulaDTO).ValueCustomType, value.Result); //else e.PropertyInfo.Value = value.Result; e.FormulaUsageParemeters = value.FormulaUsageParemeters; } else { AddException(value.Exception); } }); } else if (e.PropertyInfo.PropertyType == PropertyType.State) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = (sender as CustomObject).DataItem; e.PropertyInfo.ValueSearched = true; var result = StateHandler.GetStateResult(e.PropertyInfo.ID, (sender as CustomObject).DataItem, Requester); if (string.IsNullOrEmpty(result.Message)) { e.PropertyInfo.Value = result.Result; } else { AddException(result.Message); } }); } else if (e.PropertyInfo.PropertyType == PropertyType.Code) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = (sender as CustomObject).DataItem; e.PropertyInfo.ValueSearched = true; var result = CodeFunctionHandler.GetCodeFunctionResult(Requester, e.PropertyInfo.ID, dataItem); if (result.ExecutionException == null) { e.PropertyInfo.Value = result.Result; } else { AddException(result.ExecutionException.Message); e.PropertyInfo.Value = ""; } //if ((e.PropertyInfo.Context is CodeFunctionDTO) && (e.PropertyInfo.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None) // e.PropertyInfo.Value = GetCustomTypePropertyValue(e.PropertyInfo, (e.PropertyInfo.Context as CodeFunctionDTO).ValueCustomType, result.Result); //else }); } } if (PropertyGetCalled != null) { PropertyGetCalled(sender, e); } }
public override bool TryGetMember(GetMemberBinder binder, out object result) { if (m_properties.ContainsKey(binder.Name)) { var property = m_properties.FirstOrDefault(x => x.Key == binder.Name).Value; OnProperyCalled(property); if (!property.ValueSearched) { property.ValueSearched = true; if (Definition) { if (property.PropertyType == PropertyType.Relationship) { var dataItem = new DP_DataRepository(property.PropertyRelationship.EntityID2, property.PropertyRelationship.Entity2); var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, dataItem.TargetEntityID); var properties = FormulaInstanceInternalHelper.GetProperties(Requester, entity, property, Definition); //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //newObject.PropertySetChanged += FormulaObject_PropertySetChanged; //newObject.PropertyChanged += FormulaObject_PropertyChanged; if (property.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany) { var newObject = GetCustomSingleData(property, dataItem, Requester, Definition, properties, UsedFormulaIDs); //var list = new List<MyCustomSingleData>(); //DataItems.Add(newObject); property.Value = new MyCustomMultipleData(Requester, entity.ID, new List <MyCustomSingleData>() { newObject }); } else { var newObject = GetCustomSingleData(property, dataItem, Requester, Definition, properties, UsedFormulaIDs); property.Value = newObject; } } else { property.Value = GetPropertyDefaultValue(property); } } else { if (property.PropertyType == PropertyType.Relationship) { var entity = bizTableDrivedEntity.GetPermissionedEntity(Requester, property.PropertyRelationship.EntityID2); var properties = FormulaInstanceInternalHelper.GetProperties(Requester, entity, property, Definition); if (property.PropertyRelationshipProperties == null || property.PropertyRelationshipProperties.Count == 0) { throw new Exception("adasdasd"); } List <DP_DataRepository> relatedDataItems = GetRelatedDataItems(DataItem, property.PropertyRelationship, property.PropertyRelationshipProperties); if (property.PropertyRelationship.TypeEnum == Enum_RelationshipType.OneToMany) { var list = new List <MyCustomSingleData>(); foreach (var relatedDataItem in relatedDataItems) { list.Add(GetCustomSingleData(property, relatedDataItem, Requester, Definition, GetCloneProperties(properties), UsedFormulaIDs)); } var newObject = new MyCustomMultipleData(Requester, entity.ID, list); // DataItems.Add(newObject); // //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //} property.Value = newObject; } else if (relatedDataItems.Any()) { var newObject = GetCustomSingleData(property, relatedDataItems.First(), Requester, Definition, properties, UsedFormulaIDs); //newObject.PropertyGetCalled += BindableTypeDescriptor_PropertyGetCalled; //newObject.PropertySetChanged += FormulaObject_PropertySetChanged; //newObject.PropertyChanged += FormulaObject_PropertyChanged; property.Value = newObject; } } else { if (property.PropertyType == PropertyType.Column) { EntityInstanceProperty dataproperty = DataItem.GetProperty(property.ID); if (dataproperty != null) { property.Value = dataproperty.Value; } else { throw new Exception("Date property" + " " + property.Name + " not found!"); } } else if (property.PropertyType == PropertyType.FormulaParameter) { var formula = property.Context as FormulaDTO; if (UsedFormulaIDs != null && UsedFormulaIDs.Contains(formula.ID)) { throw new Exception("Loop"); } if (UsedFormulaIDs == null) { UsedFormulaIDs = new List <int>(); } UsedFormulaIDs.Add(formula.ID); Application.Current.Dispatcher.Invoke((Action) delegate { var value = FormulaFunctionHandler.CalculateFormula(formula.ID, DataItem, Requester, UsedFormulaIDs); if (value.Exception == null) { //if ((property.Context is FormulaDTO) && (property.Context as FormulaDTO).ValueCustomType != ValueCustomType.None) // property.Value = GetCustomTypePropertyValue(property, (property.Context as FormulaDTO).ValueCustomType, value.Result); //else property.Value = value.Result; // e.FormulaUsageParemeters = value.FormulaUsageParemeters; } else { throw value.Exception; } }); } else if (property.PropertyType == PropertyType.State) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = DataItem; var stateresult = StateHandler.GetStateResult(property.ID, DataItem, Requester); if (string.IsNullOrEmpty(stateresult.Message)) { property.Value = stateresult.Result; } else { throw new Exception(stateresult.Message); } }); } else if (property.PropertyType == PropertyType.Code) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = DataItem; var coderesult = CodeFunctionHandler.GetCodeFunctionResult(Requester, property.ID, dataItem); if (coderesult.Exception == null) { property.Value = coderesult.Result; } else { throw coderesult.Exception; } //if ((property.Context is CodeFunctionDTO) && (property.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None) // property.Value = GetCustomTypePropertyValue(property, (property.Context as CodeFunctionDTO).ValueCustomType, result.Result); //else }); } else if (property.PropertyType == PropertyType.DBFunction) { Application.Current.Dispatcher.Invoke((Action) delegate { DP_DataRepository dataItem = DataItem; var coderesult = DatabaseFunctionHandler.GetDatabaseFunctionValue(Requester, property.ID, dataItem); if (coderesult.Exception == null) { property.Value = coderesult.Result; } else { throw coderesult.Exception; } //if ((property.Context is CodeFunctionDTO) && (property.Context as CodeFunctionDTO).ValueCustomType != ValueCustomType.None) // property.Value = GetCustomTypePropertyValue(property, (property.Context as CodeFunctionDTO).ValueCustomType, result.Result); //else }); } } } } result = property.Value; return(true); } else { throw new Exception("Property" + " " + binder.Name + " not found!"); } }