private void Create <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, string display, TSToreObject data, Action <IIndexItem <TExtraInfo> > onSuccess, Action <TSToreObject> onChange, OnErr onError, TExtraInfo extraInfo = null) where TSToreObject : class, IDisplayable, IIndexible where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (display.Length == 0) { onError.Invoke(this.GetText(MsgCode.EmptyName)); } else { IIndexItem <TExtraInfo> idx = (extraInfo == null) ? new IndexItem <TExtraInfo>(data.UId) : new IndexItem <TExtraInfo>(data.UId, extraInfo); idx.Display = display; this.Save(manager, idx, data, (obj, idx) => { }, () => onSuccess(idx), onChange, onError); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }); }
public void ValidateScriptItem(ScriptItem item, Action onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (string.IsNullOrWhiteSpace(item.Display)) { onError.Invoke(this.GetText(MsgCode.EmptyName)); } else if (string.IsNullOrWhiteSpace(item.Command)) { onError.Invoke( string.Format("{0} ({1})", this.GetText(MsgCode.EmptyParameter), this.GetText(MsgCode.command))); } else { onSuccess.Invoke(); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }); }
public void DeleteTerminatorData(IIndexItem <DefaultFileExtraInfo> index, Action <bool> onComplete, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.DeleteFromStorageNotLast(this.terminatorStorage, index, (tf) => { this.GetCurrentTerminator( (data) => { if (data.UId == index.UId_Object) { this.RetrieveTerminatorData( this.terminatorStorage.IndexedItems[0], (newData) => { // TODO error handling if we fail to set current // TODO what if it is current for the BT,WIFI,USB,Ethernet this.SetCurrentTerminators(newData, (err) => { }); }, // TODO error handling if we fail to retrieve current terminator (err) => { }); } }, (err) => { }); onComplete(tf); }, onError); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void DeleteFromStorageNotLast <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, IIndexItem <TExtraInfo> indexItem, string msg, Func <string, bool> areYouSure, Action <bool> onComplete, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (indexItem == null) { onError(this.GetText(MsgCode.NothingSelected)); } else if (manager.IndexedItems.Count < 2) { onError(this.GetText(MsgCode.CannotDeleteLast)); } else { if (areYouSure(msg)) { bool ok = manager.DeleteFile(indexItem); onComplete(ok); } } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.DeleteFailure)); } }); }
private void SaveOrCreate <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, string display, TSToreObject data, Action <TSToreObject, IIndexItem <TExtraInfo> > preSaveIndexUpdate, Action <IIndexItem <TExtraInfo> > onSuccess, Action <TSToreObject> onChange, OnErr onError, TExtraInfo extraInfo = null) where TSToreObject : class, IDisplayable, IIndexible where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.RetrievelIndexedItem(manager, data, (idx) => { // Found. Save this.Save(manager, idx, data, preSaveIndexUpdate, () => onSuccess(idx), onChange, onError); }, () => { // Not found. Create this.Create(manager, display, data, onSuccess, onChange, onError, extraInfo); }, onError); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); }
public void RetrieveCodeFile(CodeSelectDisplayDataModel dataModel, Action <string> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (dataModel == null) { onError(this.GetText(MsgCode.NothingSelected)); } else { string filename = this.CodeFileName(dataModel.Code); if (File.Exists(filename)) { onSuccess.Invoke(File.ReadAllText(filename)); } else { onError.Invoke(this.GetText(MsgCode.NotFound)); } } }); if (report.Code != 0) { WrapErr.SafeAction(() => onError(report.Msg)); } }); }
private void Delete <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, IIndexItem <TExtraInfo> indexItem, Action onSuccess, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (indexItem == null) { onError(this.GetText(MsgCode.NothingSelected)); } else { if (manager.DeleteFile(indexItem)) { onSuccess(); } else { onError(this.GetText(MsgCode.DeleteFailure)); } } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.DeleteFailure)); } }); }
private void Delete <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, IIndexItem <TExtraInfo> indexItem, string title, string msg, Func <string, string, bool> areYouSure, Action onComplete, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (indexItem == null) { onError(this.GetText(MsgCode.NothingSelected)); } else { if (areYouSure(title, msg)) { this.Delete(manager, indexItem, onComplete, onError); } } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.DeleteFailure)); } }); }
private void Delete <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, TSToreObject data, Func <string, bool> areYouSure, Action <bool> onComplete, OnErr onError) where TSToreObject : class, IDisplayable, IIndexible where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.RetrievelIndexedItem(manager, data, (ndx) => { if (areYouSure(data.Display)) { bool ok = manager.DeleteFile(ndx); onComplete(ok); } }, onError); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.DeleteFailure)); } }); }
public void ValidateBLECmdItem(BLE_DataType dataType, ScriptItem item, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (item.Display.Length > 0) { this.ValidateBLEValue(dataType, item.Command, onSuccess, onError); } else { onError.Invoke(this.GetText(MsgCode.EmptyName)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }
public void SaveSettings(SettingItems settings, Action onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (this.settings.WriteObjectToDefaultFile(settings)) { onSuccess.Invoke(); } else { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); }
public void DeleteWifiCredData(IIndexItem <DefaultFileExtraInfo> index, Action <bool> onComplete, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (index == null) { onError.Invoke(this.GetText(MsgCode.NothingSelected)); } else { bool ok = this.wifiCredStorage.DeleteFile(index); onComplete(ok); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void RetrieveItem <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, IIndexItem <TExtraInfo> index, Action <TSToreObject> onSuccess, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (index == null) { onError(this.GetText(MsgCode.NothingSelected)); } else { if (manager.FileExists(index)) { TSToreObject item = manager.Retrieve(index); if (item != null) { onSuccess.Invoke(item); } else { onError.Invoke(this.GetText(MsgCode.NotFound)); } } else { onError.Invoke(this.GetText(MsgCode.NotFound)); } } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
public void GetCurrentScript(CommMedium medium, Action <ScriptDataModel> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { // Force default creation var x = this.scriptStorage; SettingItems items = this.settings.ReadObjectFromDefaultFile(); ScriptDataModel dm = null; switch (medium) { case CommMedium.Bluetooth: dm = items.CurrentScriptBT; break; case CommMedium.BluetoothLE: dm = items.CurrentScriptBLE; break; case CommMedium.Ethernet: dm = items.CurrentScriptEthernet; break; case CommMedium.Usb: dm = items.CurrentScriptUSB; break; case CommMedium.Wifi: dm = items.CurrentScriptWIFI; break; default: dm = items.CurrentScript; break; } if (dm == null) { if (items.CurrentScript == null) { items.CurrentScript = this.AssureScript(new ScriptDataModel()); } dm = items.CurrentScript; } onSuccess(dm); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
public void GetSettings(Action <SettingItems> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess.Invoke(this.settings.ReadObjectFromDefaultFile()); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void DeleteAllFilesFromStorage <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, Action onSuccess, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (manager.DeleteAllFiles()) { onSuccess.Invoke(); } else { onError.Invoke(this.GetText(MsgCode.DeleteFailure)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }); }
public void GetTerminatorEntitiesList(Action <List <TerminatorInfo> > onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess.Invoke(this.terminatorEntityFactory.Items); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
// TODO - need a private function for internal use during connections public void GetWifiCredList(Action <List <IIndexItem <DefaultFileExtraInfo> > > onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess.Invoke(this.wifiCredStorage.IndexedItems); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void Save <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, IIndexItem <TExtraInfo> idx, TSToreObject data, Action <TSToreObject, IIndexItem <TExtraInfo> > preSaveIndexUpdate, Action onSuccess, Action <TSToreObject> onChange, OnErr onError) where TSToreObject : class, IDisplayable where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (idx == null) { onError.Invoke(this.GetText(MsgCode.NothingSelected)); } else if (string.IsNullOrWhiteSpace(data.Display)) { onError.Invoke(this.GetText(MsgCode.EmptyName)); } else { // Transfer display name idx.Display = data.Display; // update index preSaveIndexUpdate(data, idx); manager.Store(data, idx); onSuccess.Invoke(); onChange.Invoke(data); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); }
public void GetCurrentTerminator(CommMedium medium, Action <TerminatorDataModel> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { // Force default creation var x = this.terminatorStorage; SettingItems items = this.settings.ReadObjectFromDefaultFile(); TerminatorDataModel dm = null; switch (medium) { case CommMedium.Bluetooth: dm = items.CurrentTerminatorBT; break; case CommMedium.BluetoothLE: dm = items.CurrentTerminatorBLE; break; case CommMedium.Ethernet: dm = items.CurrentTerminatorEthernet; break; case CommMedium.Usb: dm = items.CurrentTerminatorUSB; break; case CommMedium.Wifi: dm = items.CurrentTerminatorWIFI; break; default: dm = items.CurrentTerminator; break; } if (dm == null) { this.log.Error(9999, () => string.Format("Default terminators for {0} not found", medium)); dm = items.CurrentTerminator; } dm = this.AssureTerminators(dm); onSuccess(dm); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
public void BLE_Send(string value, BLE_CharacteristicDataModel dataModel, Action onSuccess, OnErr onError) { try { if (dataModel != null) { RangeValidationResult result = dataModel.Write(value); if (result.Status == BLE_DataValidationStatus.Success) { onSuccess.Invoke(); } else { onError.Invoke(this.Translate(result)); } } } catch (Exception e) { this.log.Exception(9999, "BLE_Send", "", e); WrapErr.SafeAction(() => { onError.Invoke(this.GetText(MsgCode.UnhandledError)); }); } }
public void ValidateBLEValue(BLE_DataType dataType, string command, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.log.Info("", () => string.Format("Validate:{0} '{1}'", dataType.ToStr(), command)); RangeValidationResult result = this.bleRangeValidator.Validate(command, dataType); if (result.Status == BLE_DataValidationStatus.Success) { onSuccess.Invoke(); } else { onError.Invoke(this.Translate(result)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.UnknownError)); } }
public void RetrieveWifiCredData(IIndexItem <DefaultFileExtraInfo> index, Action <WifiCredentialsDataModel> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { // TODO - check if exists onSuccess.Invoke(this.wifiCredStorage.Retrieve(index)); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
public void BLE_GetShortRangeDisplay(BLE_DataType dataType, Action <string> onSuccess, OnErr onError) { try { DataTypeDisplay display = this.validator.GetRange(dataType); onSuccess( string.Format("{0}, {1}: {2}, {3}: {4}", display.DataType, this.GetText(MsgCode.Min), display.Min, this.GetText(MsgCode.Max), display.Max)); } catch (Exception e) { this.log.Exception(9999, "", e); WrapErr.SafeAction(() => { onError.Invoke(this.GetText(MsgCode.UnhandledError)); }); } }
public void GetEthernetDataList(Action <List <IIndexItem <EthernetExtraInfo> > > onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { // TODO - they would have a blank extra info. Need to fill onSuccess.Invoke(this.ethernetStorage.IndexedItems); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void Save <TStoredObject>( IStorageManager <TStoredObject> manager, TStoredObject data, Action onSuccess, OnErr onError) where TStoredObject : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (manager.WriteObjectToDefaultFile(data)) { onSuccess.Invoke(); } else { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); }
public void CreateNewWifiCred(string display, WifiCredentialsDataModel data, Action <IIndexItem <DefaultFileExtraInfo> > onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { if (display.Length == 0) { onError.Invoke(this.GetText(MsgCode.EmptyName)); } else { IIndexItem <DefaultFileExtraInfo> idx = new IndexItem <DefaultFileExtraInfo>(data.UId) { Display = display, }; this.SaveWifiCred(idx, data, () => { onSuccess(idx); }, onError); } }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.SaveFailed)); } }); }
public void GetCurrentScript(Action <ScriptDataModel> onSuccess, OnErr onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { // Force creations if not yet created var x = this.scriptStorage; SettingItems items = this.settings.ReadObjectFromDefaultFile(); onSuccess(items.CurrentScript); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void RetrieveIndex <TSToreObject, TExtraInfo>( IIndexedStorageManager <TSToreObject, TExtraInfo> manager, Action <List <IIndexItem <TExtraInfo> > > onSuccess, OnErr onError) where TSToreObject : class where TExtraInfo : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess.Invoke(manager.IndexedItems); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }
private void Load <TStoredObject>( IStorageManager <TStoredObject> manager, Action <TStoredObject> onSuccess, OnErr onError) where TStoredObject : class { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess.Invoke(manager.ReadObjectFromDefaultFile()); }); if (report.Code != 0) { onError.Invoke(this.GetText(MsgCode.LoadFailed)); } }); }