Exemplo n.º 1
0
        public virtual void MapValueToObjectProperty(XPObjectSpace objectSpace, XPMemberInfo prop, string value,
                                                     ref IXPSimpleObject newObj)
        {
            object convertedValue = null;

            //if simple property
            if (prop.ReferenceType == null)
            {
                bool isNullable = prop.MemberType.IsGenericType &&
                                  prop.MemberType.GetGenericTypeDefinition().IsNullableType();

                if (prop.MemberType == null)
                {
                    return;
                }


                convertedValue = isNullable ? MapStringToNullable(prop, value) : MapStringToValueType(prop, value);
            }

            //if referenced property
            else if (prop.ReferenceType != null)
            {
                convertedValue = MapStringToReferenceType(objectSpace, prop, value);
            }

            if (convertedValue != null)
            {
                convertedValue = AppllyDoubleValueRounding(convertedValue);
            }

            prop.SetValue(newObj, convertedValue);
        }
Exemplo n.º 2
0
 public override void CopyMemberValue(XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject)
 {
     if (!((memberInfo.MappingField == "Correlativo") || (memberInfo.MappingField == "CodigoDeActivo")))
     {
         base.CopyMemberValue(memberInfo, sourceObject, targetObject);
     }
 }
Exemplo n.º 3
0
 public override void CopyMemberValue(XPMemberInfo memberInfo, IXPSimpleObject sourceObject, IXPSimpleObject targetObject)
 {
     if (!memberInfo.IsAssociation)
     {
         base.CopyMemberValue(memberInfo, sourceObject, targetObject);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Создание нового версионного слоя. Возвращает главный объект слоя (например, для контракта объект из
        /// слоя типа crmComplexContractVersion)
        /// </summary>
        /// <param name="sourceObj"></param>
        /// <returns></returns>
        public virtual IVersionSupport CreateNewVersion(IVersionSupport sourceObj, VersionHelper vHelper)
        {
            source = sourceObj as IXPSimpleObject;
            if (source == null)
            {
                return(null);
            }

            // Алгоритм.
            // 1. Вычисляется версионный слой sourceVersionStrate
            // 2. Создаётся массив пар зависмых объектов и их клонов - dict
            // 3. Все вхождения подобъектов в исходный версионный слой, говоря приблизительно, заменяются на их клоны согласно dict
            // 4. У нового версионного слоя у всех входящих в него версионных объектов проставляется статус VERSION_PROJECT

            // Версионный слой от sourceObj - это версионный слой, из которого будет делаться новый версионный слой
            // Замечание. Свм объект по построению входит в свой версионный слой.
            List <IVersionSupport> sourceVersionStrate = GetVersionedStrate(sourceObj, vHelper);

            // Создаём словарь с копиями объектов из newVersionStrate
            Dictionary <IVersionSupport, IVersionSupport> dict = GenerateCopyOfObjects(sourceVersionStrate, source.Session, sourceObj);

            // Проставляем статус и некоторые другие свойства
            SetVersionState(dict, VersionStates.VERSION_PROJECT);

            // Меняем свойства на версионные
            ResetVersionProperty(vHelper.sourceSession, ignoredProperties, dict);

            // На выходе - копия основного объекта новой версии
            return(dict[sourceObj]);
        }
Exemplo n.º 5
0
        private void ProcessSingleRow(XPObjectSpace objectSpace, Type type, string keyPropertyName, Row excelRow, List <XPMemberInfo> props, int i, out string message, Action <string> notify)
        {
            IXPSimpleObject newObj = GetExistingOrCreateNewObject(objectSpace, keyPropertyName, excelRow, type);

            message = null;
            if (newObj == null)
            {
                message = string.Format(Resources.newObjectError, i);
                return;
            }
            foreach (Mapping mapping in ImportMap.Mappings)
            {
                XPMemberInfo prop = props.First(p => p.Name == mapping.MapedTo);

                try{
                    Cell val = excelRow[mapping.Column];

                    if (val != null)
                    {
                        _propertyValueMapper(objectSpace, prop, val.Value, ref newObj);
                    }
                }

                catch (Exception ee) {
                    message = string.Format(Resources.ErrorProcessingRecord,
                                            i - 1, ee);
                    notify(message);
                }
            }

            objectSpace.Session.Save(newObj);
        }
Exemplo n.º 6
0
        public static void Commit(object obj)
        {
            if (obj == null)
            {
                return;
            }

            UnitOfWork wrk = obj as UnitOfWork;

            if (wrk != null)
            {
                wrk.CommitChanges();
                return;
            }

            IXPSimpleObject dataObject = obj as IXPSimpleObject;

            if (obj != null)
            {
                wrk = dataObject.Session as UnitOfWork;
                if (wrk != null)
                {
                    wrk.CommitChanges();
                }
                else
                {
                    dataObject.Session.Save(dataObject);
                }
            }
        }
Exemplo n.º 7
0
 public ManyToManyCollectionHelper(IXPSimpleObject owner, XPBaseCollection hiddenCollection, string
                                   hiddenCollectionName)
 {
     intermediateClassInfo = owner.ClassInfo.GetMember(hiddenCollectionName).IntermediateClass;
     this.owner            = owner;
     this.hiddenCollection = hiddenCollection;
 }
Exemplo n.º 8
0
        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);
        }
        XPClassInfo GetClassInfo(TObject obj)
        {
            IXPSimpleObject simpleObj = obj as IXPSimpleObject;

            if (obj == null)
            {
                throw new ArgumentException("DataSource does not contain XPO objects.");
            }
            return(simpleObj.ClassInfo);
        }
Exemplo n.º 10
0
 public static IXPSimpleObject CloneLocal(IXPSimpleObject source, IXPSimpleObject clone)
 {
     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);
 }
Exemplo n.º 11
0
        public ReportsV2Helper(XafApplication Application, IXPSimpleObject CurrentObject)
        {
            this._currentObject = CurrentObject;

            if (Application != null)
            {
                this._reportDataSourceHelper = new ReportDataSourceHelper(Application);
            }
            else
            {
                this._reportV2DataSourceHelper = new ReportV2DataSourceHelper(this._currentObject.Session);
            }
        }
Exemplo n.º 12
0
        /// <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);
        }
Exemplo n.º 13
0
        /// <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);
        }
Exemplo n.º 14
0
        private void ProcessSingleRow(XPObjectSpace objectSpace, DoWorkEventArgs e, Type type, string keyPropertyName,
                                      Row excelRow, List <XPMemberInfo> props, int i, out string message)
        {
            IXPSimpleObject newObj = GetExistingOrCreateNewObject(objectSpace, keyPropertyName, excelRow, type);

            if (newObj == null)
            {
                message = string.Format(Resources.newObjectError, i);
                return;
            }
            foreach (Mapping mapping in ImportMap.Mappings)
            {
                if (_bgWorker.CancellationPending)
                {
                    e.Cancel = true;
                    break;
                }
                Application.DoEvents();

                XPMemberInfo prop = props.Single(p => p.Name == mapping.MapedTo);

                try{
                    Cell val = excelRow[mapping.Column];

                    if (val != null)
                    {
                        _propertyValueMapper(objectSpace, prop, val.Value, ref newObj);
                    }
                }

                catch (Exception ee) {
                    message = string.Format(Resources.ErrorProcessingRecord,
                                            i - 1, ee);
                    _bgWorker.ReportProgress(0, message);
                }

                if (CurrentCollectionSource != null)
                {
                    AddNewObjectToCollectionSource(CurrentCollectionSource, newObj, ObjectSpace);
                }
            }

            objectSpace.Session.Save(newObj);
            message = string.Format(Resources.SuccessProcessingRecord, i - 1);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Снятие непосредственно прилегающих к объекту версионных объектов
        /// </summary>
        /// <param name="sourceObj"></param>
        /// <param name="dependentObjectList"></param>
        /// <param name="vHelper"></param>
        /// <returns></returns>
        public List <IVersionSupport> GetFirstDependentList(IVersionSupport sourceObj, VersionHelper vHelper)
        {
            List <IVersionSupport> ResList = new List <IVersionSupport>();

            if (sourceObj == null)
            {
                return(ResList);
            }

            IXPSimpleObject sourceObject    = (IXPSimpleObject)sourceObj;
            XPClassInfo     sourceClassInfo = sourceObject.ClassInfo; // sourceSession.GetClassInfo(sourceObject);

            foreach (XPMemberInfo m in sourceClassInfo.PersistentProperties)
            {
                if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                {
                    continue;
                }
                if (m.ReferenceType != null)
                {
                    IVersionSupport ob = m.GetValue(sourceObj) as IVersionSupport;
                    if (ob != null)
                    {
                        AddObjectToList(ob, ResList);
                    }
                }
            }

            foreach (XPMemberInfo m in sourceClassInfo.CollectionProperties)
            {
                //if (m.HasAttribute(typeof(AggregatedAttribute))) {
                XPBaseCollection colSource = (XPBaseCollection)m.GetValue(sourceObj);
                foreach (IXPSimpleObject obj in colSource)
                {
                    if (obj is IVersionSupport)
                    {
                        AddObjectToList((IVersionSupport)obj, ResList);
                    }
                }
                //}
            }

            return(ResList);
        }
Exemplo n.º 16
0
        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)));
        }
Exemplo n.º 17
0
        private IXPSimpleObject GetExistingOrCreateNewObject(XPObjectSpace objectSpace, string keyPropertyName,
                                                             Row excelRow, Type type)
        {
            Mapping         idMapping = ImportMap.Mappings.SingleOrDefault(p => p.MapedTo == keyPropertyName);
            IXPSimpleObject newObj    = null;

            if (idMapping != null && ImportUtils.GetQString(excelRow[idMapping.Column].Value) != string.Empty)
            {
                try{
                    //find existing object
                    Cell val  = excelRow[idMapping.Column];
                    var  gwid = new Guid(ImportUtils.GetQString(val.Value));
                    newObj =
                        objectSpace.FindObject(type, new BinaryOperator(keyPropertyName, gwid), true) as IXPSimpleObject;
                }
                catch {
                }
            }
            return(newObj ?? (objectSpace.CreateObject(type) as IXPSimpleObject));
        }
Exemplo n.º 18
0
        public static void Rollback(object obj)
        {
            UnitOfWork wrk = obj as UnitOfWork;

            if (wrk != null)
            {
                wrk.CommitChanges();
                return;
            }

            IXPSimpleObject dataObject = obj as IXPSimpleObject;

            if (obj != null)
            {
                wrk = dataObject.Session as UnitOfWork;
                if (wrk != null)
                {
                    wrk.RollbackTransaction();
                }
            }
        }
Exemplo n.º 19
0
        public virtual void MapValueToObjectProperty(XPObjectSpace objectSpace, XPMemberInfo prop, string value,
            ref IXPSimpleObject newObj){
            object convertedValue = null;

            //if simple property
            if (prop.ReferenceType == null){
                bool isNullable = prop.MemberType.IsGenericType &&
                                  prop.MemberType.GetGenericTypeDefinition().IsNullableType();

                if (prop.MemberType == null) return;


                convertedValue = isNullable ? MapStringToNullable(prop, value) : MapStringToValueType(prop, value);
            }

                //if referenced property
            else if (prop.ReferenceType != null)
                convertedValue = MapStringToReferenceType(objectSpace, prop, value);

            if (convertedValue != null)
                convertedValue = AppllyDoubleValueRounding(convertedValue);

            prop.SetValue(newObj, convertedValue);
        }
Exemplo n.º 20
0
 /// <summary>
 /// Устанавливает ссылку на объект
 /// </summary>
 /// <param name="value">Объект, на который устанавливается ссылка</param>
 public void SetObject(IXPSimpleObject value)
 {
     if (value == null)
         TargetKeyValue = null;
     else
         SetObject(value.Session, value);
 }
Exemplo n.º 21
0
            /// <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);
            }
Exemplo n.º 22
0
 public object Clone(IXPSimpleObject source, bool synchronize)
 {
     return(Clone(source, _target, synchronize));
 }
Exemplo n.º 23
0
 public object Clone(IXPSimpleObject source)
 {
     return(Clone(source, _target, false));
 }
Exemplo n.º 24
0
 public static int GetNextUniqueValue(IXPSimpleObject simpleObject) {
     return GetNextUniqueValue(simpleObject.Session.DataLayer, simpleObject.GetType().FullName);
 }
Exemplo n.º 25
0
        /// <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);
        }
Exemplo n.º 26
0
 public object Clone(IXPSimpleObject source)
 {
     return(Clone(source, targetSession, false));
 }
Exemplo n.º 27
0
        public ReportsV2Helper(IXPSimpleObject CurrentObject)
        {
            this._currentObject = CurrentObject;

            this._reportV2DataSourceHelper = new ReportV2DataSourceHelper(this._currentObject.Session);
        }
Exemplo n.º 28
0
        static Dictionary <string, object> RetrieveIndexedProperties(XPClassInfo classInfo, IXPSimpleObject source)
        {
            Dictionary <string, object> indexedProperties = new Dictionary <string, object>();

            foreach (XPMemberInfo item in classInfo.PersistentProperties)
            {
                if (item.HasAttribute(typeof(IndexedAttribute)))
                {
                    IndexedAttribute attribute = (IndexedAttribute)item.GetAttributeInfo(typeof(IndexedAttribute));
                    if (attribute.Unique)
                    {
                        indexedProperties.Add(item.Name, item.GetValue(source));
                    }
                    else
                    {
                        continue;
                    }
                    if (attribute.AdditionalFields != null && attribute.AdditionalFields.Count > 0)
                    {
                        foreach (string fieldName in attribute.AdditionalFields)
                        {
                            indexedProperties.Add(fieldName, classInfo.GetMember(fieldName).GetValue(source));
                        }
                    }
                }
            }
            return(indexedProperties);
        }
Exemplo n.º 29
0
 public ReportV2DataSourceHelper(IXPSimpleObject CurrentObject)
     : this()
 {
     this.session       = CurrentObject.Session;
     this.currentObject = CurrentObject;
 }
 public InplaceFileData(IXPSimpleObject host, XPMemberInfo member, string extension)
 {
     this.host      = host;
     this.member    = member;
     this.extension = extension;
 }
Exemplo n.º 31
0
 public static bool IsNewObject(this IXPSimpleObject simpleObject)
 {
     return(simpleObject.Session.IsNewObject(simpleObject));
 }
Exemplo n.º 32
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ivCopiedObj">основной объект для копированя</param>
        /// <param name="ivTargetObj">Новая версия объекта ivCopiedObj</param>
        /// <param name="ignoredProperties">Список игнорируемых свойств</param>
        /// <param name="dict">Словарь с копиями версионируемых объектов</param>
        public void ResetVersionProperty(Session ssn, string ignoredProperties, Dictionary <IVersionSupport, IVersionSupport> dict)
        {
            if (dict == null || dict.Count == 0)
            {
                return;
            }
            //if (ivCopiedObj == null) return;
            //Session ssn = ivCopiedObj.Session;
            ArrayList IgnoredPropertiesList = new ArrayList(ignoredProperties.Split(new string[] { ";" }, StringSplitOptions.RemoveEmptyEntries));


            // Прогон по словарю объектов
            foreach (IVersionSupport sourceObj in dict.Keys)
            {
                if (dict[sourceObj] == null)
                {
                    continue;
                }

                IXPSimpleObject sourceObject = (IXPSimpleObject)sourceObj;
                IXPSimpleObject targetObject = (IXPSimpleObject)dict[sourceObj];
// Паша
                IVersionSupport to = (IVersionSupport)targetObject;

                XPClassInfo sourceClassInfo = sourceObject.ClassInfo;   // ssn.GetClassInfo(sourceObject.GetType());

                foreach (XPMemberInfo m in sourceClassInfo.PersistentProperties)
                {
                    if (m is DevExpress.Xpo.Metadata.Helpers.ServiceField || m.IsKey)
                    {
                        continue;
                    }
                    if (IgnoredPropertiesList.Contains(m.Name))
                    {
                        continue;
                    }
                    //if (m.GetValue(sourceObject) is IVersionSupport == null) continue;

                    IVersionSupport ob = m.GetValue(sourceObject) as IVersionSupport;
                    if (ob != null && dict.ContainsKey(ob))
                    {
                        IXPSimpleObject newValue = dict[ob] as IXPSimpleObject;
                        if (newValue != null)
                        {
                            m.SetValue(targetObject, newValue);
                        }
                    }
                }


                // Здесь надо иметь основной объект исходного слоя(source) и его версию (clone)
                foreach (XPMemberInfo m in sourceClassInfo.CollectionProperties)
                {
                    //if (m.HasAttribute(typeof(AggregatedAttribute))) {
                    XPBaseCollection colSource = (XPBaseCollection)m.GetValue(sourceObject);
                    XPBaseCollection colTarget = (XPBaseCollection)m.GetValue(targetObject);
                    foreach (IXPSimpleObject obj in new ArrayList(colSource))
                    {
                        if (obj == null)
                        {
                            continue;
                        }
                        if (obj is IVersionSupport)
                        {
                            if (dict.ContainsKey((IVersionSupport)obj))
                            {
                                IVersionSupport objClone = dict[(IVersionSupport)obj];
                                colTarget.BaseAdd(objClone);
                            }
                        }
                        else
                        {
                            colTarget.BaseAdd(obj);
                        }
                    }
                    //}
                }
                to.IsProcessCloning = false;
            }
        }
Exemplo n.º 33
0
 public static int GetNextUniqueValue(IXPSimpleObject simpleObject)
 {
     return(GetNextUniqueValue(simpleObject.Session.DataLayer, simpleObject.GetType().FullName));
 }
Exemplo n.º 34
0
 /// <summary>Конструктор с объектом ссылки</summary>
 /// <param name="target">Объект, на который указывает ссылка</param>
 public XPReference(IXPSimpleObject target)
     : this(target.Session, target)
 {
 }