예제 #1
0
        private async Task Update(object obj, bool hasParameters, bool bypassIsDirtyTest, params object[] parameters)
        {
            if (obj == null)
            {
                return;
            }

            if (obj is Core.BusinessBase busObj && busObj.IsDirty == false && bypassIsDirtyTest == false)
            {
                // if the object isn't dirty, then just exit
                return;
            }

            var criteria = DataPortal <object> .GetCriteriaFromArray(parameters);

            var              operation  = DataPortalOperations.Update;
            Type             objectType = obj.GetType();
            DataPortalTarget lb         = new DataPortalTarget(obj);

            ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance);

            try
            {
                lb.Child_OnDataPortalInvoke(
                    new DataPortalEventArgs(null, objectType, obj, operation));
                await lb.UpdateChildAsync(criteria).ConfigureAwait(false);

                lb.Child_OnDataPortalInvokeComplete(
                    new DataPortalEventArgs(null, objectType, obj, operation));
            }
            catch (Exception ex)
            {
                try
                {
                    if (lb != null)
                    {
                        lb.Child_OnDataPortalException(
                            new DataPortalEventArgs(null, objectType, obj, operation), ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new Csla.DataPortalException(
                          "ChildDataPortal.Update " + Properties.Resources.FailedOnServer, ex, obj);
            }
            finally
            {
                ApplicationContext.DataPortalActivator.FinalizeInstance(lb.Instance);
            }
        }