Solved

read contents of file and return boolean

Posted on 2007-04-09
11
185 Views
Last Modified: 2013-11-26
i  have a log file that is created with the following syntax

{
-name "Adidas Blend"
-start -cron 30 9 * * 7
-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -pwd CUR_DIR
-action -print "Current directory is %CUR_DIR%"
-action -cd "D:\DMS_Live\ADS_Blend"
-action -pwd CUR_DIR
-action -print "After CD, current directory is %CUR_DIR%"
-action -spawn "ADS_Blend.exe"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"
}

Each day this file adds a new line.  I need to be able to right some vb.net code that opens the file and checks to see that the two lines are created each day.  maybe it wiill return a boolean value.
0
Comment
Question by:Robb Hill
  • 6
  • 5
11 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878082
A boolean value with respect to what?...
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18878139
the program should open the file...verify the last two lines are there ....if they are both there..then return true..else return false.  These two lines are appended to the file everytime the job runs.  Im trying to create an alert when this file is missing these two lines on a given day.

-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878261
Ok...do those two lines have anything to indicate WHEN they were added?

Does "%c%" get replaced by something in the actual file or is that literally what is there?

Or do I have it all wrong?

Is the file recreated each day with the stuff you originally posted and then the two lines from your last post are added at some point?
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
LVL 11

Author Comment

by:Robb Hill
ID: 18878336
each day a process runs.  This scheduler program called wincron runs the exe files....
This program appends to a log file.  The %c% will put a date at the end of the log.

And yes, the file created each day is an append of the original file.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878810
"The %c% will put a date at the end of the log."

In what format will the date be so we can check against the current date?
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18881804
12/21/03 11:37:54
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18890555
This is what I have so far.  I wish there was a way so that my date test was always the current Saturday of the month.

'Open a file for reading
        Dim FILENAME As String = "c:/Scheduler.log"
        Dim looptest As Boolean = True

        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        Dim contents As String = objStreamReader.ReadToEnd()

        Dim a() As String = Split(contents, vbCrLf)
        Dim now As DateTime = DateTime.Now.ToShortDateString
        For i As Integer = 0 To a.Length - 1

            Dim strArray() As String = a(i).Split("-")
            strArray(1) = LTrim(strArray(1))
            Dim strDate() As String = strArray(1).Split(" ")

            If strDate(0) = now Then
                looptest = True
                Exit Sub
            Else
                looptest = False
            End If
        Next
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18891917
How about something like?...

(This is the .Net Framework 2.0 TA so I assume you are using VB.Net 2005)

    Private Function FileUpdated() As Boolean
        Dim fileName As String = "c:\Scheduler.log"
        Dim contents As String = My.Computer.FileSystem.ReadAllText(fileName)
        Dim lines() As String = contents.Replace(vbCrLf, vbCr).TrimEnd(vbCr).Split(vbCr)
        Dim curSaturday As Date = DateTime.Today.AddDays(DayOfWeek.Saturday - DateTime.Today.DayOfWeek)
        Dim lastLine As String = lines(lines.GetUpperBound(0))
        If lastLine.IndexOf("ADS Blend Task End Time") <> -1 Then
            Dim lastDash As Integer = lastLine.LastIndexOf("-")
            Dim strDateTime As String = lastLine.Substring(lastDash + 1).Trim
            Dim lastDateTime As DateTime
            If DateTime.TryParse(strDateTime, lastDateTime) Then
                Dim lastDate As Date = lastDateTime.Date
                If lastDate.CompareTo(curSaturday) = 0 Then
                    Return True
                End If
            End If
        End If
        Return False
    End Function
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892111
I really like your use of my...im still trying to learn all the advantages of some of the new 2.0 stuff.
Do you have any recomendations.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18892133
Don't have any recommendations sorry...I'm still learning them myself!  =)
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892151
Well thanks again.  
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question