private TerminatorDataModel Validate(TerminatorDataModel data, string display, List <TerminatorInfo> infos) { Assert.AreEqual(display, data.Display); Assert.AreEqual(infos.Count, data.TerminatorInfos.Count, "Terminator infos"); Assert.AreEqual(infos.Count, data.TerminatorBlock.Length, "Terminator block"); for (int i = 0; i < infos.Count; i++) { Assert.AreEqual(infos[i].Code, data.TerminatorInfos[i].Code); Assert.AreEqual(infos[i].Description, data.TerminatorInfos[i].Description); Assert.AreEqual(infos[i].Display, data.TerminatorInfos[i].Display); Assert.AreEqual(infos[i].HexDisplay, data.TerminatorInfos[i].HexDisplay); Assert.AreEqual(infos[i].Value, data.TerminatorInfos[i].Value); } return(data); }
private void TEditor_OnSave(object sender, TerminatorDataModel data) { if (this.index == null) { data.Display = this.txtBoxDisplay.Text; this.wrapper.CreateNewTerminator( this.txtBoxDisplay.Text, data, this.OnSaveOk, this.OnSaveFailed); } else { this.index.Display = this.txtBoxDisplay.Text; data.Display = this.index.Display; this.wrapper.SaveTerminator(this.index, data, this.OnSaveOk, this.OnSaveFailed); } }
/// <summary>Assure at least one terminator in case settings file erased</summary> /// <param name="dm"></param> /// <returns></returns> private TerminatorDataModel AssureTerminators(TerminatorDataModel dm) { if (string.IsNullOrWhiteSpace(dm.Display)) { dm.Display = "TMP terminators"; } if (dm.TerminatorInfos.Count == 0) { List <TerminatorInfo> infos = new List <TerminatorInfo>(); infos.Add(new TerminatorInfo(Terminator.LF)); infos.Add(new TerminatorInfo(Terminator.CR)); dm.Init(infos); } return(dm); }
private void SetupData(uint count) { try { //this.Subscribe(); for (uint i = 0; i < count; i++) { TerminatorDataModel dm = this.CreateTerminatorDm(string.Format("Terminators {0}", i), 5); TDI.Wrapper.CreateNewTerminator(dm.Display, dm, this.OnSuccessDummy, this.AssertErr); this.AssertCompleteFired(); //this.AssertChanged(); } } finally { //this.Unsubscribe(); } }
public void CreateDefaultTerminators(Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 2000306, "Failure on CreateDefaultTerminators", () => { List <TerminatorInfo> infos = new List <TerminatorInfo>(); infos.Add(new TerminatorInfo(Terminator.LF)); infos.Add(new TerminatorInfo(Terminator.CR)); TerminatorDataModel dm = new TerminatorDataModel(infos) { Display = string.Format("{0} \\n\\r", this.GetText(MsgCode.Default)), }; this.Create(dm.Display, dm, this.terminatorStorage, (ndx) => onSuccess(), onError); }); this.RaiseIfException(report); }
public void CreateArduinoTerminators(Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 2000305, "Failure on CreateArduinoTerminators", () => { List <TerminatorInfo> infos = new List <TerminatorInfo>(); infos.Add(new TerminatorInfo(Terminator.CR)); infos.Add(new TerminatorInfo(Terminator.LF)); TerminatorDataModel dm = new TerminatorDataModel(infos) { Display = "Arduino \\r\\n" }; this.Create(dm.Display, dm, this.terminatorStorage, (ndx) => onSuccess(), onError); }); this.RaiseIfException(report); }
private void PopulateTerminators(TerminatorDataModel data) { this.lbTerminatorsName.Text = data.Name; this.lbTerminatorsText.Text = ""; StringBuilder tmp = new StringBuilder(); for (int i = 0; i < data.TerminatorInfos.Count; i++) { if (i > 0) { tmp.Append(","); } tmp.Append(data.TerminatorInfos[i].Display); } this.lbTerminatorsText.Text = tmp.ToString(); }
public void SetCurrentTerminators(TerminatorDataModel data, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 2000302, "Failure on SetCurrentTerminators", () => { this.GetSettings((settings) => { settings.CurrentTerminator = data; this.SaveSettings(settings, () => { if (this.CurrentTerminatorChanged != null) { this.CurrentTerminatorChanged(this, data); } }, onError); }, onError); }); this.RaiseIfException(report); }
public void SetCurrentTerminators(TerminatorDataModel data, CommMedium medium, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 2000301, "Failure on SetCurrentTerminators", () => { this.GetSettings((settings) => { EventHandler <TerminatorDataModel> ev = null; switch (medium) { case CommMedium.Bluetooth: settings.CurrentTerminatorBT = data; ev = this.CurrentTerminatorChangedBT; break; case CommMedium.BluetoothLE: settings.CurrentTerminatorBLE = data; ev = this.CurrentTerminatorChangedBLE; break; case CommMedium.Ethernet: settings.CurrentTerminatorEthernet = data; ev = this.CurrentTerminatorChangedEthernet; break; case CommMedium.Usb: settings.CurrentTerminatorUSB = data; ev = this.CurrentTerminatorChangedUSB; break; case CommMedium.Wifi: settings.CurrentTerminatorWIFI = data; ev = this.CurrentTerminatorChangedWIFI; break; default: settings.CurrentTerminator = data; ev = this.CurrentTerminatorChanged; break; } this.SaveSettings(settings, () => { ev?.Invoke(this, data); }, onError); }, onError); }); this.RaiseIfException(report); }
private TerminatorDataModel RetrieveAndValidate( IIndexItem <DefaultFileExtraInfo> index, string display, List <TerminatorInfo> infos) { TerminatorDataModel data = this.RetrieveData(index); Assert.AreEqual(display, data.Display); Assert.AreEqual(infos.Count, data.TerminatorInfos.Count, "Terminator infos"); Assert.AreEqual(infos.Count, data.TerminatorBlock.Length, "Terminator block"); for (int i = 0; i < infos.Count; i++) { Assert.AreEqual(infos[i].Code, data.TerminatorInfos[i].Code); Assert.AreEqual(infos[i].Description, data.TerminatorInfos[i].Description); Assert.AreEqual(infos[i].Display, data.TerminatorInfos[i].Display); Assert.AreEqual(infos[i].HexDisplay, data.TerminatorInfos[i].HexDisplay); Assert.AreEqual(infos[i].Value, data.TerminatorInfos[i].Value); } return(data); }
public void InitialiseEditor(Window parent, TerminatorDataModel dataModel) { this.parent = parent; this.objUID = dataModel.UId; this.ResetAllBoxes(); // Make a copy to not mess up the original in case you do not save List <TerminatorInfo> infos = new List <TerminatorInfo>(); foreach (var i in dataModel.TerminatorInfos) { infos.Add(new TerminatorInfo(i.Code)); } foreach (TerminatorInfo info in infos) { this.AddTerminator(info); } }
/// <summary> /// If no terminators defined, create default, store and set as default in settings /// </summary> private void AssureTerminatorsDefault(IIndexedStorageManager <TerminatorDataModel, DefaultFileExtraInfo> data) { // If nothing exists create default List <IIndexItem <DefaultFileExtraInfo> > index = data.IndexedItems; if (index.Count == 0) { // For a new one. Different when updating. Do not need to create new index List <TerminatorInfo> infos = new List <TerminatorInfo>(); infos.Add(new TerminatorInfo(Terminator.LF)); infos.Add(new TerminatorInfo(Terminator.CR)); TerminatorDataModel dm = new TerminatorDataModel(infos) { Display = "Demo terminator set \\n\\r" }; IIndexItem <DefaultFileExtraInfo> idx = new IndexItem <DefaultFileExtraInfo>(dm.UId) { Display = dm.Display }; data.Store(dm, idx); this.GetSettings( (settings) => { settings.CurrentTerminator = dm; settings.CurrentTerminatorBLE = dm; settings.CurrentTerminatorBT = dm; settings.CurrentTerminatorEthernet = dm; settings.CurrentTerminatorUSB = dm; settings.CurrentTerminatorWIFI = dm; this.SaveSettings(settings, () => { }, (err) => { }); }, (err) => { }); this.CreateArduinoTerminators(() => { }, (err) => { }); } else { // back compatible to add the display name into the data object this.BackCompatibilityInitializeExistingTerminatorNames(); } }
private void Subscribe() { this.changed = null; TDI.Wrapper.CurrentTerminatorChanged += changedOther; // TODO - look at the BT, BLE, etc terminator changes }
private void CurrentTerminatorChangedHandler(object sender, TerminatorDataModel e) { this.PopulateTerminators(e); }
public void CreateNewTerminator(string display, TerminatorDataModel data, Action onSuccess, OnErr onError) { this.Create(display, data, this.terminatorStorage, (idx) => onSuccess(), (obj) => {}, onError); }
private void GetTerminatorsOk(TerminatorDataModel data) { this.terminatorView.Initialise(data); }
private void Wrapper_CurrentTerminatorChanged(object sender, TerminatorDataModel data) { this.terminatorView.Initialise(data); }
public void CreateNewTerminator(string display, TerminatorDataModel data, Action <IIndexItem <DefaultFileExtraInfo> > onSuccess, OnErr onError) { this.Create(display, data, this.terminatorStorage, onSuccess, onError); }
public void SaveTerminator(IIndexItem <DefaultFileExtraInfo> idx, TerminatorDataModel data, Action onSuccess, OnErr onError) { this.Save(this.terminatorStorage, idx, data, (dm, index) => { }, onSuccess, onError); }
private void currentTerminatorChangedHandler(object sender, TerminatorDataModel terminators) { this.SetTerminators(terminators); }
private void AssertChanged() { Assert.NotNull(this.changed, "Did not receive terminator changed event"); this.changed = null; }
private void OnCurrentTerminatorChanged(object sender, TerminatorDataModel e) { Xamarin.Forms.Device.BeginInvokeOnMainThread(() => { TerminatorsUpdated?.Invoke(this, e); }); }
private void OnInitOk(TerminatorDataModel dataModel) { this.txtBoxDisplay.Text = index.Display; dataModel.Display = index.Display; this.tEditor.InitialiseEditor(parent, dataModel); }
private void changedOther(object sender, TerminatorDataModel e) { this.changed = e; }