示例#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>
 /// 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;
 }
示例#4
0
        public DataPortalResult Create(
          Type objectType, object criteria, DataPortalContext context)
        {
            object obj = null;

            try
            {
                // create an instance of the business object.
                obj = Activator.CreateInstance(objectType, true);

                // tell the business object we're about to make a DataPortal_xyz call
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvoke", new DataPortalEventArgs(context));

                // tell the business object to create its data
                MethodInfo method = MethodCaller.GetCreateMethod(objectType, criteria);
                if (criteria is int)
                    MethodCaller.CallMethod(obj, method);
                else
                    MethodCaller.CallMethod(obj, method, criteria);

                // mark the object as new
                MethodCaller.CallMethodIfImplemented(
                  obj, "MarkNew");

                // tell the business object the DataPortal_xyz call is complete
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvokeComplete",
                  new DataPortalEventArgs(context));

                // return the populated business object as a result
                return new DataPortalResult(obj);
            }
            catch (Exception ex)
            {
                try
                {
                    // tell the business object there was an exception
                    MethodCaller.CallMethodIfImplemented(
                      obj, "DataPortal_OnDataPortalException",
                      new DataPortalEventArgs(context), ex);
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException(
                  "DataPortal.Create " + "Failed on server",
                  ex, new DataPortalResult(obj));
            }

        }
示例#5
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                // tell the business object we're about to make a DataPortal_xyz call
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvoke",
                  new DataPortalEventArgs(context));

                // tell the business object to update itself
                if (obj is Core.BusinessBase)
                {
                    Core.BusinessBase busObj = (Core.BusinessBase)obj;
                    if (busObj.IsDeleted)
                    {
                        if (!busObj.IsNew)
                        {
                            // tell the object to delete itself
                            MethodCaller.CallMethod(
                              busObj, "DataPortal_DeleteSelf");
                        }
                        // mark the object as new
                        MethodCaller.CallMethodIfImplemented(
                          busObj, "MarkNew");
                    }
                    else
                    {
                        if (busObj.IsNew)
                        {
                            // tell the object to insert itself
                            MethodCaller.CallMethod(
                              busObj, "DataPortal_Insert");
                        }
                        else
                        {
                            // tell the object to update itself
                            MethodCaller.CallMethod(
                              busObj, "DataPortal_Update");
                        }
                        // mark the object as old
                        MethodCaller.CallMethodIfImplemented(
                          busObj, "MarkOld");
                    }
                }
                else if (obj is CommandBase)
                {
                    // tell the object to update itself
                    MethodCaller.CallMethod(
                      obj, "DataPortal_Execute");
                }
                else
                {
                    // this is an updatable collection or some other
                    // non-BusinessBase type of object
                    // tell the object to update itself
                    MethodCaller.CallMethod(
                      obj, "DataPortal_Update");
                    // mark the object as old
                    MethodCaller.CallMethodIfImplemented(
                      obj, "MarkOld");
                }

                // tell the business object the DataPortal_xyz is complete
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvokeComplete",
                  new DataPortalEventArgs(context));

                return new DataPortalResult(obj);
            }
            catch (Exception ex)
            {
                try
                {
                    // tell the business object there was an exception
                    MethodCaller.CallMethodIfImplemented(
                      obj, "DataPortal_OnDataPortalException",
                      new DataPortalEventArgs(context), ex);
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException(
                  "DataPortal.Update " + "Failed on server",
                  ex, new DataPortalResult(obj));
            }
        }
示例#6
0
 public DataPortalResult Delete(object criteria, DataPortalContext context)
 {
     SimpleDataPortal portal = new SimpleDataPortal();
     return portal.Delete(criteria, context);
 }
示例#7
0
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     SimpleDataPortal portal = new SimpleDataPortal();
     return portal.Update(obj, context);
 }
示例#8
0
 public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
 {
     SimpleDataPortal portal = new SimpleDataPortal();
     return portal.Fetch(objectType, criteria, context);
 }
示例#9
0
 /// <summary>
 /// Called by <see cref="DataPortal" /> to delete a
 /// business object.
 /// </summary>
 /// <param name="criteria">Criteria object describing business object.</param>
 /// <param name="context">
 /// <see cref="Server.DataPortalContext" /> object passed to the server.
 /// </param>
 public DataPortalResult Delete(object criteria, DataPortalContext context)
 {
     return _portal.Delete(criteria, context);
 }
示例#10
0
 /// <summary>
 /// Called by <see cref="DataPortal" /> to update a
 /// business object.
 /// </summary>
 /// <param name="obj">The 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)
 {
     return _portal.Update(obj, context);
 }
示例#11
0
 /// <summary>
 /// Called by <see cref="DataPortal" /> to 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)
 {
     return _portal.Create(objectType, criteria, context);
 }
示例#12
0
 /// <summary>
 /// Creates an instance of the object.
 /// </summary>
 /// <param name="dataPortalContext">
 /// Data portal context object.
 /// </param>
 public DataPortalEventArgs(Server.DataPortalContext dataPortalContext)
 {
     _dataPortalContext = dataPortalContext;
 }
示例#13
0
 private static void ClearContext(DataPortalContext context)
 {
     // if the dataportal is not remote then
     // do nothing
     if (!context.IsRemotePortal) return;
     ApplicationContext.Clear();
     if (ApplicationContext.AuthenticationType != "Windows")
         ApplicationContext.User = null;
 }
示例#14
0
        private static void SetContext(DataPortalContext context)
        {
            // if the dataportal is not remote then
            // do nothing
            if (!context.IsRemotePortal) return;

            // set the context value so everyone knows the
            // code is running on the server
            ApplicationContext.SetExecutionLocation(ApplicationContext.ExecutionLocations.Server);

            // set the app context to the value we got from the
            // client
            ApplicationContext.SetContext(context.ClientContext, context.GlobalContext);

            // set the thread's culture to match the client
            System.Threading.Thread.CurrentThread.CurrentCulture =
              new System.Globalization.CultureInfo(context.ClientCulture);
            System.Threading.Thread.CurrentThread.CurrentUICulture =
              new System.Globalization.CultureInfo(context.ClientUICulture);

            if (ApplicationContext.AuthenticationType == "Windows")
            {
                // When using integrated security, Principal must be null
                if (context.Principal == null)
                {
                    // Set .NET to use integrated security
                    AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
                    return;
                }
                else
                {
                    System.Security.SecurityException ex =
                      new System.Security.SecurityException("No Princioal allowed");
                    ex.Action = System.Security.Permissions.SecurityAction.Deny;
                    throw ex;
                }
            }
            // We expect the Principal to be of the type BusinesPrincipal
            if (context.Principal != null)
            {
                if (context.Principal is Security.BusinessPrincipalBase)
                {
                    ApplicationContext.User = context.Principal;
                }
                else
                {
                    System.Security.SecurityException ex =
                      new System.Security.SecurityException(
                        "Business Pricipal exception" + " " +
                        ((object)context.Principal).ToString());
                    ex.Action = System.Security.Permissions.SecurityAction.Deny;
                    throw ex;
                }
            }
            else
            {
                System.Security.SecurityException ex =
                  new System.Security.SecurityException(
                    "Business Pricipal exception" + " Nothing");
                ex.Action = System.Security.Permissions.SecurityAction.Deny;
                throw ex;
            }
        }
示例#15
0
        public DataPortalResult Delete(object criteria, DataPortalContext context)
        {
            object obj = null;
            try
            {
                // create an instance of the business objet
                obj = CreateBusinessObject(criteria);

                // tell the business object we're about to make a DataPortal_xyz call
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvoke",
                  new DataPortalEventArgs(context));

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

                // tell the business object the DataPortal_xyz call is complete
                MethodCaller.CallMethodIfImplemented(
                  obj, "DataPortal_OnDataPortalInvokeComplete",
                  new DataPortalEventArgs(context));

                return new DataPortalResult();
            }
            catch (Exception ex)
            {
                try
                {
                    // tell the business object there was an exception
                    MethodCaller.CallMethodIfImplemented(
                      obj, "DataPortal_OnDataPortalException",
                      new DataPortalEventArgs(context), ex);
                }
                catch
                {
                    // ignore exceptions from the exception handler
                }
                throw new DataPortalException(
                  "DataPortal.Delete " + "Failed on server",
                  ex, new DataPortalResult());
            }
        }
示例#16
0
 /// <summary>
 /// Called by <see cref="DataPortal" /> to load 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)
 {
     return _portal.Fetch(objectType, criteria, context);
 }
示例#17
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;
            }
            catch (DataPortalException ex)
            {
                Exception tmp = ex;
                throw;
            }
            catch (Exception ex)
            {
                throw new DataPortalException(
                  "DataPortal.Update " + "Failed on server",
                  ex, new DataPortalResult());
            }
            finally
            {
                ClearContext(context);
            }
        }