Implements the server-side DataPortal as discussed in Chapter 4.
Inheritance: IDataPortalServer
Beispiel #1
0
 /// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="objectType">Type of business object to retrieve.</param>
 /// <param name="criteria">Criteria object describing business object.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
 public async Task <DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(await dp.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(await dp.Fetch(objectType, criteria, context, isSync).ConfigureAwait(false));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw DataPortal.NewDataPortalException(
                   "DataPortal.Fetch " + Resources.FailedOnServer,
                   ex, null);
     }
 }
Beispiel #2
0
 /// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="objectType">Type of business object to retrieve.</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 Fetch(Type objectType, object criteria, DataPortalContext context)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(dp.Fetch(objectType, criteria, context));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(dp.Fetch(objectType, criteria, context));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new DataPortalException(
                   "DataPortal.Fetch " + Resources.FailedOnServer,
                   ex, new DataPortalResult());
     }
 }
        public DataPortalResult Create(
            Type objectType, object criteria, DataPortalContext context)
        {
            SimpleDataPortal portal = new SimpleDataPortal();

            return(portal.Create(objectType, criteria, context));
        }
 /// <summary>
 /// Update a business object.
 /// </summary>
 /// <param name="obj">Business object to update.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
 public async Task <DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(await dp.Update(obj, context, isSync));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(await dp.Update(obj, context, isSync));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw DataPortal.NewDataPortalException(
                   "DataPortal.Update " + Resources.FailedOnServer,
                   ex, obj);
     }
 }
Beispiel #5
0
 /// <summary>
 /// Update a business object.
 /// </summary>
 /// <param name="obj">Business object to update.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     try
     {
         context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
         if (context.FactoryInfo == null)
         {
             var dp = new SimpleDataPortal();
             return(dp.Update(obj, context));
         }
         else
         {
             var dp = new FactoryDataPortal();
             return(dp.Update(obj, context));
         }
     }
     catch (DataPortalException)
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new DataPortalException(
                   "DataPortal.Update " + Resources.FailedOnServer,
                   ex, new DataPortalResult(obj));
     }
 }
 /// <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>
 /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
 public async Task<DataPortalResult> Create(Type objectType, object criteria, DataPortalContext context, bool isSync)
 {
   try
   {
     context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
     if (context.FactoryInfo == null)
     {
       return await SimpleDataPortal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
     }
     else
     {
       return await FactoryDataPortal.Create(objectType, criteria, context, isSync).ConfigureAwait(false);
     }
   }
   catch (DataPortalException)
   {
     throw;
   }
   catch (Exception ex)
   {
     throw DataPortal.NewDataPortalException(
       ApplicationContext, "DataPortal.Create " + Resources.FailedOnServer,
       ex, null);
   }
 }
 /// <summary>
 /// Get an existing business object.
 /// </summary>
 /// <param name="objectType">Type of business object to retrieve.</param>
 /// <param name="criteria">Criteria object describing business object.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
 public async Task<DataPortalResult> Fetch(Type objectType, object criteria, DataPortalContext context, bool isSync)
 {
   try
   {
     context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(objectType);
     if (context.FactoryInfo == null)
     {
       var dp = new SimpleDataPortal();
       return await dp.Fetch(objectType, criteria, context, isSync);
     }
     else
     {
       var dp = new FactoryDataPortal();
       return await dp.Fetch(objectType, criteria, context, isSync);
     }
   }
   catch (DataPortalException)
   {
     throw;
   }
   catch (Exception ex)
   {
     throw DataPortal.NewDataPortalException(
       "DataPortal.Fetch " + Resources.FailedOnServer,
       ex, null);
   }
 }
        /// <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())
            {
                SimpleDataPortal portal = new SimpleDataPortal();
                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())
            {
                SimpleDataPortal portal = new SimpleDataPortal();
                result = portal.Fetch(objectType, criteria, context);
                tr.Complete();
            }
            return(result);
        }
        /// <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.GetMethod(
                    objectType, "DataPortal_Create", 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);
            }
            finally
            {
                ClearContext(context);
            }
        }
        public DataPortalResult Delete(object criteria, DataPortalContext context)
        {
            SimpleDataPortal portal = new SimpleDataPortal();

            return(portal.Delete(criteria, context));
        }
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            SimpleDataPortal portal = new SimpleDataPortal();

            return(portal.Update(obj, context));
        }
Beispiel #13
0
 /// <summary>
 /// Update a business object.
 /// </summary>
 /// <param name="obj">Business object to update.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 /// <param name="isSync">True if the client-side proxy should synchronously invoke the server.</param>
 public async Task<DataPortalResult> Update(object obj, DataPortalContext context, bool isSync)
 {
   try
   {
     context.FactoryInfo = ObjectFactoryAttribute.GetObjectFactoryAttribute(obj.GetType());
     if (context.FactoryInfo == null)
     {
       var dp = new SimpleDataPortal();
       return await dp.Update(obj, context, isSync);
     }
     else
     {
       var dp = new FactoryDataPortal();
       return await dp.Update(obj, context, isSync);
     }
   }
   catch (DataPortalException)
   {
     throw;
   }
   catch (Exception ex)
   {
     throw DataPortal.NewDataPortalException(
       "DataPortal.Update " + Resources.FailedOnServer,
       ex, obj);
   }
 }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="applicationContext"></param>
 /// <param name="simpleDataPortal"></param>
 /// <param name="factoryDataPortal"></param>
 public DataPortalSelector(ApplicationContext applicationContext, SimpleDataPortal simpleDataPortal, FactoryDataPortal factoryDataPortal)
 {
   ApplicationContext = applicationContext;
   SimpleDataPortal = simpleDataPortal;
   FactoryDataPortal = factoryDataPortal;
 }
Beispiel #15
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                DataPortalResult result;

                MethodInfo method;
                string     methodName;
                if (obj is CommandBase)
                {
                    methodName = "DataPortal_Execute";
                }
                else if (obj is Core.BusinessBase)
                {
                    Core.BusinessBase tmp = (Core.BusinessBase)obj;
                    if (tmp.IsDeleted)
                    {
                        methodName = "DataPortal_DeleteSelf";
                    }
                    else
                    if (tmp.IsNew)
                    {
                        methodName = "DataPortal_Insert";
                    }
                    else
                    {
                        methodName = "DataPortal_Update";
                    }
                }
                else
                {
                    methodName = "DataPortal_Update";
                }

                method = MethodCaller.GetMethod(obj.GetType(), methodName);

                IDataPortalServer portal;
                switch (TransactionalType(method))
                {
                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 SimpleDataPortal();
                    result = portal.Update(obj, context);
                    break;
                }
                return(result);
            }
            finally
            {
                ClearContext(context);
            }
        }
Beispiel #16
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="simpleDataPortal"></param>
 /// <param name="factoryDataPortal"></param>
 public DataPortalSelector(SimpleDataPortal simpleDataPortal, FactoryDataPortal factoryDataPortal)
 {
     SimpleDataPortal  = simpleDataPortal;
     FactoryDataPortal = factoryDataPortal;
 }