Solved

read contents of file and return boolean

Posted on 2007-04-09
11
191 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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

Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

756 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