예제 #1
0
 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();
     }
 }
예제 #2
0
        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();
            }
        }
예제 #3
0
 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();
     }
 }
예제 #4
0
        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();
            }
        }
예제 #5
0
        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();
            }
        }
예제 #6
0
        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();
            }
        }
예제 #7
0
        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();
            }
        }
예제 #8
0
        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();
            }


        }
예제 #9
0
        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();
            }
        }