Exemplo n.º 1
0
        public DataPortalResult Create(
            Type objectType, object criteria, DataPortalContext context)
        {
            var portal = new DataPortalSelector();

            return(portal.Create(objectType, criteria, context));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Create a new business object.
        /// </summary>
        /// <param name="objectType">Type of business object to create.</param>
        /// <param name="criteria">Criteria object describing business object.</param>
        /// <param name="context">
        /// <see cref="Server.DataPortalContext" /> object passed to the server.
        /// </param>
        public DataPortalResult Create(
            Type objectType, object criteria, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                Authorize(new AuthorizeRequest(objectType, criteria, DataPortalOperations.Create));

                DataPortalResult result;

                DataPortalMethodInfo method = DataPortalMethodCache.GetCreateMethod(objectType, criteria);

                IDataPortalServer portal;
                switch (method.TransactionalType)
                {
                case TransactionalTypes.EnterpriseServices:
                    portal = new ServicedDataPortal();
                    try
                    {
                        result = portal.Create(objectType, criteria, context);
                    }
                    finally
                    {
                        ((ServicedDataPortal)portal).Dispose();
                    }

                    break;

                case TransactionalTypes.TransactionScope:

                    portal = new TransactionalDataPortal();
                    result = portal.Create(objectType, criteria, context);

                    break;

                default:
                    portal = new DataPortalSelector();
                    result = portal.Create(objectType, criteria, context);
                    break;
                }
                return(result);
            }
            catch (YYT.Server.DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                          "DataPortal.Create " + Resources.FailedOnServer,
                          ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }
        /// <summary>
        /// Called by the client-side DataPortal to update an object.
        /// </summary>
        /// <remarks>
        /// This method delegates to
        /// <see cref="SimpleDataPortal">SimpleDataPortal</see>
        /// but wraps that call within a
        /// <see cref="TransactionScope">TransactionScope</see>
        /// to provide transactional support via
        /// System.Transactions.
        /// </remarks>
        /// <param name="obj">A reference to the object being updated.</param>
        /// <param name="context">Context data from the client.</param>
        /// <returns>A reference to the newly updated object.</returns>
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            DataPortalResult result;

            using (TransactionScope tr = new TransactionScope())
            {
                var portal = new DataPortalSelector();
                result = portal.Update(obj, context);
                tr.Complete();
            }
            return(result);
        }
        /// <summary>
        /// Called by the client-side DataProtal to retrieve an object.
        /// </summary>
        /// <remarks>
        /// This method delegates to
        /// <see cref="SimpleDataPortal">SimpleDataPortal</see>
        /// but wraps that call within a
        /// <see cref="TransactionScope">TransactionScope</see>
        /// to provide transactional support via
        /// System.Transactions.
        /// </remarks>
        /// <param name="objectType">Type of business object to retrieve.</param>
        /// <param name="criteria">Object-specific criteria.</param>
        /// <param name="context">Object containing context data from client.</param>
        /// <returns>A populated business object.</returns>
        public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
        {
            DataPortalResult result;

            using (TransactionScope tr = new TransactionScope())
            {
                var portal = new DataPortalSelector();
                result = portal.Fetch(objectType, criteria, context);
                tr.Complete();
            }
            return(result);
        }
Exemplo n.º 5
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                Authorize(new AuthorizeRequest(obj.GetType(), obj, DataPortalOperations.Update));

                DataPortalResult     result;
                DataPortalMethodInfo method;
                var factoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
                if (factoryInfo != null)
                {
                    var factoryType = FactoryDataPortal.FactoryLoader.GetFactoryType(factoryInfo.FactoryTypeName);
                    var bbase       = obj as Core.BusinessBase;
                    if (bbase != null && bbase.IsDeleted)
                    {
                        method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, factoryInfo.DeleteMethodName, new object[] { obj });
                    }
                    else
                    {
                        method = Server.DataPortalMethodCache.GetMethodInfo(factoryType, factoryInfo.UpdateMethodName, new object[] { obj });
                    }
                }
                else
                {
                    string methodName;
                    var    bbase = obj as Core.BusinessBase;
                    if (bbase != null)
                    {
                        if (bbase.IsDeleted)
                        {
                            methodName = "DataPortal_DeleteSelf";
                        }
                        else
                        if (bbase.IsNew)
                        {
                            methodName = "DataPortal_Insert";
                        }
                        else
                        {
                            methodName = "DataPortal_Update";
                        }
                    }
                    else if (obj is CommandBase)
                    {
                        methodName = "DataPortal_Execute";
                    }
                    else
                    {
                        methodName = "DataPortal_Update";
                    }
                    method = DataPortalMethodCache.GetMethodInfo(obj.GetType(), methodName);
                }

                context.TransactionalType = method.TransactionalType;
                IDataPortalServer portal;
                switch (method.TransactionalType)
                {
                case TransactionalTypes.EnterpriseServices:
                    portal = new ServicedDataPortal();
                    try
                    {
                        result = portal.Update(obj, context);
                    }
                    finally
                    {
                        ((ServicedDataPortal)portal).Dispose();
                    }
                    break;

                case TransactionalTypes.TransactionScope:
                    portal = new TransactionalDataPortal();
                    result = portal.Update(obj, context);
                    break;

                default:
                    portal = new DataPortalSelector();
                    result = portal.Update(obj, context);
                    break;
                }
                return(result);
            }
            catch (YYT.Server.DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                          "DataPortal.Update " + Resources.FailedOnServer,
                          ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }
Exemplo n.º 6
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            var portal = new DataPortalSelector();

            return(portal.Update(obj, context));
        }