コード例 #1
0
        public static async Task <bool> tryLogin(string username, string password)
        {
            Boolean success = false;

            try
            {
                Uri uri = new Uri(String.Format(loginURL, username));
                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AllowUI = false;

                filter.ServerCredential =
                    new Windows.Security.Credentials.PasswordCredential(
                        uri.ToString(),
                        username,
                        password);

                var httpClient = new HttpClient(filter);

                var response = await httpClient.GetAsync(uri);

                response.EnsureSuccessStatusCode();

                var jsonString        = response.Content.ToString();
                var result            = JsonConvert.DeserializeAnonymousType(jsonString, new { personal_info = new PersonalInfo() });
                var personalPhotoUrl  = String.Format(photoURL, username);
                var photoHttpResponse = await httpClient.GetAsync(new Uri(personalPhotoUrl));

                var     repository = new PersonalInfoRespository();
                IBuffer buffer     = await photoHttpResponse.Content.ReadAsBufferAsync();

                String photo = await repository.SavePhotoAsync(buffer, username);

                result.personal_info.photo = photo;
                await repository.SaveAsync(result.personal_info);

                var vault = new PasswordVault();
                vault.Add(new PasswordCredential(VAULT_RESOURCE, username, password));
                success = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);
            }

            return(success);
        }
コード例 #2
0
        public static async Task<bool> tryLogin(string username, string password){
            
            Boolean success = false;
            try
            {
                Uri uri = new Uri(String.Format(loginURL, username));
                HttpBaseProtocolFilter filter = new HttpBaseProtocolFilter();
                filter.AllowUI = false;

                filter.ServerCredential =
                   new Windows.Security.Credentials.PasswordCredential(
                       uri.ToString(),
                       username,
                       password);

                var httpClient = new HttpClient(filter);

                var response = await httpClient.GetAsync(uri);
                response.EnsureSuccessStatusCode();

                var jsonString = response.Content.ToString();
                var result = JsonConvert.DeserializeAnonymousType(jsonString, new { personal_info = new PersonalInfo() });
                var personalPhotoUrl = String.Format(photoURL, username);
                var photoHttpResponse = await httpClient.GetAsync(new Uri(personalPhotoUrl));
                
                var repository = new PersonalInfoRespository();
                IBuffer buffer = await photoHttpResponse.Content.ReadAsBufferAsync();
                String photo = await repository.SavePhotoAsync(buffer, username);
                result.personal_info.photo = photo;
                await repository.SaveAsync(result.personal_info);

                var vault = new PasswordVault();
                vault.Add(new PasswordCredential(VAULT_RESOURCE, username, password));
                success = true;
            }
            catch (Exception e)
            {
                Debug.WriteLine(e.StackTrace);  
            }
            
            return success;
        }
コード例 #3
0
        public static async Task<ObservableCollection<Month>> Get()
        {
            if (historic != null)
                return historic;

            PersonalInfoRespository repository = new PersonalInfoRespository();

            PersonalInfo personalInfo = await repository.LoadAsync();

            var ttRepository = new TTRepository();

            var storedHistoricalChecks = await ttRepository.FindAllByUserNameAsync(personalInfo.login);

            int daysToCheck;
            if (DateTime.Now.Day > 20)
            {  // do dia 21 ao 20 do próximo mês
                daysToCheck = DateTime.Now.Day - 20;

            }
            else
            { // do dia 21 do mês passado ao dia 20 do mês atual
                var day20 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 20).AddMonths(-1);
                daysToCheck = (int)DateTime.Now.Subtract(day20).TotalDays;
            }

            var historicalChecks = new List<TTCheck>(storedHistoricalChecks);

            // Add empty checks to days without checks
            for (var i = 0; i < daysToCheck; i++)
            {
                var day = DateTime.Now.AddDays(-i);
                if (!day.IsWeekend() && !HasCheckInDay(storedHistoricalChecks, day))
                {
                    historicalChecks.Add(new TTCheck() { DateTime = day, UserName = String.Empty });
                }
            }

            historic = getMonths(historicalChecks);

            return historic;
        }
コード例 #4
0
        private async void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {
            if (!SecurityService.IsLogged)
            {
                GoToLoginPage();
            }
            else
            {
                try
                {
                    PersonalInfoRespository repository = new PersonalInfoRespository();

                    HubSectionProfile.DataContext = await repository.LoadAsync();

                    HubSectionHistoricalChecks.DataContext = await Historic.Historic.Get();
                }
                catch
                {
                    SecurityService.logoff();
                    GoToLoginPage();
                }
                
            }
        }