Ejemplo n.º 1
0
        protected async Task Startup()
        {
            if (!_applicationService.Accounts.Any())
            {
                ShowViewModel <LoginViewModel>();
                return;
            }

            var account = GetDefaultAccount();

            if (account == null)
            {
                ShowViewModel <AccountsViewModel>();
                return;
            }

            if (string.IsNullOrEmpty(account.Token) || string.IsNullOrEmpty(account.RefreshToken))
            {
                await AlertService.Alert("Welcome!", "CodeBucket is now OAuth compliant!\n\nFor your security, " +
                                         "you will now be prompted to login to Bitbucket via their OAuth portal. This will swap out your credentials" +
                                         " for an OAuth token you may revoke at any time!");

                ShowViewModel <LoginViewModel>();
                return;
            }

            try
            {
                IsLoggingIn = true;
                Status      = "Logging in as " + account.Username;

                var ret = await Task.Run(() => Client.RefreshToken(LoginViewModel.ClientId, LoginViewModel.ClientSecret, account.RefreshToken));

                if (ret == null)
                {
                    await DisplayAlert("Unable to refresh OAuth token. Please login again.");

                    ShowViewModel <AccountsViewModel>();
                    ShowViewModel <LoginViewModel>();
                    return;
                }

                account.RefreshToken = ret.RefreshToken;
                account.Token        = ret.AccessToken;
                _accountsService.Update(account);

                await AttemptLogin(account);

                ShowViewModel <MenuViewModel>();
            }
            catch (Exception e)
            {
                DisplayAlert("Unable to login successfully: " + e.Message).FireAndForget();
                ShowViewModel <AccountsViewModel>();
            }
            finally
            {
                IsLoggingIn = false;
            }
        }
        async Task Ctx.IAppConfigInfo.SetDefaultConnectionAsync(string ConnnectionCode)
        {
            var cbuilder = new SqlConnectionStringBuilder();

            cbuilder.DataSource         = Server;
            cbuilder.InitialCatalog     = Database;
            cbuilder.UserID             = UserId;
            cbuilder.Password           = Password;
            cbuilder.IntegratedSecurity = false;

            string cs = cbuilder.ConnectionString;

            WaitingService.Wait("Testing Connection to", $"Server {cbuilder.DataSource}/{cbuilder.InitialCatalog}");


            var dic = ((IAppConfigInfo)this).GetApplicationConfigInfos();

            dic.InsertUpdate(Ctx.AppConfig.SQLConnectionString, cs);
            dic.InsertUpdate(nameof(Ctx.AppConfig.DBEngine), "SQL");
            dic.InsertUpdate(nameof(Ctx.AppConfig.UseAppServer), "N");


            using (IDbConnection con = await SPC.Database.ConnectionFactory.GetDBConnectionAsync(true))
            {
                if (con.State == ConnectionState.Open)
                {
                    AlertService.Alert($"Connected to Server {cbuilder.DataSource}/{cbuilder.InitialCatalog}");
                }
                else
                {
                    AlertService.Alert($"Failed to connect to Server {cbuilder.DataSource}/{cbuilder.InitialCatalog}");
                }
            }
        }
        static void Main(string[] args)
        {
            //1.取得欲比對帳號密碼的清單
            SyncService     syncService       = new SyncService();
            IList <Profile> profileCollection = syncService.GetCheckList();

            //2.檢查是否與Authentication的資料一致
            StringBuilder mailContent = new StringBuilder();

            mailContent.AppendLine(string.Format("檢查時間:{0}", System.DateTime.Now.ToString()));

            AuthenticationService authenticationService = new AuthenticationService();
            bool IsAnyError = false;

            foreach (var item in profileCollection)
            {
                //3.將不一致的資料記錄下來,發送Email
                if (authenticationService.VerifyPasswordById(item.Id, item.Password) != VerifyStatus.Passed)
                {
                    string message = string.Format("同步異常的帳號:{0}", item.Id);
                    mailContent.AppendLine(message);
                    IsAnyError = true;
                }
            }

            //4.如果有不一致的資料,則發送通知
            if (IsAnyError)
            {
                AlertService alertService = new AlertService();
                alertService.Alert(mailContent.ToString());
            }
        }
        async Task OnRowInserting(IDictionary <string, object> newValue)
        {
            if (newValue != null && newValue.Count > 0)
            {
                Dictionary <string, string> dic = CreateStringDic(newValue);

                var pUserId = dic.GetValueByKey(nameof(CompanyUser.UserId), "");

                Status = $"Thêm tài khoản {pUserId}";

                StateHasChanged();


                foreach (var item in Users)
                {
                    if (item.UserId == pUserId)
                    {
                        AlertService.Alert($"Tài khoản {pUserId} đã tồn tại");
                        return;
                    }
                }

                await CompanyUser.RegisterANewUserAsync(TaxId, dic);

                await SearchAsync();
            }
        }