This repository contains a solution which serves as an example for publisher-subscriber pattern in C#.
Program.cs
serves as the entry point of the solution.
Secret operation is a program in which messages which are tagged to different departments like finance, defence, internal security are
encrypted and send to the listeners. There are listeners who listens to particular topic or all topics. Here the publisher is the
MessageEncryptor.cs
class which encrypts and notifies the subscirbers after the message gets encrypted. The encrypted message is read
by the subscribers and displayed.
For keeping the program simple, the subscribers display the encrypted message as it is and there is no decryption method.
The encryption method used is very simple as the main objective of program is not about the encryption. Encryption method is called as
Ceasor Cipher With Key
where the letters in the message is replaced with letter which comes after N shifts in ASCII table where N is thekey
The input is read from file which is kept under
Resources
folder. Each file type is named accordingly. In theMessage.cs
class invocation of correct type takes place. Again this hard coded approach is taken to attain simplicity of program and to concentrate on pattern demo.
'Program.cs' will first instantiate the message with its type, which can be any one from Defence, finance or internal security. After that encrytption technique is chosen (here its a dummy technique) and instantiate MessageEncryptor
using that. After that different type of subscriber will subscribe to the message with topics they are interested about. There is a general listener which is interested in all the message irrespective of its type.
After the encryption subscribers are notified with encrypted message which will be printed in the console.