private async Task Update(object obj, bool hasParameters, bool bypassIsDirtyTest, params object[] parameters) { if (obj == null) { return; } if (obj is Core.BusinessBase busObj && busObj.IsDirty == false && bypassIsDirtyTest == false) { // if the object isn't dirty, then just exit return; } var criteria = DataPortal <object> .GetCriteriaFromArray(parameters); var operation = DataPortalOperations.Update; Type objectType = obj.GetType(); DataPortalTarget lb = new DataPortalTarget(obj); ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance); try { lb.Child_OnDataPortalInvoke( new DataPortalEventArgs(null, objectType, obj, operation)); await lb.UpdateChildAsync(criteria).ConfigureAwait(false); lb.Child_OnDataPortalInvokeComplete( new DataPortalEventArgs(null, objectType, obj, operation)); } catch (Exception ex) { try { if (lb != null) { lb.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); } finally { ApplicationContext.DataPortalActivator.FinalizeInstance(lb.Instance); } }
public async Task <DataPortalResult> Create( Type objectType, object criteria, DataPortalContext context, bool isSync) { DataPortalTarget obj = null; var eventArgs = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Create); try { obj = ApplicationContext.CreateInstance <DataPortalTarget>(ApplicationContext.CreateInstance(objectType)); //ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); obj.OnDataPortalInvoke(eventArgs); obj.MarkNew(); await obj.CreateAsync(criteria, isSync); obj.ThrowIfBusy(); obj.OnDataPortalInvokeComplete(eventArgs); return(new DataPortalResult(obj.Instance)); } catch (Exception ex) { try { if (obj != null) { obj.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); } }
private async Task <object> Create(System.Type objectType, bool hasParameters, params object[] parameters) { var criteria = DataPortal <object> .GetCriteriaFromArray(parameters); DataPortalTarget obj = null; var eventArgs = new DataPortalEventArgs(null, objectType, criteria, DataPortalOperations.Create); try { obj = new DataPortalTarget(ApplicationContext.DataPortalActivator.CreateInstance(objectType)); ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); obj.Child_OnDataPortalInvoke(eventArgs); obj.MarkAsChild(); obj.MarkNew(); await obj.CreateChildAsync(criteria).ConfigureAwait(false); obj.OnDataPortalInvokeComplete(eventArgs); return(obj.Instance); } catch (Exception ex) { try { if (obj != null) { obj.Child_OnDataPortalException(eventArgs, ex); } } catch { // ignore exceptions from the exception handler } object outval = null; if (obj != null) { outval = obj.Instance; } throw new Csla.DataPortalException( "ChildDataPortal.Create " + Properties.Resources.FailedOnServer, ex, outval); } finally { object reference = null; if (obj != null) { reference = obj.Instance; } ApplicationContext.DataPortalActivator.FinalizeInstance(reference); } }
public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync) { DataPortalOperations operation = DataPortalOperations.Update; Type objectType = obj.GetType(); var lb = new DataPortalTarget(obj); if (lb.Instance is Core.ICommandObject) { return(await Execute(lb, context, isSync)); } var eventArgs = new DataPortalEventArgs(context, objectType, obj, operation); try { ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance); lb.OnDataPortalInvoke(eventArgs); await lb.UpdateAsync(isSync); lb.ThrowIfBusy(); lb.OnDataPortalInvokeComplete(eventArgs); return(new DataPortalResult(lb.Instance)); } catch (Exception ex) { try { lb.OnDataPortalException(eventArgs, ex); } catch { // ignore exceptions from the exception handler } throw DataPortal.NewDataPortalException( "DataPortal.Update " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex), obj); } finally { object reference = null; if (lb != null) { reference = lb.Instance; } ApplicationContext.DataPortalActivator.FinalizeInstance(reference); } }
private async Task <object> Fetch(Type objectType, bool hasParameters, params object[] parameters) { DataPortalTarget obj = null; var eventArgs = new DataPortalEventArgs(null, objectType, parameters, DataPortalOperations.Fetch); try { // create an instance of the business object obj = ApplicationContext.CreateInstanceDI <DataPortalTarget>(ApplicationContext.CreateInstanceDI(objectType)); //ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); obj.Child_OnDataPortalInvoke(eventArgs); obj.MarkAsChild(); obj.MarkOld(); await obj.FetchChildAsync(parameters).ConfigureAwait(false); obj.Child_OnDataPortalInvokeComplete(eventArgs); return(obj.Instance); } catch (Exception ex) { try { if (obj != null) { obj.Child_OnDataPortalException(eventArgs, ex); } } catch { // ignore exceptions from the exception handler } object outval = null; if (obj != null) { outval = obj.Instance; } throw ApplicationContext.CreateInstanceDI <Csla.DataPortalException>( "ChildDataPortal.Fetch " + Properties.Resources.FailedOnServer, ex, outval); } //finally //{ // ApplicationContext.DataPortalActivator.FinalizeInstance(obj.Instance); //} }
private async Task <DataPortalResult> Execute(DataPortalTarget obj, DataPortalContext context, bool isSync) { DataPortalOperations operation = DataPortalOperations.Execute; Type objectType = obj.Instance.GetType(); var eventArgs = new DataPortalEventArgs(context, objectType, obj, operation); try { //ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance); obj.OnDataPortalInvoke(eventArgs); await obj.ExecuteAsync(isSync); obj.ThrowIfBusy(); obj.OnDataPortalInvokeComplete(eventArgs); return(new DataPortalResult(obj.Instance)); } catch (Exception ex) { try { obj.OnDataPortalException(eventArgs, ex); } catch { // ignore exceptions from the exception handler } object reference = null; reference = obj.Instance ?? obj; throw DataPortal.NewDataPortalException( "DataPortal.Execute " + Resources.FailedOnServer, new DataPortalExceptionHandler().InspectException(reference.GetType(), reference, null, "DataPortal.Execute", ex), reference); } finally { object reference = null; if (obj != null) { reference = obj.Instance; } //ApplicationContext.DataPortalActivator.FinalizeInstance(reference); } }