IFPCExplicitLinkTranslationMappings::Add method

Applies to: desktop apps only

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

Syntax

HRESULT Add(
  [in]   BSTR OriginalUrl,
  [in]   BSTR TranslatedUrl,
  [out]  IFPCExplicitLinkTranslationMapping **ppNewMapping
);
FPCExplicitLinkTranslationMappings.Add( _
  ByVal OriginalUrl As String, _
  ByVal TranslatedUrl As String, _
  ByRef ppNewMapping As IFPCExplicitLinkTranslationMapping _
) As FPCExplicitLinkTranslationMapping

Parameters

  • OriginalUrl [in]

    C++ Required. BSTR that specifies the original URL in the new mapping.
    VB Required. String that specifies the original URL in the new mapping.
  • TranslatedUrl [in]

    C++ Required. BSTR that specifies the translated URL in the new mapping.
    VB Required. String that specifies the translated URL in the new mapping.
  • ppNewMapping [out]
    Address of an interface pointer that on return points to the new IFPCExplicitLinkTranslationMapping interface created.

Return value

C++

This method can return one of the following:

  • S_OK, indicating that the operation succeeded.
  • An error code, indicating that the operation failed. In this case, the [out] parameter returned is a null object.

VB

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.

Remarks

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

Examples

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

Requirements

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2008 R2, Windows Server 2008 with SP2 (64-bit only)

Version

Forefront Threat Management Gateway (TMG) 2010

IDL

Msfpccom.idl

DLL

Msfpccom.dll

See also

FPCExplicitLinkTranslationMappings

 

 

Build date: 7/12/2010