Beispiel #1
0
        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);
            }
        }
Beispiel #2
0
        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);
            //}
        }