Example #1
0
        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
                }
                throw DataPortal.NewDataPortalException(
                          "DataPortal.Execute " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Execute", ex),
                          obj);
            }
            finally
            {
                object reference = null;
                if (obj != null)
                {
                    reference = obj.Instance;
                }
                ApplicationContext.DataPortalActivator.FinalizeInstance(reference);
            }
        }