public Service() { Instance = this; this.displayResponder = new DisplayResponder(); this.reader = new ReaderService(); this.settings = Properties.Settings.Default; this.socket = new serviceSocket("127.0.0.1", 2345); this.ConnectViewModel = new ConnectViewModel(this.reader, this.settings); this.MainViewModel = new MainViewModel(this.displayResponder, this.reader.Commander, this.settings, this.socket); }
/// <summary> /// Initializes a new instance of the MainViewModel class /// </summary> /// <param name="displayResponder">Captures all responses from the reader and relays them to the user interface</param> /// <param name="commander">Used to setup the responder chain and execute ASCII commands</param> /// <param name="settings">The display settings</param> public MainViewModel(DisplayResponder displayResponder, IAsciiCommandExecuting commander, IDisplaySettings settings, serviceSocket socket) { InventoryCommand inventoryResponder; BarcodeCommand barcodeResponder; if (displayResponder == null) { throw new ArgumentNullException("displayResponder"); } if (commander == null) { throw new ArgumentNullException("commander"); } if (settings == null) { throw new ArgumentNullException("settings"); } this.socket = socket; this.settings = settings; // Create a display responder to capture and display all reader responses displayResponder.ReceivedLine += delegate(object sender, AsciiLineEventArgs e) { this.OnResponseLine(e.Line.FullLine); }; // setup an asynchronous responder for inventory inventoryResponder = new InventoryCommand(); inventoryResponder.TransponderReceived += this.AsynchronousTransponder_Received; // setup an asynchronous responder for barcodes barcodeResponder = new BarcodeCommand(); barcodeResponder.BarcodeReceived += this.AsynchronousBarcode_Received; // set up the responder chain this.commander = commander; this.commander.ClearResponders(); this.commander.AddResponder(new LoggerResponder()); this.commander.AddResponder(displayResponder); this.commander.AddSynchronousResponder(); this.commander.AddResponder(inventoryResponder.Responder); this.commander.AddResponder(barcodeResponder.Responder); this.synchronousBarcodeCommand = new BarcodeCommand(); this.synchronousBarcodeCommand.BarcodeReceived += this.SynchronousBarcode_Received; this.synchronousInventoryCommand = new InventoryCommand(); this.synchronousInventoryCommand.TransponderReceived += this.SynchronousTransponder_Received; }