Example #1
0
        private async Task <GradeObjectsList> GetGradesRemote(string sNummer, string rZLogin, string abschlNr, string stgNr, string pOVersion)
        {
            // TODO: Regex zum Prüfen der Werte
            if (!sNummer.Equals("") && !rZLogin.Equals("") && !abschlNr.Equals("") && !stgNr.Equals("") && !pOVersion.Equals(""))
            {
                try {
                    string requestData = WebUtility.UrlEncode("sNummer") + "=" + WebUtility.UrlEncode(sNummer) + "&"
                                         + WebUtility.UrlEncode("RZLogin") + "=" + WebUtility.UrlEncode(rZLogin) + "&"
                                         + WebUtility.UrlEncode("AbschlNr") + "=" + WebUtility.UrlEncode(abschlNr) + "&"
                                         + WebUtility.UrlEncode("StgNr") + "=" + WebUtility.UrlEncode(stgNr) + "&"
                                         + WebUtility.UrlEncode("POVersion") + "=" + WebUtility.UrlEncode(pOVersion);
                    Uri                 uri      = new Uri("https://wwwqis.htw-dresden.de/appservice/getgrades?" + requestData);
                    HttpClient          client   = new HttpClient();
                    HttpResponseMessage response = await client.PostAsync(uri, new StringContent(""));

                    string content = await response.Content.ReadAsStringAsync();

                    Debug.WriteLine(content);
                    List <GradeObject> gradeObjects     = JsonConvert.DeserializeObject <List <GradeObject> >(content);
                    GradeObjectsList   gradeObjectsList = new GradeObjectsList();
                    gradeObjectsList.gradeObjects = gradeObjects;
                    gradeObjectsList.timestamp    = DateTime.Now;
                    return(gradeObjectsList);
                }
                catch (Exception e) {
                    Debug.WriteLine(e.ToString());
                    return(null);
                }
            }
            else
            {
                return(null);
            }
        }
Example #2
0
        /*
         * Returns the number of new grades.
         */
        public async Task <int> GetNewGradesCount(string sNummer, string rZLogin)
        {
            GradeObjectsList backupGrades = await LoadGradesBackup(sNummer);

            GradeObjectsList newGrades = await GetGrades(sNummer, rZLogin);

            if (backupGrades != null && newGrades != null)
            {
                int count = newGrades.gradeObjects.Count - backupGrades.gradeObjects.Count;
                return(count >= 0 ? count : -1);
            }
            else
            {
                return(-1);
            }
        }
Example #3
0
        private async Task <bool> SaveGradesBackup(GradeObjectsList gradeObjectsList, string sNummer)
        {
            try {
                StorageFile saveFile = await ApplicationData.Current.LocalFolder.CreateFileAsync(filename + sNummer + ".xml", CreationCollisionOption.ReplaceExisting);

                using (Stream writeStream = await saveFile.OpenStreamForWriteAsync()) {
                    DataContractSerializer serializer = new DataContractSerializer(typeof(GradeObjectsList));
                    serializer.WriteObject(writeStream, gradeObjectsList);
                    await writeStream.FlushAsync();

                    writeStream.Dispose();
                }
                return(true);
            }
            catch (Exception e) {
                throw new Exception("Unable to save grades", e);
            }
        }