|
Develop any MIS as Hospital Management System, Student Information System etc.
|
|
|
|
|
Thanks all, great answers. Some of you suggested to brush up on my C#, I actually have. I have read all the basics of the C# language, thats why I was looking for some project to get into and apply the principles that I know. Talkingto SQL database is always similar to other languages, no big deal. I didn't want to learn all aspects in details, just do something simple with webservces, WCF..etc to know how it works for the most part.
Someone suggested a hospital or student Information system, I think either one is a good example.
Thanks again
|
|
|
|
|
Hello,
I have been digging on this topic for several days now, and cant seem to get started... Any advice is appreciated.
I have an application that outputs its log files to a txt file. I would like to write an app that can monitor that txt file for a keyword. Once that keyword is written to that log file, my app will send me an email notification.
If that keyword is appended to the log file, and I am successfully notified, I dont want the app to keep notifying me. Just one time per event.
I could do this in linux with tail -f, but am unsure how to complete this task in windows with C#...
I am currently using FileStream/StreamReader to search my text file for the keyword, and that works. But it keeps scanning the entire text file and keeps notifying me. I would just like it to read lines that are "new".
Thanks for any ideas... Would love to get started on this project...
Currently I am using this code found on codeproject forums:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.IO;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
DirectoryInfo dirInf = new DirectoryInfo(@"C:\Program Files\Temp");
FileInfo[] files = dirInf.GetFiles("*.txt");
foreach (FileInfo currentFile in files)
{
FileStream fs = new FileStream(currentFile.FullName, FileMode.Open);
StreamReader reader = new StreamReader(fs);
string fileContent = reader.ReadToEnd();
if (fileContent.Contains("Failed"))
{
MessageBox.Show("The File " + currentFile.FullName +
" Contains the text your searching for");
}
fs.Flush();
reader.Close();
fs.Close();
}
}
}
}
modified 25-Sep-11 15:34pm.
|
|
|
|
|
Hi,
1.
the cleanest approach would be to adapt the producer, which could not be acceptable or doable at all.
2.
the best approach on the consumer side depends on how (and how long) you want to run this. It could either be a utility that runs periodically, or an application that runs all the time and has a big delay (Thread.Sleep) or timer built in. If it is to run independent of a user being logged in, it better be a Windows Service.
3.
You need to remember how long the files were the last time you inspected them, and then only inspect whatever has been added to them. For a periodical utility this requires external storage (maybe an XML file), for a continuous app a mere Dictionary<string fileName, long fileLength> could do.
4.
You are currently reading the entire file; rather than using StreamReader.ReadToEnd , you could have used File.ReadAllText or File.ReadAllLines . However, if the observed app runs for hours or more, the log files could grow into the MB or GB, so that would not be practical. The latter two return the whole file, whereas the former returns anything from the current position to the end, so what you should do is use StreamReader.Position and StreamReader.ReadToEnd .
5.
BTW: there is no need for fs.Flush(); , and this for two reasons: (a) the file is being read, not written, so there is no dirty data anywhere; and (b) it is followed right away by an fs.Close(); , which always takes care of dirty data.
6.
There might be a slight chance that the things you are looking for get straddled over the "old" and the "new" log file (as in the log first ending on "Fai", then "led in some method" being appended); so it would be wise to back up a little when restoring the most recent position.
HTH
|
|
|
|
|
Thanks for the heads up...
This log file is only going to be about 1mb at max. During the day, I keep an eye on the log file. When I leave work for the night, I would like to be notified if the word "Failure" is written to the log. At the end of the week, the job is over and the log will be cleared and start all over on Monday.
|
|
|
|
|
you're welcome.
|
|
|
|
|
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
|
|
|
|
|