Platform SDK: Team Productivity Update |
The first stage in creating an instance of the document review application in a Team Workspace is to create a physical directory on the server to hold the files the application needs. This task requires the use of several Active Server Pages (ASP) objects and components. 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 document review 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 a request for the application approved.
' Setup source name and path SourceName = "review" ' 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 where 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", and if the file does not yet exist, 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 uses the ServerVariables collection of the ASP Request object to obtain the name of the server computer running the Instantiation 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 that uses these names. In this case, the script designates an IIS virtual directory, a server computer physical directory, and a SQL Server database as "Revw_App1", concatenating the string "Revw_App" 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.