Add Method of the IFPCExplicitLinkTranslationMappings Interface

The Add method creates a new FPCExplicitLinkTranslationMapping object in the collection and returns a reference to it.

[C++]

Syntax

HRESULT Add(
  [in]   BSTR OriginalUrl,
  [in]   BSTR TranslatedUrl,
  [out]  IFPCExplicitLinkTranslationMapping** ppNewMapping
);

Parameters

OriginalUrl
Required. BSTR that specifies the original URL in the new mapping.
TranslatedUrl
Required. BSTR that specifies the translated URL in the new mapping.
ppNewMapping

Address of an interface pointer that on return points to the new IFPCExplicitLinkTranslationMapping interface created.

Return Value

This method can return one of the following:

[Visual Basic]

Syntax

Function Add( _
  ByVal OriginalUrl As String, _
  ByVal TranslatedUrl As String _
) As FPCExplicitLinkTranslationMapping

Parameters

OriginalUrl
Required. String that specifies the original URL in the new mapping.
TranslatedUrl
Required. String that specifies the translated URL in the new mapping.

Return Value

This method returns a reference to an FPCExplicitLinkTranslationMapping object if successful. Otherwise, an error is raised that can be intercepted by using an error handler.

Example Code

This VBScript script adds user-defined (explicit) global link translation mappings for the local array from a user-specified file. Note that the text file must contain a list of mappings consisting of two strings separated by a tab character with each mapping on a separate line.
Option Explicit
'Define the constants needed
Const Error_FileNotFound = &H80070002
Const Error_FileAlreadyExits = &H800700B7
Const Error_NoProtocol = &HC00403E0
Const ForReading = 1
Main(WScript.Arguments)
Sub Main(args)
	If(args.Count <> 1) Then
		Usage()
	End If
	AddGlobalMappings args(0)
End Sub
Sub AddGlobalMappings(fileName)
	' Create the root object.
	Dim root  ' The FPCLib.FPC root object
	Set root = CreateObject("FPC.Root")
	'Declare the other objects needed.
	Dim isaArray	' An FPCArray object
	Dim mappings	' An FPCExplicitLinkTranslationMappings collection
	Dim fso		 ' A FileSystem object
	Dim fileStream  ' A TextStream object
	Dim textRead	' A String
	Dim original	' A String
	Dim translated  ' A String
	DIm i		 ' An Integer
	Dim pos		 ' An Integer
	' Get references to the array object and the collection of user-defined
	' global mappings.
	Set isaArray = root.GetContainingArray()
	Set mappings = isaArray.ArrayPolicy.WebProxy.ExplicitLinkTranslationMappings
	Set fso = CreateObject("Scripting.FileSystemObject")
	On Error Resume Next
	Set fileStream = fso.OpenTextFile(fileName, ForReading)
	If Err.Number <> 0 Then
		WScript.Echo "The file specified could not be found."
		WScript.Quit
	End If
	On Error GoTo 0
	' Clear the existing user-defined global mappings for the array
	' and then add the explicit global mappings from the file.
	WScript.Echo "Removing the existing user-defined global mappings..." 
	i = mappings.Count
	Do While i > 0
		mappings.Remove i
		i = i - 1	 
	Loop
	WScript.Echo "Adding user-defined global mappings "  _ 
				 & "from the file " & fileName & "..."
	Do While fileStream.AtEndOfStream <> True
		textRead = fileStream.ReadLine
		If textRead <> "" Then
			pos = InStr(1, textRead, vbTab, vbTextCompare)
			If (pos <> 0) Then
				original = Left(textRead, pos - 1)
				translated = Right(textRead, Len(textRead) - pos)
				On Error Resume Next
				mappings.Add original, translated
				If Err.Number = Error_FileAlreadyExits Then
					WScript.Echo "A duplicate mapping for " & original _
								 & " was ignored."
					Err.Clear
				ElseIf Err.Number = Error_NoProtocol Then
					WScript.Echo "A mapping without a valid protocol was ignored."
					Err.Clear
				End If
				On Error GoTo 0
			End If
		End If
	Loop
	isaArray.Save True
	WScript.Echo "Done!"
End Sub 
Sub Usage()
	WScript.Echo "Usage:" & VbCrLf _
		& "  CScript " & WScript.ScriptName & " FileName" & VbCrLf _
		& "" & VbCrLf _
		& "  FileName  - Text file containing a list of mappings" 
	WScript.Quit
End Sub

Remarks

The URLs specified in the OriginalUrl and TranslatedUrl parameters must specify HTTP or HTTPS as the protocol.

Requirements

Client Requires Windows Vista or Windows XP.
Server Requires Windows Server 2008.
Version Requires Forefront Threat Management Gateway (TMG).
IDL

Declared in Msfpccom.idl.

DLL

Requires Msfpccom.dll.

See Also

FPCExplicitLinkTranslationMappings


Send comments about this topic to Microsoft

Build date: 11/30/2009

© 2008 Microsoft Corporation. All rights reserved.