internal void OnDataPortalException(DataPortalEventArgs eventArgs, Exception ex) { if (_target != null) _target.DataPortal_OnDataPortalException(eventArgs, ex); else CallMethodIfImplemented(_methodNames.OnDataPortalException, eventArgs, ex); }
public DataPortalResult Delete(Type objectType, object criteria, DataPortalContext context) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, DataPortalOperations.Delete); try { // create an instance of the business objet obj = new LateBoundObject(objectType); target = obj.Instance as IDataPortalTarget; if (target != null) { target.DataPortal_OnDataPortalInvoke(eventArgs); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); } // tell the business object to delete itself obj.CallMethod("DataPortal_Delete", criteria); if (target != null) { target.DataPortal_OnDataPortalInvokeComplete(eventArgs); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete", eventArgs); } return(new DataPortalResult()); } catch (Exception ex) { try { if (target != null) { target.DataPortal_OnDataPortalException(eventArgs, ex); } else { obj.CallMethodIfImplemented( "DataPortal_OnDataPortalException", eventArgs, ex); } } catch { // ignore exceptions from the exception handler } throw new DataPortalException( "DataPortal.Delete " + Resources.FailedOnServer, ex, new DataPortalResult()); } }
public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Delete); try { // create an instance of the business objet obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType)); ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); target = obj.Instance as IDataPortalTarget; if (target != null) { target.DataPortal_OnDataPortalInvoke(eventArgs); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); } // tell the business object to delete itself await obj.CallMethodTryAsync("DataPortal_Delete", 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(new DataPortalResult()); } 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 } throw DataPortal.NewDataPortalException( "DataPortal.Delete " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, obj, null, "DataPortal.Delete", ex), null); } }
public async Task <DataPortalResult> Create( Type objectType, object criteria, DataPortalContext context, bool isSync) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Create); 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.MarkNew(); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkNew"); } // tell the business object to create its data if (criteria is EmptyCriteria) { await obj.CallMethodTryAsync("DataPortal_Create").ConfigureAwait(false); } else { await obj.CallMethodTryAsync("DataPortal_Create", 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.Create " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex), outval); } finally { object reference = null; if (obj != null) { reference = obj.Instance; } ApplicationContext.DataPortalActivator.FinalizeInstance(reference); } }
public DataPortalResult Create( Type objectType, object criteria, DataPortalContext context) { LateBoundObject obj = null; IDataPortalTarget target = null; var eventArgs = new DataPortalEventArgs(context, objectType, DataPortalOperations.Create); 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.MarkNew(); } else { obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs); obj.CallMethodIfImplemented("MarkNew"); } // tell the business object to create its data if (criteria is EmptyCriteria) { obj.CallMethod("DataPortal_Create"); } else { obj.CallMethod("DataPortal_Create", 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.Create " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex), new DataPortalResult(outval)); } }