예제 #1
0
        public async Task LoadTwitterDataAsync(Action <bool> loadCompleted)
        {
            if (SaveData.IsTwitterDataInitializeCompleted())
            {
                var data = await SaveData.LoadTwitterDataAsync();

                foreach (TwitterAccount account in data.AccountList)
                {
                    await account.InitializeAsync();

                    AddAccountCommand.Execute(account);
                }

                var nowTabCount = data.TimelineTabList.Where(q => q.IsNowTab).Select(q => q).Count();
                if (nowTabCount != 0)
                {
                    var nowTab = data.TimelineTabList.Where(q => q.IsNowTab).Select(q => q).Single();
                    foreach (TimelineTab tab in data.TimelineTabList)
                    {
                        tab.Initialize(CallTabAction, CallTimelineAction, CallRowAction);
                        AddTimelineTabCommand.Execute(tab);
                        foreach (TimelineBase timeline in tab.TimelineList)
                        {
                            timeline.Initialize(
                                AccountList.Single(
                                    q => q.UserInfomation.id_str == timeline.Account.UserInfomation.id_str), Setting,
                                CallTimelineAction, CallRowAction);
                            timeline.AddTimeLine();
                        }
                        ResetTimeline();
                        if (tab.IsNowTab)
                        {
                            ChangeTabCommand.Execute(tab);
                        }
                    }
                    ChangeTabCommand.Execute(nowTab);
                }

                IsFirstLaunch = false;
                loadCompleted(true);
            }
            else
            {
                IsFirstLaunch = true;

                loadCompleted(false);
            }
        }
        // Chooses specific command to execute depending on the input given.
        public string Dispatch(string input)
        {
            string[] inputArgs   = input.Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
            string   commandName = input.Length != 0 ? inputArgs[0].ToLower() : string.Empty;

            inputArgs = inputArgs.Skip(1).ToArray();
            string output = string.Empty;

            switch (commandName)
            {
            case "register":
                RegisterCommand register = new RegisterCommand()
                {
                    UserValidator = new UserValidator()
                };
                output = register.Execute(inputArgs);
                break;

            case "login":
                LoginCommand login = new LoginCommand();
                output = login.Execute(inputArgs);
                break;

            case "logout":
                LogoutCommand logout = new LogoutCommand();
                output = logout.Execute(inputArgs);
                break;

            case "exit":
                ExitCommand exit = new ExitCommand();
                output = exit.Execute(inputArgs);
                break;

            case "add":
                AddAccountCommand add = new AddAccountCommand()
                {
                    CheckingAccountValidator = new CheckingAccountValidator(),
                    SavingAccountValidator   = new SavingAccountValidator()
                };
                output = add.Execute(inputArgs);
                break;

            case "deposit":
                DepositCommand deposit = new DepositCommand();
                output = deposit.Execute(inputArgs);
                break;

            case "withdraw":
                WithdrawCommand withdraw = new WithdrawCommand();
                output = withdraw.Execute(inputArgs);
                break;

            // List Accounts
            case "listaccounts":
                ListAccountsCommand list = new ListAccountsCommand();
                output = list.Execute(inputArgs);
                break;

            // Deduct Fee
            case "deductfee":
                DeductFeeCommand deduct = new DeductFeeCommand();
                output = deduct.Execute(inputArgs);
                break;

            // Add Interest
            case "addinterest":
                AddInterestCommand addInterest = new AddInterestCommand();
                output = addInterest.Execute(inputArgs);
                break;

            default:
                throw new ArgumentException($"Command \"{commandName}\" not supported!");
            }

            return(output);
        }