Using Using Using Using Using Namespace

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 6

using using using using using

System; System.Collections.Generic; System.Linq; System.Text; System.IO;

namespace MyEventHandler { //Our Business Logic will be in this class //along with this it will have delegate and event + my Attendence Logic public class DelegateEvent { public delegate void AttendenceLogHandler(string message); public event AttendenceLogHandler Eventlog; public void LogProcess() { string Reason = null;

Console.WriteLine("Please Enter Your Employee Id"); string UserName = Console.ReadLine(); DateTime dt = DateTime.Now; int hr = dt.Hour; int min = dt.Minute; if (!((hr >= 1 && hr < 2) || (hr == 2 && min == 0))) { Console.WriteLine("Enter The Reason to Be Late In Office"); Reason = Console.ReadLine(); } if ((hr >= 1 && hr < 2) || (hr == 2 && min == 0)) { OnEventLog("logged In At" + hr.ToString() + " :0 " +

min.ToString() + "." + " You Are With In With In Time"); } else { OnEventLog("logged In At" + hr.ToString() + " :0 " + min.ToString() + "Not With In Time." + "Reason to Be Late Is " + Reason); } } protected void OnEventLog(string message) { if(Eventlog != null) { Eventlog(message); } } } //A class which will take care of writing log

public class AttendenceLogger { FileStream fstream; StreamWriter swriter; public AttendenceLogger(string fileName) { fstream = new FileStream(fileName,FileMode.Append ,FileAccess.Write); swriter = new StreamWriter(fstream); } public void Logger(string logInfo) { swriter.WriteLine(logInfo); swriter.Flush(); } public void Close() { swriter.Close(); fstream.Close(); } }

//My Subscriber class public class RecordAttendenceLog { static void Logger(string lofInfo) { Console.WriteLine(lofInfo); } public static void Main(String[] args) { AttendenceLogger fileLogObj = new AttendenceLogger(@"c:\MyWrittenFile "); DelegateEvent delEventObj = new DelegateEvent(); delEventObj.Eventlog += new DelegateEvent.AttendenceLogHandler( Logger); delEventObj.Eventlog += new

DelegateEvent.AttendenceLogHandler( fileLogObj.Logger); delEventObj.LogProcess(); Console.ReadLine(); } } }

You might also like