コード例 #1
0
        /// <summary>
        /// Builds the class snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        private void buildClassSnapshot(ClassBuildContext context)
        {
            // Prepare snapshot read only parameters
            SnapshotNodeParameter.Instance.SnapshotNode     = context.TargetNode;
            SnapshotNodeIdParameter.Instance.SnapshotNodeId = context.TargetNode.NodeId;
            try
            {
                //var includeObjects = getSourceObjects(context, SelectorType.Include);
                //var excludeObjects = getSourceObjects(context, SelectorType.Exclude);

                //var sourceObjects = includeObjects.Except(excludeObjects).Where(x => !context.DoneObjects.ContainsKey(x)).ToList();

                var sourceObjects = getSourceObjects(context);

                if (sourceObjects.Count() > 0)
                {
                    context.Worker.ReportProgress(string.Format(Localizer.SourceObjectsFoundForClass, sourceObjects.Count, context.ModelClass.Name));
                }

                // for each selected objects build snapshots
                foreach (var sourceObject in sourceObjects.TakeWhile(x => !context.Worker.CancellationPending))
                {
                    buildObjectSnapshot(context, sourceObject);
                }
            }
            finally
            {
                SnapshotNodeParameter.Instance.SnapshotNode = null;
            }
        }
コード例 #2
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Determines whether source object is source for snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <returns>
        ///   <c>true</c> if the source object is source for snapshort; otherwise, <c>false</c>.
        /// </returns>
        private bool isSourceObject(ClassBuildContext context, object sourceObject)
        {
            var modelClass    = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
            var sourceContext = new ClassBuildContext(context, modelClass);
            var result        = !modelClass.NonSnapshot() && getSnapShourceList(sourceContext).Contains(sourceObject);

            return(result);
        }
コード例 #3
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Builds the object snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <returns></returns>
        private object buildObjectSnapshot(ClassBuildContext context, object sourceObject)
        {
            if (!isSourceObject(context, sourceObject) || context.Worker.CancellationPending)
            {
                return(null);
            }
            object snapObject;

            if (!context.Map.TryGetValue(sourceObject, out snapObject))
            {
                var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
                snapObject = context.SnapObjectSpace.CreateObject(modelClass.TypeInfo.Type);
                storeObjectState(context, sourceObject, snapObject);
                context.DoneObjects.Enqueue(sourceObject);
            }
            return(snapObject);
        }
コード例 #4
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Gets objects to be snapshoted.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private IList <object> getSnapShourceList(ClassBuildContext context)
        {
            IList <object> result;

            if (!context.SnapSources.TryGetValue(context.ModelClass, out result))
            {
                IEnumerable <object> resultEnum = new List <object>();
                var classType = context.ModelClass.TypeInfo.Type;
                var tuple     = from c in context.AppObjectSpace.GetObjects(classType).Cast <object>() select c;

                if (Owner.SelectorMode == SelectorMode.BlackList)
                {
                    resultEnum = tuple;
                }

                foreach (var selector in context.ModelClass.AllSnapshotSelectors())
                {
                    IEnumerable <object> selectedObjects;
                    if (string.IsNullOrEmpty(selector.Expression))
                    {
                        selectedObjects = tuple;
                    }
                    else
                    {
                        selectedObjects =
                            from c in
                            context.AppObjectSpace.GetObjects(classType, CriteriaOperator.Parse(selector.Expression))
                            .Cast <object>()
                            select c;
                    }

                    resultEnum = selector.SelectorType == SelectorType.Include
                                     ? resultEnum.Union(selectedObjects)
                                     : resultEnum.Except(selectedObjects);
                }
                result =
                    resultEnum.Except(context.DoneObjects).Where(
                        x => XafDeltaModule.XafApp.FindModelClass(x.GetType()) == context.ModelClass).ToList();
                context.SnapSources.Add(context.ModelClass, result);
            }
            return(result);
        }
コード例 #5
0
        private bool availableForSnapshot(object sourceObject, ClassBuildContext context)
        {
            var result = context.DoneObjects.ContainsKey(sourceObject);

            if (!result)
            {
                var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
                if (modelClass != null)
                {
                    if (!context.SelectedTypes.Contains(modelClass))
                    {
                        getSourceObjects(context, modelClass);
                    }
                    var seekKey = sourceObject.GetType().AssemblyQualifiedName +
                                  context.ObjectSpace.GetKeyValue(sourceObject);
                    result = context.SelectedSourceObjects.Contains(seekKey);
                }
            }
            return(result);
        }
コード例 #6
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Builds the class snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private int buildClassSnapshot(ClassBuildContext context)
        {
            var snapSourceList = getSnapShourceList(context);
            var result         = snapSourceList.Count;

            if (result > 0)
            {
                context.Worker.ReportProgress(string.Format(Localizer.SourceObjectsFoundForClass,
                                                            result, context.ModelClass.Name));
            }
            int i = 0;

            foreach (var sourceObject in snapSourceList.TakeWhile(x => !context.Worker.CancellationPending))
            {
                context.Worker.ReportPercent((double)i++ / (double)result);
                buildObjectSnapshot(context, sourceObject);
            }

            return(result);
        }
コード例 #7
0
        /// <summary>
        /// Builds object snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <returns></returns>
        private object buildObjectSnapshot(ClassBuildContext context, object sourceObject)
        {
            object result;

            if (!availableForSnapshot(sourceObject, context))
            {
                return(null);
            }

            if (!context.DoneObjects.TryGetValue(sourceObject, out result))
            {
                var packageUow = ((ObjectSpace)context.PackageObjectSpace).Session;
                var classInfo  = packageUow.GetClassInfo(sourceObject.GetType());
                var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
                result = context.ObjectSpace.CreateObject(modelClass.TypeInfo.Type);
                // result = classInfo.CreateObject(packageUow);

                context.DoneObjects.Add(sourceObject, result);

                storeObjectState(context, sourceObject, result);
                context.MapQueue.Enqueue(sourceObject);
            }
            return(result);
        }
コード例 #8
0
        private List <object> getSourceObjects(ClassBuildContext context, IModelClass modelClass)
        {
            if (modelClass == null)
            {
                modelClass = context.ModelClass;
            }

            IEnumerable <object> result = new List <object>();
            var targetType = modelClass.TypeInfo.Type;
            var allObjects = (from c in context.ObjectSpace.GetObjects(targetType).Cast <object>() select c).ToList();

            if (Owner.SelectorMode == SelectorMode.BlackList)
            {
                result = allObjects;
            }
            foreach (var selector in modelClass.AllSnapshotSelectors())
            {
                IEnumerable <object> selectResult;

                var expression = selector.Expression;
                if (string.IsNullOrEmpty(expression))
                {
                    selectResult = allObjects;
                }
                else
                {
                    selectResult = context.ObjectSpace.GetObjects(targetType, CriteriaOperator.Parse(expression)).Cast <object>();
                }

                if (selector.SelectorType == SelectorType.Include)
                {
                    result = result.Union(selectResult).Distinct();
                }
                else
                {
                    result = result.Except(selectResult);
                }
            }
            result = result.Where(x => !context.DoneObjects.ContainsKey(x)).Distinct();
            result = from c in result where !(c is ISnapshotable) ||
                     ((ISnapshotable)c).ShouldBeIncludedInSnapshot(context.TargetNode) select c;

            var resultList = result.ToList();

            // register class done
            context.SelectedTypes.Add(modelClass);

            foreach (var resultObject in resultList)
            {
                // store selected objects hashes
                if (XafDeltaModule.XafApp.FindModelClass(resultObject.GetType()) == modelClass)
                {
                    var seekKey = resultObject.GetType().AssemblyQualifiedName +
                                  context.ObjectSpace.GetKeyValue(resultObject);

                    context.SelectedSourceObjects.Add(seekKey);
                }
            }

            return(resultList);
        }
コード例 #9
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Stores the state of the object.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="snapObject">The snap object.</param>
        private void storeObjectState(ClassBuildContext context, object sourceObject, object snapObject)
        {
            if (context.Worker.CancellationPending) return;

            if (sourceObject == null || snapObject == null) return;
            if (context.Map.ContainsKey(sourceObject)) return;

            context.Map.Add(sourceObject, snapObject);
            context.Worker.ShowStatus(string.Format(Localizer.SnapshotObject, sourceObject));

            var classInfo = ((IXPObject) sourceObject).ClassInfo;
            var modelClass = XafDeltaModule.XafApp.FindModelClass(classInfo.ClassType);

            IEnumerable<XPMemberInfo> sourceMembers = classInfo.Members;
            if (modelClass != null && modelClass.TypeInfo.IsInterface)
                sourceMembers = from m in modelClass.AllMembers select classInfo.FindMember(m.Name);

            foreach (var memberInfo in sourceMembers.Where(x => !(x is ServiceField) && x.IsPersistent
                                                                && !x.IsReadOnly && !x.IsKey).TakeWhile(
                                                                    x => !context.Worker.CancellationPending))
            {
                if (modelClass != null)
                {
                    var modelMember = modelClass.AllMembers[memberInfo.Name];
                    if (modelMember != null && modelMember.NonSnapshot())
                        continue;
                }

                context.Worker.ShowStatus(string.Format(Localizer.SnapshotProperty, sourceObject, memberInfo.Name));

                var sourceValue = memberInfo.GetValue(sourceObject);
                var memberIsCloned = false;

                // XP object references
                if (memberInfo.ReferenceType != null)
                {
                    // aggregated objects
                    if (memberInfo.IsAggregated && sourceValue != null)
                    {
                        var aggrObj = memberInfo.GetValue(snapObject);
                        // if aggregated object in target is not null
                        // then link it to source value and clone state
                        if (aggrObj != null)
                        {
                            storeObjectState(context, sourceValue, aggrObj);
                            memberIsCloned = true;
                        }
                    }

                    if (sourceValue != null && !memberIsCloned)
                    {
                        memberInfo.SetValue(snapObject, buildObjectSnapshot(context, sourceValue));
                        memberIsCloned = true;
                        context.Worker.ShowStatus(string.Format(Localizer.SnapshotObject, sourceObject));
                    }
                }

                if (!memberIsCloned)
                    memberInfo.SetValue(snapObject, sourceValue);
            }

            // clone collections
            if (modelClass != null)
            {
                foreach (var modelMember in modelClass.AllMembers.Where(x => x.MemberInfo.IsAssociation
                                                                             && x.MemberInfo.IsList).TakeWhile(
                                                                                 x =>
                                                                                 !context.Worker.CancellationPending))
                {
                    if (modelMember == null || modelMember.NonSnapshot())
                        continue;

                    context.Worker.ShowStatus(string.Format(Localizer.SnapshotProperty, sourceObject, modelMember.Name));

                    var sourceCollection = modelMember.MemberInfo.GetValue(sourceObject) as IList;
                    var targetMember = ((IXPObject) snapObject).ClassInfo.GetMember(modelMember.Name);

                    var targetCollection = targetMember.GetValue(snapObject) as IList;
                    if (sourceCollection != null && targetCollection != null)
                    {
                        var sourceObjectList = new List<object>();
                        sourceObjectList.AddRange(sourceCollection.Cast<object>());
                        foreach (var sourceElement in sourceObjectList)
                        {
                            var targeElement = buildObjectSnapshot(context, sourceElement);
                            if (targeElement != null && !targetCollection.Contains(targeElement))
                                targetCollection.Add(targeElement);
                        }
                    }
                }
            }
        }
コード例 #10
0
        /// <summary>
        /// Builds object snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <returns></returns>
        private object buildObjectSnapshot(ClassBuildContext context, object sourceObject)
        {
            object result;

            if (!availableForSnapshot(sourceObject, context)) return null;

            if (!context.DoneObjects.TryGetValue(sourceObject, out result))
            {
                var packageUow = ((ObjectSpace)context.PackageObjectSpace).Session;
                var classInfo = packageUow.GetClassInfo(sourceObject.GetType());
                var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
                result = context.ObjectSpace.CreateObject(modelClass.TypeInfo.Type);
                // result = classInfo.CreateObject(packageUow);

                context.DoneObjects.Add(sourceObject, result);

                storeObjectState(context, sourceObject, result);
                context.MapQueue.Enqueue(sourceObject);
            }
            return result;
        }
コード例 #11
0
 private List <object> getSourceObjects(ClassBuildContext context)
 {
     return(getSourceObjects(context, null));
 }
コード例 #12
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Stores the state of the object.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="snapObject">The snap object.</param>
        private void storeObjectState(ClassBuildContext context, object sourceObject, object snapObject)
        {
            if (context.Worker.CancellationPending)
            {
                return;
            }

            if (sourceObject == null || snapObject == null)
            {
                return;
            }
            if (context.Map.ContainsKey(sourceObject))
            {
                return;
            }

            context.Map.Add(sourceObject, snapObject);
            context.Worker.ShowStatus(string.Format(Localizer.SnapshotObject, sourceObject));

            var classInfo  = ((IXPObject)sourceObject).ClassInfo;
            var modelClass = XafDeltaModule.XafApp.FindModelClass(classInfo.ClassType);

            IEnumerable <XPMemberInfo> sourceMembers = classInfo.Members;

            if (modelClass != null && modelClass.TypeInfo.IsInterface)
            {
                sourceMembers = from m in modelClass.AllMembers select classInfo.FindMember(m.Name);
            }

            foreach (var memberInfo in sourceMembers.Where(x => !(x is ServiceField) && x.IsPersistent &&
                                                           !x.IsReadOnly && !x.IsKey).TakeWhile(
                         x => !context.Worker.CancellationPending))
            {
                if (modelClass != null)
                {
                    var modelMember = modelClass.AllMembers[memberInfo.Name];
                    if (modelMember != null && modelMember.NonSnapshot())
                    {
                        continue;
                    }
                }

                context.Worker.ShowStatus(string.Format(Localizer.SnapshotProperty, sourceObject, memberInfo.Name));

                var sourceValue    = memberInfo.GetValue(sourceObject);
                var memberIsCloned = false;

                // XP object references
                if (memberInfo.ReferenceType != null)
                {
                    // aggregated objects
                    if (memberInfo.IsAggregated && sourceValue != null)
                    {
                        var aggrObj = memberInfo.GetValue(snapObject);
                        // if aggregated object in target is not null
                        // then link it to source value and clone state
                        if (aggrObj != null)
                        {
                            storeObjectState(context, sourceValue, aggrObj);
                            memberIsCloned = true;
                        }
                    }

                    if (sourceValue != null && !memberIsCloned)
                    {
                        memberInfo.SetValue(snapObject, buildObjectSnapshot(context, sourceValue));
                        memberIsCloned = true;
                        context.Worker.ShowStatus(string.Format(Localizer.SnapshotObject, sourceObject));
                    }
                }

                if (!memberIsCloned)
                {
                    memberInfo.SetValue(snapObject, sourceValue);
                }
            }

            // clone collections
            if (modelClass != null)
            {
                foreach (var modelMember in modelClass.AllMembers.Where(x => x.MemberInfo.IsAssociation &&
                                                                        x.MemberInfo.IsList).TakeWhile(
                             x =>
                             !context.Worker.CancellationPending))
                {
                    if (modelMember == null || modelMember.NonSnapshot())
                    {
                        continue;
                    }

                    context.Worker.ShowStatus(string.Format(Localizer.SnapshotProperty, sourceObject, modelMember.Name));

                    var sourceCollection = modelMember.MemberInfo.GetValue(sourceObject) as IList;
                    var targetMember     = ((IXPObject)snapObject).ClassInfo.GetMember(modelMember.Name);

                    var targetCollection = targetMember.GetValue(snapObject) as IList;
                    if (sourceCollection != null && targetCollection != null)
                    {
                        var sourceObjectList = new List <object>();
                        sourceObjectList.AddRange(sourceCollection.Cast <object>());
                        foreach (var sourceElement in sourceObjectList)
                        {
                            var targeElement = buildObjectSnapshot(context, sourceElement);
                            if (targeElement != null && !targetCollection.Contains(targeElement))
                            {
                                targetCollection.Add(targeElement);
                            }
                        }
                    }
                }
            }
        }
コード例 #13
0
 private List<object> getSourceObjects(ClassBuildContext context)
 {
     return getSourceObjects(context, null);
 }
コード例 #14
0
        /// <summary>
        /// Clones the state of the source object into target one.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="targetObject">The target object.</param>
        private void storeObjectState(ClassBuildContext context, object sourceObject, object targetObject)
        {
            var classInfo = ((IXPObject) sourceObject).ClassInfo;
            var modelClass = XafDeltaModule.XafApp.FindModelClass(classInfo.ClassType);

            foreach (var memberInfo in classInfo.Members.Where(x => !(x is ServiceField) && x.IsPersistent
                && !x.IsReadOnly && !x.IsKey))
            {
                if(modelClass != null)
                {
                    var modelMember = modelClass.AllMembers[memberInfo.Name];
                    if(modelMember != null && modelMember.NonSnapshot())
                        continue;
                }

                var sourceValue = memberInfo.GetValue(sourceObject);
                var memberIsCloned = false;

                // XP object references
                if (memberInfo.ReferenceType != null)
                {
                    // aggregated objects
                    if(memberInfo.IsAggregated && sourceValue != null)
                    {
                        var aggrObj = memberInfo.GetValue(targetObject);
                        // if aggregated object in target is not null
                        // then link it to source value and clone state
                        if (aggrObj != null)
                        {
                            if (!context.DoneObjects.ContainsValue(aggrObj))
                            {
                                if(!context.DoneObjects.ContainsKey(sourceValue))
                                    context.DoneObjects.Add(sourceValue, aggrObj);
                                storeObjectState(context, sourceValue, aggrObj);
                            }
                            memberIsCloned = true;
                        }
                    }

                    if(sourceValue != null && !memberIsCloned)
                    {
                        memberInfo.SetValue(targetObject, buildObjectSnapshot(context, sourceValue));
                        memberIsCloned = true;
                    }
                }

                if (!memberIsCloned)
                    memberInfo.SetValue(targetObject, sourceValue);
            }

            // clone collections
            if (modelClass != null)
            {
                foreach (var modelMember in modelClass.AllMembers.Where(x => x.MemberInfo.IsAssociation
                    && x.MemberInfo.IsList))
                {
                    if (modelMember == null || modelMember.NonSnapshot())
                        continue;

                    var sourceCollection = modelMember.MemberInfo.GetValue(sourceObject) as IList;
                    var targetMember = ((IXPObject) targetObject).ClassInfo.GetMember(modelMember.Name);

                    var targetCollection = targetMember.GetValue(targetObject) as IList;
                    if (sourceCollection != null && targetCollection != null)
                    {
                        var sourceObjectList = new List<object>();
                        sourceObjectList.AddRange(sourceCollection.Cast<object>());
                        foreach (var sourceElement in sourceObjectList)
                        {
                            var targeElement = buildObjectSnapshot(context, sourceElement);
                            if (targeElement != null && !targetCollection.Contains(targeElement))
                                targetCollection.Add(targeElement);
                        }
                    }
                }
            }
        }
コード例 #15
0
        private List<object> getSourceObjects(ClassBuildContext context, IModelClass modelClass)
        {
            if (modelClass == null)
                modelClass = context.ModelClass;

            IEnumerable<object> result = new List<object>();
            var targetType = modelClass.TypeInfo.Type;
            var allObjects = (from c in context.ObjectSpace.GetObjects(targetType).Cast<object>() select c).ToList();
            if (Owner.SelectorMode == SelectorMode.BlackList)
                result = allObjects;
            foreach (var selector in modelClass.AllSnapshotSelectors())
            {
                IEnumerable<object> selectResult;

                var expression = selector.Expression;
                if (string.IsNullOrEmpty(expression))
                    selectResult = allObjects;
                else
                    selectResult = context.ObjectSpace.GetObjects(targetType, CriteriaOperator.Parse(expression)).Cast<object>();

                if (selector.SelectorType == SelectorType.Include)
                    result = result.Union(selectResult).Distinct();
                else
                    result = result.Except(selectResult);
            }
            result = result.Where(x => !context.DoneObjects.ContainsKey(x)).Distinct();
            result = from c in result where !(c is ISnapshotable)
                         || ((ISnapshotable)c).ShouldBeIncludedInSnapshot(context.TargetNode) select c;

            var resultList = result.ToList();

            // register class done
            context.SelectedTypes.Add(modelClass);

            foreach (var resultObject in resultList)
            {
                // store selected objects hashes
                if (XafDeltaModule.XafApp.FindModelClass(resultObject.GetType()) == modelClass)
                {
                    var seekKey = resultObject.GetType().AssemblyQualifiedName +
                        context.ObjectSpace.GetKeyValue(resultObject);

                    context.SelectedSourceObjects.Add(seekKey);
                }
            }

            return resultList;
        }
コード例 #16
0
        /// <summary>
        /// Builds the class snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        private void buildClassSnapshot(ClassBuildContext context)
        {
            // Prepare snapshot read only parameters
            SnapshotNodeParameter.Instance.SnapshotNode = context.TargetNode;
            SnapshotNodeIdParameter.Instance.SnapshotNodeId = context.TargetNode.NodeId;
            try
            {
                //var includeObjects = getSourceObjects(context, SelectorType.Include);
                //var excludeObjects = getSourceObjects(context, SelectorType.Exclude);

                //var sourceObjects = includeObjects.Except(excludeObjects).Where(x => !context.DoneObjects.ContainsKey(x)).ToList();

                var sourceObjects = getSourceObjects(context);

                if(sourceObjects.Count() > 0)
                    context.Worker.ReportProgress(string.Format(Localizer.SourceObjectsFoundForClass, sourceObjects.Count, context.ModelClass.Name));

                // for each selected objects build snapshots
                foreach (var sourceObject in sourceObjects.TakeWhile(x => !context.Worker.CancellationPending))
                    buildObjectSnapshot(context, sourceObject);
            }
            finally
            {
                SnapshotNodeParameter.Instance.SnapshotNode = null;
            }
        }
コード例 #17
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Builds the class snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private int buildClassSnapshot(ClassBuildContext context)
        {
            var snapSourceList = getSnapShourceList(context);
            var result = snapSourceList.Count;
            if (result > 0)
                context.Worker.ReportProgress(string.Format(Localizer.SourceObjectsFoundForClass,
                                                            result, context.ModelClass.Name));
            int i = 0;
            foreach (var sourceObject in snapSourceList.TakeWhile(x => !context.Worker.CancellationPending))
            {
                context.Worker.ReportPercent((double) i++/(double) result);
                buildObjectSnapshot(context, sourceObject);
            }

            return result;
        }
コード例 #18
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
 /// <summary>
 /// Determines whether source object is source for snapshot.
 /// </summary>
 /// <param name="context">The context.</param>
 /// <param name="sourceObject">The source object.</param>
 /// <returns>
 ///   <c>true</c> if the source object is source for snapshort; otherwise, <c>false</c>.
 /// </returns>
 private bool isSourceObject(ClassBuildContext context, object sourceObject)
 {
     var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
     var sourceContext = new ClassBuildContext(context, modelClass);
     var result = !modelClass.NonSnapshot() && getSnapShourceList(sourceContext).Contains(sourceObject);
     return result;
 }
コード例 #19
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Gets objects to be snapshoted.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <returns></returns>
        private IList<object> getSnapShourceList(ClassBuildContext context)
        {
            IList<object> result;
            if (!context.SnapSources.TryGetValue(context.ModelClass, out result))
            {
                IEnumerable<object> resultEnum = new List<object>();
                var classType = context.ModelClass.TypeInfo.Type;
                var tuple = from c in context.AppObjectSpace.GetObjects(classType).Cast<object>() select c;

                if (Owner.SelectorMode == SelectorMode.BlackList)
                    resultEnum = tuple;

                foreach (var selector in context.ModelClass.AllSnapshotSelectors())
                {
                    IEnumerable<object> selectedObjects;
                    if (string.IsNullOrEmpty(selector.Expression))
                        selectedObjects = tuple;
                    else
                        selectedObjects =
                            from c in
                                context.AppObjectSpace.GetObjects(classType, CriteriaOperator.Parse(selector.Expression))
                                .Cast<object>()
                            select c;

                    resultEnum = selector.SelectorType == SelectorType.Include
                                     ? resultEnum.Union(selectedObjects)
                                     : resultEnum.Except(selectedObjects);

                }
                result =
                    resultEnum.Except(context.DoneObjects).Where(
                        x => XafDeltaModule.XafApp.FindModelClass(x.GetType()) == context.ModelClass).ToList();
                context.SnapSources.Add(context.ModelClass, result);
            }
            return result;
        }
コード例 #20
0
ファイル: SnapshotService.cs プロジェクト: xafdelta/xafdelta
        /// <summary>
        /// Builds the object snapshot.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <returns></returns>
        private object buildObjectSnapshot(ClassBuildContext context, object sourceObject)
        {
            if (!isSourceObject(context, sourceObject) || context.Worker.CancellationPending) return null;
            object snapObject;

            if (!context.Map.TryGetValue(sourceObject, out snapObject))
            {
                var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
                snapObject = context.SnapObjectSpace.CreateObject(modelClass.TypeInfo.Type);
                storeObjectState(context, sourceObject, snapObject);
                context.DoneObjects.Enqueue(sourceObject);
            }
            return snapObject;
        }
コード例 #21
0
        /// <summary>
        /// Clones the state of the source object into target one.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="sourceObject">The source object.</param>
        /// <param name="targetObject">The target object.</param>
        private void storeObjectState(ClassBuildContext context, object sourceObject, object targetObject)
        {
            var classInfo  = ((IXPObject)sourceObject).ClassInfo;
            var modelClass = XafDeltaModule.XafApp.FindModelClass(classInfo.ClassType);

            foreach (var memberInfo in classInfo.Members.Where(x => !(x is ServiceField) && x.IsPersistent &&
                                                               !x.IsReadOnly && !x.IsKey))
            {
                if (modelClass != null)
                {
                    var modelMember = modelClass.AllMembers[memberInfo.Name];
                    if (modelMember != null && modelMember.NonSnapshot())
                    {
                        continue;
                    }
                }

                var sourceValue    = memberInfo.GetValue(sourceObject);
                var memberIsCloned = false;

                // XP object references
                if (memberInfo.ReferenceType != null)
                {
                    // aggregated objects
                    if (memberInfo.IsAggregated && sourceValue != null)
                    {
                        var aggrObj = memberInfo.GetValue(targetObject);
                        // if aggregated object in target is not null
                        // then link it to source value and clone state
                        if (aggrObj != null)
                        {
                            if (!context.DoneObjects.ContainsValue(aggrObj))
                            {
                                if (!context.DoneObjects.ContainsKey(sourceValue))
                                {
                                    context.DoneObjects.Add(sourceValue, aggrObj);
                                }
                                storeObjectState(context, sourceValue, aggrObj);
                            }
                            memberIsCloned = true;
                        }
                    }

                    if (sourceValue != null && !memberIsCloned)
                    {
                        memberInfo.SetValue(targetObject, buildObjectSnapshot(context, sourceValue));
                        memberIsCloned = true;
                    }
                }

                if (!memberIsCloned)
                {
                    memberInfo.SetValue(targetObject, sourceValue);
                }
            }

            // clone collections
            if (modelClass != null)
            {
                foreach (var modelMember in modelClass.AllMembers.Where(x => x.MemberInfo.IsAssociation &&
                                                                        x.MemberInfo.IsList))
                {
                    if (modelMember == null || modelMember.NonSnapshot())
                    {
                        continue;
                    }

                    var sourceCollection = modelMember.MemberInfo.GetValue(sourceObject) as IList;
                    var targetMember     = ((IXPObject)targetObject).ClassInfo.GetMember(modelMember.Name);

                    var targetCollection = targetMember.GetValue(targetObject) as IList;
                    if (sourceCollection != null && targetCollection != null)
                    {
                        var sourceObjectList = new List <object>();
                        sourceObjectList.AddRange(sourceCollection.Cast <object>());
                        foreach (var sourceElement in sourceObjectList)
                        {
                            var targeElement = buildObjectSnapshot(context, sourceElement);
                            if (targeElement != null && !targetCollection.Contains(targeElement))
                            {
                                targetCollection.Add(targeElement);
                            }
                        }
                    }
                }
            }
        }
コード例 #22
0
 private bool availableForSnapshot(object sourceObject, ClassBuildContext context)
 {
     var result = context.DoneObjects.ContainsKey(sourceObject);
     if(!result)
     {
         var modelClass = XafDeltaModule.XafApp.FindModelClass(sourceObject.GetType());
         if(modelClass != null)
         {
             if (!context.SelectedTypes.Contains(modelClass))
                 getSourceObjects(context, modelClass);
             var seekKey = sourceObject.GetType().AssemblyQualifiedName +
                           context.ObjectSpace.GetKeyValue(sourceObject);
             result = context.SelectedSourceObjects.Contains(seekKey);
         }
     }
     return result;
 }