|
Good answer. I was going to mention the storage of the last location (or the end of the last complete line, most likely, for a log file, another way of saying your 6) and just reading from there.
|
|
|
|
|
Here's an idea:
1. in your monitoring class keep a class-instance-scoped (or static ?) variable that maintains the index in the log file where the last instance of 'failed' was seen.
public int lastFailIndex;
2. on notification:
a. read in the file, as you do now
1. get the index of the last instance of the string 'failed'
int currentFailIndex = fileContent.LastIndexOf("failed");
2. compare to stored Index
if(currentFailIndex > lastFailIndex)
{
lastFailIndex = currentFailIndex;
}
2. another simple remedy to see if the file has changed at all would be to store the length of the string created by ReadToEnd, and compare each time to see if the file has become larger: of course, you may know the log file, inherently, will be larger each time you open it, in which case: forget about that.
But, it's more interesting to think a little "out of the box" here:
1. if your log-file is delineated by lines (carriage returns and/or linefeeds) you could use File.ReadAllLine(/filepath/) to return an array of strings, and then work backwards from the end of that array to see if you have a new instance of a "failed."
In this case the 'Count property of the string array could be preserved to test for file change ?
For discussions on other (more elaborate) techniques to read a file from the end, and even a code example from Master Jon Skeet himself, check out[^].
best, Bill
"Beauty is in the eye of the beholder, and it may be necessary from time to time to give a stupid or misinformed beholder a black eye." Miss Piggy"
|
|
|
|
|
On a previous job, I had to do something similar with a log file created by a third-party product (but storing the data in a database). I wrote a Windows Service that did it.
When the Service cycled, it read the last Position from the database, opened the file, set the Position and continued reading. I had to be sure that only complete lines were processed, so I read one character at a time and considered a line to begin with a linefeed and end with a carriagereturn. Upon reading the carriage return, the line would be processed and the Position stored in the database. If the end of the file was reached, the cycle stopped. Processing over midnight was a little problematic because the previous day's file (which might not have been completely processed yet) was renamed and a new log started.
|
|
|
|
|
In the last few days I decided to create a new dictionary application, I searched the internet for how to implement database files and search algorithms but I found nothing
If you have any idea about how dictionaries are created and how a its database files are structured, please help !!
<b>Note: I don't want to use DMS (data base management system) like MS SQL server or MySql, I just want to use text files or custom format file</b>
|
|
|
|
|
A regular dictionary with words and meanings? Or a spell-check dictionary (no meanings)?
Back in college (late 80s), one of the assignments was to implement a spell-check dictionary. For that, the words were stored in a text file, but read into a special structure. I suppose it could be extended to include a meaning too.
Either way, today I'd just stick with a database. In fact a few years back I wrote a simple Scrabble word checker application -- currently it uses an Access database.
|
|
|
|
|
Check out the following links:
http://www.dotnetperls.com/dictionary
http://www.dotnetperls.com/word-search
|
|
|
|
|
Please make your links into clickable links.
|
|
|
|
|
Thanks it helped
|
|
|
|
|
You already posted this in Q&A; please post in one location only.
|
|
|
|
|
thank you, but can you help?
|
|
|
|
|
Hi, I am working on a C# project in visual studio 2010. I have finished the project and now working on its setup project. I created a setup project and another Installer class project. In custom actions of my setup project I use my Installer class to add a login user to the database. However after coppied the project files to the target machine, when my installer class needs to work en error occurs. It says unable to get installer types in InstallHelper.dll assembly which is created by me. I could not understand why it is happening. One important thing is that, It does not occur on my machine maybe it is because i devolopped the project in my machine and it is windows 7 professional. However in other machines always this error occurs. For example, I tried it in Windows Vista, Windows 7 Professional (32-bit) and also (64-bit) always this error occurs. Can anyone help me in this issue ? What should I do ? Please it is a bit urgent.
|
|
|
|
|
Hi,
As a try you can add the installerclass files with setup project and then publish it.
It's an idea..
Thanks
|
|
|
|
|
Actually I have solved it but in a different way. The problem was a class library project. The output of it is a *.dll file and installer could not find that file. In that installer class I called a windows form to enable to add user while setup. However, when dll file could not find, then instead of it I tried to add an *.exe output as my Installer class. So, instead of class library project I have added a windows form project to my setup project. Since its output is .exe file, then it works great. Now my setup works correctly. If anyone encountered this problem may try to replace class library project with windows form project. It is a lazy solution for my situation. But, still I am wondering what the actual reason to this problem is.
|
|
|
|
|
facing same problem . i will try your solution
|
|
|
|
|
Hi I have a little problem with c # code. I wonder if you can help me because I have tried to solve this problem for several days. I get the error: "No overload for method 'ReserveOrCancelSeat' takes '0 'arguments
Here is the code:
private void ReserveOrCancelSeat(SeatManager.DisplayOptions choice)
{
if (CheckSelectedIndex() == false)
{
MessageBox.Show("a seat must be selected", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
// Is reserve selected
if (rbtnReserve.Checked == true)
{
// Validate data
string name = null;
double price = 0.0;
if (ReadAndValidateInput(out name, out price) == true)
{
// Data is ok, reserve seat
if (!m_seatMngr.ReserveSeat(name, price, lbSeats.SelectedIndex))
{
// The seat was already reserved, ask user if we should continue with reservation
if (MessageBox.Show("The seat is already reserved, continue with reservation?", "Seat already reserved", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// We continue. First cancel seat.
if (!m_seatMngr.CancelSeat(lbSeats.SelectedIndex))
{
// This should not happen, throw exception
throw new Exception("The seat could not be canceled.");
}
// Then we reserve it
if (!m_seatMngr.ReserveSeat(name, price, lbSeats.SelectedIndex))
{
// This should not happen, throw exception
throw new Exception("The seat could not be reserved.");
}
}
}
}
}
}
private void btnOK_Click(object sender, EventArgs e)
{
ReserveOrCancelSeat(); // here comes the error message
}
|
|
|
|
|
you have no choice.
|
|
|
|
|
Yes but it says " The name 'choice' does not exist in the current context
|
|
|
|
|
Funniest thing I've seen on this site for a while. Thanks for the laugh!
It’s not because things are difficult that we do not dare, it’s because we do not dare that things are difficult. ~Seneca
|
|
|
|
|
You have implemented the function ReserveOrCancelSeat to accept one parameter SeatManager.DisplayOptions choice . This means that when you call the function you should supply the needed parameter. Have a look at this tutorial: Functions - C# Tutorial[^].
In your implementation of the ReserveOrCancelSeat function the parameter SeatManager.DisplayOptions choice is not used. So removing the parameter would solve your problem, but you first might want to look into why you are not using it.
Good luck.
0100000101101110011001000111001011101001
|
|
|
|
|
ReserveOrCancelSeat(SeatManager.DisplayOptions choice); gives me 3 errors
1. ) expected
2. ; expected
3. Invalid expression term ')'
|
|
|
|
|
Did you change
private void btnOK_Click(object sender, EventArgs e)
{
ReserveOrCancelSeat();
}
into
private void btnOK_Click(object sender, EventArgs e)
{
ReserveOrCancelSeat(SeatManager.DisplayOptions choice);
} because that is not going to work.
Did you read the tutorial[^]. You really need to understand how functions work.
0100000101101110011001000111001011101001
|
|
|
|
|
Yes i changed it into ReserveOrCancelSeat(SeatManager.DisplayOptions choice);
So whats the solution i have been trying to figure it out for long time. im a beginner
|
|
|
|
|
Reverse the changes you made.
Then change your function implementation from
private void ReserveOrCancelSeat(SeatManager.DisplayOptions choice) into
private void ReserveOrCancelSeat()
If you want to improve your knowledge of functions read the tutorial[^].
0100000101101110011001000111001011101001
|
|
|
|
|
you have to provide us with the members of the SeatManager.DisplayOptions enum to help you choose one of them as a parameter to you function
as example if your SeatManager.DisplayOptionsenum is
<pre lang="C#">
enum SeatManager.DisplayOptionsenum
{
choice1
choice2
choice3
choice4
}
</pre>
you can call your function like this
<pre lang="C#">
private void btnOK_Click(object sender, EventArgs e)
{
ReserveOrCancelSeat( SeatManager.DisplayOptionsenum.choice1); // here comes the error message
}
</pre>
|
|
|
|
|
Thank you that helpt alot!
|
|
|
|