Пример #1
0
        public async Task <bool> RefreshAsync(IProgressDialog progressDialog)
        {
            APIResult fooAPIResult;

            progressDialog.Title = $"檢查與更新存取權杖";
            bool fooRefreshTokenResult = await RefreshTokenHelper.CheckAndRefreshToken(dialogService, refreshTokenManager, systemStatusManager, appStatus);

            if (fooRefreshTokenResult == false)
            {
                return(false);
            }
            //progressDialog.Title = $"回報例外異常資料中";
            //await exceptionRecordsManager.ReadFromFileAsync();
            //if (exceptionRecordsManager.Items.Count > 0)
            //{
            //    List<ExceptionRecordRequestDTO> fooExceptionRecordRequestDTOList = new List<ExceptionRecordRequestDTO>();
            //    foreach (var item in exceptionRecordsManager.Items)
            //    {
            //        ExceptionRecordRequestDTO fooExceptionRecordRequestDTO = new ExceptionRecordRequestDTO()
            //        {
            //            CallStack = item.CallStack,
            //            DeviceModel = item.DeviceModel,
            //            DeviceName = item.DeviceName,
            //            ExceptionTime = item.ExceptionTime,
            //            Message = item.Message,
            //            OSType = item.OSType,
            //            OSVersion = item.OSVersion,
            //            User = new UserDTO() { Id = appStatus.SystemStatus.UserID },
            //        };
            //        fooExceptionRecordRequestDTOList.Add(fooExceptionRecordRequestDTO);
            //    }
            //    fooAPIResult = await exceptionRecordsManager.PostAsync(fooExceptionRecordRequestDTOList);
            //    if (fooAPIResult.Status != true)
            //    {
            //        await dialogService.DisplayAlertAsync("回報例外異常資料中 發生錯誤", fooAPIResult.Message, "確定");
            //        return false;
            //    }
            //}
            progressDialog.Title = $"更新系統最新狀態資料中";
            fooAPIResult         = await systemEnvironmentsManager.GetAsync();

            if (fooAPIResult.Status != true)
            {
                await dialogService.DisplayAlertAsync("更新系統最新狀態資料中 發生錯誤", fooAPIResult.Message, "確定");

                return(false);
            }
            progressDialog.Title = $"更新請假類別代碼資料中";
            fooAPIResult         = await leaveFormTypesManager.GetAsync();

            if (fooAPIResult.Status != true)
            {
                await dialogService.DisplayAlertAsync("更新請假類別代碼資料中 發生錯誤", fooAPIResult.Message, "確定");

                return(false);
            }
            progressDialog.Title = $"更新部門資料中";
            fooAPIResult         = await departmentsManager.GetAsync();

            if (fooAPIResult.Status != true)
            {
                await dialogService.DisplayAlertAsync("更新部門資料中 發生錯誤", fooAPIResult.Message, "確定");

                return(false);
            }
            progressDialog.Title = $"更新通訊群組資料中";
            fooAPIResult         = await commUserGroupsManager.GetAsync();

            if (fooAPIResult.Status != true)
            {
                await dialogService.DisplayAlertAsync("更新部門資料中 發生錯誤", fooAPIResult.Message, "確定");

                return(false);
            }

            return(true);
        }
Пример #2
0
        static async Task Main(string[] args)
        {
            LoginManager loginManager = new LoginManager();

            Output("進行登入身分驗證");
            APIResult result = await loginManager.PostAsync(new LoginRequestDTO()
            {
                Account  = "user50",
                Password = "******"
            });

            if (result.Status == true)
            {
                Console.WriteLine($"登入成功");
                Console.WriteLine($"{result.Payload}");
            }
            else
            {
                Console.WriteLine($"登入失敗");
                Console.WriteLine($"{result.Message}");
            }
            Thread.Sleep(2000);

            Output("利用取得的 JTW Token 呼叫取得部門資訊 Web API");
            DepartmentsManager departmentsManager = new DepartmentsManager();

            result = await departmentsManager.GetAsync(loginManager.SingleItem.Token);

            if (result.Status == true)
            {
                Console.WriteLine($"取得部門資料成功");
                Console.WriteLine($"{result.Payload}");
            }
            else
            {
                Console.WriteLine($"取得部門資料失敗");
                Console.WriteLine($"{result.Message}");
            }

            Console.WriteLine("等候10秒鐘,等待 JWT Token 失效");
            await Task.Delay(10000);

            departmentsManager = new DepartmentsManager();
            Output("再次呼叫取得部門資訊 Web API,不過,該 JWT Token已經失效了");
            result = await departmentsManager.GetAsync(loginManager.SingleItem.Token);

            if (result.Status == true)
            {
                Console.WriteLine($"取得部門資料成功");
                Console.WriteLine($"{result.Payload}");
            }
            else
            {
                Console.WriteLine($"取得部門資料失敗");
                Console.WriteLine($"{result.Message}");
            }
            Thread.Sleep(2000);

            RefreshTokenService refreshTokenService = new RefreshTokenService();

            Output("呼叫更新 JWT Token API,取得更新的 JWT Token");
            result = await refreshTokenService.GetAsync(loginManager.SingleItem.RefreshToken);

            if (result.Status == true)
            {
                Console.WriteLine($"更新 JWT Token 成功");
                Console.WriteLine($"{result.Payload}");
            }
            else
            {
                Console.WriteLine($"更新 JWT Token 失敗");
                Console.WriteLine($"{result.Message}");
            }
            Thread.Sleep(2000);

            departmentsManager = new DepartmentsManager();
            Output("再次呼叫取得部門資訊 Web API,不過,使用剛剛取得的更新 JWT Token");
            result = await departmentsManager.GetAsync(refreshTokenService.SingleItem.Token);

            if (result.Status == true)
            {
                Console.WriteLine($"取得部門資料成功");
                Console.WriteLine($"{result.Payload}");
            }
            else
            {
                Console.WriteLine($"取得部門資料失敗");
                Console.WriteLine($"{result.Message}");
            }
            Thread.Sleep(2000);

            Console.WriteLine("Press any key for continuing...");
            Console.ReadKey();
        }