Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Threading;
- namespace EventsAndDelegates
- {
- class MessagingService
- {
- public void OnPatcherFinished(object source, PatcherEventArgs e)
- {
- Console.WriteLine("Check to see if your patch was successful? Y or N\n");
- char input = Convert.ToChar(Console.ReadKey().KeyChar);
- Console.WriteLine("\n");
- if (input == 'y' || input == 'Y')
- {
- Console.WriteLine("Checking to see if game is up-to-date...\n");
- Thread.Sleep(3000);
- if (e.UpdateData.IsGameUpToDate == true)
- {
- Console.WriteLine("Game is up to date! Press any key to close!\n");
- Console.ReadLine();
- }
- else
- {
- Console.WriteLine("Game is no up to date. Please re-run the patcher. :(\n");
- Console.ReadLine();
- }
- }
- else
- {
- Console.WriteLine("Game patch was no validated. Goodbye.\n");
- Console.ReadLine();
- }
- }
- }
- public class UpdateData
- {
- public string DataToBeAppendedLocation { get; set; }
- public bool IsGameUpToDate { get; set; }
- }
- }
- public class PatcherEventArgs : EventArgs
- {
- public UpdateData UpdateData { get; set; }
- }
- public class Patcher
- {
- // 1 - Define a delegate { No need, used pre-defined "EventHandler" from System namespace }
- // 2 - Define an event based on that delegate { Line 21 }
- // 3 - Raise that event in a protected, virtual method { Line 36-41 }
- // 4 - Derive a new class from EventArts containing event arguments to be passed { Line 9-12 }
- // 5 - Link event to function to be calling on the event { in Program.cs, Line 17 }
- // 6 - Call the method that raises the event { Line 35 }
- public event EventHandler<PatcherEventArgs> PatcherFinished;
- public void Patch(UpdateData data)
- {
- Console.WriteLine("Patching game files from {0}...", data.DataToBeAppendedLocation);
- Thread.Sleep(3000);
- Console.WriteLine("\nSuccess! Press any key to continue...");
- Console.ReadLine();
- data.IsGameUpToDate = true;
- OnPatcherFinished(data);
- }
- protected virtual void OnPatcherFinished(UpdateData data)
- {
- if (PatcherFinished != null)
- PatcherFinished(this, new PatcherEventArgs() { UpdateData = data });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement