//********************************************************
// Project: News Checker for aSocks Library - CRT Version
//********************************************************
// Author: Michael Mc Vicker
// Copyright: © 01/19/01 - All Rights Reserved
// FileName: NewsCheckCRT.PRG
//********************************************************
//
// aSocks Sample Application:
// Sample application to demonstrate the functionallity
// of the aSocks TCP/IP Library.
//
// Components:
// NNTP Class
//
// Updates:
// Last Update: 01/20/01 by MMM
//
// Notes:
//
//********************************************************
// Required for MsgArray()
#pragma Library( "XppUI2.LIB" )
#pragma Library( "ADAC20b.LIB" )
// SocketTools License Key Include
#Include "CSKeys.ch"
#Include "ASocksKey.ch"
#Include "aSocksConst.ch"
#Include "aSocksError.ch"
Static aGroups := {} // Holder for Group List
Static aLast := {} // Holder for Highest Article Number
Static aNew := {} // Holder for New Articles Flag
Static lFirstRun := .T. // Flag to supress "New Article"
// Notification when Application
// First Runs
//*******************************
Procedure DBESys ( )
//** Stop Requiremnet of DLLs ***
Return
Procedure Main()
Local oNNTP, nKey := 0
SetMouse(.T.)
oNNTP := aprNNTP():New(ASOCKS_LICENSE_KEY,CSTOOLS_LICENSE_KEY)
// Make sure ::Debug Display is OFF
oNNTP:Debug := .F.
// Display Column Titles
@ 0, 0 say "News Groups"
@ 0,41 say "First"
@ 0,52 say "Last"
@ 0,61 say "Total"
@ 1, 0 say "===================================="
@ 1,40 say "======"
@ 1,50 say "======"
@ 1,60 say "======"
// Check for new articles every 15 minutes
SetTimerEvent( 90000, {|| CheckNews( oNNTP ) } )
@ 21,22 say "Press [Space] to recheck immediately."
@ 22,29 say "Press [Escape] to Quit."
Do While nKey != 27 // [Esc]
nKey := Inkey( 0 )
If nKey = 32 // [Space]
CheckNews( oNNTP )
EndIF
If nKey = -4 // [F5]
CheckNews( oNNTP )
EndIF
Enddo
SetTimerEvent(0)
Return
//*******************************
Procedure CheckNews ( oNNTP )
//*******************************
Local aArticles := {}, x := 0, aCount := {}
@ 24, 30 say "Checking News Groups"
// News Server
oNNTP:Connect("news.alaska-software.com",IPPORT_NNTP,15) > 0
// Check to see if we have a list of Groups yet
If Len(aGroups) <= 0
// If not, List Groups
aGroups := oNNTP:ListGroups(RETURN_ARRAY)
// Put Group List in Alphabetical order
aGroups := aSort(aGroups)
EndIF
// Size the New Article Monitoring Arrays
If Len(aLast) < Len(aGroups)
aSize(aLast,Len(aGroups))
aFill(aLast,0)
Endif
If Len(aNew) < Len(aGroups)
aSize(aNew,Len(aGroups))
aFill(aNew,.F.)
EndIF
// Get Article Count for each Group
For x = 1 To Len(aGroups)
// Join Group [x]
if !Empty(oNNTP:SelectGroup(substr(aGroups[x],1,At(" ",aGroups[x]))))
// Get First, Last and Total Count
aCount := oNNTP:GetArticleRange()
// Build Display Information
aAdd(aArticles,{substr(aGroups[x],1,At(" ",aGroups[x])),aCount[1],aCount[2],aCount[3]})
Else
// Add some default values if Errored
aAdd(aArticles,{substr(aGroups[x],1,At(" ",aGroups[x])),-1,-1,-1 })
Endif
Next
// Close Connection
oNNTP:DisConnect()
@ 24, 30 say " "
WriteResults(aArticles)
Return
//*******************************
Procedure WriteResults ( aArticles )
//*******************************
Local x := 0
For x = 1 To Len(aArticles)
@ x+1, 0 say aArticles[x,1]
@ x+1,40 say Str(aArticles[x,2],6)
@ x+1,50 say Str(aArticles[x,3],6)
@ x+1,60 say Str(aArticles[x,4],6)
If aLast[x] < aArticles[x,3] // Check Last Posted Article Number
aLast[x] := aArticles[x,3]
If !lFirstRun
If aArticles[x,3] = -1
// An error occured during News Group Check
aNew[x] := NIL
Else
aNew[x] := .T.
// Notify User that there is a New Article
Tone(500,9)
EndIF
EndIF
Endif
Next
// Build New Article List
For x = 1 To Len(aNew)
If ValType(aNew[x]) = NIL
@ x+1,60 say "-"
ElseIf aNew[x]
@ x+1,60 say "*"
Else
@ x+1,60 say " "
EndIF
Next
// Turn OFF First Run Flag
If lFirstRun
lFirstRun := .F.
EndIF
Return
|