Ejemplo n.º 1
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            if (isDeposit)
            {
                proxy.DepositCompleted += OnSavingCompleted;
                proxy.DepositAsync(userId: userId,
                                   accountId: accountId,
                                   operationDate: operationDate,
                                   price: price,
                                   quantity: quantity,
                                   comment: comment,
                                   categoryId: categoryId
                                   );
            }
            else
            {
                proxy.WithdrawalCompleted += OnSavingCompleted;
                proxy.WithdrawalAsync(userId: userId,
                                      accountId: accountId,
                                      operationDate: operationDate,
                                      price: price,
                                      quantity: quantity,
                                      comment: comment,
                                      categoryId: categoryId
                                      );
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create MoneyService client proxy.
        /// </summary>
        /// <returns>New MoneyService client proxy.</returns>
        public static MoneyServiceClient CreateMoneyService()
        {
            var proxy = new MoneyServiceClient();

            SetupServiceUri(proxy.Endpoint);
            SetupClientCredentials(proxy.ClientCredentials);
            SetupPersonalServiceUri(proxy);
            return(proxy);
        }
Ejemplo n.º 3
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.DeleteTransactionCompleted += OnDeleteCompleted;
            proxy.DeleteTransactionAsync(userId,
                                         accountId,
                                         transactionId,
                                         DateTime.UtcNow
                                         );
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Use personal service host only if available.
        /// </summary>
        /// <param name="proxy">Client proxy instance.</param>
        private static void SetupPersonalServiceUri(MoneyServiceClient proxy)
        {
            if (proxy == null)
            {
                throw new ArgumentNullException("proxy");
            }

            if (!string.IsNullOrEmpty(PersonalServiceUri))
            {
                proxy.Endpoint.Address = new EndpointAddress(PersonalServiceUri);
            }
        }
Ejemplo n.º 5
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.TransferCompleted += OnTransferCompleted;
            proxy.TransferAsync(user1Id,
                                account1Id,
                                user2Id,
                                account2Id,
                                operationDate,
                                amount,
                                comment
                                );
        }
Ejemplo n.º 6
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.UpdateTransactionCompleted += OnUpdateTransactionCompleted;
            proxy.UpdateTransactionAsync(transactionId,
                                         userId,
                                         accountId,
                                         operationDate,
                                         price,
                                         quantity,
                                         comment,
                                         categoryId,
                                         isDeposit
                                         );
        }
Ejemplo n.º 7
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.GetAllAccountsCompleted += (s, e) =>
            {
                if (e.Error != null)
                {
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(
                        () => Completed(this, new ResultCompletionEventArgs {
                        Error = e.Error
                    }));
                }
                else
                {
                    Accounts = e.Result;
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
                }
            };

            proxy.GetAllAccountsAsync(userId: userId);
        }
Ejemplo n.º 8
0
        public void Execute(ResultExecutionContext context)
        {
            var proxy = new MoneyServiceClient();

            proxy.GetTransactionCompleted += (sender, args) =>
            {
                if (args.Error != null)
                {
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(
                        () => Completed(this, new ResultCompletionEventArgs {
                        Error = args.Error
                    }));
                }
                else
                {
                    Transaction = args.Result;
                    Caliburn.PresentationFramework.Invocation.Execute.OnUIThread(() => Completed(this, new ResultCompletionEventArgs()));
                }
            };
            proxy.GetTransactionAsync(userId,
                                      accountId,
                                      transactionId);
        }
Ejemplo n.º 9
0
        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var serviceUrl = ServiceUrl.Text;
            var service    = new MoneyServiceClient();

            service.ClientCredentials.UserName.UserName = Username.Text;
            service.ClientCredentials.UserName.Password = Password.Text;

            SetupServiceUri(service.Endpoint, serviceUrl);

            var accountsResult = await service.GetAllAccountsAsync();

            Frame.Navigate(typeof(GroupedItemsPage), accountsResult);

/*
 *              new SampleDataGroup(
 *              "AllGroups",
 *              "Group Title",
 *              accountsResult.First().Name,
 *              string.Empty,
 *              accountsResult.First().Balance.ToString()));
 */
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Start import data from old SQL database to new one via service calls.
        /// </summary>
        /// <param name="sender">Start button.</param>
        /// <param name="e">Routed event data.</param>
        private void StartButtonClick(object sender, RoutedEventArgs e)
        {
            canselPending = false;
            Clear();
            EnableUI(false);

            stopWatch = Stopwatch.StartNew();

            try
            {
                moneyClient = new MoneyServiceClient(
                    new BasicHttpBinding(),
                    new EndpointAddress(ServiceUrlTextBox.Text.Trim() + MoneyServiceUrlPostfix));

                userСlient = new UserServiceClient(
                    new BasicHttpBinding(),
                    new EndpointAddress(ServiceUrlTextBox.Text.Trim() + UserServiceUrlPostfix));

                UpdateStatus("Registering user \"" + UsernameTextBox.Text.Trim() + "\"...");
                user   = userСlient.Register(UsernameTextBox.Text.Trim(), PasswordTextBox.Text.Trim());
                userId = user.Id;

                if (canselPending)
                {
                    UpdateStatus("Canceled");
                    return;
                }

                UpdateStatus("Creating account \"" + AccountTextBox.Text.Trim() + "\"...");
                accountId = moneyClient.CreateAccount(userId, AccountTextBox.Text.Trim(), 1);                 // UAH account by default

                if (canselPending)
                {
                    UpdateStatus("Canceled");
                    return;
                }

                using (var context = new ProfitAndExpenseEntities(new EntityConnection(string.Format(ConnectionStringTemplate, ConnectionStringTextBox.Text.Trim()))))
                {
                    UpdateStatus("Retrieving expense category list...");
                    List <ExpenseGroup> expenseGroups = context.TblExpenseGroups.OrderBy(expenseGroup => expenseGroup.Id).ToList();

                    if (canselPending)
                    {
                        UpdateStatus("Canceled");
                        return;
                    }

                    for (int i = 0; i < expenseGroups.Count; i++)
                    {
                        if (canselPending)
                        {
                            break;
                        }

                        UpdateStatus("Creating " + i + " / " + expenseGroups.Count + " expense category...");
                        int categoryId = moneyClient.CreateCategory(userId, expenseGroups[i].Name, CategoryType.Withdrawal);                         // withdrawal category
                        categoryMap.Add(new KeyValuePair <int, bool>(expenseGroups[i].Id, true), categoryId);
                    }

                    if (canselPending)
                    {
                        UpdateStatus("Canceled");
                        return;
                    }

                    UpdateStatus("Retrieving revenue category list...");
                    List <RevenueGroup> revenueGroups = context.TblRevenueGroups.OrderBy(revenueGroup => revenueGroup.Id).ToList();

                    if (canselPending)
                    {
                        UpdateStatus("Canceled");
                        return;
                    }

                    for (int i = 0; i < revenueGroups.Count; i++)
                    {
                        if (canselPending)
                        {
                            break;
                        }

                        UpdateStatus("Creating " + i + " / " + revenueGroups.Count + " revenue category...");
                        int categoryId = moneyClient.CreateCategory(userId, revenueGroups[i].Name, CategoryType.Deposit);                         // deposit category
                        categoryMap.Add(new KeyValuePair <int, bool>(revenueGroups[i].Id, false), categoryId);
                    }

                    if (canselPending)
                    {
                        UpdateStatus("Canceled");
                        return;
                    }

                    Import(context);

                    stopWatch.Stop();
                    UpdateStatus(
                        string.Format(
                            "Done in {0:00}:{1:00}:{2:00}.{3:00}",
                            stopWatch.Elapsed.TotalHours,
                            stopWatch.Elapsed.Minutes,
                            stopWatch.Elapsed.Seconds,
                            stopWatch.Elapsed.Milliseconds));
                }
            }
            catch (Exception exception)
            {
                stopWatch.Stop();
#if DEBUG
                throw;
#endif
#pragma warning disable 162
                ShowError(exception);
#pragma warning restore 162
            }
            finally
            {
                stopWatch.Stop();
                EnableUI(true);
            }
        }