//-- UserRequestEventArgs.cs
using System;
namespace EventSample
{
public enum RequestType {AdRequest ,PersonalMessageRequest};
/// <summary>
/// Description of UserRequestEventArgs.
/// </summary>
public class UserRequestEventArgs:EventArgs
{
private RequestType request ;
public UserRequestEventArgs(RequestType request)
:base()
{
this.request = request;
}
public RequestType Request
{
get
{
return request;
}
}
}
}
//-- UserInputMonitor.cs
using System;
namespace EventSample
{
/// <summary>
/// Description of UserInputMonitor.
/// </summary>
public class UserInputMonitor
{
public UserInputMonitor()
{
}
public delegate void UserRequest(object sender, UserRequestEventArgs e);
public event UserRequest OnUserRequest;
public void Run()
{
while(true)
{
Console.WriteLine("select preferred option ");
Console.WriteLine(" request advertisement - hit A then return " );
Console.WriteLine(" request personal message from mortimer ---------" +
" hit P then return " );
Console.WriteLine(" Exit - hit X then return " );
string response = Console.ReadLine();
char responseChar = (response == "")?'-':char.ToUpper(response[0]);
switch(responseChar)
{
case 'A':
OnUserRequest(this,
new UserRequestEventArgs(RequestType.AdRequest));
break;
case 'P':
OnUserRequest(this,
new UserRequestEventArgs(RequestType.PersonalMessageRequest));
break;
case 'X':
return ;
}
}
}
}
}
//--MessageDisplayer.cs
using System;
namespace EventSample
{
/// <summary>
/// Description of Class1.
/// </summary>
public class MessageDisplayer
{
public MessageDisplayer(UserInputMonitor monitor)
{
monitor.OnUserRequest +=
new UserInputMonitor.UserRequest(UserRequestHandler);
}
protected void UserRequestHandler(object sender,UserRequestEventArgs e)
{
switch(e.Request)
{
case RequestType.AdRequest:
Console.WriteLine("Monitor Phone is better than anyone else" +
" because \n all our software is written in C#!\n");
break;
case RequestType.PersonalMessageRequest:
Console.WriteLine("Today Monitor issued the following " +
"statement: \n Nevermore !\n ");
break;
}
}
}
}
//-- ManagersStaffMonitor.cs
using System;
using System.Windows.Forms;
namespace EventSample
{
/// <summary>
/// Description of ManagersStaffMonitor.
/// </summary>
public class ManagersStaffMonitor
{
public ManagersStaffMonitor(UserInputMonitor monitor)
{
monitor.OnUserRequest +=
new UserInputMonitor.UserRequest(UserRequestHandler);
}
protected void UserRequestHandler(object sender , UserRequestEventArgs e)
{
if(e.Request == RequestType.PersonalMessageRequest)
{
MessageBox.Show("Kaak!","Mortimer says ");
}
}
}
}
//-- Main.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace EventSample
{
class MainClass
{
public static void Main(string[] args)
{
UserInputMonitor inputMonitor = new UserInputMonitor();
MessageDisplayer inputProcessor = new MessageDisplayer(inputMonitor);
ManagersStaffMonitor mortimer = new ManagersStaffMonitor(inputMonitor);
inputMonitor.Run();
}
}
}
using System;
namespace EventSample
{
public enum RequestType {AdRequest ,PersonalMessageRequest};
/// <summary>
/// Description of UserRequestEventArgs.
/// </summary>
public class UserRequestEventArgs:EventArgs
{
private RequestType request ;
public UserRequestEventArgs(RequestType request)
:base()
{
this.request = request;
}
public RequestType Request
{
get
{
return request;
}
}
}
}
//-- UserInputMonitor.cs
using System;
namespace EventSample
{
/// <summary>
/// Description of UserInputMonitor.
/// </summary>
public class UserInputMonitor
{
public UserInputMonitor()
{
}
public delegate void UserRequest(object sender, UserRequestEventArgs e);
public event UserRequest OnUserRequest;
public void Run()
{
while(true)
{
Console.WriteLine("select preferred option ");
Console.WriteLine(" request advertisement - hit A then return " );
Console.WriteLine(" request personal message from mortimer ---------" +
" hit P then return " );
Console.WriteLine(" Exit - hit X then return " );
string response = Console.ReadLine();
char responseChar = (response == "")?'-':char.ToUpper(response[0]);
switch(responseChar)
{
case 'A':
OnUserRequest(this,
new UserRequestEventArgs(RequestType.AdRequest));
break;
case 'P':
OnUserRequest(this,
new UserRequestEventArgs(RequestType.PersonalMessageRequest));
break;
case 'X':
return ;
}
}
}
}
}
//--MessageDisplayer.cs
using System;
namespace EventSample
{
/// <summary>
/// Description of Class1.
/// </summary>
public class MessageDisplayer
{
public MessageDisplayer(UserInputMonitor monitor)
{
monitor.OnUserRequest +=
new UserInputMonitor.UserRequest(UserRequestHandler);
}
protected void UserRequestHandler(object sender,UserRequestEventArgs e)
{
switch(e.Request)
{
case RequestType.AdRequest:
Console.WriteLine("Monitor Phone is better than anyone else" +
" because \n all our software is written in C#!\n");
break;
case RequestType.PersonalMessageRequest:
Console.WriteLine("Today Monitor issued the following " +
"statement: \n Nevermore !\n ");
break;
}
}
}
}
//-- ManagersStaffMonitor.cs
using System;
using System.Windows.Forms;
namespace EventSample
{
/// <summary>
/// Description of ManagersStaffMonitor.
/// </summary>
public class ManagersStaffMonitor
{
public ManagersStaffMonitor(UserInputMonitor monitor)
{
monitor.OnUserRequest +=
new UserInputMonitor.UserRequest(UserRequestHandler);
}
protected void UserRequestHandler(object sender , UserRequestEventArgs e)
{
if(e.Request == RequestType.PersonalMessageRequest)
{
MessageBox.Show("Kaak!","Mortimer says ");
}
}
}
}
//-- Main.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;
namespace EventSample
{
class MainClass
{
public static void Main(string[] args)
{
UserInputMonitor inputMonitor = new UserInputMonitor();
MessageDisplayer inputProcessor = new MessageDisplayer(inputMonitor);
ManagersStaffMonitor mortimer = new ManagersStaffMonitor(inputMonitor);
inputMonitor.Run();
}
}
}