程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> Visual Basic語言 >> VB.NET >> 游戲大廳從根底開端(4)-經過L2X用配置文件反射組裝順序(VB only)

游戲大廳從根底開端(4)-經過L2X用配置文件反射組裝順序(VB only)

編輯:VB.NET

游戲大廳從根底開端(4)-經過L2X用配置文件反射組裝順序(VB only)。本站提示廣大學習愛好者:(游戲大廳從根底開端(4)-經過L2X用配置文件反射組裝順序(VB only))文章只能為提供參考,不一定能成為您想要的結果。以下是游戲大廳從根底開端(4)-經過L2X用配置文件反射組裝順序(VB only)正文


很久沒更新了。前一陣任務比擬空虛(就是比擬勞累拉~),加上向老趙學習努力瘦身,肉體愈發痛 苦,難免就懶散上去。通用倒了,項目忽然死亡,On bench了一個月,越發的有力。

好音訊也是 有的,在m$ msdn論壇努力答復問題,總算當上了個版主。雖然7月請求mvp失敗 但是鄙人生性好顯擺,難聽一點就是愛分享,所以一個咕噜爬起來,又是條好漢。

-----------------------閒話到此 為止-----------------------

經過配置來制定順序

說起經過配置來制定順序,不得不 提及asp.net

還記得asp.net membership 在web.config中的聲明麼?

<membership defaultProvider="Main_SqlMemberShipProvider" userIsOnlineTimeWindow="20">

<providers>

<add connectionStringName="GTSCOM_DATABASE_DATAConnectionString1" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" passwordFormat="Clear" applicationName="GTSCOM_Customer" name="Main_SqlMemberShipProvider" type="System.Web.Security.SqlMembershipProvider"/>

</providers>

</membership>

完成不同工廠發生了相反接口的實體類型 MembershipUser

Web.config 就是這麼神奇,動不動什麼東西就參加出去了~ 編譯器往往是依據web.config生成 暫時cs/vb代碼,將其編譯後果作為網站的根底 。

編譯config提升的功能我可是十分羨慕阿,但 是改配置就重新編譯這樣的事情也常常被诟病。改一個銜接字符串整個網站編譯5分鐘的埋怨,偶然也會 聽到。

我們的游戲大廳,無論是做web game 還是做聯眾,都不合適

另一種方法就是反射 了。

l 大廳組裝要求

n 靜態加載需求的類庫(多種游戲邏輯、房間邏輯、正本類型的 工廠載入)

n 戰略配置 (戰略形式的戰略類的載入)

n 經過reload config 修正工廠 類和戰略類 完成無重啟的“下一場游戲失效”配置更新。

n 功能不能遭到過多影 響

Okay,反射都能勝任。

假如反射失掉的都是完成主順序援用中IFactory接口的工廠,返 回的都是契合IProductClass 接口的對象,訪問成員都經過訪問接口停止,初始化以外功能上也不會受 影響。看起來非常可行!

另一方面:

l 配置文件要求

n 讓我這個懶蛋比擬容易 讀(架構明晰)

n 讓我這個懶蛋比擬方便寫 (編寫智能提示)

n 寫順序的時分比擬舒 坦 (編程智能提示)

恩,眼睛裡冒賊光了。

我們看看上面的xsd文件

WGSConfig.xsd
<?xml  version="1.0" encoding="utf-8"?>
<xs:schema  attributeFormDefault="unqualified" elementFormDefault="qualified"  xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xs:element  name="config">
         <xs:complexType>
             <xs:all>
                 <xs:element name="Assemblies" minOccurs="0"  maxOccurs="1">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element maxOccurs="unbounded"  name="Assembly" minOccurs="1">
                                 <xs:complexType>
                                     <xs:attribute  name="relativepath" type="xs:string" use="required"  />
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="LinkListeners" maxOccurs="1"  minOccurs="1">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element maxOccurs="unbounded"  name="LinkListener">
                                 <xs:complexType>
                                     <xs:sequence>
                                          <xs:element maxOccurs="unbounded" name="param"  type="KeyValuePair">
                                         </xs:element>
                                      </xs:sequence>
                                     <xs:attribute  name="namespace" type="xs:string" use="required" />
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="Construction" maxOccurs="1"  minOccurs="1">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element name="Services">
                                 <xs:complexType>
                                     <xs:sequence>
                                         <xs:element  name="Service" maxOccurs="unbounded">
                                              <xs:complexType>
                                                  <xs:sequence>
                                                      <xs:element name="Createparam" maxOccurs="unbounded"  type="KeyValuePair">
                                                      </xs:element>
                                                      <xs:element name="ServiceConfig" type="xs:anyType" />
                                                  </xs:sequence>
                                                 <xs:attribute  name="builderNamespace" type="xs:string" />
                                              </xs:complexType>
                                         </xs:element>
                                      </xs:sequence>
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="DataAccess" maxOccurs="1"  minOccurs="1">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element name="compoment">
                                 <xs:complexType>
                                     <xs:sequence>
                                         <xs:element  name="ConnectionString" type="xs:string" />
                                     </xs:sequence>
                                     <xs:attribute  name="namespace" type="xs:string" use="required" />
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="Membership" maxOccurs="1"  minOccurs="1">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element name="UserFactory">
                                 <xs:complexType>
                                     <xs:sequence>
                                         <xs:element  maxOccurs="unbounded" name="param"  type="KeyValuePair">
                                         </xs:element>
                                      </xs:sequence>
                                     <xs:attribute  name="namespace" type="xs:string" use="required" />
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
                 <xs:element name="ChatChannels" maxOccurs="1"  minOccurs="0">
                     <xs:complexType>
                         <xs:sequence>
                             <xs:element name="ChatChannel">
                                 <xs:complexType>
                                     <xs:sequence>
                                         <xs:element  name="param" type="KeyValuePair" />
                                     </xs:sequence>
                                 </xs:complexType>
                             </xs:element>
                         </xs:sequence>
                     </xs:complexType>
                 </xs:element>
             </xs:all>
         </xs:complexType>
     </xs:element>
     <xs:complexType name="KeyValuePair">
         <xs:attribute name="key" type="xs:string"  use="required" />
         <xs:attribute name="value" type="xs:string"  use="required" />
     </xs:complexType>
</xs:schema>

是不是沒什麼覺得?

換用vs2005翻開,覺得又不一樣 了.

怎樣樣 是不是很明晰呢?

*vs2008的xsd編輯不太方便,我們可以用sql2005 帶的 vs2005 設置

看看我們的要求表

配置文件要求

n 讓我這個懶蛋比擬容易讀(架構明晰) checked!

n 讓我這個懶蛋比擬方便寫 (編寫智能提示)

n 寫順序的時分比擬舒坦 ( 編程智能提示)

有了xsd文件,我們就可以更方便得樹立自己的XML 配置文件了

在工程中 添加一個xml文件 在文件的屬性窗口中選擇視圖(schemas)

把方才的xsd 選中

Oh yeah~~

我們在編輯xml的時分   可以失掉及時的智能提示了@_@

看看我們的要求表

配 置文件要求

n 讓我這個懶蛋比擬容易讀(架構明晰) checked!

n 讓我這個懶蛋比擬方 便寫 (編寫智能提示)checked!

n 寫順序的時分比擬舒坦 (編程智能提示)

恩... 間隔完滿的束縛消費力還差一點點,我們看看編成集成提示支持得怎樣

寫一條linq 查詢一切的 factory吧

嗯,,,效果不錯.看來vb 編譯器體恤的預編譯了我們的xsd文件. 

。。。。。。c# 啥時分能集成這個阿,哭啊。。。公司項目不讓用vb阿。。。。。

看看我們的要求表

配置文件要求

n 讓我這個懶蛋比擬容易讀(架構明晰) checked!

n 讓我這個懶蛋比擬 方便寫 (編寫智能提示)checked!

n 寫順序的時分比擬舒坦 (編程智能提示)checked!

於是簡直在不停的智能提示中~~  我完成了配置類...

Happy end
Imports System.Collections.Generic
Namespace StrategiesNamespace Strategies

    Public Class GlobalConfigClass GlobalConfig
        Implements IGlobalConfig

        Public ReadOnly Property Config()Property Config() As Xml.Linq.XDocument Implements IGlobalConfig.Config
            Get
                Return _ConfigFile
            End Get
        End Property

        Protected _LinkListeners As New List(Of ILinkListener)
        Public ReadOnly Property LinkListeners()Property LinkListeners() As System.Collections.Generic.IEnumerable(Of Communicate.ILinkListener) Implements IGlobalConfig.LinkListeners
             Get
                Return _LinkListeners
             End Get
        End Property

        Private Shared _Instance As GlobalConfig
        Public Shared Property Current()Property Current() As GlobalConfig

            Get

                 If _Instance Is Nothing Then
                    _Instance = New GlobalConfig
                End If

                 Return _Instance
            End Get

             Set(ByVal value As GlobalConfig)
                _Instance = value
            End Set
        End Property

        Private Shared _ConfigFile As XDocument

        Private Sub New()Sub New()
            _Instance = Me

            Dim path As String = System.Diagnostics.Process.GetCurrentProcess.MainModule.FileName

             path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), "WGSConfig.xml")
            If System.IO.File.Exists(path) Then
                _ConfigFile = XDocument.Load(path)
             Else

                Throw New Exception (WayneGameSolution.Resources.CurrentCurlture.FileLoad_ConigLoad_ErrorMessage)
             End If

            Dim tmps = From n In Config.<config>.<Assemblies>.<Assembly> _
                 Select n.@relativepath

            For Each s As String In tmps
                AttachTypes(s)
            Next

            Dim listeners = From xn As XElement In Config.<config>.<LinkListeners>.<LinkListener> _
                                     Select lk = CType(CreateObject (xn.@Namespace ,namespace, xn), ILinkListener) Where Not lk Is Nothing

_LinkListeners.AddRange(listeners)

'For Each xn As XElement In Config.<config>.<Construction>.<Services>.<Service>
             '    _Serivces.Add(CreateObject(xn.@builderNamespace, xn))

            'Next

Dim services = From xn As XElement In Config.<config>.<Construction>.<Services>.<Service> _
                                   Select builder = CType (CreateObject(xn.@builderNamespace, _
                                                                 xn), IGameServiceBuilder) Where Not builder Is Nothing _
                                                                  Select service = builder.CreateService()

            _Serivces.AddRange(services)

            _UserFactory = CreateObject(Config.<config>.<Membership>.<UserFactory>.@Namespace ,namespace, _
                                         Config.<config>.<Membership>.<UserFactory>.First)

            _PackFlagEnumType = GetTypeFrom (Config.<config>.<PackEnum>.@Namespace )namespace)

'Sub New (ByVal id As String, ByVal name As String, ByVal timeoutSecond As Int32, ByVal type As IChatChannel.ChannelType)
            Dim channelsQuery = From elm As XElement In Config.<config>.<ChatChannels>.<ChatChannel> Select New ChatChannel(elm.@channelID, elm.@channelName, CInt(elm.@timeout), CInt(elm.@type))

            For Each chn As Chat.IChatChannel In channelsQuery
                 Me.ChatChannels.Add(chn.ID, chn)

            Next

        End Sub
        Public Function params2Dic()Function params2Dic(ByVal nodes As IEnumerable(Of XElement)) As Dictionary(Of String, String)
            Dim dic As New Sync.SyncDictionary(Of String, String)
            For Each xn As XElement In nodes
                 dic.Add(xn.@key, xn.@value)

            Next
            Return dic
        End Function

         Public Shared Function GetTypeFrom()Function GetTypeFrom(ByVal name_space As String) As Type
            Dim T As Type = Nothing
            T = Type.GetType(name_space, False, True)
            If T Is Nothing Then _ReflectTypes.TryGetValue(name_space, T)
            Return T
         End Function

        Public Shared Function CreateObject_Instance()Function CreateObject_Instance(ByVal name_space As String, ByVal ParamArray parms() As Object)

            Dim T As Type = GetTypeFrom(name_space)

            If T Is Nothing Then Return Nothing

            Return Activator.CreateInstance(T, parms)

        End Function
        Private Shared _ReflectTypes As New Sync.SyncDictionary(Of String, Type)
        Public ReadOnly Property ReflectTypes()Property ReflectTypes() As System.Collections.Generic.IDictionary(Of String, System.Type) Implements IGlobalConfig.ReflectTypes
            Get
                 Return _ReflectTypes
            End Get
        End Property

        Public Function AttachTypes()Function AttachTypes(ByVal relativePath As String) As Boolean Implements IGlobalConfig.AttachTypes
            Dim path As String = System.Diagnostics.Process.GetCurrentProcess.MainModule.FileName

             path = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(path), relativePath)
            Dim asm As System.Reflection.Assembly = Nothing

            asm = System.Reflection.Assembly.LoadFrom(path)
            If asm Is Nothing Then
                Return False
            Else
                Dim tps As Type() = asm.GetTypes()

                For Each T As Type In tps
                    Dim FullName As String = T.Namespace & "." & T.Name
                    If Not _ReflectTypes.ContainsKey(FullName) Then _ReflectTypes.Add(FullName, T)
                 Next

            End If
             Return True

        End Function

        Public Function CreateObject()Function CreateObject(ByVal name_space As String, ByVal ParamArray parms() As Object) As Object Implements IGlobalConfig.CreateObject
             Return CreateObject_Instance(name_space, parms)
        End Function
        Private _ChatChannels As New Generic.Sync.SyncDictionary(Of String, Chat.IChatChannel)
        Public ReadOnly Property ChatChannels() Property ChatChannels() As System.Collections.Generic.IDictionary(Of String, Chat.IChatChannel) Implements IGlobalConfig.ChatChannels
            Get
                Return _ChatChannels
            End Get
        End Property
        Private _LogedUsers As New Generic.Sync.SyncDictionary(Of String, IUser)
        Public ReadOnly Property LogedUsers()Property LogedUsers() As System.Collections.Generic.IDictionary(Of String, Membership.IUser) Implements IGlobalConfig.LogedUsers
            Get
                Return _LogedUsers
            End Get
        End Property
        Private _MountedAreas As New Generic.Sync.SyncDictionary(Of String, IArea)
        Public ReadOnly Property MountedAreas()Property MountedAreas() As System.Collections.Generic.IDictionary(Of String, Construct.IArea) Implements IGlobalConfig.MountedAreas
            Get
                Return _MountedAreas
            End Get
        End Property

        Private _PackFlagEnumType As Type
        Public ReadOnly Property PackFlagEnumType()Property PackFlagEnumType() As System.Type Implements IGlobalConfig.PackFlagEnumType
             Get
                Return _PackFlagEnumType
             End Get
        End Property
        Friend _Serivces As New List(Of Services.IGameService)
        Public ReadOnly Property Serivces()Property Serivces() As System.Collections.Generic.IEnumerable(Of Services.IGameService) Implements IGlobalConfig.Serivces
            Get
                Return _Serivces
            End Get
        End Property
        Protected _AreaFactory As Construct.IAreaFactory
        Public ReadOnly Property AreaFactory()Property AreaFactory() As Construct.IAreaFactory Implements IGlobalConfig.AreaFactory
             Get
                Return _AreaFactory
             End Get
        End Property

        Protected _UserFactory As Membership.IUserFactory
        Public ReadOnly Property UserFactory()Property UserFactory() As Membership.IUserFactory Implements IGlobalConfig.UserFactory
            Get
                 Return _UserFactory
            End Get
        End Property
    End Class

End Namespace

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved