DNN模組可以支援匯入匯出功能,通過將模組內容匯入到XML檔案可以便於模組內容備份和轉移,也可將模組內容事先以XML格式儲存通過匯入功能實現模組內容的批量錄入。
要實現模組的匯入匯出功能,需要在模組的商務邏輯訪問對象(***Controller)中實現IPortable介面:
1、IPortable介面(components\Modules\IPortable.vb)Namespace DotNetNukeNamespace DotNetNuke.Entities.Modules
' 模組匯出匯入功能介面
Public Interface IPortableInterface IPortable
' 模組匯出
Function ExportModule()Function ExportModule(ByVal ModuleID As Integer) As String
' 模組匯入
Sub ImportModule()Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserID As Integer)
End Interface
End Namespace
2、在相應模組的商務邏輯類中實現IPortable介面(這一步可根據模組具體情況作出相應的修改,可參照DNN已有模組做,如:Links)Namespace DotNetNukeNamespace DotNetNuke.Modules.Links
Public Class LinkControllerClass LinkController
Implements Entities.Modules.IPortable
' 實現匯出功能介面
Public Function ExportModule()Function ExportModule(ByVal ModuleID As Integer) As String Implements DotNetNuke.Entities.Modules.IPortable.ExportModule
' 擷取該模組的全部連結資訊
Dim strXML As String = ""
Dim arrLinks As ArrayList = GetLinks(ModuleID)
' 根據該模組的欄位決定XML的節點
If arrLinks.Count <> 0 Then
strXML += "<links>"
Dim objLink As LinkInfo
For Each objLink In arrLinks
' 編寫模組內容的每一條記錄
strXML += "<link>"
strXML += "<title>" & XMLEncode(objLink.Title) & "</title>"
strXML += "<url>" & XMLEncode(objLink.Url) & "</url>"
strXML += "<vieworder>" & XMLEncode(objLink.ViewOrder.ToString) & "</vieworder>"
strXML += "<description>" & XMLEncode(objLink.Description) & "</description>"
strXML += "<newwindow>" & XMLEncode(objLink.NewWindow.ToString) & "</newwindow>"
strXML += "</link>"
Next
strXML += "</links>"
End If
Return strXML
End Function
' 實現匯入功能介面
Public Sub ImportModule()Sub ImportModule(ByVal ModuleID As Integer, ByVal Content As String, ByVal Version As String, ByVal UserID As Integer) Implements DotNetNuke.Entities.Modules.IPortable.ImportModule
Dim xmlLink As XmlNode
Dim xmlLinks As XmlNode = GetContent(Content, "links")
' 從XML中解析每一條記錄
For Each xmlLink In xmlLinks.SelectNodes("link")
Dim objLink As New LinkInfo
objLink.ModuleId = ModuleID
objLink.Title = xmlLink.Item("title").InnerText
objLink.Url = ImportUrl(ModuleID, xmlLink.Item("url").InnerText)
objLink.ViewOrder = Integer.Parse(xmlLink.Item("vieworder").InnerText)
objLink.Description = xmlLink.Item("description").InnerText
objLink.NewWindow = Boolean.Parse(xmlLink.Item("newwindow").InnerText)
objLink.CreatedByUser = UserId.ToString
AddLink(objLink)
Next
End Sub
End Class
End Namespace
注意:在打包安裝檔案時,需要在DNN檔案的<businesscontrollerclass>節點寫明該模組的商務邏輯類,如:<businesscontrollerclass>DNNChina.Modules.CLinks.CLinksController, DNNChina.Modules.CLinks</businesscontrollerclass>
相關內容:
DNN模組的層次劃分:http://www.cnblogs.com/esshs/archive/2005/07/27/201190.html
關於模組檔案結構:http://www.cnblogs.com/esshs/archive/2005/07/21/197198.html
關於DNN檔案結構:http://www.cnblogs.com/esshs/archive/2005/07/26/200154.html
更多相關內容>>