public async Task <String> CallPostApiWeeks(String methodName, WeekEntity we) { String rtn = String.Empty; try { using (var client = new HttpClient()) { client.BaseAddress = new Uri("http://" + InitSetting.CConf.serverIP + ":3000"); client.DefaultRequestHeaders.Accept.Add( new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = new HttpResponseMessage(); //헤더 토큰(JWT.IO) //client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(cf.accesstoken); //we.token = cf.refreshtoken; response = await client.PostAsJsonAsync(methodName, we).ConfigureAwait(false); response.EnsureSuccessStatusCode(); // 오류 코드를 던집니다. // Verification if (response.IsSuccessStatusCode) { rtn = response.Content.ReadAsStringAsync().Result; } } } catch (Newtonsoft.Json.JsonException jEx) { // 이 예외는 요청 본문을 역직렬화 할 때, 문제가 발생했음을 나타냅니다. rtn = jEx.ToString(); } catch (HttpRequestException ex) { rtn = "TokenError"; } return(rtn); }
private async void AutoLogin() { try { ClientConfig cf = InitSetting.CConf; //자동로그인 설정 if (cf.autoLogin.Equals("1")) { UserEntity ue = new UserEntity() { id = cf.userID }; var result = Task.Run(() => new CallWebApi().CallPostApiUsers("userFind", ue)); Users userList = JsonConvert.DeserializeObject <Users>(await result); //로그인 ID가 틀릴 경우 로그인창을 띄운다. if (userList == null || userList.userList.Count != 1) { Login popup = new Login(); popup.ShowDialog(); lbl_userInfo.Content = cf.userName; } else { //비밀번호가 틀릴경우 로그인창을 띄운다. if (!cf.userPass.Equals(userList.userList[0].password)) { Login popup = new Login(); popup.ShowDialog(); } else { //정상처리 cf.userName = userList.userList[0].name; cf.dept = userList.userList[0].depart; lbl_userInfo.Content = userList.userList[0].name; this.Title = cf.dept; } } } else { //자동로그인이 아닐경우 로그인창을 띄운다. Login popup = new Login(); popup.ShowDialog(); lbl_userInfo.Content = cf.userName; } //올해년도 기준 WeekEntity we = new WeekEntity() { //year = DateTime.Now.Year.ToString() }; var result2 = Task.Run(() => new CallWebApi().CallPostApiWeeks("getWeekInfo", we)); var rtn = JsonConvert.DeserializeObject <Weeks>(await result2); cf.weekList = rtn.weekInfo; //타이머처리 System.Windows.Threading.DispatcherTimer dispatcherTimer = new System.Windows.Threading.DispatcherTimer(); dispatcherTimer.Tick += DispatcherTimer_Tick; dispatcherTimer.Interval = new TimeSpan(0, 0, 1); dispatcherTimer.Start(); //마우스 이동이 없을 경우 처리(1분씩 체크) //System.Windows.Threading.DispatcherTimer CheckIdleTimer = new System.Windows.Threading.DispatcherTimer(); //CheckIdleTimer.Tick += CheckIdleTimer_Tick; //CheckIdleTimer.Interval = new TimeSpan(0, 1, 0); //CheckIdleTimer.Start(); _uc_dashboard = new uc_DashBoard(); uc_Class.Uc_Link(Contents_Border, _uc_dashboard); showNotify(); //전에 처리하지 않은 데이터 확인 checkData(); } catch (Exception ex) { MessageBox.Show("관리자에게 문의 부탁드립니다."); System.Windows.Application.Current.Shutdown(); } }