/// <summary> /// Default ctor /// </summary> public LocoNet(LocoBuffer lb, LocoNetConfiguration configuration) { this.lb = lb; this.configuration = configuration; state = new LocoNetState(lb); unknownLocoIoDetector = new UnknownLocoIODetector(this); }
/// <summary> /// Try to load an item from the given element into the given configuration. /// </summary> /// <returns>True on success, false otherwise. When false, subsequent loaders are called.</returns> public override bool TryLoad(XElement element, LocoNetConfiguration configuration) { if (element.Name.LocalName != ElementName) { return(false); } var config = new LocoIOConfig(element); return(true); }
/// <summary> /// Open a configuration from the given path. /// </summary> internal void OpenConfiguration(string path) { try { // Open var tmp = LocoNetConfiguration.Load(path); // Can we close? if (SaveConfigurationIfDirty()) { Setup(null, tmp); UserPreferences.Preferences.LocoNetConfigurationPath = path; UserPreferences.SaveNow(); PathChanged.Fire(this); } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
/// <summary> /// Pass the given locobuffer on to all components. /// </summary> internal void Setup(LocoBuffer lb, LocoNetConfiguration configuration) { // Allow for null arguments lb = lb ?? ConfiguredLocoBuffer; configuration = configuration ?? Configuration; if ((ConfiguredLocoBuffer != lb) || (Configuration != configuration)) { CloseLocoBuffer(); locoNet = new LocoNet(lb, configuration); asyncLb = new AsyncLocoBuffer(ui, lb); lb.SendMessage += LbForwardSendMessage; lb.PreviewMessage += LbForwardPreviewMessage; var lnState = locoNet.State; lnState.StateChanged += LnStateStateChanged; lnState.LocoIOQuery += LnStateLocoIoQuery; lnState.LocoIOFound += LnStateLocoIoFound; lnState.Idle += LnStateIdle; LocoNetChanged.Fire(this); } }