private void UndeleteObjectCore(object obj, ITypeInfo currenttypeinfo) { if (currenttypeinfo.IsDomainComponent) { System.Reflection.MethodInfo method = obj.GetType().GetMethod("SetMemberValue"); method.Invoke(obj, new object[] { "GCRecord", null }); } else if (currenttypeinfo.FindAttribute <DeferredDeletionAttribute>() != null && currenttypeinfo.FindMember("GCRecord").GetValue(obj) != null) { currenttypeinfo.FindMember("GCRecord").SetValue(obj, null); } }
public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object val, System.Type destType) { if (destType == typeof(string)) { ITypeInfo typeInfo = XafTypesInfo.Instance.FindTypeInfo((Type)val); var displayNameAttribute = typeInfo.FindAttribute <DisplayNameAttribute>(); if (displayNameAttribute != null) { return(displayNameAttribute.DisplayName); } } return(base.ConvertTo(context, culture, val, destType)); }
private void application_CustomProcessShortcut(object sender, CustomProcessShortcutEventArgs e) { if (e.Shortcut != null && !string.IsNullOrEmpty(e.Shortcut.ViewId)) { IModelView modelView = Application.FindModelView(e.Shortcut.ViewId); if (modelView is IModelObjectView) { ITypeInfo typeInfo = ((IModelObjectView)modelView).ModelClass.TypeInfo; AutoCreatableObjectAttribute attribute = typeInfo.FindAttribute <AutoCreatableObjectAttribute>(true); if (attribute != null && attribute.AutoCreatable) { IObjectSpace objSpace = Application.CreateObjectSpace(typeInfo.Type); object obj; if (typeof(XPBaseObject).IsAssignableFrom(typeInfo.Type) || (typeInfo.IsInterface && typeInfo.IsDomainComponent)) { obj = objSpace.FindObject(typeInfo.Type, null); if (obj == null) { obj = objSpace.CreateObject(typeInfo.Type); } } else { if (typeInfo.Type == typeof(WelcomeObject)) { obj = WelcomeObject.Instance; } else { obj = Activator.CreateInstance(typeInfo.Type); } } //obj = typeof(BaseObject).IsAssignableFrom(typeInfo.Type) ? objSpace.CreateObject(typeInfo.Type) : Activator.CreateInstance(typeInfo.Type); DetailView detailView = Application.CreateDetailView(objSpace, obj, true); if (attribute.ViewEditMode == ViewEditMode.Edit) { detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; } e.View = detailView; e.Handled = true; } } } }
public CodeInfo GetCode(ITypeInfo typeInfo) { _typeInfo = typeInfo; var objectToViewAttribute = _typeInfo.FindAttribute <ObjectToViewAttribute>(); if (objectToViewAttribute != null) { _viewName = objectToViewAttribute.ViewName; string classDeclaration = CreateClassDeclaration(); var classConstructor = CreateClassConstructor(); string properties = CreateProperties(); var source = string.Join(Environment.NewLine, new[] { classDeclaration, classConstructor, properties, "}" }); _referencesCollector.Add(_usingTypes); string[] references = _referencesCollector.References.ToArray(); return(new CodeInfo(typeInfo, source, references.ToList(), _viewName)); } return(null); }
private void NavigationController_NavigationItemCreated(object sender, NavigationItemCreatedEventArgs e) { ChoiceActionItem navigationItem = e.NavigationItem; if (navigationItem.Items != null && navigationItem.Items.Count > 0) { foreach (ChoiceActionItem item in navigationItem.Items) { IModelObjectView viewNode = ((IModelNavigationItem)item.Model).View as IModelObjectView; if (viewNode != null) { ITypeInfo objectTypeInfo = XafTypesInfo.Instance.FindTypeInfo(viewNode.ModelClass.Name); var attr = objectTypeInfo.FindAttribute <NavigationItemCaptionAttribute>(); if (attr != null) { navigationItem.Caption = attr.Caption; break; } } } } }
public CodeInfo GetCode(ITypeInfo typeInfo) { _typeInfo = typeInfo; var objectToViewAttribute = _typeInfo.FindAttribute<ObjectToViewAttribute>(); if (objectToViewAttribute != null) { _viewName = objectToViewAttribute.ViewName; string classDeclaration = CreateClassDeclaration(); var classConstructor = CreateClassConstructor(); string properties = CreateProperties(); var source = string.Join(Environment.NewLine, new[] { classDeclaration, classConstructor, properties, "}" }); _referencesCollector.Add(_usingTypes); string[] references = _referencesCollector.References.ToArray(); return new CodeInfo(typeInfo, source, references.ToList(), _viewName); } return null; }
private static string GetName(ITypeInfo typeInfo) { var displayNameAttribute = typeInfo.FindAttribute <ModelDisplayNameAttribute>(false); return(displayNameAttribute != null ? displayNameAttribute.ModelDisplayName : typeInfo.Type.Name.Replace("IModel", "")); }
static bool B(IContextLogicRule contextLogicRule, ITypeInfo info) { return(typeof(ILogicRule).IsAssignableFrom(info.Type) && info.Type.IsInstanceOfType(contextLogicRule) && info.FindAttribute <ModelAbstractClassAttribute>(false) == null); }
private void SetValues() { Edit.Items.List.Clear(); IList <TagSourceAttribute> tagSources = MemberInfo.FindAttributes <TagSourceAttribute>().ToList(); var settingsAttribute = MemberInfo.FindAttribute <TagSettingsAttribute>(); if (settingsAttribute != null) { Edit.Delimeter = String.Concat(settingsAttribute.ValueSeparator); Edit.AllowAddCustomValues = settingsAttribute.AllowNew; Edit.AllowSelectValues = settingsAttribute.AllowSelect; } IMemberInfo info; #region Set values from tag sources foreach (var tagSource in tagSources) { switch (tagSource.Kind) { case TagSourceKind.TypeSource: if (typeof(Enum).IsAssignableFrom(tagSource.Type)) { IList <String> Names = Enum.GetNames(tagSource.Type); Array Values = Enum.GetValues(tagSource.Type); String format = String.Concat(tagSource.ValueFormat); if (format == "") { format = "{0}"; } for (int i = 0; i < Names.Count; i++) { String imageName = Helpers.GetXafImageName((Enum)Values.GetValue(i)); if (Edit.Items.List.Where(f => f.Text == String.Format(format, Names[i])).Count() == 0) { var item = Edit.Items.Add(); var displayText = Helpers.GetXafDisplayName((Enum)Values.GetValue(i)); item.Text = String.Format(format, displayText); item.Value = String.Concat(Values.GetValue(i)); if (imageName == "") { imageName = String.Concat(tagSource.ImageName); } } } } else { var tagSourceType = tagSource.Type; if (tagSourceType == typeof(SecuritySystemUser)) { tagSourceType = SecuritySystem.UserType; } IObjectSpace os = ObjectSpace; CollectionSource cs = new CollectionSource(os, tagSourceType); if (tagSource.Criteria != null) { cs.Criteria["Criteria"] = PrepareCriteria(tagSource.Criteria); } String format = String.Concat(tagSource.ValueFormat); if (format == "") { ITypeInfo TypeInfo = XafTypesInfo.Instance.FindTypeInfo(tagSourceType); if (TypeInfo != null) { ObjectCaptionFormatAttribute attr = TypeInfo.FindAttribute <ObjectCaptionFormatAttribute>(); if (attr != null) { format = attr.FormatString; } else { var defPropAttr = TypeInfo.FindAttribute <XafDefaultPropertyAttribute>(); if (defPropAttr != null) { format = "{0:" + defPropAttr.Name + "}"; } } } } IList list = null; switch (String.Concat(tagSource.Sorting).ToLower()) { case "asc": case "ascending": list = cs.List.OfType <object>().OrderBy(f => String.Format(new ObjectFormatter(), format, f)).ToList(); break; case "desc": case "descending": list = cs.List.OfType <object>().OrderByDescending(f => String.Format(new ObjectFormatter(), format, f)).ToList(); break; default: list = cs.List; break; } foreach (object obj in list) { var text = String.Format(new ObjectFormatter(), format, obj); if (Edit.Items.List.Where(f => f.Text == text).Count() == 0) { var item = Edit.Items.Add(); item.Text = String.Format(new ObjectFormatter(), format, obj); item.Value = String.Concat(ObjectFormatValues.GetValueRecursive(tagSource.Key, obj, out info)); } } } break; case TagSourceKind.Values: String Items = ""; try { Boolean IsProperty = false; var property = ObjectFormatValues.GetValueRecursive(tagSource.CommaValues, CurrentObject, out info); IObjectSpace os = ObjectSpace; if (property is IEnumerable) { var coll = (property as IEnumerable); var format = ""; if (info.MemberTypeInfo != null) { var attr = info.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>(); if (attr != null) { format = attr.FormatString; } else { var defPropAttr = info.MemberTypeInfo.FindAttribute <XafDefaultPropertyAttribute>(); if (defPropAttr != null) { format = "{0:" + defPropAttr.Name + "}"; } } } Items = String.Join("*;*", coll.OfType <object>().Select(f => String.Format("{0}|{1}" , (format == "" ? f : String.Format(new ObjectFormatter(), format, f)) , f is String ? String.Concat(f).Trim() : ObjectFormatValues.GetValueRecursive(os.GetKeyPropertyName(f.GetType()), f, out info)))); IsProperty = true; if (String.Concat(tagSource.ValueFormat) != "") { format = tagSource.ValueFormat; } var selectCollection = coll.OfType <object>().Select(f => new { text = (format == "" ? f : String.Format(new ObjectFormatter(), format, f)), value = f is String ? String.Concat(f).Trim() : ObjectFormatValues.GetValueRecursive(String.Concat(tagSource.Key) == "" ? os.GetKeyPropertyName(f.GetType()) : tagSource.Key, f, out info) }).GroupBy(f => f).Select(f => new { f.Key.text, f.Key.value }).OrderBy(f => f.text); foreach (var item in selectCollection) { var tagItem = Edit.Items.Add(); tagItem.Text = String.Concat(item.text).Trim(); tagItem.Value = String.Concat(item.value).Trim(); } } else { Items = String.Concat(property); foreach (var item in String.Concat(tagSource.CommaValues).Split(',').Where(f => String.Concat(f) != "")) { if (Edit.Items.List.Where(f => f.Text == item.Split('|')[0]).Count() == 0) { var tagItem = Edit.Items.Add(); tagItem.Text = item.Split('|')[0]; if (item.Split('|').Count() > 1) { tagItem.Value = item.Split('|')[1]; } String imageName = tagSource.ImageName; if (item.Split('|').Count() > 2) { imageName = item.Split('|')[2]; } if (imageName != "") { tagItem.ImageUrl = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo(tagSource.ImageName).ImageUrl; } } } } } catch (Exception ex) { Items = tagSource.CommaValues; } break; } foreach (var item in Edit.Items.List.ToList()) { if (String.Concat(item.Text) == "" && String.Concat(item.Value) == "") { Edit.Items.List.Remove(item); } } } #endregion }
static bool B(IContextLogicRule contextLogicRule, ITypeInfo info) { return typeof(ILogicRule).IsAssignableFrom(info.Type) && info.Type.IsInstanceOfType(contextLogicRule)&& info.FindAttribute<ModelAbstractClassAttribute>(false)==null; }
private void ProcessAutoCreatableShortcut(CustomProcessShortcutEventArgs e) { IModelView modelView = Application.FindModelView(e.Shortcut.ViewId); if (modelView is IModelObjectView) { ITypeInfo typeInfo = ((IModelObjectView)modelView).ModelClass.TypeInfo; Xafology.ExpressApp.Attributes.AutoCreatableObjectAttribute attribute = typeInfo.FindAttribute <Xafology.ExpressApp.Attributes.AutoCreatableObjectAttribute>(true); if (attribute != null && attribute.AutoCreatable) { // create new instance of object of it is marked as AutoCreatable IObjectSpace objSpace = Application.CreateObjectSpace(); object obj; if (typeof(XPBaseObject).IsAssignableFrom(typeInfo.Type) || (typeInfo.IsInterface && typeInfo.IsDomainComponent)) { obj = objSpace.FindObject(typeInfo.Type, null); if (obj == null) { obj = objSpace.CreateObject(typeInfo.Type); } } else { obj = typeof(BaseObject).IsAssignableFrom(typeInfo.Type) ? objSpace.CreateObject(typeInfo.Type) : Activator.CreateInstance(typeInfo.Type); } DetailView detailView = Application.CreateDetailView(objSpace, obj, true); if (attribute.ViewEditMode == ViewEditMode.Edit) { detailView.ViewEditMode = DevExpress.ExpressApp.Editors.ViewEditMode.Edit; } e.View = detailView; e.Handled = true; } } }
private void SetValues() { Edit.Items.List.Clear(); IList <TagSourceAttribute> tagSources = MemberInfo.FindAttributes <TagSourceAttribute>().ToList(); IMemberInfo info; #region Set values from tag sources foreach (var tagSource in tagSources) { switch (tagSource.Kind) { case TagSourceKind.TypeSource: if (typeof(Enum).IsAssignableFrom(tagSource.Type)) { IList <String> Names = Enum.GetNames(tagSource.Type); Array Values = Enum.GetValues(tagSource.Type); String format = String.Concat(tagSource.ValueFormat); if (format == "") { format = "{0}"; } for (int i = 0; i < Names.Count; i++) { String imageName = Helpers.GetXafImageName((Enum)Values.GetValue(i)); if (Edit.Items.List.Where(f => f.Text == String.Format(format, Names[i])).Count() == 0) { var item = Edit.Items.Add(); item.Text = String.Format(format, Names[i]); item.Value = String.Concat(Values.GetValue(i)); if (imageName == "") { imageName = String.Concat(tagSource.ImageName); } } } } else { IObjectSpace os = (WebApplication.Instance as XafApplication).CreateObjectSpace(tagSource.Type); CollectionSource cs = new CollectionSource(os, tagSource.Type); if (tagSource.Criteria != null) { cs.Criteria["Criteria"] = PrepareCriteria(tagSource.Criteria); } String format = String.Concat(tagSource.ValueFormat); if (format == "") { ITypeInfo TypeInfo = XafTypesInfo.Instance.FindTypeInfo(tagSource.Type); if (TypeInfo != null) { ObjectCaptionFormatAttribute attr = TypeInfo.FindAttribute <ObjectCaptionFormatAttribute>(); if (attr != null) { format = attr.FormatString; } else { var defPropAttr = TypeInfo.FindAttribute <XafDefaultPropertyAttribute>(); if (defPropAttr != null) { format = "{0:" + defPropAttr.Name + "}"; } } } } IList list = null; switch (String.Concat(tagSource.Sorting).ToLower()) { case "asc": case "ascending": list = cs.List.OfType <object>().OrderBy(f => String.Format(new ObjectFormatter(), format, f)).ToList(); break; case "desc": case "descending": list = cs.List.OfType <object>().OrderByDescending(f => String.Format(new ObjectFormatter(), format, f)).ToList(); break; default: list = cs.List; break; } foreach (object obj in list) { var text = String.Format(new ObjectFormatter(), format, obj); if (Edit.Items.List.Where(f => f.Text == text).Count() == 0) { var item = Edit.Items.Add(); item.Text = String.Format(new ObjectFormatter(), format, obj); item.Value = String.Concat(ObjectFormatValues.GetValueRecursive(tagSource.Key, obj, out info)); } } } break; case TagSourceKind.Values: String Items = ""; try { Boolean IsProperty = false; var property = ObjectFormatValues.GetValueRecursive(tagSource.CommaValues, CurrentObject, out info); IObjectSpace os = (WebApplication.Instance as XafApplication).CreateObjectSpace(CurrentObject.GetType()); if (property is IEnumerable) { var coll = (property as IEnumerable); var format = ""; if (info.MemberTypeInfo != null) { var attr = info.MemberTypeInfo.FindAttribute <ObjectCaptionFormatAttribute>(); if (attr != null) { format = attr.FormatString; } else { var defPropAttr = info.MemberTypeInfo.FindAttribute <XafDefaultPropertyAttribute>(); if (defPropAttr != null) { format = "{0:" + defPropAttr.Name + "}"; } } } Items = String.Join(",", coll.OfType <object>().Select(f => String.Format("{0}|{1}" , (format == "" ? f : String.Format(new ObjectFormatter(), format, f)) , ObjectFormatValues.GetValueRecursive(os.GetKeyPropertyName(f.GetType()), f, out info)))); IsProperty = true; } else { Items = String.Concat(property); } if (!IsProperty) { Items = tagSource.CommaValues; } } catch (Exception ex) { Items = tagSource.CommaValues; } foreach (var item in Items.Split(',').Where(f => String.Concat(f) != "")) { if (Edit.Items.List.Where(f => f.Text == item.Split('|')[0]).Count() == 0) { var tagItem = Edit.Items.Add(); tagItem.Text = item.Split('|')[0]; if (item.Split('|').Count() > 1) { tagItem.Value = item.Split('|')[1]; } String imageName = tagSource.ImageName; if (item.Split('|').Count() > 2) { imageName = item.Split('|')[2]; } if (imageName != "") { tagItem.ImageUrl = DevExpress.ExpressApp.Utils.ImageLoader.Instance.GetImageInfo(tagSource.ImageName).ImageUrl; } } } break; } } #endregion }