亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? dataportal.cs

?? C# 版本的一個三層商業架構
?? CS
字號:
using System;
using System.Threading;
using System.Collections;
using System.Reflection;
using System.Runtime.Remoting;
using System.Runtime.Remoting.Channels;
using System.Runtime.Remoting.Channels.Http;

namespace CSLA
{
  /// <summary>
  /// This is the client-side DataPortal as described in
  /// Chapter 5.
  /// </summary>
  public class DataPortal
  {
    static bool _portalRemote = false;

    #region DataPortal events

    /// <summary>
    /// Delegate used by the OnDataPortalInvoke
    /// and OnDataPortalInvokeComplete events.
    /// </summary>
    public delegate void DataPortalInvokeDelegate(DataPortalEventArgs e);

    /// <summary>
    /// Raised by DataPortal prior to calling the 
    /// requested server-side DataPortal method.
    /// </summary>
    public static event DataPortalInvokeDelegate OnDataPortalInvoke;
    /// <summary>
    /// Raised by DataPortal after the requested 
    /// server-side DataPortal method call is complete.
    /// </summary>
    public static event DataPortalInvokeDelegate OnDataPortalInvokeComplete;

    #endregion

    #region Data Access methods

    /// <summary>
    /// Called by a factory method in a business class to create 
    /// a new object, which is loaded with default
    /// values from the database.
    /// </summary>
    /// <param name="Criteria">Object-specific criteria.</param>
    /// <returns>A new object, populated with default values.</returns>
    static public object Create(object criteria)
    {
      Server.DataPortalResult result;

      MethodInfo method = GetMethod(GetObjectType(criteria), "DataPortal_Create");

      bool forceLocal = RunLocal(method);
      bool isRemotePortal = _portalRemote && !forceLocal;
      Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), isRemotePortal);

      if(OnDataPortalInvoke != null)
        OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

      try
      {
        if(IsTransactionalMethod(method))
          result = (Server.DataPortalResult)ServicedPortal(forceLocal).Create(criteria, dpContext);
        else
          result = (Server.DataPortalResult)Portal(forceLocal).Create(criteria, dpContext);
      }
      catch(Server.DataPortalException ex)
      {
        result = ex.Result;
        if(isRemotePortal)
          RestoreContext(result);
        throw new DataPortalException("DataPortal.Create " + Resources.Strings.GetResourceString("Failed"), ex.InnerException, result.ReturnObject);
      }

      if(isRemotePortal)
      {
        RestoreContext(result);
        Serialization.SerializationNotification.OnDeserialized(result.ReturnObject);
      }

      if(OnDataPortalInvokeComplete != null)
        OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));

      return result.ReturnObject;
    }

    /// <summary>
    /// Called by a factory method in a business class to retrieve
    /// an object, which is loaded with values from the database.
    /// </summary>
    /// <param name="Criteria">Object-specific criteria.</param>
    /// <returns>An object populated with values from the database.</returns>
    static public object Fetch(object criteria)
    {
      Server.DataPortalResult result;

      MethodInfo method = GetMethod(GetObjectType(criteria), "DataPortal_Fetch");

      bool forceLocal = RunLocal(method);
      bool isRemotePortal = _portalRemote && !forceLocal;
      Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), isRemotePortal);

      if(OnDataPortalInvoke != null)
        OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

      try
      {
        if(IsTransactionalMethod(method))
          result = (Server.DataPortalResult)ServicedPortal(forceLocal).Fetch(criteria, dpContext);
        else
          result = (Server.DataPortalResult)Portal(forceLocal).Fetch(criteria, dpContext);
      }
      catch(Server.DataPortalException ex)
      {
        result = ex.Result;
        if(isRemotePortal)
          RestoreContext(result);
        throw new DataPortalException("DataPortal.Fetch " + Resources.Strings.GetResourceString("Failed"), ex.InnerException, result.ReturnObject);
      }

      if(isRemotePortal)
      {
        RestoreContext(result);
        Serialization.SerializationNotification.OnDeserialized(result.ReturnObject);
      }

      if(OnDataPortalInvokeComplete != null)
        OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));

      return result.ReturnObject;
    }

    /// <summary>
    /// Called by the <see cref="M:CSLA.BusinessBase.Save" /> method to
    /// insert, update or delete an object in the database.
    /// </summary>
    /// <remarks>
    /// Note that this method returns a reference to the updated business object.
    /// If the server-side DataPortal is running remotely, this will be a new and
    /// different object from the original, and all object references MUST be updated
    /// to use this new object.
    /// </remarks>
    /// <param name="obj">A reference to the business object to be updated.</param>
    /// <returns>A reference to the updated business object.</returns>
    static public object Update(object obj)
    {
      Server.DataPortalResult result;

      MethodInfo method = GetMethod(obj.GetType(), "DataPortal_Update");

      bool forceLocal = RunLocal(method);
      bool isRemotePortal = _portalRemote && !forceLocal;
      Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), isRemotePortal);

      if(OnDataPortalInvoke != null)
        OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

      if(isRemotePortal)
        Serialization.SerializationNotification.OnSerializing(obj);

      try
      {
        if(IsTransactionalMethod(method))
          result = (Server.DataPortalResult)ServicedPortal(forceLocal).Update(obj, dpContext);
        else
          result = (Server.DataPortalResult)Portal(forceLocal).Update(obj, dpContext);
      }
      catch(Server.DataPortalException ex)
      {
        result = ex.Result;
        if(isRemotePortal)
          RestoreContext(result);
        throw new DataPortalException("DataPortal.Update " + Resources.Strings.GetResourceString("Failed"), ex.InnerException, result.ReturnObject);
      }

      if(isRemotePortal)
      {
        RestoreContext(result);
        Serialization.SerializationNotification.OnSerialized(obj);
        Serialization.SerializationNotification.OnDeserialized(result.ReturnObject);
      }

      if(OnDataPortalInvokeComplete != null)
        OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));

      return result.ReturnObject;
    }

    /// <summary>
    /// Called by a <c>Shared</c> method in the business class to cause
    /// immediate deletion of a specific object from the database.
    /// </summary>
    /// <param name="Criteria">Object-specific criteria.</param>
    static public void Delete(object criteria)
    {
      Server.DataPortalResult result;

      MethodInfo method = GetMethod(GetObjectType(criteria), "DataPortal_Delete");

      bool forceLocal = RunLocal(method);
      bool isRemotePortal = _portalRemote && !forceLocal;
      Server.DataPortalContext dpContext = new Server.DataPortalContext(GetPrincipal(), isRemotePortal);

      if(OnDataPortalInvoke != null)
        OnDataPortalInvoke(new DataPortalEventArgs(dpContext));

      try
      {
        if(IsTransactionalMethod(method))
          result = (Server.DataPortalResult)ServicedPortal(forceLocal).Delete(criteria, dpContext);
        else
          result = (Server.DataPortalResult)Portal(forceLocal).Delete(criteria, dpContext);
      }
      catch(Server.DataPortalException ex)
      {
        result = ex.Result;
        if(isRemotePortal)
          RestoreContext(result);
        throw new DataPortalException("DataPortal.Delete " + Resources.Strings.GetResourceString("Failed"), ex.InnerException, result.ReturnObject);
      }

      if(isRemotePortal)
        RestoreContext(result);

      if(OnDataPortalInvokeComplete != null)
        OnDataPortalInvokeComplete(new DataPortalEventArgs(dpContext));
    }

    #endregion

    #region Server-side DataPortal

    static Server.DataPortal _portal;
    static Server.ServicedDataPortal.DataPortal _servicedPortal;
    static Server.DataPortal _remotePortal;
    static Server.ServicedDataPortal.DataPortal _remoteServicedPortal;

    private static Server.DataPortal Portal(bool forceLocal)
    {
      if(!forceLocal & _portalRemote)
      {
        // return remote instance
        if(_remotePortal == null)
          _remotePortal = (Server.DataPortal)Activator.GetObject(typeof(Server.DataPortal), PORTAL_SERVER);
        return _remotePortal;
      }
      else
      {
        // return local instance
        if(_portal == null)
          _portal = new Server.DataPortal();
        return _portal;
      }
    }

    private static Server.ServicedDataPortal.DataPortal ServicedPortal(bool forceLocal)
    {
      if(!forceLocal & _portalRemote)
      {
        // return remote instance
        if(_remoteServicedPortal == null)
          _remoteServicedPortal = (Server.ServicedDataPortal.DataPortal)Activator.GetObject(
            typeof(Server.ServicedDataPortal.DataPortal), SERVICED_PORTAL_SERVER);
        return _remoteServicedPortal;
      }
      else
      {
        // return local instance
        if(_servicedPortal == null)
          _servicedPortal = new Server.ServicedDataPortal.DataPortal();
        return _servicedPortal;
      }
    }

    static private string PORTAL_SERVER
    {
      get
      {
        return ConfigurationSettings.AppSettings["PortalServer"];
      }
    }

    static private string SERVICED_PORTAL_SERVER
    {
      get
      {
        return ConfigurationSettings.AppSettings["ServicedPortalServer"];
      }
    }

    #endregion

    #region Security

    static private string AUTHENTICATION
    {
      get
      {
        return ConfigurationSettings.AppSettings["Authentication"];
      }
    }

    static private System.Security.Principal.IPrincipal GetPrincipal()
    {
      if(AUTHENTICATION == "Windows")
        // Windows integrated security 
        return null;
      else
        // we assume using the CSLA framework security
        return System.Threading.Thread.CurrentPrincipal;
    }

    #endregion

    #region Helper methods

    private static void RestoreContext(object result)
    {
      System.LocalDataStoreSlot slot = Thread.GetNamedDataSlot("CSLA.GlobalContext");
      Thread.SetData(slot, ((Server.DataPortalResult)result).GlobalContext);
    }

    static private bool IsTransactionalMethod(MethodInfo method)
    {
      return Attribute.IsDefined(method, typeof(TransactionalAttribute));
    }

    static private bool RunLocal(MethodInfo method)
    {
      return Attribute.IsDefined(method, typeof(RunLocalAttribute));
    }

    static private MethodInfo GetMethod(Type objectType, string method)
    {
      return objectType.GetMethod(method, 
        BindingFlags.FlattenHierarchy | 
        BindingFlags.Instance |
        BindingFlags.Public | 
        BindingFlags.NonPublic);
    }

    static private Type GetObjectType(object criteria)
    {
      if(criteria.GetType().IsSubclassOf(typeof(CriteriaBase)))
      {
        // get the type of the actual business object
        // from CriteriaBase (using the new scheme)
        return ((CriteriaBase)criteria).ObjectType;
      }
      else
      {
        // get the type of the actual business object
        // based on the nested class scheme in the book
        return criteria.GetType().DeclaringType;
      }
    }

    static DataPortal()
    {
      // see if we need to configure remoting at all
      if(PORTAL_SERVER.Length > 0 || SERVICED_PORTAL_SERVER.Length > 0)
      {
        _portalRemote = true;
        // create and register our custom HTTP channel
        // that uses the binary formatter
        Hashtable properties = new Hashtable();
        properties["name"] = "HttpBinary";
        if(AUTHENTICATION == "Windows")
        {
          // make sure we pass the user's Windows credentials
          // to the server
          properties["useDefaultCredentials"] = true;
        }

        BinaryClientFormatterSinkProvider formatter = 
                                        new BinaryClientFormatterSinkProvider();

        HttpChannel channel = new HttpChannel(properties, formatter, null);

        ChannelServices.RegisterChannel(channel);

//        // register the data portal types as being remote
//        if(PORTAL_SERVER.Length > 0)
//        {
//          RemotingConfiguration.RegisterWellKnownClientType(
//            typeof(Server.DataPortal), 
//            PORTAL_SERVER);
//        }
//        if(SERVICED_PORTAL_SERVER.Length > 0)
//        {
//          RemotingConfiguration.RegisterWellKnownClientType(
//            typeof(Server.ServicedDataPortal.DataPortal), 
//            SERVICED_PORTAL_SERVER);
//        }
      }

    }

    #endregion

  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
成人av资源在线| 日韩一区二区电影网| 欧美美女视频在线观看| 久久综合久久鬼色| 亚洲小少妇裸体bbw| 成人午夜精品在线| 91精品麻豆日日躁夜夜躁| 亚洲欧洲一区二区在线播放| 男人的天堂久久精品| 91老师国产黑色丝袜在线| 26uuu久久天堂性欧美| 亚洲综合自拍偷拍| 成人动漫中文字幕| 欧美精品一区二区三区高清aⅴ | 欧洲视频一区二区| 久久无码av三级| 日韩中文字幕区一区有砖一区| 成人教育av在线| 精品国产精品网麻豆系列| 亚洲成在线观看| 一本久道中文字幕精品亚洲嫩| 国产亚洲精品7777| 激情丁香综合五月| 欧美zozozo| 日韩国产在线一| 欧美中文字幕一二三区视频| 国产精品乱码一区二三区小蝌蚪| 美腿丝袜亚洲综合| 3atv一区二区三区| 日日摸夜夜添夜夜添精品视频| 日本久久一区二区| 亚洲自拍偷拍图区| 欧美在线不卡一区| 艳妇臀荡乳欲伦亚洲一区| 色哟哟一区二区| 亚洲视频一区二区免费在线观看| 成人免费视频视频在线观看免费 | 99在线热播精品免费| 国产亚洲欧洲997久久综合| 国产一区二区三区免费| 久久久久久9999| 国产精品一区二区x88av| 久久精子c满五个校花| 国产精一品亚洲二区在线视频| 欧美成人精品1314www| 韩国v欧美v日本v亚洲v| 欧美精品一区男女天堂| 粉嫩欧美一区二区三区高清影视| 国产精品网曝门| 91麻豆国产香蕉久久精品| 一区二区三区欧美亚洲| 欧美日韩三级一区二区| 蜜桃av一区二区三区电影| 精品国产乱码91久久久久久网站| 懂色av一区二区三区蜜臀| 国产精品网友自拍| 欧美无乱码久久久免费午夜一区| 日韩高清不卡一区| 国产午夜精品福利| 日本道免费精品一区二区三区| 亚洲成人在线免费| 2020国产成人综合网| 高清久久久久久| 亚洲最大成人网4388xx| 欧美不卡一二三| 成人av在线资源网站| 亚洲成年人影院| 久久婷婷一区二区三区| 91香蕉视频黄| 秋霞午夜av一区二区三区| 久久精品综合网| 欧美日韩一区久久| 东方欧美亚洲色图在线| 午夜影院久久久| 国产丝袜欧美中文另类| 欧美日韩国产影片| 成人一区二区三区中文字幕| 午夜精品久久久久久不卡8050| 久久久久久久国产精品影院| 在线精品视频免费播放| 国产一区二区免费在线| 一区二区免费视频| 久久久久97国产精华液好用吗| 欧美在线观看18| 成人av资源站| 韩国精品主播一区二区在线观看| 亚洲日本欧美天堂| 国产亚洲一区二区三区四区| 欧美精品日日鲁夜夜添| www.亚洲免费av| 精品一区二区三区不卡 | av电影天堂一区二区在线观看| 免费在线视频一区| 一区二区三区精品在线| 久久精品日产第一区二区三区高清版| 91国产免费看| k8久久久一区二区三区| 精品系列免费在线观看| 秋霞电影一区二区| 亚洲电影视频在线| 亚洲人成网站色在线观看| 国产日韩一级二级三级| 欧美电影免费观看完整版| 欧美日韩精品一区视频| 色哟哟国产精品免费观看| 高潮精品一区videoshd| 国产一区二区在线免费观看| 免费在线看成人av| 日韩二区在线观看| 日本不卡在线视频| 午夜精品久久久久久| 亚洲一区在线视频观看| 一区二区日韩电影| 亚洲精品欧美专区| 怡红院av一区二区三区| 亚洲欧洲在线观看av| 中文字幕一区二区三区乱码在线| 国产调教视频一区| 国产精品热久久久久夜色精品三区| 日韩精品中文字幕在线一区| 欧美v国产在线一区二区三区| 日韩精品最新网址| 久久这里只有精品视频网| 精品国一区二区三区| 精品久久99ma| 久久免费视频色| 久久日一线二线三线suv| 久久日韩粉嫩一区二区三区| 久久精品欧美日韩精品| 国产精品国产三级国产aⅴ无密码| 日本一区二区三区四区 | 懂色一区二区三区免费观看| 成人涩涩免费视频| 91免费视频观看| 欧美伊人精品成人久久综合97 | 亚洲日本在线a| 洋洋av久久久久久久一区| 五月天视频一区| 裸体歌舞表演一区二区| 国产成人精品免费看| 色综合一个色综合亚洲| 欧美日韩mp4| 精品动漫一区二区三区在线观看| 久久久精品国产99久久精品芒果| 国产精品久久久久一区| 亚洲一区二区三区中文字幕 | 中文字幕国产一区| 亚洲综合一区二区精品导航| 视频一区免费在线观看| 国产在线精品国自产拍免费| 成人av集中营| 88在线观看91蜜桃国自产| 国产亚洲精品bt天堂精选| 一个色综合网站| 久久er99精品| 91天堂素人约啪| 欧美电影免费观看高清完整版在| 国产精品网曝门| 日精品一区二区| 成人午夜av电影| 欧美猛男gaygay网站| 久久色.com| 五月综合激情网| 成人综合激情网| 日本高清成人免费播放| 精品久久久久久无| 一区二区三区国产精品| 国产成人啪免费观看软件| 欧美日韩国产美女| 精品粉嫩aⅴ一区二区三区四区| 亚洲少妇最新在线视频| 久久精品国产99久久6| 欧美色视频在线观看| 欧美视频一区二区三区四区| 青娱乐精品在线视频| 国产成人激情av| 欧美一区二区三区播放老司机| 国产精品嫩草99a| 免费一区二区视频| 91高清在线观看| 亚洲国产成人私人影院tom| 美日韩黄色大片| 欧美日韩一级片在线观看| 亚洲色图20p| www.亚洲色图.com| 久久一区二区三区四区| 免播放器亚洲一区| 欧美精品三级日韩久久| 亚洲国产视频一区二区| 色哟哟亚洲精品| 1024精品合集| 成人爱爱电影网址| 日本一区二区三区国色天香| 九九九精品视频| 日韩视频一区二区在线观看| 午夜精品久久久久| 欧美日本一区二区三区| 亚洲综合一区二区| 国产九色精品成人porny| 日韩视频一区二区三区|