/// <summary> /// Set up to handle change events from the Strut and Cooler pickers. /// /// Would like to do this in the constructor, but the pickers need a reference to this object so they /// can get their Materials and Coolers lists. Since they need that reference, they cannot be constructed /// until after this object is constructed. Therefore this routine starts everything going. /// </summary> /// <param name="strutPicker"></param> /// <param name="coolerPicker"></param> public void SetControllers(StrutPicker strutPicker, CoolerPicker coolerPicker) { // Set initial cooler and strut choices into the simulator Strut strut = strutPicker.Strut; Cooler cooler = coolerPicker.Cooler; webServiceAdapter.SetStrut(strut.Material.Name, strut.Length, strut.CrossSectionalArea); webServiceAdapter.SetCooler(cooler.Name, coolerPicker.PowerFactor); // Run the simulator for the first time simulate(); // Set up to handle change events from the controllers strutPicker.RaiseStrutChangedEvent += new EventHandler(handle_StrutChangedEvent); coolerPicker.RaiseCoolerChangedEvent += new EventHandler(handle_CoolerChangedEvent); }
/// <summary> /// Constructor /// </summary> public MainForm() { InitializeComponent(); // Connect to the CoolIt web service coolItWebService = connect(); if (coolItWebService == null) { return; } login(); // Create a local simulator stub and connect it to the Web Service. // From now on we treat this as though it were the whole simulator. The fact that it // calls a Web Service to do its work is transparent from here on. simulator = new SimulatorStub(coolItWebService); // Subscribe to Simulation Changed events so we can update our temp monitor, cost monitor, ... simulator.SimulationChangedEvent += new EventHandler(handle_SimulationChangedEvent); // Create the cooler and strut pickers and tell the simulator about them so it can subscribe to // their change events. strutPicker = new StrutPicker(simulator); coolerPicker = new CoolerPicker(simulator); challengePicker = new ChallengePicker(simulator); simulator.SetControllers(strutPicker, coolerPicker); string title = string.Format("CoolIt Desktop Client - Version {0}.{1}", coolItWebService.DesktopClientVersion.Major, coolItWebService.DesktopClientVersion.Minor); this.Text = title; bankBalanceTextBox.Text = bankBalance.ToString("C"); mathGates = coolItWebService.GetMathGates(); pickChallenge(); }