Subversion Repositories DevTools

Rev

Rev 4482 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

<%@LANGUAGE="VBSCRIPT"%>
<%
'=====================================================
'       Release Manager Admin Tests
'       Designed to be called via AJAX and to return
'       JSON formatted data to dynamic page
'=====================================================
%>
<%
Option explicit
' Good idea to set when using redirect
Response.Expires = 0   ' always load the page, dont store
%>
<!--#include file="common/conf.asp"-->
<!--#include file="common/globals.asp"-->
<!--#include file="common/qstr.asp"-->
<!--#include file="common/common_subs.asp"-->
<!--#include file="common/formating.asp"-->
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="common/base64encode.vbs"></SCRIPT> 
<SCRIPT LANGUAGE="VBScript" RUNAT=SERVER SRC="class/classaspJSON.vbs"></SCRIPT> 
<%
'------------ Variable Definition -------------
Dim parOpr, newitem
Dim result

' Basic Parameters
parOpr = QStrPar("Opr")
result = -1

' Init the output JSON class
'   Operations can add data
'   Default data will be added at the end
Dim oJSON
Set oJSON = New aspJSON

'
'   Determine the operation to be performed
'
If (parOpr = "zipTest") Then

    '
    ' Create a test file in a known directory
    '
    Dim objZIPObject, ZipFile
    Dim outFile, objFSO, LocalDir, objFile
    Set objFSO=CreateObject("Scripting.FileSystemObject")
    LocalDir = Request.ServerVariables("APPL_PHYSICAL_PATH") & "release_manager\temp\"

    If NOT objFSO.FolderExists( LocalDir ) Then
        result = 1
        oJSON.data("emsgSummary") = "Folder not found:" & LocalDir
    Else
        ' Create a known file to zip up
        '
        outFile = LocalDir & "zipTestFile.txt"
        Set objFile = objFSO.CreateTextFile(outFile,True)
        objFile.Write "test string" & vbCrLf
        objFile.Close

        ' Zip up a test file
        '
        ZipFile = LocalDir & "zipTest.zip"
        If objFSO.FileExists(ZipFile) Then
            objFSO.DeleteFile ZipFile, TRUE
        End If

        On Error Resume Next
        Set objZIPObject = Server.CreateObject("XStandard.Zip")
        If Err.Number <> 0 then
            result = 1
            oJSON.data("emsgSummary") = "Create XStandard.Zip:" & Err.Description
        Else
            objZIPObject.Pack outFile, ZipFile

            If objZIPObject.ErrorCode <> 0 then
                    result = 1
                    oJSON.data("emsgSummary") = "Zip Error XStandard:" & objZIPObject.ErrorCode & ":" & objZIPObject.ErrorDescription
            Else
                ' All done - must have passed
                result = 0

            End If
        End If

        '
        ' Clean up
        If objFSO.FileExists(outFile) Then
            objFSO.DeleteFile outFile, TRUE
        End If

        If objFSO.FileExists(ZipFile) Then
            objFSO.DeleteFile ZipFile, TRUE
        End If

        objZIPObject = Nothing

    End If
    set objFSO = Nothing

Else
    oJSON.data("emsgSummary") = "Unknown operation requested:" & parOpr
End If

'
'   Create JSON data for the user
'   Important fields
'       result
'
'   Debug fields
'       Request (Array)
'
'Write single value
oJSON.data("result") = result

' DEBUG: An array of the user provided requests
Set oJSON.data("Request") = oJSON.Collection()
Set newitem = oJSON.AddToCollection(oJSON.data("Request"))
Dim variableName
for each variableName in Request.QueryString
    newitem.add variableName, Request.QueryString(variableName)
next

'Return the object
Response.Write oJSON.JSONoutput()
%>