예제 #1
0
        /// <summary>
        /// Merges static properties of DataObject.
        /// </summary>
        /// <param name="baseObject">Base DataObject to be merged.</param>
        /// <param name="mergingObject">Merging DataObject to be merged into base DataObject.</param>
        /// <param name="checkPaths">Consider paths in the merging.</param>
        private void MergeProperties(IDataObject baseObject, IDataObject mergingObject, Boolean checkPaths)
        {
            foreach (PropertyInfo propertyInfo in mergingObject.GetType().GetRuntimeProperties())
            {
                Boolean includePath = true;

                if (this.Paths != null)
                {
                    includePath = !checkPaths;

                    foreach (String path in this.Paths)
                    {
                        if (propertyInfo.Name == path)
                        {
                            includePath = true;
                        }
                    }
                }

                if ((propertyInfo.CanWrite) && (!mergingObject.GetProxyState(propertyInfo.Name)) && (includePath))
                {
                    if (IsDataList(propertyInfo.PropertyType))
                    {
                        IDataList propertyValue = (IDataList)propertyInfo.GetValue(mergingObject, new Object[] { });

                        if (propertyValue != null)
                        {
                            IDataList dataList = (IDataList)LightHouse.Elite.Core.Builder.Get(propertyValue.GetType());

                            for (int i = 0; i < propertyValue.Count; i++)
                            {
                                if (IsReferenceObject((IDataObject)propertyValue[i]))
                                {
                                    dataList.Add(GetReferencedObject((IDataObject)propertyValue[i]));
                                }
                                else
                                {
                                    IDataObject referencedObject = GetProxyObject((IDataObject)propertyValue[i]);
                                    dataList.Add(referencedObject);
                                }
                            }

                            propertyInfo.SetValue(baseObject, dataList, new Object[] { });
                        }
                    }
                    else if (IsDataObject(propertyInfo.PropertyType))
                    {
                        DataObject propertyValue = (DataObject)propertyInfo.GetValue(mergingObject, new Object[] { });

                        if (propertyValue != null)
                        {
                            if (IsReferenceObject(propertyValue))
                            {
                                // If the Object hasn't been saved, it is persisted as such to the database
                                if (String.IsNullOrEmpty(propertyValue.ID))
                                {
                                    IDataObject referencedObject = GetProxyObject(propertyValue);
                                    propertyInfo.SetValue(baseObject, referencedObject, new Object[] { });
                                }
                                else
                                {
                                    propertyInfo.SetValue(baseObject, GetReferencedObject(propertyValue), new Object[] { });
                                }
                            }
                            else
                            {
                                IDataObject referencedObject = GetProxyObject(propertyValue);
                                propertyInfo.SetValue(baseObject, referencedObject, new Object[] { });
                            }
                        }
                        else
                        {
                            propertyInfo.SetValue(baseObject, null, new Object[] { });
                        }
                    }
                    else
                    {
                        propertyInfo.SetValue(baseObject, propertyInfo.GetValue(mergingObject, new Object[] { }), new Object[] { });
                    }
                }
            }
        }
예제 #2
0
        /// <summary>
        /// Merges dynamic properties of DataObject.
        /// </summary>
        /// <param name="baseObject">Base DataObject to be merged.</param>
        /// <param name="mergingObject">Merging DataObject to be merged into base DataObject.</param>
        /// <param name="checkPaths">Consider paths in the merging.</param>
        private void MergeDynamicProperties(IDataObject baseObject, IDataObject mergingObject, Boolean checkPaths)
        {
            baseObject.DynamicType = mergingObject.DynamicType;

            DataCache dynamicCache = (DataCache)typeof(DataObject).GetTypeInfo().GetDeclaredField("dynamicCache").GetValue(mergingObject);

            foreach (KeyValuePair<String, Object> propertyValue in dynamicCache.GetObjectsInRegion("Properties"))
            {
                Boolean includePath = true;

                if (this.Paths != null)
                {
                    includePath = !checkPaths;

                    foreach (String path in this.Paths)
                    {
                        if (propertyValue.Key == path)
                        {
                            includePath = true;
                        }
                    }
                }

                if ((!mergingObject.GetProxyState(propertyValue.Key)) && (includePath))
                {
                    if (propertyValue.Value != null)
                    {
                        Type propertyType = propertyValue.Value.GetType();

                        if (IsDataList(propertyType))
                        {
                            IDataList mergingList = ((IDataList)propertyValue.Value);
                            IDataList dataList = (IDataList)LightHouse.Elite.Core.Builder.Get(propertyValue.Value.GetType());

                            for (int i = 0; i < mergingList.Count; i++)
                            {
                                IDataObject cloningObject = (IDataObject)mergingList[i];

                                if (IsReferenceObject(cloningObject))
                                {
                                    //Proxy on new generated object should be set to false, otherwise will bet unproxied on storing

                                    if (String.IsNullOrEmpty(cloningObject.ID))
                                    {
                                        IDataObject referencedObject = GetProxyObject(cloningObject);
                                        dataList.Add(referencedObject);
                                    }
                                    else
                                    {

                                        dataList.Add(GetReferencedObject(cloningObject));
                                    }
                                }
                                else
                                {
                                    IDataObject referencedObject = GetProxyObject(cloningObject);
                                    dataList.Add(referencedObject);
                                }
                            }

                            baseObject.SetProperty(propertyValue.Key, dataList);
                        }
                        else if (IsDataObject(propertyType))
                        {
                            DataObject cloningObject = ((DataObject)propertyValue.Value);

                            if (IsReferenceObject(cloningObject))
                            {
                                // If the Object hasn't been saved, it is persisted as such to the database
                                if (String.IsNullOrEmpty(cloningObject.ID))
                                {
                                    IDataObject referencedObject = GetProxyObject(cloningObject);
                                    baseObject.SetProperty(propertyValue.Key, referencedObject);
                                }
                                else
                                {
                                    baseObject.SetProperty(propertyValue.Key, GetReferencedObject(cloningObject));
                                }
                            }
                            else
                            {
                                IDataObject referencedObject = GetProxyObject(cloningObject);
                                baseObject.SetProperty(propertyValue.Key, referencedObject);
                            }
                        }
                        else
                        {
                            baseObject.SetProperty(propertyValue.Key, propertyValue.Value);
                        }
                    }
                    else
                    {
                        baseObject.SetProperty(propertyValue.Key, propertyValue.Value);
                    }
                }
            }
        }