private void SubscribeToService() { try { // Get User User msgUser = new User(); var msg = new GetUserMessage(this, message => { msgUser = message; }); Messenger.Default.Send(msg); // Create Registration Registration registration = new Registration(); registration.URI = httpChannel.ChannelUri.ToString(); registration.UserId = msgUser.UserId; // Register CapitalServiceClient client = new CapitalServiceClient(); client.RegisterCompleted += (s, e) => { }; client.RegisterAsync(registration); } catch { } }
private void LoadAccounts(AccountLoadMessage message) { CapitalServiceClient client = new CapitalServiceClient(); try { IsBusy = true; client.GetAccountsCompleted += (s, e) => { if (e.Error == null) { if (e.Result != null) { Accounts = e.Result; if (Accounts.Count < 1) IsEmpty = true; else IsEmpty = false; } else { IsEmpty = true; } } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; client.GetAccountsAsync(GetUser()); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void Init() { // Load Account Types CapitalServiceClient service = service = new CapitalServiceClient(); try { IsBusy = true; service.GetAccountTypesCompleted += (s, e) => { if (e.Error == null) { if (e.Result != null) { AccountTypes = e.Result; } } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; service.GetAccountTypesAsync(); } catch (Exception) { service.Abort(); } finally { service.CloseAsync(); } }
public void LoginFail() { CapitalServiceClient client = new CapitalServiceClient(); try { User user = client.Login(new User() { Email = "*****@*****.**", Password = "******" }); } catch (FaultException<CapitalError> ex) { client.Abort(); throw ex; } catch (Exception ex) { client.Abort(); throw ex; } finally { client.Close(); } }
public void AppInit(NavigationService navServiceParam, NavigationContext navContextParam) { // This is the primary location for special logic when entering the app. // Here is where we determine to go to the home screen or login screen. // And it will be the starting point for ALL tile entries // Instaniate here and not in the constructor // If you do it in the constructor the MainFrame will be null. navService = new MyNavigationService(navServiceParam as NavigationService); if(isStartup) { isStartup = false; popup.IsOpen = true; NavigationContext navContext = (navContextParam as NavigationContext); var settings = IsolatedStorageSettings.ApplicationSettings; User savedUser; //settings.Remove("appUser"); settings.TryGetValue<User>("appUser", out savedUser); if (savedUser == null) { popup.IsOpen = false; GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } else { CapitalServiceClient client = new CapitalServiceClient(); client.LoginCompleted += (s, e) => { try { popup.IsOpen = false; if (e.Result != null) { User = e.Result; // Needed for Notification/Tile/Toast Config Messenger.Default.Send(new ToastMessage()); if (navContext.QueryString.ContainsKey("Statement")) { int id = Convert.ToInt32(navContext.QueryString["Statement"]); LoadStatement(id); } else { GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Home", OnStack = false }); } } else { GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } } catch(Exception) { //MessageBox.Show(ex.Message); GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Login", OnStack = false }); } }; client.LoginAsync(savedUser); } } }
private void LoadStatement(int key) { try { IsBusy = true; CapitalServiceClient client = new CapitalServiceClient(); client.GetStatementByIdCompleted += (s, e) => { try { if (e.Error == null) { if (e.Result != null) { Messenger.Default.Send(new StatementEditMessage { Statement = e.Result }); GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "StatementViewer", OnStack = false }); } else { GoToView(new NavigationMessage() { Source = this.GetType().Assembly.ToString(), Destination = "Home", OnStack = false }); } } else MessageBox.Show(e.Error.Message, "Error", MessageBoxButton.OK); IsBusy = false; popup.IsOpen = false; } catch { IsBusy = false; } }; client.GetStatementByIdAsync(User, key); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButton.OK); } }
private void SendFeedback() { try { object focusObj = FocusManager.GetFocusedElement(); if (focusObj != null && focusObj is TextBox) { var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); (focusObj as TextBox).IsEnabled = false; (focusObj as TextBox).IsEnabled = true; return; } IsBusy = true; CapitalServiceClient client = new CapitalServiceClient(); client.SendFeedbackCompleted += (s, e) => { IsBusy = false; if (e.Error != null) MessageBox.Show("Error sending feedback.", "Error", MessageBoxButton.OK); else { MessageBoxResult result = MessageBox.Show("Thank You!"); Messenger.Default.Send(new NavigateBackMessage()); } }; client.SendFeedbackAsync(new Feedback { Message = this.Message, ReportType = FeedbackItems[SelectedFeedbackIndex], UserId = GetUser().UserId }); } catch { } }
private void SaveStatement() { object focusObj = FocusManager.GetFocusedElement(); if (focusObj != null && focusObj is TextBox) { var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); (focusObj as TextBox).IsEnabled = false; (focusObj as TextBox).IsEnabled = true; return; } CapitalServiceClient client = new CapitalServiceClient(); try { IsBusy = true; client.UpdateStatementCompleted += (s, e) => { if (e.Error == null) { // Check for tile and remove string navParam = string.Format("Statement={0}", EditStatement.StatementId); ShellTile TileToFind = ShellTile.ActiveTiles.Where(x => x.NavigationUri.ToString().Contains(navParam)).FirstOrDefault(); if (TileToFind != null) { if (EditStatement.IsPaid) TileToFind.Delete(); else { // Update old tile PinStatementFromCommand(); } } UpdateViews(); } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; client.UpdateStatementAsync(editStatement); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void LoadStatements(StatementLoadMessage msg) { CapitalServiceClient client = new CapitalServiceClient(); try { IsBusy = true; client.GetStatementsCompleted += (s, e) => { IsBusy = false; if (e.Error == null) { // Remove Paid Statements Messenger.Default.Send(new StatementLoadRecentMessage { Statements = e.Result.Where(x => x.IsPaid == true) }); PrimaryStatements = new ObservableCollection<Statement>(e.Result.Where(x => x.IsPaid == false)); StatementFilterRefresh(SelectedFilter); } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; client.GetStatementsAsync(GetUser()); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void SaveAccount() { object focusObj = FocusManager.GetFocusedElement(); if (focusObj != null && focusObj is TextBox) { var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); (focusObj as TextBox).IsEnabled = false; (focusObj as TextBox).IsEnabled = true; return; } if (!Validate()) return; CapitalServiceClient client = new CapitalServiceClient(); try { IsBusy = true; client.UpdateAccountCompleted += (s, e) => { if (e.Error == null) { UpdateViews(); } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; client.UpdateAccountAsync(EditAccount); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void DeleteAccount() { MessageBoxResult result = MessageBox.Show("Are You Sure?", "Account Deletion", MessageBoxButton.OKCancel); if (result != MessageBoxResult.OK) return; CapitalServiceClient client = new CapitalServiceClient(); try { IsBusy = true; client.DeleteAccountCompleted += (s, e) => { if (e.Error == null) { EditAccount = null; UpdateViews(); } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; client.DeleteAccountAsync(EditAccount); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void Init(Account account) { EditAccount = account; IsBusy = true; CapitalServiceClient client = new CapitalServiceClient(); try { client.GetFrequenciesCompleted += (s, e) => { if (e.Error == null) { FreqCollection = e.Result; } else ErrorMessages.UnexpectedError(); Frequency = FreqCollection.Where(x => x.FrequencyId == editAccount.FrequencyId).FirstOrDefault(); if (Frequency == null) { Frequency = FreqCollection[0]; } IsBusy = false; }; client.GetFrequenciesAsync(); } catch { client.Abort(); } finally { client.CloseAsync(); } }
private void UserLogin() { object focusObj = FocusManager.GetFocusedElement(); if (focusObj != null && focusObj is TextBox) { var binding = (focusObj as TextBox).GetBindingExpression(TextBox.TextProperty); binding.UpdateSource(); (focusObj as TextBox).IsEnabled = false; (focusObj as TextBox).IsEnabled = true; return; } else if (focusObj != null && focusObj is PasswordBox) { var binding = (focusObj as PasswordBox).GetBindingExpression(PasswordBox.PasswordProperty); binding.UpdateSource(); (focusObj as PasswordBox).IsEnabled = false; (focusObj as PasswordBox).IsEnabled = true; return; } if (!ModelValidation()) { return; } CapitalServiceClient service = service = new CapitalServiceClient(); try { IsBusy = true; // Encrypt Password before sending across the wire string key = "BLANDDIESEL"; UTF8Encoding encoding = new UTF8Encoding(); byte[] keyByte = encoding.GetBytes(key); HMACSHA256 sha256 = new HMACSHA256(keyByte); byte[] passwordbytes = encoding.GetBytes(password); byte[] hashMessage = sha256.ComputeHash(passwordbytes); loginUser.Password = ConvertToString(hashMessage); loginUser.Devices = new System.Collections.ObjectModel.ObservableCollection<Device>(); byte[] uniqueId = (byte[])DeviceExtendedProperties.GetValue("DeviceUniqueId"); loginUser.Devices.Add(new Device { // Get Phone Data UniqueDeviceId = BitConverter.ToString(uniqueId), Manufacturer = DeviceStatus.DeviceManufacturer, Model = DeviceStatus.DeviceHardwareVersion, DeviceName = DeviceStatus.DeviceName, }); service.LoginCompleted += (s, e) => { if (e.Error == null) { if (e.Result != null) { var settings = IsolatedStorageSettings.ApplicationSettings; settings.Remove("appUser"); settings.Add("appUser", e.Result); Messenger.Default.Send<SetUserMessage>(new SetUserMessage { User = e.Result }); Messenger.Default.Send<NavigationMessage>(new NavigationMessage { Destination = "Home", Source = this.GetType().Name, OnStack = false }); } } else if (e.Error is FaultException<CapitalError>) { ErrorMessages.FaultError(e.Error.Message); } else { ErrorMessages.UnexpectedError(); } IsBusy = false; }; service.LoginAsync(loginUser); } catch (Exception) { service.Abort(); } finally { service.CloseAsync(); } }