让模块支持“导入”“导出”功能
生活随笔
收集整理的這篇文章主要介紹了
让模块支持“导入”“导出”功能
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
讓模塊支持“導入”“導出”功能
DNN模塊可以支持導入導出功能,通過將模塊內容導入到XML文件可以便于模塊內容備份和轉移,也可將模塊內容事先以XML格式保存通過導入功能實現模塊內容的批量錄入。
如圖:
[img]http://esshs.cnblogs.com/images/cnblogs_com/esshs/20050804.gif[/img]
要實現模塊的導入導出功能,需要在模塊的業務邏輯訪問對象(***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模塊可以支持導入導出功能,通過將模塊內容導入到XML文件可以便于模塊內容備份和轉移,也可將模塊內容事先以XML格式保存通過導入功能實現模塊內容的批量錄入。
如圖:
[img]http://esshs.cnblogs.com/images/cnblogs_com/esshs/20050804.gif[/img]
要實現模塊的導入導出功能,需要在模塊的業務邏輯訪問對象(***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>
總結
以上是生活随笔為你收集整理的让模块支持“导入”“导出”功能的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 梦到放鱼是什么征兆
- 下一篇: 晚上做梦梦到钱好不好