static void Main(string[] args) { // This needs an explicit type IDataSource dataSource = new FileDataSource("somefile.dat"); dataSource.WriteData("Hello, world!"); dataSource = new EncryptionDecorator(dataSource); dataSource.WriteData("Something confidential."); dataSource = new CompressionDecorator(dataSource); dataSource.WriteData("Something need to be compressed."); }
public void DumbUsageExample() { IDataSource source = new FileDataSource("somefile.data"); source.WriteData(); // The target file has been written with plain data. source = new CompressionDecorator(source); source.WriteData(); // The target file has been written with compressed data. source = new EncryptionDecorator(source); source.WriteData(); // The target file has been written with encrypted data. }
static void Main(string[] args) { List <object> commandParameters = new List <object>(); commandParameters.Add(1); commandParameters.Add(2); Command command = new Command(commandParameters); Flux flux = new Flux(); CompressionDecorator compressedFlux = new CompressionDecorator(flux); EncryptionDecorator encryptedCompressedFlux = new EncryptionDecorator(compressedFlux); encryptedCompressedFlux.WriteData(Command.Serialize(command)); List <object> parameters = new List <object>(); parameters.Add("localhost"); parameters.Add(8888); flux = new WebSocketSender().Send(flux, parameters); Console.WriteLine("Command result : " + BitConverter.ToInt32(flux.ReadData(), 0)); Console.Write("Type any key to end the program"); Console.ReadLine(); }