Ejemplo n.º 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
                }
                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);
            }
        }