[DNN模組開發]讓模組支援“匯入”“匯出”功能

來源:互聯網
上載者:User
  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

更多相關內容>>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.