public void GetMenuItemDataModel( MenuCode menuCode, MsgCode msgCode, UIIcon iconCode, string padding, Action <MenuItemDataModel> onSuccess, Action <MenuItemDataModel> onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { onSuccess(new MenuItemDataModel() { Code = menuCode, Display = this.GetText(msgCode), IconSource = this.IconSource(iconCode), Padding = padding, }); }); if (report.Code != 0) { WrapErr.SafeAction(() => { onError.Invoke(new MenuItemDataModel() { Code = menuCode, Display = "**NA**", IconSource = "", Padding = padding, }); }); } }); }
public void SaveLanguage(LangCode code, Action onSuccess, Action <string> onError) { WrapErr.ToErrReport(9999, () => { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { this.languages.SetCurrentLanguage(code); SettingItems items = this.settings.ReadObjectFromDefaultFile(); items.Language = code; items.LanguageName = this.languages.CurrentLanguage.Language.Display; if (this.settings.WriteObjectToDefaultFile(items)) { onSuccess.Invoke(); } else { // TODO Language onError.Invoke("Failed"); } }); if (report.Code != 0) { // TODO - language WrapErr.SafeAction(() => { onError.Invoke("Unhandled Error on saving language"); }); } }); }
/// <summary>Fired when a device is discovered</summary> /// <param name="sender"></param> /// <param name="deviceInfo">Info on the discovered device</param> private void DevWatcher_Added(DeviceWatcher sender, DeviceInformation deviceInfo) { if (deviceInfo.Name.Length > 0) { WrapErr.ToErrReport(9999, () => { // TODO - find out what comes in with no name this.log.Info("DevWatcher_Added", () => string.Format("+++++ {0} : {1}", deviceInfo.Name, deviceInfo.Id)); this.DebugDumpDeviceInfo(deviceInfo); if (this.DeviceDiscovered != null) { BluetoothLEDeviceInfo dev = new BluetoothLEDeviceInfo(new BLE_WinPropertyKeys()) { Name = deviceInfo.Name, Id = deviceInfo.Id, IsDefault = deviceInfo.IsDefault, CanPair = deviceInfo?.Pairing.CanPair ?? false, IsPaired = deviceInfo?.Pairing.IsPaired ?? false, IsConnectable = deviceInfo.IsConnectable(), IsConnected = deviceInfo.IsConnected(), ServiceProperties = deviceInfo.CreatePropertiesDictionary(), // This would be the DeviceInformation object. Not required // but handy for updates in Windows OSSpecificObj = deviceInfo, }; this.DeviceDiscovered(sender, dev); } }); } }
public void GetCodeSample(CommMedium helpType, Action <string> onSuccess, OnErrTitle onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => string.Format(""), () => { string filename = this.GetFilename(helpType); if (filename.Length > 0) { // TODO - Move to cross platform access if (File.Exists(filename)) { onSuccess.Invoke(File.ReadAllText(filename)); return; } } onError(this.GetText(MsgCode.Error), "* N/Ax *"); }); if (report.Code != 0) { WrapErr.SafeAction(() => { onError.Invoke(this.GetText(MsgCode.Error), report.Msg); }); } }
private T DispatchProxy <T>(Func <T> func) { return(this.Dispatcher.Invoke(new Func <T>(() => { ErrReport report; return WrapErr.ToErrReport(out report, 9999, "", func); }))); }
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)); } }); }
private void BTClassic_PairInfoRequested(object sender, BT_PairInfoRequest e) { ErrReport report; WrapErr.ToErrReport(out report, 20017, "Failure on BTClassic_PairInfoRequested", () => { if (this.BT_PairInfoRequested != null) { // Build title BT_PairingInfoDataModel dataModel = new BT_PairingInfoDataModel() { RequestTitle = string.Format("{0} ({1})", this.GetText(MsgCode.PairBluetooth), e.DeviceName) }; dataModel.IsPinRequested = e.PinRequested; // Build message dataModel.RequestMsg = e.PinRequested ? this.GetText(MsgCode.EnterPin) : this.GetText(MsgCode.Continue); // push up to user this.BT_PairInfoRequested(sender, dataModel); // copy data from user so BT calling up can determine what to do e.Response = dataModel.HasUserConfirmed; e.Pin = dataModel.PIN; } else { this.log.Error(9999, "No subscribers to the wrapper pair info"); } }); this.RaiseIfException(report); }
/// <summary>Get discovered info to look up the stored WifiCredentials object to check for credentials /// /// </summary> /// <param name="discoverData">The WifiNetworkInfo with info from discovered devices</param> /// <returns></returns> public WifiCredAndIndex ValidateCredentials(WifiNetworkInfo discoverData, OnErr onError) { WifiCredAndIndex result = null; ErrReport report; WrapErr.ToErrReport(out report, 2000353, "Failure on ValidateCredentials", () => { this.log.Info("WifiGetConnectCredentials", () => string.Format("")); if (discoverData.SSID.Trim().Length == 0) { this.log.Error(9999, "ValidateCredentialsAsync", () => string.Format("No SSID in data retrieved from Discover")); } else { this.log.Info("ValidateCredentialsAsync", () => string.Format("SSID:{0}", discoverData.SSID)); result = this.WifiGetStoredCredentials(discoverData.SSID, onError); if (result != null && !result.RequiresUserData) { // initialize the fields in the data model sent to connect to WIFI discoverData.RemoteHostName = result.Data.RemoteHostName; discoverData.RemoteServiceName = result.Data.RemoteServiceName; discoverData.Password = result.Data.WifiPassword; } } }); this.RaiseIfException(report); return(result); }
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, 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)); } }); }
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)); } }); }
// TODO - add the Update because of Characteristics can be added and removed private void RemoveIfFound(string id, bool postErrorNotFound, bool msgIfFound) { WrapErr.ToErrReport(9999, "Fail on Remove if found", () => { // Disconnect the list from control before changing. Maybe change to Observable collection this.listBox_BLE.ItemsSource = null; var item = this.infoList_BLE.Find((x) => x.Id == id); if (item != null) { if (msgIfFound) { this.log.Info("RemoveIfFound", () => string.Format("REMOVE DEVICE:{0}", id)); } if (!this.infoList_BLE.Remove(item)) { this.log.Error(9999, "BLE_DeviceRemovedHander", () => string.Format("Failed to remove '{0}'", id)); } } else { if (postErrorNotFound) { this.log.Error(9999, "BLE_DeviceRemovedHander", () => string.Format("Item not found to be removed '{0}'", id)); } } this.listBox_BLE.ItemsSource = this.infoList_BLE; }); }
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)); } }); }
private void Wifi_OnWifiConnectionAttemptCompletedHandler(object sender, MsgPumpResults result) { ErrReport report; WrapErr.ToErrReport(out report, 2000355, "Failure on Wifi_OnWifiConnectionAttemptCompletedHandler", () => { this.log.Info("Wifi_OnWifiConnectionAttemptCompletedHandler", () => string.Format( "Is OnWifiConnectionAttemptCompleted null={0}", this.OnWifiConnectionAttemptCompleted == null)); // Set when the current connection is using new parameters if (this.pendingSaveConnectNetInfo != null) { if (result.Code == MsgPumpResultCode.Connected) { this.WifiStoreNewCredentials(this.pendingSaveConnectNetInfo); } else { // Wipping out password will cause dialog to come up on next connect this.pendingSaveConnectNetInfo.Password = ""; } this.pendingSaveConnectNetInfo = null; } this.OnWifiConnectionAttemptCompleted?.Invoke(sender, result); }); this.RaiseIfException(report); }
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 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 ValidateRanges(BLECommandSetDataModel data, Action onSuccess, OnErr onError) { ErrReport report; WrapErr.ToErrReport(out report, 9999, () => { string error = string.Empty; foreach (ScriptItem item in data.Items) { this.ValidateBLECmdItem(data.DataType, item, () => { }, (err) => { if (error == string.Empty) { error = err; } }); } if (error == string.Empty) { onSuccess(); } else { onError(error); } }); if (report.Code != 0) { WrapErr.SafeAction(() => onError(report.Msg)); } }
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)); } }); }
/// <summary> /// Raise an event in a thread pool if there are subscribers to the event /// </summary> /// <param name="action">The action to raise</param> /// <param name="msg">The message or response to push</param> /// <param name="type">Either message or response identifier string</param> private void RaiseEvent(Action <ISpEventMessage> action, ISpEventMessage msg, string type) { Log.Info("SimpleEventListner", "RaiseEvent", String.Format("Raising Event:{0} type:{1} Event Id:{2}", type, msg.TypeId, msg.EventId)); if (action != null) { ThreadPool.QueueUserWorkItem((threadContext) => { WrapErr.ToErrReport(50030, () => { return(String.Format("Unexpected Error Raising Event '{0}'", type)); }, () => { // Check again just before execution if (action != null) { action.Invoke(msg); } else { Log.Warning(50031, String.Format("No subscribers to '{0}' message", type)); } }); }); } else { Log.Warning(50031, String.Format("No subscribers to '{0}' message", type)); } }
private void BleStack_MsgReceived(object sender, byte[] e) { ErrReport report; WrapErr.ToErrReport(out report, 200054, "Failure on BleStack_MsgReceived", () => { }); }
public void BLE_GetInfo(BluetoothLEDeviceInfo device) { ErrReport report; WrapErr.ToErrReport(out report, 200059, "Failure on BluetoothLEDeviceInfo", () => { this.bleBluetooth.GetInfo(device); }); }
private void BLE_DeviceDiscoveryCompleteHandler(object sender, bool e) { this.Dispatcher.Invoke(() => { WrapErr.ToErrReport(9999, "Failure on BLE Device Discovery Complete", () => { this.gridWait.Collapse(); }); }); }
private void BLE_DeviceRemovedHandler(object sender, string e) { ErrReport report; WrapErr.ToErrReport(out report, 200051, "Failure on BLE_DeviceRemovedHandler", () => { this.BLE_DeviceRemoved?.Invoke(this, e); }); }
private void BLE_DeviceDiscoveryCompleted(object sender, bool e) { ErrReport report; WrapErr.ToErrReport(out report, 200053, "Failure on BLE_DeviceDiscoveryCompleted", () => { this.BLE_DeviceDiscoveryComplete?.Invoke(this, e); }); }
private void BLE_DeviceUpdatedHandler(object sender, NetPropertiesUpdateDataModel args) { ErrReport report; WrapErr.ToErrReport(out report, 200052, "Failure on BLE_DeviceUpdatedHandler", () => { this.BLE_DeviceUpdated?.Invoke(this, args); }); }
public void BLE_CancelDiscover() { ErrReport report; WrapErr.ToErrReport(out report, 200057, "Failure on BLE_CancelDiscover", () => { this.bleBluetooth.CancelDiscoverDevices(); }); }
public void BLE_Disconnect() { ErrReport report; WrapErr.ToErrReport(out report, 200060, "Failure on BLE_Disconnect", () => { this.bleBluetooth.Disconnect(); }); }
public void BLE_DiscoverAsync() { ErrReport report; WrapErr.ToErrReport(out report, 200056, "Failure on BLE_DiscoverAsync", () => { this.bleBluetooth.DiscoverDevices(); }); }
public void BLE_ConnectAsync(BluetoothLEDeviceInfo device) { ErrReport report; WrapErr.ToErrReport(out report, 200058, "Failure on BLE_ConnectAsync", () => { this.bleBluetooth.Connect(device); }); }