Exemple #1
0
 public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
 {
     var cf = GetChannelFactory();
     var proxy = GetProxy(cf);
     try
     {
         WcfResponse response = null;
         try
         {
             LEnvironment.ThreadPortalCount++;
             response = proxy.Action(new ActionRequest(objectType, methodName, criteria, context));
         }
         finally
         {
             LEnvironment.ThreadPortalCount--;
         }
         if (cf != null) cf.Close();
         return ReturnResult(response);
     }
     catch
     {
         cf.Abort();
         throw;
     }
 }
Exemple #2
0
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            /*********************** 代码块解释 *********************************
             * 
             * 由于开发人员平时会使用单机版本开发,而正式部署时,又会选用 C/S 架构。
             * 所以需要保证单机版本和 C/S 架构版本的模式是一样的。也就是说,在单机模式下,
             * 在通过门户访问时,模拟网络版,clone 出一个新的对象。
             * 这样,在底层 Update 更改 obj 时,不会影响上层的实体。
             * 而是以返回值的形式把这个被修改的实体返回给上层。
             * 
             * 20120828 
             * 但是,当在服务端本地调用时,不需要此模拟功能。
             * 这是因为在服务端本地调用时(例如服务端本地调用 RF.Save),
             * 在开发体验上,数据层和上层使用的实体应该是同一个,数据层的修改应该能够带回到上层,不需要克隆。
             * 
            **********************************************************************/

            //ThreadPortalCount == 0 表示第一次进入数据门户
            if (LEnvironment.Location.IsWPFUI && LEnvironment.Location.ConnectDataDirectly &&
                LEnvironment.ThreadPortalCount == 1)
            {
                obj = ObjectCloner.Clone(obj);
            }

            var server = new DataPortalFacade();
            try
            {
                LEnvironment.ThreadPortalCount++;
                return server.Update(obj, context);
            }
            finally
            {
                LEnvironment.ThreadPortalCount--;
            }
        }
 public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
 {
     var obj = Activator.CreateInstance(objectType, true);
     var res = MethodCaller.CallMethodIfImplemented(obj, FetchMethod, criteria);
     if (res != null)
         return new DataPortalResult(res);
     else
         return new DataPortalResult(obj);
 }
 public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
 {
     var obj = RF.Find(objectType);
     var res = MethodCaller.CallMethodIfImplemented(obj, methodName, criteria);
     if (res != null)
         return new DataPortalResult(res);
     else
         return new DataPortalResult(obj);
 }
Exemple #5
0
        public static object Update(object obj, DataPortalLocation loc = DataPortalLocation.Dynamic)
        {
            var proxy = GetDataPortalProxy(loc);

            var dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            var result = proxy.Update(obj, dpContext);

            if (proxy.IsServerRemote) DistributionContext.SetGlobalContext(result.GlobalContext);

            return result.ReturnObject;
        }
Exemple #6
0
 public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
 {
     var server = new DataPortalFacade();
     try
     {
         LEnvironment.ThreadPortalCount++;
         return server.Action(objectType, methodName, criteria, context);
     }
     finally
     {
         LEnvironment.ThreadPortalCount--;
     }
 }
Exemple #7
0
 public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
 {
     var server = new DataPortalFacade();
     try
     {
         LEnvironment.ThreadPortalCount++;
         return server.Fetch(objectType, criteria, context);
     }
     finally
     {
         LEnvironment.ThreadPortalCount--;
     }
 }
        public static object Update(object obj, DataPortalLocation loc = DataPortalLocation.Dynamic)
        {
            var proxy = GetDataPortalProxy(loc);

            var dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            var result = proxy.Update(obj, dpContext);

            if (proxy.IsServerRemote)
            {
                DistributionContext.SetGlobalContext(result.GlobalContext);
            }

            return(result.ReturnObject);
        }
        public DataPortalResult Update(object obj, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                var portal = DataPortalFactory.Factory();
                var result = portal.Update(obj, context);

                return result;
            }
            finally
            {
                ClearContext(context);
            }
        }
        public DataPortalResult Fetch(Type objectType, object criteria, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                var portal = DataPortalFactory.Factory();
                var result = portal.Fetch(objectType, criteria, context);

                return result;
            }
            finally
            {
                ClearContext(context);
            }
        }
        public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                var portal = DataPortalFactory.Factory();
                var result = portal.Action(objectType, methodName, criteria, context);

                return result;
            }
            finally
            {
                ClearContext(context);
            }
        }
 public DataPortalResult Update(object obj, DataPortalContext context)
 {
     var target = obj as Entity;
     if (target != null)
     {
         target.SaveRoot();
     }
     else if (obj is DomainService)
     {
         (obj as DomainService).ExecuteByDataPortal();
     }
     else
     {
         MethodCaller.CallMethodIfImplemented(obj, UpdateMethod);
     }
     return new DataPortalResult(obj);
 }
Exemple #13
0
        public static object Fetch(Type objectType, object criteria, DataPortalLocation loc = DataPortalLocation.Dynamic)
        {
            var proxy = GetDataPortalProxy(loc);

            var dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            Server.DataPortalResult result = null;

            try
            {
                result = proxy.Fetch(objectType, criteria, dpContext);
            }
            finally
            {
                if (proxy.IsServerRemote && result != null) { DistributionContext.SetGlobalContext(result.GlobalContext); }
            }
            //不能等于 ReturnObject=null
            return result.ReturnObject;
        }
Exemple #14
0
        private static void SetContext(DataPortalContext context)
        {
            DistributionContext.SetLogicalExecutionLocation(DistributionContext.LogicalExecutionLocations.Server);
            if (!context.IsRemotePortal)
            {
                return;
            }
            DistributionContext.SetExecutionLocation(DistributionContext.ExecutionLocations.Server);
            DistributionContext.SetContext(context.ClientContext, context.GlobalContext);

            System.Threading.Thread.CurrentThread.CurrentCulture =
                new System.Globalization.CultureInfo(context.ClientCulture);
            System.Threading.Thread.CurrentThread.CurrentUICulture =
                new System.Globalization.CultureInfo(context.ClientUICulture);

            if (DistributionContext.AuthenticationType == "Windows")
            {
                if (context.Principal != null)
                {
                    System.Security.SecurityException ex =
                        new System.Security.SecurityException("Resources.NoPrincipalAllowedException");
                    ex.Action = System.Security.Permissions.SecurityAction.Demand;
                    throw ex;
                }
                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            }
            else
            {
                if (context.Principal == null)
                {
                    System.Security.SecurityException ex =
                        new System.Security.SecurityException(
                            "Resources.BusinessPrincipalException" + " Nothing");
                    ex.Action = System.Security.Permissions.SecurityAction.Demand;
                    throw ex;
                }
                DistributionContext.User = context.Principal;
                LEnvironment.Principal   = context.Principal;
            }
        }
        public static object Fetch(Type objectType, object criteria, DataPortalLocation loc = DataPortalLocation.Dynamic)
        {
            var proxy = GetDataPortalProxy(loc);

            var dpContext = new Server.DataPortalContext(GetPrincipal(), proxy.IsServerRemote);

            Server.DataPortalResult result = null;

            try
            {
                result = proxy.Fetch(objectType, criteria, dpContext);
            }
            finally
            {
                if (proxy.IsServerRemote && result != null)
                {
                    DistributionContext.SetGlobalContext(result.GlobalContext);
                }
            }
            //不能等于 ReturnObject=null
            return(result.ReturnObject);
        }
        private static void SetContext(DataPortalContext context)
        {
            DistributionContext.SetLogicalExecutionLocation(DistributionContext.LogicalExecutionLocations.Server);
            if (!context.IsRemotePortal) return;
            DistributionContext.SetExecutionLocation(DistributionContext.ExecutionLocations.Server);
            DistributionContext.SetContext(context.ClientContext, context.GlobalContext);

            System.Threading.Thread.CurrentThread.CurrentCulture =
              new System.Globalization.CultureInfo(context.ClientCulture);
            System.Threading.Thread.CurrentThread.CurrentUICulture =
              new System.Globalization.CultureInfo(context.ClientUICulture);

            if (DistributionContext.AuthenticationType == "Windows")
            {
                if (context.Principal != null)
                {
                    System.Security.SecurityException ex =
                      new System.Security.SecurityException("Resources.NoPrincipalAllowedException");
                    ex.Action = System.Security.Permissions.SecurityAction.Demand;
                    throw ex;
                }
                AppDomain.CurrentDomain.SetPrincipalPolicy(PrincipalPolicy.WindowsPrincipal);
            }
            else
            {
                if (context.Principal == null)
                {
                    System.Security.SecurityException ex =
                      new System.Security.SecurityException(
                        "Resources.BusinessPrincipalException" + " Nothing");
                    ex.Action = System.Security.Permissions.SecurityAction.Demand;
                    throw ex;
                }
                DistributionContext.User = context.Principal;
                LEnvironment.Principal = context.Principal;
            }
        }
        public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
        {
            var obj = Activator.CreateInstance(objectType, true);
            var res = MethodCaller.CallMethodIfImplemented(obj, methodName, criteria);

            if (res != null)
            {
                return(new DataPortalResult(res));
            }
            else
            {
                return(new DataPortalResult(obj));
            }
        }
Exemple #18
0
        public DataPortalResult Action(Type objectType, string methodName, object criteria, DataPortalContext context)
        {
            try
            {
                SetContext(context);

                var portal = DataPortalFactory.Factory();
                var result = portal.Action(objectType, methodName, criteria, context);

                return(result);
            }
            finally
            {
                ClearContext(context);
            }
        }
Exemple #19
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)
 {
     var cf = GetChannelFactory();
     var proxy = GetProxy(cf);
     try
     {
         WcfResponse response = null;
         try
         {
             LEnvironment.ThreadPortalCount++;
             response = proxy.Update(new UpdateRequest(obj, context));
         }
         finally
         {
             LEnvironment.ThreadPortalCount--;
         }
         if (cf != null) cf.Close();
         return ReturnResult(response);
     }
     catch
     {
         cf.Abort();
         throw;
     }
 }
 private static void ClearContext(DataPortalContext context)
 {
     DistributionContext.SetLogicalExecutionLocation(DistributionContext.LogicalExecutionLocations.Client);
     if (!context.IsRemotePortal) return;
     DistributionContext.Clear();
     if (DistributionContext.AuthenticationType != "Windows")
         DistributionContext.User = null;
     LEnvironment.Principal = null;
 }