public async Task <IndexViewModel> Getbuslocations(DateTime date) { session = _sesionService.GetOrCreate(); Client.DefaultRequestHeaders.Accept.Clear(); var request = new HttpRequestMessage(HttpMethod.Post, "/api/location/getbuslocations"); var sessionPostData = new BuslocationsRequestModel(); sessionPostData.device_session = new BuslocationsRequestModel.DeviceSession() { device_id = session.Data.DeviceId, session_id = session.Data.SessionId }; sessionPostData.date = date.ObiletDateFormat(); sessionPostData.language = "tr-TR"; var payload = JsonConvert.SerializeObject(sessionPostData); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); request.Content = content; var response = await Client.SendAsync(request); var resultContent = await response.Content.ReadAsStringAsync(); IndexViewModel indexViewModel = new IndexViewModel(); BuslocationsResponseModel buslocation = JsonConvert.DeserializeObject <BuslocationsResponseModel>(resultContent); indexViewModel.OutDestination = GetLocaitonOutDestination(buslocation); indexViewModel.InDestination = GetLocaitonInDestination(buslocation); return(indexViewModel); }
public SessionResponseModel GetOrCreate() { SessionResponseModel sesion = new SessionResponseModel(); string SessionId = context.Session.GetString("SessionId"); if (SessionId == null) { sesion = CreateSesion().Result; var item = _cache.GetOrCreate(sesion.Data.SessionId, cacheEntry => { cacheEntry.SlidingExpiration = TimeSpan.FromHours(1); cacheEntry.Value = sesion; return(sesion); }); context.Session.SetString("SessionId", sesion.Data.SessionId); } else { sesion = (SessionResponseModel)_cache.Get(SessionId); if (sesion == null) { sesion = CreateSesion().Result; var item = _cache.GetOrCreate(SessionId, cacheEntry => { cacheEntry.SlidingExpiration = TimeSpan.FromHours(1); cacheEntry.Value = sesion; return(sesion); }); sesion = item; } } return(sesion); }
public static async Task <HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Anonymous, "post")] HttpRequestMessage req, TraceWriter log) { try { log.Info("C# HTTP trigger function processed a request."); var data = await RequestDecoder.Decode <SessionCreatePostModel>(req); try { var jwt = Jwt.Decode(data.password); if (jwt.subject != data.username) { throw new Exception("Username/JWT-subject mismatch"); } } catch { throw new HttpResponseException(req.CreateErrorResponse(HttpStatusCode.Forbidden, "Forbidden")); } var response = new SessionResponseModel { id = Guid.NewGuid().ToString("N"), username = data.username }; return(req.CreateResponse(HttpStatusCode.OK, response)); } catch (HttpResponseException error) { return(error.Response); } }
public async Task <SessionResponseModel> CreateSesion() { client = _clientServices.GetClient(); requestModel = new SessionRequestModel(); string useragent = context.Request.Headers["User-Agent"]; UserAgent ua = new UserAgent(useragent); requestModel.type = 1; requestModel.browser = new SessionRequestModel.Browser() { name = ua.Browser.Name, version = ua.Browser.Version }; if (env.IsDevelopment()) { requestModel.connection = new SessionRequestModel.Connection() { ip_address = "145.214.41.21", port = _config.Port }; } else { requestModel.connection = new SessionRequestModel.Connection() { ip_address = FindIpAddress().ToString(), port = _config.Port }; } var request = new HttpRequestMessage(HttpMethod.Post, "/api/client/getsession"); var payload = JsonConvert.SerializeObject(requestModel); HttpContent content = new StringContent(payload, Encoding.UTF8, "application/json"); request.Content = content; var response = await client.SendAsync(request); var resultContent = await response.Content.ReadAsStringAsync(); SessionResponseModel sessionResponseModel = JsonConvert.DeserializeObject <SessionResponseModel>(resultContent); return(sessionResponseModel); }
public async Task <JourneysResponseModel> Getbusjourneys(DateTime date, DateTime departure_date, int destination_id, int origin_id) { session = _sesionService.GetOrCreate(); Client.DefaultRequestHeaders.Accept.Clear(); var request = new HttpRequestMessage(HttpMethod.Post, "/api/journey/getbusjourneys"); var journeysRequestModel = new JourneysRequestModel(); journeysRequestModel.device_session = new DeviceSession() { DeviceId = session.Data.DeviceId, SessionId = session.Data.SessionId }; journeysRequestModel.data = new Data() { departure_date = departure_date.ObiletDateFormat(), destination_id = destination_id, origin_id = origin_id }; journeysRequestModel.date = date.ObiletDateFormat(); journeysRequestModel.language = "tr-TR"; string body = JsonConvert.SerializeObject(journeysRequestModel); StringContent content = new StringContent(body); content.Headers.ContentType = new MediaTypeWithQualityHeaderValue("application/json"); try { var response = await Client.PostAsync("/api/journey/getbusjourneys", content).Result.Content.ReadAsStringAsync(); JourneysResponseModel obje = JsonConvert.DeserializeObject <JourneysResponseModel>(response); return(obje); } catch (Exception ex) { var hata = ex.ToString(); return(null); } }