Esempio n. 1
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);

                DataPortalResult result;

                MethodInfo method = MethodCaller.GetCreateMethod(objectType, criteria);

                IDataPortalServer portal;
                switch (TransactionalType(method))
                {
                    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 SimpleDataPortal();
                        result = portal.Create(objectType, criteria, context);
                        break;
                }
                return result;
            }
            catch (DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                  "DataPortal.Create " + "Failed on server",
                  ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }
 /// <summary>
 /// Wraps a Create call in a TransactionScope
 /// </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">A <see cref="Type">Type</see> object
 /// indicating the type of business object to be created.</param>
 /// <param name="criteria">A custom criteria object providing any
 /// extra information that may be required to properly create
 /// the object.</param>
 /// <param name="context">Context data from the client.</param>
 /// <returns>A populated business object.</returns>
 public DataPortalResult Create(
   System.Type objectType, object criteria, DataPortalContext context)
 {
     DataPortalResult result;
     using (TransactionScope tr = new TransactionScope())
     {
         SimpleDataPortal portal = new SimpleDataPortal();
         result = portal.Create(objectType, criteria, context);
         tr.Complete();
     }
     return result;
 }
Esempio n. 3
0
 public DataPortalResult Create(
   Type objectType, object criteria, DataPortalContext context)
 {
     SimpleDataPortal portal = new SimpleDataPortal();
     return portal.Create(objectType, criteria, context);
 }