/// <summary> /// /// </summary> private void LoadRessouce() { //Fill RessouceManager this.RessourcesManagers = new Dictionary <string, ResourceManager>(); RessoucesManagerHelper.FillResourcesManager(this.TypeOfEntity, this.RessourcesManagers); // BaseEntity RessouceManager string BaseEntityRessouceFullName = typeof(BaseEntity).Namespace + ".Resources." + typeof(BaseEntity).Name + "." + typeof(BaseEntity).Name; baseEntityResourceManager = new ResourceManager(BaseEntityRessouceFullName, typeof(BaseEntity).Assembly); }
/// <summary> /// Read configuration of entity /// </summary> private void ReadConfiguration() { #region Load RessouceManager //Fill RessouceManager this.RessourcesManagers = new Dictionary <string, ResourceManager>(); RessoucesManagerHelper.FillResourcesManager(this.TypeOfEntity, this.RessourcesManagers); // BaseEntity RessouceManager string BaseEntityRessouceFullName = typeof(BaseEntity).Namespace + ".Resources." + typeof(BaseEntity).Name + "." + typeof(BaseEntity).Name; baseEntityResourceManager = new ResourceManager(BaseEntityRessouceFullName, typeof(BaseEntity).Assembly); #endregion #region Read GwinForm Object[] ls_attribut_GwinForm = this.TypeOfEntity.GetCustomAttributes(typeof(GwinFormAttribute), false); if (ls_attribut_GwinForm != null && ls_attribut_GwinForm.Count() > 0) { this.GwinForm = (GwinFormAttribute)ls_attribut_GwinForm[0]; } #endregion #region Load PresentationLogic Object[] ls_PresentationLogic = this.TypeOfEntity.GetCustomAttributes(typeof(PresentationLogicAttribute), false); if (ls_PresentationLogic != null && ls_PresentationLogic.Count() > 0) { this.PresentationLogic = (PresentationLogicAttribute)ls_PresentationLogic[0]; } #endregion #region Read DisplayEntityAttribute // // Read GwinEntity Configuration // // Load and Check Existance of DisplayEntityAttribute Object[] ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(GwinEntityAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { string msg_excepion = "The meta annotation :" + nameof(GwinEntityAttribute) + " not exist "; msg_excepion += " in Entity : " + this.TypeOfEntity.Name; msg_excepion += ". It is required, because it contain DiplayMameber config that is used by ToString method to diply Entity"; throw new GwinException(msg_excepion); } this.GwinEntity = (GwinEntityAttribute)ls_attribut[0]; // Check DisplayMember existance if (this.GwinEntity.DisplayMember == null) { throw new DisplayMember_NotExist_In_DisplayEntityAttribute_Exception("DisplayMember not exist in " + typeof(GwinEntityAttribute).ToString() + " : " + this.TypeOfEntity.Name); } if (this.GwinEntity.Localizable) { // set all attribute Localizable this.Localizable = this.GwinEntity.Localizable; // Titre this.GwinEntity.PluralName = this.GetStringFromRessource("PluralName", true); this.GwinEntity.SingularName = this.GetStringFromRessource("SingularName", true); // Load Title with Name of Entity if PluraleNameKay Not exist if (this.GwinEntity.PluralName == null) { this.GwinEntity.PluralName = this.GetStringFromRessource(this.TypeOfEntity + "_PluraleName", false); } if (this.GwinEntity.SingularName == null) { this.GwinEntity.SingularName = this.GetStringFromRessource(this.TypeOfEntity + "_SingularName", false); } } #endregion #region Read : ManagementFormAttribute ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(ManagementFormAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.ManagementForm = new ManagementFormAttribute(); } else { this.ManagementForm = (ManagementFormAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.ManagementForm.TitrePageGridView != null) { this.ManagementForm.TitrePageGridView = GetStringFromRessource(this.ManagementForm.TitrePageGridView); } if (this.ManagementForm.FormTitle != null) { this.ManagementForm.FormTitle = GetStringFromRessource(this.ManagementForm.FormTitle); } } if (this.ManagementForm.FormTitle == null) { this.ManagementForm.FormTitle = Glossary.management_of + " " + this.GwinEntity.PluralName?.ToLower(); } if (this.ManagementForm.TitrePageGridView == null) { this.ManagementForm.TitrePageGridView = this.ManagementForm.FormTitle; } #endregion #region Read AddButtonAttribute ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(AddButtonAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.AddButton = new AddButtonAttribute(); } else { this.AddButton = (AddButtonAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.AddButton.Title != null) { this.AddButton.Title = GetStringFromRessource(this.AddButton.Title); } } if (this.AddButton.Title == null) { switch (this.CultureInfo.TwoLetterISOLanguageName) { case "fr": this.AddButton.Title = Glossary.Add + " " + (this.GwinEntity.isMaleName ? "un" : "une") + " " + this.GwinEntity.SingularName.ToLower(); break; default: this.AddButton.Title = baseEntityResourceManager .GetString("Add", this.CultureInfo) + " " + this.GwinEntity.SingularName; break; } } #endregion #region Read Menu ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(MenuAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.Menu = new MenuAttribute(); } else { this.Menu = (MenuAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.Menu.Title != null) { this.Menu.Title = GetStringFromRessource(this.Menu.Title); } } if (this.Menu.Title == null || this.Menu.Title == string.Empty) { this.Menu.Title = this.ManagementForm.FormTitle; } #endregion #region Read DataGridSelectedAction ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(DataGridSelectedActionAttribute), false); if (ls_attribut != null) { this.ListDataGridSelectedAction = ls_attribut.OfType <DataGridSelectedActionAttribute>().ToList(); } if (this.Localizable) { foreach (var item in this.ListDataGridSelectedAction) { if (item.Title != null) { item.Title = GetStringFromRessource(item.Title); } if (item.Description != null) { item.Description = GetStringFromRessource(item.Description); } } } // if Text is null; we use form.Text foreach (var item in this.ListDataGridSelectedAction) { if (item.TypeOfForm == null) { throw new GwinException(string.Format("The TypeOfFrom of DataGridSelectedAction in Entity :{0} must not be null,it is used to Create Instance of Form to execute traitement action", this.TypeOfEntity.FullName)); } if (item.Title == null || item.Title == string.Empty) { Form form = Activator.CreateInstance(item.TypeOfForm) as Form; item.Title = form.Text; } } #endregion #region Read SelectionCriteria Object[] ls_attribut_SelectionCriteria = this.TypeOfEntity.GetCustomAttributes(typeof(SelectionCriteriaAttribute), false); if (ls_attribut_SelectionCriteria != null && ls_attribut_SelectionCriteria.Count() > 0) { this.SelectionCriteria = (SelectionCriteriaAttribute)ls_attribut_SelectionCriteria[0]; } #endregion }
public ConfigEntity(Type type_of_entity, Dictionary <string, ResourceManager> RessoucesManagers = null) { this.TypeOfEntity = type_of_entity; //Fill RessouceManager this.RessoucesManagers = RessoucesManagers; if (RessoucesManagers == null) { this.RessoucesManagers = new Dictionary <string, ResourceManager>(); RessoucesManagerHelper.FillResourcesManager(type_of_entity, this.RessoucesManagers); } else { this.RessoucesManagers = RessoucesManagers; } // Culture Info this.CultureInfo = Thread.CurrentThread.CurrentCulture; // BaseEntity RessouceManager string BaseEntityRessouceFullName = typeof(BaseEntity).Namespace + ".Resources." + typeof(BaseEntity).Name + "." + typeof(BaseEntity).Name; baseEntityResourceManager = new ResourceManager(BaseEntityRessouceFullName, typeof(BaseEntity).Assembly); #region Read DisplayEntityAttribute Object[] ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(DisplayEntityAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { throw new AnnotationNotExistException(typeof(DisplayEntityAttribute).ToString()); } this.DisplayEntity = (DisplayEntityAttribute)ls_attribut[0]; if (this.DisplayEntity.DisplayMember == null) { throw new DisplayMember_NotExist_In_DisplayEntityAttribute_Exception("DisplayMember not exist in " + typeof(DisplayEntityAttribute).ToString() + " : " + type_of_entity.Name); } if (this.DisplayEntity.Localizable) { // set all attribute Localizable this.Localizable = this.DisplayEntity.Localizable; // Titre this.DisplayEntity.PluralName = this.GetStringFromRessource(nameof(this.DisplayEntity.PluralName), true); this.DisplayEntity.SingularName = this.GetStringFromRessource(nameof(this.DisplayEntity.SingularName), true); } if (this.DisplayEntity.SingularName == null) { this.DisplayEntity.SingularName = this.CultureInfo.TwoLetterISOLanguageName + "_" + this.TypeOfEntity.Name; this.DisplayEntity.PluralName = this.CultureInfo.TwoLetterISOLanguageName + "_" + PluralizationService .CreateService(new CultureInfo("en")).Pluralize(this.TypeOfEntity.Name); } #endregion #region Read : ManagementFormAttribute ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(ManagementFormAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.ManagementForm = new ManagementFormAttribute(); } else { this.ManagementForm = (ManagementFormAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.ManagementForm.TitrePageGridView != null) { this.ManagementForm.TitrePageGridView = GetStringFromRessource(this.ManagementForm.TitrePageGridView); } if (this.ManagementForm.FormTitle != null) { this.ManagementForm.FormTitle = GetStringFromRessource(this.ManagementForm.FormTitle); } } if (this.ManagementForm.TitrePageGridView == null) { this.ManagementForm.TitrePageGridView = this.DisplayEntity.PluralName; } if (this.ManagementForm.FormTitle == null) { this.ManagementForm.FormTitle = baseEntityResourceManager .GetString("management_of", this.CultureInfo) + " " + this.DisplayEntity.PluralName?.ToLower(); } #endregion #region Read AddButtonAttribute ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(AddButtonAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.AddButton = new AddButtonAttribute(); } else { this.AddButton = (AddButtonAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.AddButton.Title != null) { this.AddButton.Title = GetStringFromRessource(this.AddButton.Title); } } if (this.AddButton.Title == null) { switch (this.CultureInfo.TwoLetterISOLanguageName) { case "fr": this.AddButton.Title = baseEntityResourceManager .GetString("Add", this.CultureInfo) + " " + (this.DisplayEntity.isMaleName ? "un" : "une") + " " + this.DisplayEntity.SingularName.ToLower(); break; default: this.AddButton.Title = baseEntityResourceManager .GetString("Add", this.CultureInfo) + " " + this.DisplayEntity.SingularName; break; } } #endregion #region Read Menu ls_attribut = this.TypeOfEntity.GetCustomAttributes(typeof(MenuAttribute), false); if (ls_attribut == null || ls_attribut.Count() == 0) { this.Menu = new MenuAttribute(); } else { this.Menu = (MenuAttribute)ls_attribut[0]; } if (this.Localizable) { if (this.Menu.Title != null) { this.Menu.Title = GetStringFromRessource(this.Menu.Title); } } if (this.Menu.Title == null || this.Menu.Title == string.Empty) { this.Menu.Title = this.ManagementForm.FormTitle; } #endregion }