Skip to content

Commit

Permalink
WC: fixed bug with TargetObjectCrietria
Browse files Browse the repository at this point in the history
  • Loading branch information
apobekiaris committed Aug 7, 2011
1 parent 7ec2daa commit 65d44e2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public static string GenerateCode(IPersistentAttributeCreator persistentAttribut
}
}
string properties = GetPropertiesCode(attributeInfoAttribute);
return string.Format("[{0}{1}({2}){3}]", assemblyDecleration, attribute.GetType().FullName, args, properties);
return string.Format("[{0}{1}({2}{3})]", assemblyDecleration, attribute.GetType().FullName, args, properties);
}

static string GetPropertiesCode(AttributeInfoAttribute attributeInfoAttribute) {
Expand All @@ -185,13 +185,13 @@ static string GetPropertiesCode(AttributeInfoAttribute attributeInfoAttribute) {
Func<string, IMemberInfo, string> func = (current, memberInfo)
=> current + (memberInfo.Name + "=" + GetArgumentCodeCore(memberInfo.MemberType, memberInfo.GetValue(attributeInfoAttribute.Instance)) + ",");
string code = memberInfos.Aggregate(null, func).TrimEnd(',');
return string.Format("{{{0}}}", code);
return string.IsNullOrEmpty(code) ? null : string.Format(",{0}", code);
}

private static object GetArgumentCodeCore(Type type, object argumentValue) {
if (type == typeof(string))
return @"@""" + argumentValue + @"""";
if (type == typeof(Type))
if (typeof(Type).IsAssignableFrom(type))
return "typeof(" + ((Type)argumentValue).FullName + ")";
if (typeof(Enum).IsAssignableFrom(type))
return argumentValue.GetType().FullName + "." + argumentValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ public Type CompileModule(IPersistentAssemblyBuilder persistentAssemblyBuilder,
return CompileModule(persistentAssemblyBuilder.PersistentAssemblyInfo, true, path);
}


static void RegisterPersistentTypes(Type compileModule) {
foreach (var type in compileModule.Assembly.GetTypes()) {
XafTypesInfo.Instance.RegisterEntity(type);
}
}
public Type CompileModule(IPersistentAssemblyInfo persistentAssemblyInfo, bool registerPersistentTypes, string path) {
Type compileModule = CompileModule(persistentAssemblyInfo, path);
if (registerPersistentTypes && compileModule != null)
foreach (var type in compileModule.Assembly.GetTypes()) {
XafTypesInfo.Instance.RegisterEntity(type);
}
RegisterPersistentTypes(compileModule);
return compileModule;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using DevExpress.ExpressApp;
using DevExpress.Persistent.Base;
using DevExpress.Xpo;
using DevExpress.Xpo.Metadata;
Expand All @@ -15,9 +16,9 @@ public void CreateMembers(Session session) {
var types = CreateCollectionMembers(session);
types.AddRange(CreateReferenceMembers(session));
types.AddRange(CreateCoreMembers(session));

foreach (var type in types) {
XpandModuleBase.TypesInfo.RefreshInfo(type);
XafTypesInfo.Instance.RefreshInfo(type);
}
}

Expand All @@ -27,7 +28,7 @@ public IEnumerable<IExtendedMemberInfo> GetMembers(Session session, Type infoTyp
}

private bool memberExists(IExtendedMemberInfo info) {
return XpandModuleBase.TypesInfo.FindTypeInfo(info.Owner).FindMember(info.Name) != null;
return XafTypesInfo.Instance.FindTypeInfo(info.Owner).FindMember(info.Name) != null;
}

public List<Type> CreateCollectionMembers(Session session) {
Expand All @@ -43,7 +44,7 @@ public List<Type> CreateCollectionMembers(Session session) {
}

XPCustomMemberInfo GetXPCustomMemberInfo(IExtendedCollectionMemberInfo info) {
var classInfo = XpandModuleBase.Dictiorary.GetClassInfo(info.Owner);
var classInfo = XafTypesInfo.XpoTypeInfoSource.XPDictionary.GetClassInfo(info.Owner);
if (!(info is IExtendedOrphanedCollection)) {
return classInfo.CreateMember(info.Name, typeof(XPCollection), true);
}
Expand All @@ -63,20 +64,20 @@ public List<Type> CreateReferenceMembers(Session session) {
return types;
}

public List<Type> CreateCoreMembers(Session session){
public List<Type> CreateCoreMembers(Session session) {
var types = new List<Type>();
var memberInfos = GetMembers(session, WCTypesInfo.Instance.FindBussinessObjectType<IExtendedCoreTypeMemberInfo>());
foreach (var info in memberInfos.Cast<IExtendedCoreTypeMemberInfo>()){
foreach (var info in memberInfos.Cast<IExtendedCoreTypeMemberInfo>()) {
var referenceType = Type.GetType("System." + info.DataType, true);
var member = GetMember(info,referenceType);
var member = GetMember(info, referenceType);
CreateAttributes(info, member);
types.Add(info.Owner);
}
return types;
}

XPCustomMemberInfo GetMember(IExtendedMemberInfo info, Type referenceType) {
var classInfo = XpandModuleBase.Dictiorary.GetClassInfo(info.Owner);
var classInfo = XafTypesInfo.XpoTypeInfoSource.XPDictionary.GetClassInfo(info.Owner);
return info.TypeAttributes.OfType<IPersistentPersistentAliasAttribute>().FirstOrDefault() == null
? classInfo.CreateMember(info.Name, referenceType)
: classInfo.CreateCalculabeMember(info.Name, referenceType);
Expand Down
28 changes: 11 additions & 17 deletions Xpand/Xpand.ExpressApp.Modules/WorldCreator/Core/WCTypesInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,23 @@
using Xpand.Persistent.Base.PersistentMetaData;

namespace Xpand.ExpressApp.WorldCreator.Core {
public class WCTypesInfo
{
public class WCTypesInfo {
static readonly WCTypesInfo _instance;
Dictionary<Type, Type> _dictionary;

static WCTypesInfo() {
_instance=new WCTypesInfo();
_instance = new WCTypesInfo();
Instance._dictionary = new Dictionary<Type, Type>();
}

public static WCTypesInfo Instance
{
public static WCTypesInfo Instance {
get { return _instance; }
}
public Type FindBussinessObjectType(Type type) {
Type findBussinessObjectType;
try
{
try {
findBussinessObjectType = _dictionary[type];
}
catch (KeyNotFoundException)
{
} catch (KeyNotFoundException) {
throw new KeyNotFoundException("Register " + type + " at your AdditionalBusinessClasses");
}
return findBussinessObjectType;
Expand All @@ -35,25 +30,24 @@ public Type FindBussinessObjectType<T>() {
return FindBussinessObjectType(typeof(T));
}

public void Reset()
{
_dictionary.Clear();
public void Reset() {
_dictionary.Clear();
}
public void Register(IEnumerable<Type> types) {
IEnumerable<Type> persistentTypes = GetPersistentTypes(types);
foreach (var persistentType in persistentTypes) {
var interfaceType = persistentType.GetCustomAttributes(typeof(InterfaceRegistratorAttribute),false).OfType<InterfaceRegistratorAttribute>().Single().InterfaceType;
var interfaceType = persistentType.GetCustomAttributes(typeof(InterfaceRegistratorAttribute), false).OfType<InterfaceRegistratorAttribute>().Single().InterfaceType;
if (!_dictionary.ContainsKey(interfaceType))
_dictionary.Add(interfaceType,persistentType);
_dictionary.Add(interfaceType, persistentType);
}
}

IEnumerable<Type> GetPersistentTypes(IEnumerable<Type> types) {
return types.Where(type => type.GetCustomAttributes(typeof(InterfaceRegistratorAttribute),false).OfType<InterfaceRegistratorAttribute>().Count()==1);
return types.Where(type => type.GetCustomAttributes(typeof(InterfaceRegistratorAttribute), false).OfType<InterfaceRegistratorAttribute>().Count() == 1);
}

public void Register(Type type) {
Register(new List<Type>{type});
Register(new List<Type> { type });
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public XpandSystemModule() {
} catch (Exception) {

}
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.SystemModule.SystemModule));
RequiredModuleTypes.Add(typeof(DevExpress.ExpressApp.Security.SecurityModule));
}

static XpandSystemModule() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@

namespace Xpand.Persistent.Base.General {
public static class ObjectSpaceExtensions {

public static void RollBackSilent(this IObjectSpace objectSpace) {
objectSpace.ConfirmationRequired += (sender, args) => args.ConfirmationResult = ConfirmationResult.No;
objectSpace.Rollback();
}

public static IEnumerable<ClassType> GetNonDeletedObjectsToSave<ClassType>(this IObjectSpace objectSpace) {
return objectSpace.GetObjectsToSave(true).OfType<ClassType>().Where(type => !(objectSpace.IsDeletedObject(type)));
}
Expand Down Expand Up @@ -66,7 +72,7 @@ static XPClassInfo GetClassInfo(this ObjectSpace objectSpace, object currentObje
public static T FindObject<T>(this ObjectSpace objectSpace, Expression<Func<T, bool>> expression, PersistentCriteriaEvaluationBehavior persistentCriteriaEvaluationBehavior) {
var objectType = XafTypesInfo.Instance.FindBussinessObjectType<T>();
CriteriaOperator criteriaOperator = GetCriteriaOperator(objectType, expression, objectSpace);
bool inTransaction = persistentCriteriaEvaluationBehavior == PersistentCriteriaEvaluationBehavior.InTransaction ? true : false;
bool inTransaction = persistentCriteriaEvaluationBehavior == PersistentCriteriaEvaluationBehavior.InTransaction;
return (T)objectSpace.FindObject(objectType, criteriaOperator, inTransaction);
}

Expand Down

0 comments on commit 65d44e2

Please sign in to comment.