Пример #1
0
        void getLatestClass()
        {
            HttpHandler hh         = new HttpHandler();
            var         x          = hh.Get(@"/api/CurrentLesson/latest");
            var         jsonString = x.Result;

            jsonString = jsonString.Replace("null", "-1");

            JObject obj = JObject.Parse(jsonString);

            GambitLessonModel.LatestLesson = GambitLessonModel.buildLesson(obj);

            if (obj["date"].ToString() == DateTime.Today.ToString("d"))
            {
                cur = CurriculumModel.allCurriculum[(int)obj["curriculum_id"]];

                if ((int)obj["curriculum1_id"] >= 0)
                {
                    cur1 = CurriculumModel.allCurriculum[(int)obj["curriculum1_id"]];

                    if ((int)obj["curriculum2_id"] >= 0)
                    {
                        cur2 = CurriculumModel.allCurriculum[(int)obj["curriculum2_id"]];
                    }
                }
            }
        }
Пример #2
0
        public async Task <NorthApiResult <DeviceActivatedResult> > DeviceActivated(string deviceId)
        {
            var result = new NorthApiResult <DeviceActivatedResult>();

            if (deviceId.IsNull())
            {
                result.Msg = "deviceId不能为空";
                return(result);
            }

            var url        = $"{_urls.DeviceActivated}/{deviceId}";
            var httpResult = await _httpHandler.Get(url);

            result.StatusCode = httpResult.StatusCode;

            if (result.StatusCode == HttpStatusCode.OK)
            {
                result.Success = true;
                result.Data    = JsonConvert.DeserializeObject <DeviceActivatedResult>(httpResult.Content);
                _logger?.LogDebug("DeviceDelete:{@Result}", result.Data);
            }
            else
            {
                result.Error = JsonConvert.DeserializeObject <HttpError>(httpResult.Content);
                _logger?.LogDebug("DeviceDelete:{@Error}", result.Error);
            }

            return(result);
        }
Пример #3
0
        public void HttpHandlerGet_GetSingleCallById_ReturnsSingleCallModel()
        {
            var client = new HttpClient();
            
            var httpHandler = new HttpHandler<CallModel>(client);
            httpHandler.Uri = "api/call";

            var singleCall = httpHandler.Get("563c930402a93d01d0d8506c");

            Assert.AreEqual(singleCall.GetType(), typeof(CallModel));
        }
Пример #4
0
        public void TestGetAsync()
        {
            var client = new HttpClient();

            var httpHandler = new HttpHandler<CallModel>(client);
            httpHandler.Uri = "api/call";

            var returnedFromRequest = httpHandler.Get();

            Assert.IsNotNull(returnedFromRequest);
        }
        void getCurriculum()
        {
            HttpHandler hh         = new HttpHandler();
            var         x          = hh.Get(@"/api/Curriculum");
            var         jsonString = x.Result;

            JArray jsonArray = JArray.Parse(jsonString);

            foreach (JObject obj in jsonArray)
            {
                CurriculumCounter cm = new CurriculumCounter();
                cm.id   = (int)obj["id"];
                cm.name = (string)obj["name"];
                if (!String.IsNullOrEmpty(cm.name))
                {
                    this.curriculm.Add(cm);
                }
            }
        }
        List <LessonModel> getLessons(int studentID = 1)
        {
            var         lessons    = new List <LessonModel>();
            HttpHandler hh         = new HttpHandler();
            var         x          = hh.Get(@"/api/LessonCount/" + studentID.ToString());
            var         jsonString = x.Result;

            JArray jsonArray = JArray.Parse(jsonString);

            foreach (JObject obj in jsonArray)
            {
                count++;
                var lesson = new LessonModel();
                lesson.lesson_id   = (int)obj["class_id"];
                lesson.curriculum  = (string)obj["curriculum"];
                lesson.curriculum1 = (string)obj["curriculum1"];
                lesson.curriculum2 = (string)obj["curriculum2"];
                lessons.Add(lesson);
            }
            return(lessons);
        }
Пример #7
0
        internal PictureModel GetImageDetail(string token, PictureModel input)
        {
            PictureModel output = null;

            try
            {
                HttpHandler http = new HttpHandler();
                output    = new PictureModel();
                output.Id = input.Id;
                output.Cropped_picture = input.Cropped_picture;

                dynamic respImage = http.Get(Config.Url + "/images/" + input.Id, AuthorizationType.Bearer, token, ResultType.JsonObj);

                if (respImage == null || respImage.id == null)
                {
                    throw new Exception("Error getting image data");
                }

                if (respImage.author != null)
                {
                    output.Author = Convert.ToString(respImage.author);
                }
                if (respImage.camera != null)
                {
                    output.Camera = Convert.ToString(respImage.camera);
                }
                if (respImage.tags != null)
                {
                    output.Tags = Convert.ToString(respImage.tags);
                }
            }
            catch (Exception)
            {
            }

            return(output);
        }
Пример #8
0
        /// <summary>
        /// Versucht sich einzuloggen
        /// </summary>
        public void Login()
        {
            Logger.Log(LoggingCategories.NavigationAction, "Login");
            //Zur Ogame Startseite navigieren
            Logger.Log(LoggingCategories.NavigationAction, "Navigate to Startpage");

            HttpHandler.Get(_stringManager.StartUrl);

            //Logindaten senden^^
            Logger.Log(LoggingCategories.NavigationAction, "Sending Login Data");
            this._lastResult = HttpHandler.Post(_stringManager.LoginUrl, _stringManager.LoginParameter);

            //Nach Logout Link suchen... falls vorhanden => login war erfolgreich, sonst nicht
            if (!Regex.IsMatch(LastResult.ResponseContent, _stringManager.LogoutRegex))
            {
                throw new LoginFailedException("Login failed (LogoutRegex) not found");
            }

            Logger.Log(LoggingCategories.NavigationAction, "Login was successfull");

            //@CANNAP: DEIN PLANET AUSLESEN KRAM HAT BEI MIR GECRASHT

            //Todo Prüfen ob ein Gebäude im Bau ist
        }
Пример #9
0
        private List<DetailModel> GetDetails()
        {
            var client = new HttpClient();
            var handler = new HttpHandler<DetailModel>(client);
            handler.Uri = "api/detail";
            var details = handler.Get();

            var List = new List<DetailModel>();

            List.Add(new DetailModel()
            {
                DetailId = "000000",
                Name = "Ingen tilbehør valgt",
            });

            if (details != null)
            {
                if (details.Count > 0)
                {
                    foreach (var item in details)
                    {
                        List.Add(new DetailModel()
                        {
                            DetailId = item.DetailId,
                            Name = item.Name,
                        });
                    }
                }
            }
            
            return List;
        } 
Пример #10
0
        private List<CategoryModel> GetCategories()
        {
            var client = new HttpClient();
            var handler = new HttpHandler<CategoryModel>(client);
            handler.Uri = "api/category";
            var categories = handler.Get();

            var List = new List<CategoryModel>();

            List.Add(new CategoryModel()
            {
                CategoryId = "000000",
                Name = "Ingen kategori valgt"
            });
            
            if (categories != null)
            {
                if (categories.Count > 0)
                {
                    foreach (var item in categories)
                    {
                        List.Add(new CategoryModel()
                        {
                            CategoryId = item.CategoryId,
                            Name = item.Name
                        });
                    }
                }
            }
            else
            {
                List.Add(new CategoryModel()
                {
                    CategoryId = "00000",
                    Name = "Ingen kategorier fundet"
                });
            }

            return List;
        }
Пример #11
0
        internal async Task GetCache()
        {
            try
            {
                await Task.Run(() =>
                {
                    HttpHandler http = new HttpHandler();
                    var postData     = "{\"apiKey\":\"23567b218376f79d9415\"}";

                    dynamic resp = http.Post(Config.Url + "/auth", postData);

                    if (resp == null || resp.token == null)
                    {
                        throw new Exception("Error getting token data");
                    }

                    string token     = Convert.ToString(resp.token);
                    int page         = 1;
                    int imagesByPage = 10;
                    int maxIteration = 100;

                    List <PictureModel> imgList = new List <PictureModel>();

                    while (page < maxIteration)
                    {
                        dynamic respImages = http.Get(Config.Url + "/images?page=" + page, AuthorizationType.Bearer, token, ResultType.JsonObj);

                        if (respImages == null || respImages.pictures == null)
                        {
                            throw new Exception("Error getting image data");
                        }

                        if (respImages.pictures.Count < imagesByPage)
                        {
                            break;
                        }

                        page++;

                        foreach (var item in respImages.pictures)
                        {
                            if (item.id != null && item.cropped_picture != null)
                            {
                                PictureModel img    = new PictureModel();
                                img.Id              = Convert.ToString(item.id);
                                img.Cropped_picture = Convert.ToString(item.cropped_picture);

                                PictureModel m = this.GetImageDetail(token, img);

                                imgList.Add(m);
                            }
                        }
                    }

                    CacheManager cache   = new CacheManager();
                    PictureList pictures = new PictureList();
                    pictures.Pictures    = imgList;

                    cache.SetCache(pictures);
                });
            }
            catch (Exception)
            {
            }
        }
Пример #12
0
 /// <summary>
 /// Navigiert zu einer Ogame-Standard Seite
 /// </summary>
 /// <param name="page">Ogame-Standard Seite</param>
 public HttpResult NagivateToIndexPage(IndexPages page)
 {
     Logger.Log(LoggingCategories.NavigationAction, "NagivateToIndexPage(" + _stringManager.IndexPageNames [page] + ")");
     return(this._lastResult = HttpHandler.Get(this._stringManager.GetIndexPageUrl(page)));
 }