Platform SDK: Team Productivity Update |
The first stage in creating an instance of the Expense Report application in a Team Workspace is to create a physical directory on the server to hold the files the application needs. The code written for this task also includes a way to track the instances of applications that the server has instantiated into Team Workspaces.
First, the script indicates the file location where the installed version of the Expense Report application resides on the server. Using the MapPath method of the ASP Server object, the script finds the physical path that corresponds to the application's virtual root. From this source, the Instantiation URL can make copies for each Team Workspace that has an approved request for the application.
' Setup source name and path SourceName = "expense" ' Name of the application SourcePath = Server.MapPath("/" & SourceName) ' Current physical directory
Next, the script sets a variable to hold the name of a text file. This text file stores an instance number for the application copy it is instantiating. This text file resides in the same directory as the application source.
NextInstanceNumberFilename = "NextInstanceNumber.txt" ' Name of the file were we will keep the instance counter
Using the intrinsic ASP Server object, the script creates an instance of the VBScript Scripting Run-time FileSystemObject to gain access to the server computer's file system. The BuildPath method designates a path for the text file location and then appends a name to the file. In this case, the script uses the current directory (the value passed in Server.MapPath) and "NextInstanceNumber.txt", the string stored in the NextInstanceNumberFilename variable.
' Get next instance number Set oFileSystem = Server.CreateObject("Scripting.FileSystemObject") NextInstanceNumberPathFilename = oFileSystem.BuildPath(SourcePath, NextInstanceNumberFilename)
The script then attempts to open "NextInstanceNumber.txt". If the file does not exist, the script creates it. The parameters to the OpenTextFile method represent the file name, set in the preceding code example; the iomode, which in this case is set to 1 for ForReading; and create, which when set to TRUE indicates that the file can be created if it does not already exist. The script then opens the file with the iomode parameter set to 2 for ForWriting. Using the Write method, the script increments the instance number and then closes the file.
Note There are other ways to create an instance counter for applications. You could also assign each application a GUID and store the instance name in the system registry rather than a text file. Either way, it is important to create a mechanism to track application instances. The Team Productivity Update does not do this automatically.
Set oFile = oFileSystem.OpenTextFile(NextInstanceNumberPathFilename, 1, True) ' If not existing, will create a new file If oFile.AtEndOfStream = True Then NextInstanceNumber = 1 Else NextInstanceNumber = oFile.ReadAll End If Set oFile = oFileSystem.OpenTextFile(NextInstanceNumberPathFilename, 2) oFile.Write NextInstanceNumber + 1 ' Update value for next instance oFile.Close
Next, the script saves the instance number in a text file using the GUIDSessionID name. The DropConfigure URL file uses this text file to recognize which Expense Report application instance to delete. For more information about the DropConfigure URL, see Removing the Application Configuration.
' Save the instance number in a text file (using the GUIDSessionID name) ' Note, urlDropConfigure.asp uses this file know to which instance to delete. GUIDSessionID = Request.Form("ConfigSessionID") GUIDSessionID = Replace( Replace(GUIDSessionID,"{","") ,"}","") GUIDSessionIDPathFilename = oFileSystem.BuildPath(SourcePath, GUIDSessionID & ".txt") Set oFile = oFileSystem.OpenTextFile(GUIDSessionIDPathFilename, 2, True) ' For Write oFile.Write NextInstanceNumber oFile.Close
The user configuration information is read from the text file created earlier in Saving Configuration Information.
' Get User configuration info (saved from 'urlConfigure.asp') ExpenseReportConfigPathFilename = SourcePath & "\" & Replace(ExpenseReportConfigFilename,"#", NextInstanceNumber) Set oFile = oFileSystem.OpenTextFile(ExpenseReportConfigPathFilename, 1) If oFile.AtEndOfStream = True Then AccountsPayableNTUsername = "administrator" MileageRate = "0.31" Err.Clear Else tempText = Split(oFile.ReadAll,"|") AccountsPayableNTUsername = tempText(0) MileageRate = tempText(1) oFile.Close End If
Next, the script uses the ServerVariables collection of the ASP Request object to obtain the name of the server computer running the Deploy URL.
The following lines of code name the IIS virtual directories that will hold the application. The virtual directories are actually created in a later step based on the server name. In this case, the script designates an IIS virtual directory, a server computer physical directory, and a SQL Server database as "Expense1", concatenating the string "Expense" held in the variable SourceName and the value stored in the NextInstanceNumber variable.
' Setup instance names WebServerName = Request.ServerVariables("SERVER_NAME") WebVirtualDirectoryName = SourceName & NextInstanceNumber WebPhysicalDirectoryName = SourceName & NextInstanceNumber DatabaseName = SourceName & NextInstanceNumber
After the appropriate directories have been named, the script then calls the BuildPath method and passes the parameters to name the Web physical directories for the instance of the application. In addition, it names another directory to hold a subdirectory for the application's database.
' Setup instance paths WebPath = oFileSystem.BuildPath(Server.MapPath("."), WebPhysicalDirectoryName) DataPath = WebPath & "\Database"
To follow the next stage of the script's execution, see Copying Files into the Physical Directory.