Exemple #1
0
        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);
            }
        }