public DataPortalResult Delete(Type objectType, object criteria, DataPortalContext context)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(context, objectType, DataPortalOperations.Delete);

            try
            {
                // create an instance of the business objet
                obj = new LateBoundObject(objectType);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
                }

                // tell the business object to delete itself
                obj.CallMethod("DataPortal_Delete", criteria);

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete", eventArgs);
                }

                return(new DataPortalResult());
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(eventArgs, ex);
                    }
                    else
                    {
                        obj.CallMethodIfImplemented(
                            "DataPortal_OnDataPortalException",
                            eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException(
                          "DataPortal.Delete " + Resources.FailedOnServer,
                          ex, new DataPortalResult());
            }
        }
Beispiel #2
0
        private object Create(System.Type objectType, bool hasParameters, params object[] parameters)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(null, objectType, parameters, DataPortalOperations.Create);

            try
            {
                // create an instance of the business object
                obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
                ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.Child_OnDataPortalInvoke(eventArgs);
                    target.MarkAsChild();
                    target.MarkNew();
                }
                else
                {
                    obj.CallMethodIfImplemented("Child_OnDataPortalInvoke",
                                                eventArgs);
                    obj.CallMethodIfImplemented("MarkAsChild");
                    obj.CallMethodIfImplemented("MarkNew");
                }


                // tell the business object to create its data
                if (hasParameters)
                {
                    obj.CallMethod("Child_Create", parameters);
                }
                else
                {
                    obj.CallMethod("Child_Create");
                }

                if (target != null)
                {
                    target.Child_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete",
                                                eventArgs);
                }

                // return the populated business object as a result
                return(obj.Instance);
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.Child_OnDataPortalException(eventArgs, ex);
                    }
                    else if (obj != null)
                    {
                        obj.CallMethodIfImplemented("Child_OnDataPortalException",
                                                    eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                object bo = null;
                if (obj != null)
                {
                    bo = obj.Instance;
                }
                throw new Csla.DataPortalException(
                          "ChildDataPortal.Create " + Properties.Resources.FailedOnServer, ex, bo);
            }
        }
Beispiel #3
0
        private void Update(object obj, bool hasParameters, params object[] parameters)
        {
            if (obj == null)
            {
                return;
            }

            var busObj = obj as Core.BusinessBase;

            if (busObj != null && busObj.IsDirty == false)
            {
                // if the object isn't dirty, then just exit
                return;
            }

            var  operation           = DataPortalOperations.Update;
            Type objectType          = obj.GetType();
            IDataPortalTarget target = obj as IDataPortalTarget;
            LateBoundObject   lb     = new LateBoundObject(obj);

            ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance);

            try
            {
                if (target != null)
                {
                    target.Child_OnDataPortalInvoke(
                        new DataPortalEventArgs(null, objectType, obj, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented("Child_OnDataPortalInvoke",
                                               new DataPortalEventArgs(null, objectType, obj, operation));
                }

                // tell the business object to update itself
                if (busObj != null)
                {
                    if (busObj.IsDeleted)
                    {
                        if (!busObj.IsNew)
                        {
                            // tell the object to delete itself
                            lb.CallMethod("Child_DeleteSelf", parameters);
                        }
                        if (target != null)
                        {
                            target.MarkNew();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkNew");
                        }
                    }
                    else
                    {
                        if (busObj.IsNew)
                        {
                            // tell the object to insert itself
                            lb.CallMethod("Child_Insert", parameters);
                        }
                        else
                        {
                            // tell the object to update itself
                            lb.CallMethod("Child_Update", parameters);
                        }
                        if (target != null)
                        {
                            target.MarkOld();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkOld");
                        }
                    }
                }
                else if (obj is Core.ICommandObject)
                {
                    // tell the object to update itself
                    if (hasParameters)
                    {
                        lb.CallMethod("Child_Execute", parameters);
                    }
                    else
                    {
                        lb.CallMethod("Child_Execute");
                    }
                    operation = DataPortalOperations.Execute;
                }
                else
                {
                    // this is an updatable collection or some other
                    // non-BusinessBase type of object
                    // tell the object to update itself
                    if (hasParameters)
                    {
                        lb.CallMethod("Child_Update", parameters);
                    }
                    else
                    {
                        lb.CallMethod("Child_Update");
                    }
                    if (target != null)
                    {
                        target.MarkOld();
                    }
                    else
                    {
                        lb.CallMethodIfImplemented("MarkOld");
                    }
                }

                if (target != null)
                {
                    target.Child_OnDataPortalInvokeComplete(
                        new DataPortalEventArgs(null, objectType, obj, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete",
                                               new DataPortalEventArgs(null, objectType, obj, operation));
                }
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.Child_OnDataPortalException(
                            new DataPortalEventArgs(null, objectType, obj, operation), ex);
                    }
                    else if (lb != null)
                    {
                        lb.CallMethodIfImplemented("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);
            }
        }
Beispiel #4
0
        public async Task <DataPortalResult> Delete(Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Delete);

            try
            {
                // create an instance of the business objet
                obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
                ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
                }

                // tell the business object to delete itself
                await obj.CallMethodTryAsync("DataPortal_Delete", criteria).ConfigureAwait(false);

                var busy = obj.Instance as Csla.Core.ITrackStatus;
                if (busy != null && busy.IsBusy)
                {
                    throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));
                }

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete", eventArgs);
                }

                return(new DataPortalResult());
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(eventArgs, ex);
                    }
                    else if (obj != null)
                    {
                        obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw DataPortal.NewDataPortalException(
                          "DataPortal.Delete " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(objectType, obj, null, "DataPortal.Delete", ex),
                          null);
            }
        }
Beispiel #5
0
        public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
        {
            DataPortalOperations operation = DataPortalOperations.Update;
            Type            objectType     = obj.GetType();
            var             target         = obj as IDataPortalTarget;
            LateBoundObject lb             = new LateBoundObject(obj);

            ApplicationContext.DataPortalActivator.InitializeInstance(lb.Instance);
            try
            {
                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(
                        new DataPortalEventArgs(context, objectType, obj, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented(
                        "DataPortal_OnDataPortalInvoke",
                        new DataPortalEventArgs(context, objectType, obj, operation));
                }

                // tell the business object to update itself
                var busObj = obj as Core.BusinessBase;
                if (busObj != null)
                {
                    if (busObj.IsDeleted)
                    {
                        if (!busObj.IsNew)
                        {
                            // tell the object to delete itself
                            await lb.CallMethodTryAsync("DataPortal_DeleteSelf").ConfigureAwait(false);
                        }
                        if (target != null)
                        {
                            target.MarkNew();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkNew");
                        }
                    }
                    else
                    {
                        if (busObj.IsNew)
                        {
                            // tell the object to insert itself
                            await lb.CallMethodTryAsync("DataPortal_Insert").ConfigureAwait(false);
                        }
                        else
                        {
                            // tell the object to update itself
                            await lb.CallMethodTryAsync("DataPortal_Update").ConfigureAwait(false);
                        }
                        if (target != null)
                        {
                            target.MarkOld();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkOld");
                        }
                    }
                }
                else if (obj is Core.ICommandObject)
                {
                    operation = DataPortalOperations.Execute;
                    // tell the object to update itself
                    await lb.CallMethodTryAsync("DataPortal_Execute").ConfigureAwait(false);
                }
                else
                {
                    // this is an updatable collection or some other
                    // non-BusinessBase type of object
                    // tell the object to update itself
                    await lb.CallMethodTryAsync("DataPortal_Update").ConfigureAwait(false);

                    if (target != null)
                    {
                        target.MarkOld();
                    }
                    else
                    {
                        lb.CallMethodIfImplemented("MarkOld");
                    }
                }

                var busy = busObj as Csla.Core.ITrackStatus;
                if (busy != null && busy.IsBusy)
                {
                    throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));
                }

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(
                        new DataPortalEventArgs(context, objectType, obj, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete",
                                               new DataPortalEventArgs(context, objectType, obj, operation));
                }

                return(new DataPortalResult(obj));
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(
                            new DataPortalEventArgs(context, objectType, obj, operation), ex);
                    }
                    else
                    {
                        lb.CallMethodIfImplemented("DataPortal_OnDataPortalException", new DataPortalEventArgs(context, objectType, obj, operation), ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw DataPortal.NewDataPortalException(
                          "DataPortal.Update " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
                          obj);
            }
        }
Beispiel #6
0
        public async Task <DataPortalResult> Create(
            Type objectType, object criteria, DataPortalContext context, bool isSync)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(context, objectType, criteria, DataPortalOperations.Create);

            try
            {
                // create an instance of the business object.
                obj = new LateBoundObject(ApplicationContext.DataPortalActivator.CreateInstance(objectType));
                ApplicationContext.DataPortalActivator.InitializeInstance(obj.Instance);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(eventArgs);
                    target.MarkNew();
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
                    obj.CallMethodIfImplemented("MarkNew");
                }

                // tell the business object to create its data
                if (criteria is EmptyCriteria)
                {
                    await obj.CallMethodTryAsync("DataPortal_Create").ConfigureAwait(false);
                }
                else
                {
                    await obj.CallMethodTryAsync("DataPortal_Create", criteria).ConfigureAwait(false);
                }

                var busy = obj.Instance as Csla.Core.ITrackStatus;
                if (busy != null && busy.IsBusy)
                {
                    throw new InvalidOperationException(string.Format("{0}.IsBusy == true", objectType.Name));
                }

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented(
                        "DataPortal_OnDataPortalInvokeComplete", eventArgs);
                }

                // return the populated business object as a result
                return(new DataPortalResult(obj.Instance));
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(eventArgs, ex);
                    }
                    else if (obj != null)
                    {
                        obj.CallMethodIfImplemented("DataPortal_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);
            }
        }
        /// <summary>
        /// Get an existing business object.
        /// </summary>
        /// <param name="objectType">Type of business object to retrieve.</param>
        /// <param name="parameters">
        /// Criteria parameters passed from caller.
        /// </param>
        public object Fetch(Type objectType, params object[] parameters)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(null, objectType, DataPortalOperations.Fetch);

            try
            {
                // create an instance of the business object
                obj = new LateBoundObject(objectType);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.Child_OnDataPortalInvoke(eventArgs);
                    target.MarkAsChild();
                    target.MarkOld();
                }
                else
                {
                    obj.CallMethodIfImplemented("Child_OnDataPortalInvoke",
                                                eventArgs);
                    obj.CallMethodIfImplemented("MarkAsChild");
                    obj.CallMethodIfImplemented("MarkOld");
                }

                // tell the business object to fetch its data
                obj.CallMethod("Child_Fetch", parameters);

                if (target != null)
                {
                    target.Child_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented("Child_OnDataPortalInvokeComplete",
                                                eventArgs);
                }

                // return the populated business object as a result
                return(obj.Instance);
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.Child_OnDataPortalException(eventArgs, ex);
                    }
                    else
                    {
                        obj.CallMethodIfImplemented("Child_OnDataPortalException",
                                                    eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new YYT.DataPortalException(
                          "ChildDataPortal.Fetch " + Properties.Resources.FailedOnServer, ex, obj.Instance);
            }
        }
        public DataPortalResult Create(
            Type objectType, object criteria, DataPortalContext context)
        {
            LateBoundObject   obj    = null;
            IDataPortalTarget target = null;
            var eventArgs            = new DataPortalEventArgs(context, objectType, DataPortalOperations.Create);

            try
            {
                // create an instance of the business object.
                obj = new LateBoundObject(objectType);

                target = obj.Instance as IDataPortalTarget;

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(eventArgs);
                    target.MarkNew();
                }
                else
                {
                    obj.CallMethodIfImplemented("DataPortal_OnDataPortalInvoke", eventArgs);
                    obj.CallMethodIfImplemented("MarkNew");
                }

                // tell the business object to create its data
                if (criteria is EmptyCriteria)
                {
                    obj.CallMethod("DataPortal_Create");
                }
                else
                {
                    obj.CallMethod("DataPortal_Create", criteria);
                }

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(eventArgs);
                }
                else
                {
                    obj.CallMethodIfImplemented(
                        "DataPortal_OnDataPortalInvokeComplete", eventArgs);
                }

                // return the populated business object as a result
                return(new DataPortalResult(obj.Instance));
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(eventArgs, ex);
                    }
                    else if (obj != null)
                    {
                        obj.CallMethodIfImplemented("DataPortal_OnDataPortalException", eventArgs, ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                object outval = null;
                if (obj != null)
                {
                    outval = obj.Instance;
                }
                throw new DataPortalException(
                          "DataPortal.Create " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(objectType, outval, criteria, "DataPortal.Create", ex),
                          new DataPortalResult(outval));
            }
        }
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            DataPortalOperations operation = DataPortalOperations.Update;
            Type            objectType     = obj.GetType();
            var             target         = obj as IDataPortalTarget;
            LateBoundObject lb             = new LateBoundObject(obj);

            try
            {
                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvoke(
                        new DataPortalEventArgs(context, objectType, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented(
                        "DataPortal_OnDataPortalInvoke",
                        new DataPortalEventArgs(context, objectType, operation));
                }

                // tell the business object to update itself
                var busObj = obj as Core.BusinessBase;
                if (busObj != null)
                {
                    if (busObj.IsDeleted)
                    {
                        if (!busObj.IsNew)
                        {
                            // tell the object to delete itself
                            lb.CallMethod("DataPortal_DeleteSelf");
                        }
                        if (target != null)
                        {
                            target.MarkNew();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkNew");
                        }
                    }
                    else
                    {
                        if (busObj.IsNew)
                        {
                            // tell the object to insert itself
                            lb.CallMethod("DataPortal_Insert");
                        }
                        else
                        {
                            // tell the object to update itself
                            lb.CallMethod("DataPortal_Update");
                        }
                        if (target != null)
                        {
                            target.MarkOld();
                        }
                        else
                        {
                            lb.CallMethodIfImplemented("MarkOld");
                        }
                    }
                }
                else if (obj is Core.ICommandObject)
                {
                    operation = DataPortalOperations.Execute;
                    // tell the object to update itself
                    lb.CallMethod("DataPortal_Execute");
                }
                else
                {
                    // this is an updatable collection or some other
                    // non-BusinessBase type of object
                    // tell the object to update itself
                    lb.CallMethod("DataPortal_Update");
                    if (target != null)
                    {
                        target.MarkOld();
                    }
                    else
                    {
                        lb.CallMethodIfImplemented("MarkOld");
                    }
                }

                if (target != null)
                {
                    target.DataPortal_OnDataPortalInvokeComplete(
                        new DataPortalEventArgs(context, objectType, operation));
                }
                else
                {
                    lb.CallMethodIfImplemented("DataPortal_OnDataPortalInvokeComplete",
                                               new DataPortalEventArgs(context, objectType, operation));
                }

                return(new DataPortalResult(obj));
            }
            catch (Exception ex)
            {
                try
                {
                    if (target != null)
                    {
                        target.DataPortal_OnDataPortalException(
                            new DataPortalEventArgs(context, objectType, operation), ex);
                    }
                    else
                    {
                        lb.CallMethodIfImplemented("DataPortal_OnDataPortalException", new DataPortalEventArgs(context, objectType, operation), ex);
                    }
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException(
                          "DataPortal.Update " + Resources.FailedOnServer,
                          new DataPortalExceptionHandler().InspectException(obj.GetType(), obj, null, "DataPortal.Update", ex),
                          new DataPortalResult(obj));
            }
        }