public void TestAuthenticateNegative() { string UserName = "******"; string Password = "******"; string result = WebApiCaller.GetUserToken(UserName, Password); Assert.IsTrue(string.IsNullOrEmpty(result)); }
public void TestGetProducts() { string UserName = "******"; string Password = "******"; string result = WebApiCaller.GetUserToken(UserName, Password); Product[] products = WebApiCaller.GetProducts(result); Assert.IsNotNull(products); }
public ActionResult UpdateFlight(FlightModel model) { if (ModelState.IsValid) { string postBody = JsonConvert.SerializeObject(model); var response = WebApiCaller.CallSyncStatement(Config.RessourceEndPoint, WebApiRoutes.UpdateFlightListActionName, postBody); } return(RedirectToAction("index", "Flight")); }
/// <summary> /// Get countries from webapi /// </summary> /// <returns></returns> private List <CountryModel> GetCountriesList() { var response = WebApiCaller.RunGetSyncStatement(Config.RessourceEndPoint, WebApiRoutes.GetAllCountriesListActionName); List <CountryModel> countriesList = new List <CountryModel>(); if (response.IsSuccessStatusCode) { string responseString = response.Content.ReadAsStringAsync().Result; countriesList = JsonConvert.DeserializeObject <List <CountryModel> >(responseString); } return(countriesList); }
public ActionResult ListProduct() { if (System.Web.HttpContext.Current.Session["access_token"] != null) { string token = (string)System.Web.HttpContext.Current.Session["access_token"]; Product[] products = WebApiCaller.GetProducts(token); return(View(products)); } else { return(View("ViewProduct")); } }
/// <summary> /// Get detail flight by Id /// </summary> /// <param name="id"></param> /// <returns></returns> private FlightModel GetFlightById(int id) { var response = WebApiCaller.RunGetSyncStatement(Config.RessourceEndPoint, WebApiRoutes.GetFlightByIdActionName + id.ToString()); FlightModel flight = new FlightModel(); if (response.IsSuccessStatusCode) { string responseString = response.Content.ReadAsStringAsync().Result; flight = JsonConvert.DeserializeObject <FlightModel>(responseString); } return(flight); }
public ActionResult Login(string username, string password) { string access_token = WebApiCaller.GetUserToken(username, password); if (!string.IsNullOrEmpty(access_token)) { System.Web.HttpContext.Current.Session["access_token"] = access_token; return(RedirectToAction("ViewProduct", "Home")); } else { return(RedirectToAction("Login", "Home")); } }
public async Task <ObservableCollection <ProjectLocation> > RetrieveProjectList() { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.ProjectListFormat))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); // ObservableCollection <ProjectLocation> _obj = JsonConvert.DeserializeObject <ObservableCollection <ProjectLocation> >(data); return(_obj); }
public async Task <DGObject> Retrieve(int key) { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.DGObjectByIDFormat, domainType.ToLower(), dgobjectName.ToLower(), projectID, key))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); // DGObject objHelper = ObjectHelper.CreateDGObjectFromSubclassName(dgobjectName); var _obj = JsonConvert.DeserializeObject(data, objHelper.GetType()); return(_obj as DGObject); }
//获取对象列表 public async Task <List <DGObject> > GetAllByObjs(string filter) { //网络请求 string result = await Task.Run(() => WebApiCaller.HttpGet(ServiceConfig.BaseURL + string.Format(ServiceConfig.DGObjectListFormat, domainType.ToLower(), dgobjectName.ToLower(), projectID, iS3.Core.APIMessageConverter.EnCode(filter)))); // JObject obj = JObject.Parse(result); string data = obj["data"].ToString(); JArray objList = JArray.Parse(data); // if (subclasses == null) { subclasses = from assembly in AppDomain.CurrentDomain.GetAssemblies() from type in assembly.GetTypes() where type.IsSubclassOf(typeof(DGObject)) select type; } // match the subclassName with full name at first Type t = subclasses.FirstOrDefault(x => x.FullName == dgobjectName); // if not found, match the subclassName with name if (t == null) { t = subclasses.FirstOrDefault(x => x.Name == dgobjectName); } List <DGObject> list = new List <DGObject>(); foreach (JToken token in objList) { var _obj = JsonConvert.DeserializeObject(token.ToString(), t); list.Add(_obj as DGObject); } return(list); }
public ClientiController() { strUri = $"http//localhost:52244/api/"; caller = new WebApiCaller(); }
public TestControllerCaller(WebApiCaller webApiCaller) { _caller = webApiCaller; }
public TestControllerCaller(string apiUrl, DataFormat dataFormat = DataFormat.Json) { _caller = new WebApiCaller(apiUrl, dataFormat); }
static Program() { _webApiCaller = new WebApiCaller(Url); }
private static void GoRankCollector(int pEndPage) { // 1. BJ 수집 int endPage = pEndPage; var categoryRankParser = new CategoryRankParser(); var resultBjModels = new List <RankBjModel>(); foreach (RankingType rankingType in Enum.GetValues(typeof(RankingType))) { for (int i = 1; i <= endPage; i++) { var bjModels = categoryRankParser.GetData(rankingType, i); if (resultBjModels.Count <= 0) { resultBjModels.AddRange(bjModels); continue; } foreach (var bj in bjModels) { //기존 BJ 없다면 새로 추가 if (!resultBjModels.Any(b => b.BjID == bj.BjID)) { resultBjModels.Add(bj); continue; } // 기존 BJ 있으면 기존 BJ에 담고 해당 랭크만 채우기 foreach (var resultBjModel in resultBjModels) { if (resultBjModel.BjID != bj.BjID) { continue; } categoryRankParser.SetTargetRank(bj, resultBjModel, rankingType); } } } } // 2. 사용자 수집 var bjPagePaser = new BjPagePaser(); var resultUserModel = new List <RankUserModel>(); var resultBjInfo = new List <BjInfoModel>(); // BJ 수집 리스트 루프 돌기 foreach (var BjModel in resultBjModels) { // BJ 정보 var BjInfo = bjPagePaser.GetBjInfo(BjModel); resultBjInfo.AddRange(BjInfo); // 열혈팬 Top20 var bigFans = bjPagePaser.GetBigFans(BjModel.BjID); resultUserModel.AddRange(bigFans); // 서포터 Top20 var supporters = bjPagePaser.GetSupporters(BjModel.BjID); resultUserModel.AddRange(supporters); } ; var bizSettings = new BizRankCollectorSettings(); var Settings = bizSettings.GetSettings(); var bizBjRank = new BizBjRank(Settings); bizBjRank.SetInitBjValues(); bizBjRank.SetBjModels(resultBjModels); foreach (var userModel in resultUserModel) { var bjModel = resultBjModels.Find(b => b.BjID == userModel.BjID); userModel.BjNic = bjModel.BjNick; } var bizUserRank = new BizUserRank(Settings); bizUserRank.SetInitUserValues(); bizUserRank.SetUserModels(resultUserModel); bizUserRank.SetInitBjInfoValues(); bizUserRank.SetBjInfoModels(resultBjInfo); bizSettings.SetAferSettings(); ; var jsonModel = new JsonModel() { Text = "rfsStart" }; var webApiCaller = new WebApiCaller(); var result = webApiCaller.RefreshAsync(jsonModel).ConfigureAwait(true); }