溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

如何統一one.asp多項目、函數庫、類庫的版本

發布時間:2020-11-07 15:49:50 來源:億速云 閱讀:235 作者:Leah 欄目:開發技術

如何統一one.asp多項目、函數庫、類庫的版本?相信很多沒有經驗的人對此束手無策,為此本文總結了問題出現的原因和解決方法,通過這篇文章希望你能解決這個問題。

舉個簡單的應用場景,開發一個小的API系統,支持 XML、JSON輸出。區別是 基礎版(dev/dev.asp)只支持 Access,VIP版本(dev/vip.asp)支持 Access + SQL Server。這樣VIP版本就需要在現在的基礎上 增加 sqlserver的支持,增加額外的 配置項。開發過程只需要 按正常開發即可。

如何統一one.asp多項目、函數庫、類庫的版本

開發完畢后,通過 one.asp 打包成 index.asp 和 vip.asp 兩個版本,整套程序都是一個獨立的文件。

如何統一one.asp多項目、函數庫、類庫的版本

下圖演示了 解析過程:

如何統一one.asp多項目、函數庫、類庫的版本

完整的測試代碼 可以 訪問:oneasp.rar 下載

核心代碼 如下:

' ====================================================
' 類名:One
' 作者:mqycn
' 博客:http://www.miaoqiyuan.cn
' 源碼:http://www.miaoqiyuan.cn/p/one-php
' 說明:多項目 函數庫、類庫 統一為一個版本的方法
' ====================================================
Class OneAsp
  Private FSO
  Private Root
   
  Private Sub Class_Initialize()
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
  End Sub
   
  Private Sub Class_Terminate()
    Set FSO = Nothing
  End Sub
   
  Public Function Run(ByVal sourceFile, ByVal saveFile)
    Run = "<hr><b>Input:</b>" & sourceFile & "<br><b>Result:</b>" & Save(saveFile, Include(sourceFile))
  End Function
   
   
  Public Function Include(ByVal path)
    Dim tmpPath, tmpItem, arrPath, index
    tmpPath = ""
    arrPath = Split(path, "/")
    For index = 0 To UBound(arrPath) - 1
      tmpItem = arrPath(index)
      tmpPath = tmpPath & tmpItem & "/"
    Next
    Include = Parse(tmpPath, arrPath(UBound(arrPath)))
  End Function
   
  Private Function Parse(ByVal root, ByVal fileName)
    Call SetRoot(root)
    Dim html
    html = OpenRead(fileName)
     
    Dim preg, pregResult
    Set preg = New Regexp
    preg.pattern = "<!--#include file=""([^""]*)""-->"
    preg.global = True
    preg.ignorecase = True
     
    Dim htmlInclude
    Set pregResult = preg.execute(html)
    For Each htmlInclude In pregResult
      html = Replace(html, htmlInclude, Include(root & htmlInclude.submatches(0)))
    Next
     
    Parse = "<% '" & root & fileName & " Start %" & ">" & vbCrLf & html & vbCrLf & "<%  '" & root & fileName & " End %" & ">" & vbCrLf
  End Function
   
  Private Function SetRoot(ByVal rootPath)
    If Right(rootPath, 1) <> "/" Then rootPath = rootPath & "/"
    Root = rootPath
  End Function
   
  Private Function RealPath(ByVal path)
    RealPath = Server.Mappath(Root & path)
  End Function
   
  Private Function OpenRead(ByVal path)
    Dim txtFile
    Set txtFile = FSO.OpenTextFile(RealPath(path))
    OpenRead = txtFile.ReadAll()
    txtFile.close
    On Error GoTo 0
  End Function
   
  Public Function Save(ByVal path, ByVal body)
    Dim txtFile
    Set txtFile = FSO.CreateTextFile(Server.Mappath(path))
    txtFile.write body
    txtFile.close
    Set txtFile = Nothing
    Save = path
  End Function
   
End Class

使用也非常簡單,使用 Call new OneAsp.run(開發版, 打包版),可以 dev.asp 中的所有包含的代碼 打包到 index.asp,如果只想獲取解析的內容,可以使用 Response.Write Server.Htmlencode(Call new OneAsp.include(開發版))

看完上述內容,你們掌握如何統一one.asp多項目、函數庫、類庫的版本的方法了嗎?如果還想學到更多技能或想了解更多相關內容,歡迎關注億速云行業資訊頻道,感謝各位的閱讀!

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

亚洲午夜精品一区二区_中文无码日韩欧免_久久香蕉精品视频_欧美主播一区二区三区美女