private void collection_CollectionChanged(object sender, XPCollectionChangedEventArgs e) { if (e.CollectionChangedType == XPCollectionChangedType.BeforeRemove) { IntermediateObject intermediateObject; if (intermediateObjectHash.TryGetValue(e.ChangedObject, out intermediateObject)) { intermediateObject.Delete(); intermediateObjectHash.Remove(e.ChangedObject); } else { hiddenCollection.BaseRemove(e.ChangedObject); } } if (e.CollectionChangedType == XPCollectionChangedType.AfterAdd) { IntermediateObject intermediateObject = null; if (!owner.Session.IsNewObject(e.ChangedObject)) { var criteria = new GroupOperator(); foreach (XPMemberInfo memberInfo in intermediateClassInfo.PersistentProperties) { if (memberInfo.MemberType.IsAssignableFrom(owner.GetType())) { criteria.Operands.Add(new BinaryOperator(memberInfo.Name, owner)); } if (memberInfo.MemberType.IsAssignableFrom(e.ChangedObject.GetType())) { criteria.Operands.Add(new BinaryOperator(memberInfo.Name, e.ChangedObject)); } } intermediateObject = owner.Session.FindObject(intermediateClassInfo, criteria) as IntermediateObject; if (intermediateObject != null && intermediateObject.IsDeleted) { var newIntermediateObject = new IntermediateObject(owner.Session, intermediateClassInfo); intermediateObject = newIntermediateObject; newIntermediateObject.LeftIntermediateObjectField = intermediateObject.LeftIntermediateObjectField; newIntermediateObject.RightIntermediateObjectField = intermediateObject.RightIntermediateObjectField; } } if (intermediateObject == null) { intermediateObject = new IntermediateObject(owner.Session, intermediateClassInfo); foreach (XPMemberInfo memberInfo in intermediateClassInfo.PersistentProperties) { if (memberInfo.MemberType.IsAssignableFrom(owner.GetType())) { memberInfo.SetValue(intermediateObject, owner); } if (memberInfo.MemberType.IsAssignableFrom(e.ChangedObject.GetType())) { memberInfo.SetValue(intermediateObject, e.ChangedObject); } } } intermediateObjectHash.Add(e.ChangedObject, intermediateObject); } }
private void RegisterBOTypes(ITypesInfo typesInfo) { foreach (Type type in _currentObject.GetType().Assembly.GetTypes()) { typesInfo.RegisterEntity(type); } typesInfo.RegisterEntity(typeof(ReportDataV2)); }
public IXPSimpleObject Clone(IXPSimpleObject source) { if (source == null) { return(null); } if (copiedObjects.ContainsKey(source)) { return(copiedObjects[source]); } XPClassInfo targetClassInfo = targetSession.GetClassInfo(source.GetType()); IXPSimpleObject clone = (IXPSimpleObject)targetClassInfo.CreateNewObject(targetSession); copiedObjects.Add(source, clone); if (objectCopied != null) { objectCopied(this, EventArgs.Empty); } foreach (XPMemberInfo m in targetClassInfo.PersistentProperties) { if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey) { continue; } object val; if (m.ReferenceType != null) { val = Clone((IXPSimpleObject)m.GetValue(source)); } else { val = m.GetValue(source); } m.SetValue(clone, val); } foreach (XPMemberInfo m in targetClassInfo.CollectionProperties) { XPBaseCollection col = (XPBaseCollection)m.GetValue(clone); XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source); foreach (IXPSimpleObject obj in CollectionHelper.CreateList((colSource))) { col.BaseAdd(Clone(obj)); } } Dictionary <string, object> indexedProperties = RetrieveIndexedProperties(targetClassInfo, clone); if (indexedProperties.Count > 0) { string requestString = BuildRequest(indexedProperties); object[] values = BuildValuesArray(indexedProperties); IXPSimpleObject foundedClone = (IXPSimpleObject)targetSession.FindObject(PersistentCriteriaEvaluationBehavior.InTransaction, targetClassInfo, CriteriaOperator.Parse(requestString, values)); if (foundedClone != null && foundedClone != clone) { ((XPBaseObject)foundedClone).Delete(); } } return(clone); }
/// <summary> /// Копирование объекта. Результат - это копия объекта, в котором все обычные, но неверсионные, свойства копируются из прежнего объекта /// </summary> /// <param name="source"></param> /// <param name="targetSession"></param> /// <param name="synchronize"></param> /// <returns></returns> public object CopyForVersion(IXPSimpleObject source) { if (source == null) { return(null); } XPClassInfo classInfo = sourceSession.GetClassInfo(source.GetType()); // Копия объекта. Есть проблема. Если в AfterConstruction объекта создаётся некий версионный объект, то // этот версионный объект окажется незамещённым никакой копией из исходного объекта и тем самым "повиснет" IVersionSupport copy = (IVersionSupport)classInfo.CreateNewObject(sourceSession); // Паша copy.IsProcessCloning = true; foreach (XPMemberInfo m in classInfo.PersistentProperties) { if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey) { continue; } if (m is IVersionSupport) { continue; } m.SetValue(copy, m.GetValue(source)); } foreach (XPMemberInfo m in classInfo.CollectionProperties) { if (m.HasAttribute(typeof(AggregatedAttribute))) { XPBaseCollection colCopy = (XPBaseCollection)m.GetValue(copy); XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source); foreach (IXPSimpleObject obj in new ArrayList(colSource)) { if (obj is IVersionSupport) { continue; } colCopy.BaseAdd(obj); } } } return(copy); }
/// <summary> /// Clone object excluding collection properties. /// </summary> public static IXPSimpleObject CloneLocal(IXPSimpleObject source) { var targetSession = source.Session; XPClassInfo targetClassInfo = targetSession.GetClassInfo(source.GetType()); IXPSimpleObject clone = (IXPSimpleObject)targetClassInfo.CreateNewObject(targetSession); foreach (var m in source.ClassInfo.Members) { if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey || !m.IsPublic || m.IsReadOnly) { continue; } clone.ClassInfo.GetMember(m.Name).SetValue(clone, m.GetValue(source)); } return(clone); }
public static object GetObject(object obj, Session session) { IXPSimpleObject xpObject = obj as IXPSimpleObject; if (xpObject == null) { return(null); } while (xpObject.Session != session && xpObject.Session is NestedUnitOfWork) { xpObject = (IXPSimpleObject)((NestedUnitOfWork)xpObject.Session).GetParentObject(xpObject); } if (xpObject.Session == session) { return(xpObject); } XPClassInfo targetClassInfo = session.GetClassInfo(xpObject.GetType()); return(session.GetObjectByKey(targetClassInfo, xpObject.Session.GetKeyValue(xpObject))); }
/// <summary> /// Clones and / or synchronizes the given IXPSimpleObject. /// </summary> /// <param name="source"></param> /// <param name="targetSession"></param> /// <param name="synchronize">If set to true, reference properties are only cloned in case /// the reference object does not exist in the targetsession. Otherwise the exising object will be /// reused and synchronized with the source. Set this property to false when knowing at forehand /// that the targetSession will not contain any of the objects of the source.</param> /// <returns></returns> object Clone(IXPSimpleObject source, Session targetSession, bool synchronize) { if (source == null) { return(null); } if (clonedObjects.ContainsKey(source)) { return(clonedObjects[source]); } XPClassInfo targetClassInfo = targetSession.GetClassInfo(source.GetType()); if (_excluded.Contains(targetClassInfo)) { return(null); } object clone; if (synchronize) { clone = targetSession.GetObjectByKey(targetClassInfo, source.Session.GetKeyValue(source)); } else { clone = null; } if (clone == null) { clone = targetClassInfo.CreateNewObject(targetSession); } clonedObjects.Add(source, clone); foreach (XPMemberInfo m in targetClassInfo.PersistentProperties) { if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey) { continue; } object val; // makes sure when copying details entities in a master/detail relation, that the master is copied as well. if (m.ReferenceType != null) { object createdByClone = m.GetValue(clone); if ((createdByClone != null) && !synchronize) { val = createdByClone; } else if (_syncProps.Contains(m.MappingField)) { object targetSource = targetSession.GetObjectByKey(targetClassInfo, source.Session.GetKeyValue(source)); val = m.GetValue(targetSource); } else { val = Clone((IXPSimpleObject)m.GetValue(source), targetSession, synchronize); } } else { val = m.GetValue(source); } m.SetValue(clone, val); } foreach (XPMemberInfo m in targetClassInfo.CollectionProperties) { if (m.HasAttribute(typeof(AggregatedAttribute))) { XPBaseCollection col = (XPBaseCollection)m.GetValue(clone); XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source); if (col != null) { foreach (IXPSimpleObject obj in new ArrayList(colSource)) { col.BaseAdd(Clone(obj, targetSession, synchronize)); } } } } return(clone); }
public static int GetNextUniqueValue(IXPSimpleObject simpleObject) { return GetNextUniqueValue(simpleObject.Session.DataLayer, simpleObject.GetType().FullName); }
/// <summary> /// Clones and / or synchronizes the given IXPSimpleObject. /// </summary> /// <param name="source"></param> /// <param name="targetSession"></param> /// <param name="synchronize">If set to true, reference properties are only cloned in case /// the reference object does not exist in the targetsession. Otherwise the exising object will be /// reused and synchronized with the source. Set this property to false when knowing at forehand /// that the targetSession will not contain any of the objects of the source.</param> /// <returns></returns> public object Clone(IXPSimpleObject source, Session targetSession, bool synchronize) { if (source == null) { return(null); } if (clonedObjects.ContainsKey(source)) { return(clonedObjects[source]); } XPClassInfo targetClassInfo = targetSession.GetClassInfo(source.GetType()); object clone = null; if (synchronize) { clone = targetSession.GetObjectByKey(targetClassInfo, source.Session.GetKeyValue(source)); } if (clone == null) { clone = targetClassInfo.CreateNewObject(targetSession); } clonedObjects.Add(source, clone); foreach (XPMemberInfo m in targetClassInfo.PersistentProperties) { if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey) { continue; } object val; if (m.ReferenceType != null) { object createdByClone = m.GetValue(clone); if ((createdByClone != null) && synchronize == false) { val = createdByClone; } else { val = Clone((IXPSimpleObject)m.GetValue(source), targetSession, true); } } else { val = m.GetValue(source); } m.SetValue(clone, val); } foreach (XPMemberInfo m in targetClassInfo.CollectionProperties) { if (m.HasAttribute(typeof(AggregatedAttribute))) { XPBaseCollection col = (XPBaseCollection)m.GetValue(clone); XPBaseCollection colSource = (XPBaseCollection)m.GetValue(source); foreach (IXPSimpleObject obj in new ArrayList(colSource)) { col.BaseAdd(Clone(obj, targetSession, synchronize)); } } } return(clone); }
public static int GetNextUniqueValue(IXPSimpleObject simpleObject) { return(GetNextUniqueValue(simpleObject.Session.DataLayer, simpleObject.GetType().FullName)); }