static PersistentBase PopulateObjectProperties(PersistentBase persistentObject, Dictionary <string, object> propertyValues, UnitOfWork uow, XPClassInfo classInfo) { object keyValue; if (persistentObject == null && propertyValues.TryGetValue(classInfo.KeyProperty.Name, out keyValue)) { persistentObject = (PersistentBase)uow.GetObjectByKey(classInfo, keyValue); } if (persistentObject == null) { persistentObject = (PersistentBase)classInfo.CreateNewObject(uow); } foreach (KeyValuePair <string, object> pair in propertyValues) { XPMemberInfo memberInfo = classInfo.FindMember(pair.Key); if (memberInfo.IsReadOnly) { continue; } if (memberInfo.ReferenceType != null) { PopulateReferenceProperty(persistentObject, uow, pair.Value, memberInfo); } else { PopulateScalarProperty(persistentObject, pair.Value, memberInfo); } } return(persistentObject); }
public static bool IsProrpotyChanged(XPClassInfo ClassInfo, object Obj, string ProportName, out object OldValue) { XPMemberInfo memberInfo = ClassInfo.GetMember(ProportName); OldValue = PersistentBase.GetModificationsStore(Obj).GetPropertyOldValue(memberInfo); return(OldValue != null); }
private T createListViewController <T>(PersistentBase currentObject, bool activate, XPObjectSpace XPObjectSpace, HandleInfo handleInfo) where T : ViewController, new() { var controller = createController <T>(currentObject.GetType(), activate, XPObjectSpace, handleInfo); XafApplication application = controller.Application; Isolate.WhenCalled(() => application.CreateObjectSpace()).WillReturn(XPObjectSpace); return(controller); }
private static void PopulateScalarProperty(PersistentBase theObject, object theValue, XPMemberInfo memberInfo) { if (memberInfo == theObject.ClassInfo.OptimisticLockField) { SetOptimisticLockField(theObject, (int)theValue); } else { memberInfo.SetValue(theObject, theValue); } }
private static void PopulateReferenceProperty(PersistentBase parent, UnitOfWork uow, object theValue, XPMemberInfo memberInfo) { if (memberInfo.IsAggregated) { PersistentBase propertyValue = (PersistentBase)memberInfo.GetValue(parent); propertyValue = PopulateObjectProperties(propertyValue, (Dictionary <string, object>)theValue, uow, memberInfo.ReferenceType); memberInfo.SetValue(parent, propertyValue); } else { memberInfo.SetValue(parent, uow.GetObjectByKey(memberInfo.MemberType, theValue)); } }
private T createController <T>(ViewType viewType, PersistentBase currentObject, bool activate, HandleInfo handleInfo) where T : ViewController, new() { if (currentObject.Session.IsNewObject(currentObject)) { currentObject.Session.Save(currentObject); } var XPObjectSpace = new XPObjectSpace(new UnitOfWork(currentObject.Session.DataLayer), XafTypesInfo.Instance); var persistentBase = XPObjectSpace.GetObject(currentObject); T controller = viewType == ViewType.ListView ? createListViewController <T>(persistentBase, activate, XPObjectSpace, handleInfo) : createDetailViewController <T>(XPObjectSpace, persistentBase, activate, handleInfo); var frame = new Frame(controller.Application, TemplateContext.View); frame.SetView(controller.View); Isolate.WhenCalled(() => controller.Frame).WillReturn(frame); if (activate) { controller.View.CurrentObject = persistentBase; } return(controller); }
private T createDetailViewController <T>(XPObjectSpace XPObjectSpace, PersistentBase currentObject, bool activate, HandleInfo handleInfo) where T : ViewController, new() { XafTypesInfo.Instance.RegisterEntity(currentObject.GetType().BaseType); XafTypesInfo.Instance.RegisterEntity(currentObject.GetType()); XPObjectSpace.Session.UpdateSchema(currentObject.GetType().BaseType); XPObjectSpace.Session.UpdateSchema(currentObject.GetType()); XPObjectSpace.Session.DataLayer.UpdateSchema(true, XPObjectSpace.Session.GetClassInfo(currentObject.GetType().BaseType)); XPObjectSpace.Session.DataLayer.UpdateSchema(true, XPObjectSpace.Session.GetClassInfo(currentObject.GetType())); var application = Isolate.Fake.Instance <XafApplication>(); Isolate.WhenCalled(() => application.CreateObjectSpace()).WillReturn(XPObjectSpace); var detailView = new DetailView(XPObjectSpace, currentObject, application, true); var conntroller = new T(); Isolate.WhenCalled(() => conntroller.Application).WillReturn(application); conntroller.Active[""] = false; conntroller.SetView(detailView); if (activate) { Activate(conntroller, handleInfo); } return(conntroller); }
public T CreateAndActivateController <T>(ViewType viewType, PersistentBase currentObject, HandleInfo handleInfo) where T : ViewController, new() { return(createController <T>(viewType, currentObject, true, handleInfo)); }
/// <summary> /// Returns the Version number of XPO BusinessClass instance bo for ElasticSearch /// </summary> /// <param name="bo">XPO BusinessClass instance bo</param> /// <returns>Version number for ElasticSearch</returns> public int GetVersion(PersistentBase bo) { return((int)PersistentBase.GetCustomPropertyStore(bo).GetCustomPropertyValue(ClassInfo.OptimisticLockField) + 1); }
public static void PopulateObject(string json, Session session, PersistentBase obj) { PopulateObject(json, session, obj.ClassInfo, obj); }
public sealed override void SetDirtyInSystemTransaction(PersistentBase a_object) { }
static void SetOptimisticLockField(PersistentBase obj, int newValue) { obj.ClassInfo.OptimisticLockField?.SetValue(obj, newValue); obj.ClassInfo.OptimisticLockFieldInDataLayer?.SetValue(obj, newValue); }
public static object GetOldValue(XPClassInfo ClassInfo, object Obj, string ProportName) { XPMemberInfo memberInfo = ClassInfo.GetMember(ProportName); return(PersistentBase.GetModificationsStore(Obj).GetPropertyOldValue(memberInfo)); }
public override void ClearModifications(object theObject) { PersistentBase.GetModificationsStore(theObject).ClearModifications(); }
public override bool HasModifications(object theObject) { return(PersistentBase.GetModificationsStore(theObject).HasModifications()); }
public T CreateController <T>(ViewType viewType, PersistentBase currentObject) where T : ViewController, new() { return(createController <T>(viewType, currentObject, false, null)); }
public static void OnChanged(this PersistentBase persistentBase, string memberName) => persistentBase.CallMethod(nameof(OnChanged), memberName);