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