private void btnLogin_Click(object sender, RoutedEventArgs e) { UserRecord targetProfile = null; if (listUserAccounts.SelectedItem == null) { return; } UserLoginAcount selectedUserItem = listUserAccounts.SelectedItem as UserLoginAcount; if (selectedUserItem != null) { targetProfile = selectedUserItem.Profile; } if (targetProfile == null) { return; } btwatcherManager.StopBTWatcher(); messageManager.StopListen(); App.SetLogout(); btnLogin.IsEnabled = false; listUserAccounts.IsEnabled = false; btnTogglePanel.IsEnabled = false; NotifyUser("Logging in ...", NotifyType.StatusMessage); Task.Run(async() => { bool isSuccess = false; UserRecord userProfile = targetProfile; App.SetScenario(targetProfile.ScenarioID); string deviceId = await messageManager.GetDeviceId(); if (deviceId != null) { await RequestBackgroundExec(); messageManager.Init(OnRemoteNotification, OnRemoteDisconnected, App.configManager.ServiceUrl, App.configManager.ContentId); messageManager.StartListen(); btwatcherManager.Init(App.configManager.BeaconCompanyId, App.configManager.BeaconPrefix, OnBLEMessageReceived); btwatcherManager.StartBTWatcher(); isSuccess = true; } if (isSuccess) { App.SetLogin(targetProfile); } UpdateLogin(isSuccess, isSuccess, null); }); }
public static void SetLogin(UserRecord userProfile) { if (userProfile == null) { return; } if (userManager != null) { userManager.CurrentUser.Status = USERLOGIN_STATUS.LOGGED_IN; userManager.CurrentUser.Profile = userProfile; ApplicationData.Current.LocalSettings.Values[CURRENTUSER_TAG] = userProfile.ID; } }
public async Task <bool> LoadDataFromXml(string filename) { const string XMLDATA_RECORD_USER = "******"; string dataFileName = filename; bool isSuccess = false; Stream xmlStream = null; if (UserProfiles == null) { UserProfiles = new Dictionary <string, UserRecord>(); } else { UserProfiles.Clear(); } CurrentUser = new UserStatus() { Status = USERLOGIN_STATUS.LOGGED_OUT, Profile = null }; try { if (xmlStream == null) { // Try to get menu from Picture folder next try { var folder = KnownFolders.PicturesLibrary; var file = await folder.GetFileAsync(dataFileName); xmlStream = await file.OpenStreamForReadAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } if (xmlStream == null) { // Try to get menu from App's current folder try { var file = await Package.Current.InstalledLocation.GetFileAsync(dataFileName); xmlStream = await file.OpenStreamForReadAsync(); } catch (Exception ex) { Debug.WriteLine(ex.Message); } } if (xmlStream == null) { throw new FileNotFoundException("No userdata found!!", dataFileName); } XDocument dataxml = XDocument.Load(xmlStream); foreach (XElement element in dataxml.Descendants(XMLDATA_RECORD_USER)) { XAttribute attr = null; string id = null; string displayname = null; string scenario = "0"; try { attr = element.Attribute("ID"); id = (attr == null) ? null : attr.Value; if (id == null) { continue; } id = id.Trim(); if (id.Length == 0) { continue; } attr = element.Attribute("DisplayName"); displayname = (attr == null) ? null : attr.Value; displayname = displayname.Trim(); if (displayname == null || displayname.Length == 0) { displayname = "(" + id + ")"; } attr = element.Attribute("Scenario"); scenario = (attr == null) ? null : attr.Value; scenario = scenario.Trim(); UserRecord record = new UserRecord(id, displayname, scenario); UserProfiles.Add(id, record); } catch (Exception ex) { Debug.WriteLine(ex); } } isSuccess = true; } catch (Exception ex) { Debug.WriteLine(ex.Message); } return(isSuccess); }