internal void MarkOld() { if (_target != null) _target.MarkOld(); else CallMethodIfImplemented("MarkOld"); }
private void Update(object obj, bool hasParameters, params object[] parameters) { if (obj == null) { return; } var busObj = obj as Core.BusinessBase; if (busObj != null && busObj.IsDirty == false) { // if the object isn't dirty, then just exit return; } var operation = DataPortalOperations.Update; Type objectType = obj.GetType(); IDataPortalTarget target = obj as IDataPortalTarget; LateBoundObject lb = new LateBoundObject(obj); ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance); try { if (target != null) { target.Child_OnDataPortalInvoke( new DataPortalEventArgs(null, objectType, obj, operation)); } else { lb.CallMethodIfImplemented("Child_OnDataPortalInvoke", new DataPortalEventArgs(null, objectType, obj, operation)); } // tell the business object to update itself if (busObj != null) { if (busObj.IsDeleted) { if (!busObj.IsNew) { // tell the object to delete itself lb.CallMethod("Child_DeleteSelf", parameters); } if (target != null) { target.MarkNew(); } else { lb.CallMethodIfImplemented("MarkNew"); } } else { if (busObj.IsNew) { // tell the object to insert itself lb.CallMethod("Child_Insert", parameters); } else { // tell the object to update itself lb.CallMethod("Child_Update", parameters); } if (target != null) { target.MarkOld(); } else { lb.CallMethodIfImplemented("MarkOld"); } } } else if (obj is Core.ICommandObject) { // tell the object to update itself if (hasParameters) { lb.CallMethod("Child_Execute", parameters); } else { lb.CallMethod("Child_Execute"); } operation = DataPortalOperations.Execute; } else { // this is an updatable collection or some other // non-BusinessBase type of object // tell the object to update itself if (hasParameters) { lb.CallMethod("Child_Update", parameters); } else { lb.CallMethod("Child_Update"); } if (target != null) { target.MarkOld(); } else { lb.CallMethodIfImplemented("MarkOld"); } } if (target != null) { target.Child_OnDataPortalInvokeComplete( new DataPortalEventArgs(null, objectType, obj, operation)); } else { lb.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete", new DataPortalEventArgs(null, objectType, obj, operation)); } } catch (Exception ex) { try { if (target != null) { target.Child_OnDataPortalException( new DataPortalEventArgs(null, objectType, obj, operation), ex); } else if (lb != null) { lb.CallMethodIfImplemented("Child_OnDataPortalException", new DataPortalEventArgs(null, objectType, obj, operation), ex); } } catch { // ignore exceptions from the exception handler } throw new Csla.DataPortalException( "ChildDataPortal.Update " + Properties.Resources.FailedOnServer, ex, obj); } }
private object Fetch(Type objectType, bool hasParameters, params object[] parameters) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(null, objectType, parameters, DataPortalOperations.Fetch); try { // create an instance of the business object obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType)); ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); target = obj.Instance as IDataPortalTarget; if (target != null) { target.Child_OnDataPortalInvoke(eventArgs); target.MarkAsChild(); target.MarkOld(); } else { obj.CallMethodIfImplemented("Child_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkAsChild"); obj.CallMethodIfImplemented("MarkOld"); } // tell the business object to fetch its data if (hasParameters) { obj.CallMethod("Child_Fetch", parameters); } else { obj.CallMethod("Child_Fetch"); } if (target != null) { target.Child_OnDataPortalInvokeComplete(eventArgs); } else { obj.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete", eventArgs); } // return the populated business object as a result return(obj.Instance); } catch (Exception ex) { try { if (target != null) { target.Child_OnDataPortalException(eventArgs, ex); } else if (obj != null) { obj.CallMethodIfImplemented("Child_OnDataPortalException", eventArgs, ex); } } catch { // ignore exceptions from the exception handler } object bo = null; if (obj != null) { bo = obj.Instance; } throw new Csla.DataPortalException( "ChildDataPortal.Fetch " + Properties.Resources.FailedOnServer, ex, bo); } }
public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Fetch); try { // create an instance of the business object. obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType)); ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); target = obj.Instance as IDataPortalTarget; if (target != null) { target.DataPortal_OnDataPortalInvoke(eventArgs); target.MarkOld(); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkOld"); } // tell the business object to fetch its data if (criteria is EmptyCriteria) { await obj.CallMethodTryAsync("DataPortal_Fetch").ConfigureAwait(false); } else { await obj.CallMethodTryAsync("DataPortal_Fetch", criteria).ConfigureAwait(false); } var busy = obj.Instance as Csla.Core.ITrackStatus; if (busy != null && busy.IsBusy) { throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name)); } if (target != null) { target.DataPortal_OnDataPortalInvokeComplete(eventArgs); } else { obj.CallMethodIfImplemented( "DataPortal_OnDataPortalInvokeComplete", eventArgs); } // return the populated business object as a result return(new DataPortalResult(obj.Instance)); } catch (Exception ex) { try { if (target != null) { target.DataPortal_OnDataPortalException(eventArgs, ex); } else if (obj != null) { obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex); } } catch { // ignore exceptions from the exception handler } object outval = null; if (obj != null) { outval = obj.Instance; } throw DataPortal.NewDataPortalException( "DataPortal.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Fetch", ex), outval); } }
/// <summary> /// Get an existing business object. /// </summary> /// <param name="objectType">Type of business object to retrieve.</param> /// <param name="parameters"> /// Criteria parameters passed from caller. /// </param> public object Fetch(Type objectType, params object[] parameters) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(null, objectType, DataPortalOperations.Fetch); try { // create an instance of the business object obj = new LateBoundObject(objectType); target = obj.Instance as IDataPortalTarget; if (target != null) { target.Child_OnDataPortalInvoke(eventArgs); target.MarkAsChild(); target.MarkOld(); } else { obj.CallMethodIfImplemented("Child_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkAsChild"); obj.CallMethodIfImplemented("MarkOld"); } // tell the business object to fetch its data obj.CallMethod("Child_Fetch", parameters); if (target != null) { target.Child_OnDataPortalInvokeComplete(eventArgs); } else { obj.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete", eventArgs); } // return the populated business object as a result return(obj.Instance); } catch (Exception ex) { try { if (target != null) { target.Child_OnDataPortalException(eventArgs, ex); } else { obj.CallMethodIfImplemented("Child_OnDataPortalException", eventArgs, ex); } } catch { // ignore exceptions from the exception handler } throw new YYT.DataPortalException( "ChildDataPortal.Fetch " + Properties.Resources.FailedOnServer, ex, obj.Instance); } }
public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, DataPortalOperations.Fetch); try { // create an instance of the business object. obj = new LateBoundObject(objectType); target = obj.Instance as IDataPortalTarget; if (target != null) { target.DataPortal_OnDataPortalInvoke(eventArgs); target.MarkOld(); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkOld"); } // tell the business object to fetch its data if (criteria is EmptyCriteria) { obj.CallMethod("DataPortal_Fetch"); } else { obj.CallMethod("DataPortal_Fetch", criteria); } if (target != null) { target.DataPortal_OnDataPortalInvokeComplete(eventArgs); } else { obj.CallMethodIfImplemented( "DataPortal_OnDataPortalInvokeComplete", eventArgs); } // return the populated business object as a result return(new DataPortalResult(obj.Instance)); } catch (Exception ex) { try { if (target != null) { target.DataPortal_OnDataPortalException(eventArgs, ex); } else if (obj != null) { obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex); } } catch { // ignore exceptions from the exception handler } object outval = null; if (obj != null) { outval = obj.Instance; } throw new DataPortalException( "DataPortal.Fetch " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Fetch", ex), new DataPortalResult(outval)); } }