Microsoft Internet Security and Acceleration Server 2000 |
The following VBScript code example creates and updates a scheduled content download operation.
' script creates and updates a scheduled content download operation with ' depth = 9, TaskPeriod = fpcDownloadOnSpecifiedDaysOfWeek and ' DaysOfWeek = Everyday. ' Syntax: ' Scheduled-Content-Download-Job.vbs ArrayName URL JobName ' '<HTML><BODY>'<script language="VBScript"> ' Function TimeToStr( iHour, iMinute ) Dim Hour, Minute ' format hour If iHour < 10 Then Hour = "0" & FormatNumber(iHour,0,-1,0,-1) Else Hour = FormatNumber(iHour,0,-1,0,-1) End If If iMinute < 10 Then Minute = "0" & FormatNumber(iMinute,0,-1,0,-1) Else Minute = FormatNumber(iMinute,0,-1,0,-1) End If TimeToStr = Hour & ":" & Minute End Function Sub AddScheduledContentDownloadJob() Set args = Wscript.Arguments ' get FPC arrays object Set objFPC = CreateObject("FPC.Root") objFPC.Refresh Set objArrays = objFPC.Arrays output = "" ' check that we have seven arguments If args.Count <> 7 Then ' Show syntax output = "Invalid parameters" & vbCrLf & _ "Syntax:" & vbCrLf & _ " Scheduled-Content-Download-Job.vbs <ArrayName | .> JobName URL depth limit hour minute" End If ' Get the specified ISA array If args.Count = 0 Then output = output & vbCrLf & vbCrLf & "List of arrays:" & vbCrLf for each objArray in objArrays output = output & " " & objArray.Name & vbCrLf Next else ArrayName = args(0) If ArrayName = "." Then ' get the local array Set objArray = objArrays.GetContainingArray ArrayName = objArray.Name Else Set objArray = objArrays(ArrayName) If Err.Number <> 0 Then ' specified array is not available Wscript.Echo "The specified array was not found" Exit Sub End If End If ' Array found Set DownloadContainer = objArray.Cache.ScheduledContentDownload If args.Count = 1 Then output = output & vbCrLf & vbCrLf & "List of Jobs:" & vbCrLf for each Job in Downloadcontainer output = output & " " & Job.Name & " - " & Job.URL & " @ " & TimeToStr( Job.SchedTimeHour, Job.SchedTimeMinute) & " (" & Job.MaxDepth & "/" & FormatNumber(Job.MaxPages,0,-1,0,-1) & ")" & vbCrLf Next else ' look for the job On Error Resume Next ' set error handling set MyJob = Downloadcontainer.Item(args(1)) If Err.Number <> 0 Then ' Add the job set MyJob = Downloadcontainer.Add(args(1), args(2)) End If On Error GoTo 0 ' reset error handling If args.Count = 2 Then ' 2 args display the job information output = output & vbCrLf & vbCrLf & "Job parameters:" ' get job parameters: output = output & vbCrLf & " Name: " & MyJob.Name output = output & vbCrLf & " URL: " & MyJob.URL output = output & vbCrLf & " MaxDepth: " & MyJob.MaxDepth output = output & vbCrLf & " MaxPages: " & FormatNumber(MyJob.MaxPages,0,-1,0,-1) ' scheduling output = output & vbCrLf & " Runs at: " & MyJob.SchedTimeHour & ":" & FormatNumber(MyJob.SchedTimeMinute,0,-1,0,0) ' we have all the parameters, update the Job else If args.Count = 7 Then If Err.Number <> 0 Then Wscript.Echo "An error has occurred while creating job" & args(1) & vbCrLf & " Error: " & Err.Description Exit Sub End If ' set job parameters: MyJob.Name = args(1) MyJob.URL = args(2) MyJob.Enabled = true MyJob.MaxDepth = args(3) MyJob.MaxPages = args(4) MyJob.StayInDomain = true ' set scheduling MyJob.SchedTimeHour = args(5) MyJob.SchedTimeMinute = args(6) MyJob.SetTaskPeriod 2, 127 ' One fetch per day ' set FetchUrlFlags: MyJob.FetchUrlFlagForce = true MyJob.FetchUrlFlagTtlOverride = false ' use original expiration MyJob.FetchUrlFlagTtlIfNone = false ' bugbug true ' set expiration if not available MyJob.TTL = 24*60 ' expires after 24 hours ' Save DownloadContainer.Save If Err.Number <> 0 Then Wscript.Echo "An error has occurred:" & vbCrLf & Err.Description Else Wscript.Echo "Scheduled content download job successfully created/updated" End If Exit Sub ' out we go End If End If End If End If ' display message Wscript.Echo output End Sub AddScheduledContentDownloadJob '</script></BODY></HTML>