public Data.VisitsResponse MakeVisitsRequest(string requestUrl) { HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest; request.Credentials = new NetworkCredential(Properties.Settings.Default.UriUserName, Properties.Settings.Default.UriPassword); using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(String.Format( "Server error (HTTP {0}: {1}).", response.StatusCode, response.StatusDescription)); } using (var reader = new StreamReader(response.GetResponseStream())) { JavaScriptSerializer js = new JavaScriptSerializer(); string objText = reader.ReadToEnd(); objText = "{\"visits\":" + objText + "}"; object objResponse = (Data.VisitsResponse)js.Deserialize(objText, typeof(Data.VisitsResponse)); Data.VisitsResponse jsonResponse = objResponse as Data.VisitsResponse; return(jsonResponse); } } }
private void CheckVisits(Models.Queue que) { Requests request = new Requests(); string visitRequest = request.CreateVisitsRequest(que.branchId.ToString(), que.id.ToString()); Data.VisitsResponse visitsResponse = request.MakeVisitsRequest(visitRequest); _viewModel.DataContext.Visits = request.ProcessVisitsResponse(que, visitsResponse); }
public Page1() { InitializeComponent(); try { //Process requests: Requests request = new Requests(); //Branches string branchesRequest = request.CreateBranchesRequest(); Data.BranchesResponse bracnhesResponse = request.MakeBranchesRequest(branchesRequest); _viewModel.DataContext.Branches = request.ProcessBranchesResponse(bracnhesResponse); //Queues foreach (Data.Branches branch in _viewModel.DataContext.Branches) { string queuesRequest = request.CreateQueuesRequest(branch.id.ToString()); Data.QueuesResponse queuesResponse = request.MakeQueuesRequest(queuesRequest); if (_viewModel.DataContext.Queues == null) { _viewModel.DataContext.Queues = request.ProcessQueuesResponse(queuesResponse); } else { _viewModel.DataContext.Queues.AddRange(request.ProcessQueuesResponse(queuesResponse)); } } //Visits (must also be able to refresh) foreach (Models.Queue que in _viewModel.DataContext.Queues) { string visitRequest = request.CreateVisitsRequest(que.branchId.ToString(), que.id.ToString()); Data.VisitsResponse visitsResponse = request.MakeVisitsRequest(visitRequest); if (_viewModel.DataContext.Visits == null) { _viewModel.DataContext.Visits = request.ProcessVisitsResponse(que, visitsResponse); } else { _viewModel.DataContext.Visits.AddRange(request.ProcessVisitsResponse(que, visitsResponse)); } } DataContext = _viewModel; } catch (Exception e) { MessageBox.Show(e.Message); } }
public List <QueVisit> ProcessVisitsResponse(Models.Queue queuesResponse, Data.VisitsResponse visitsResponse) { List <QueVisit> visits = new List <QueVisit>(); foreach (Data.Visits visit in visitsResponse.visits) { visits.Add(new QueVisit { branchId = queuesResponse.branchId, queId = queuesResponse.branchId, waitingTime = visit.waitingTime, ticketNumber = visit.ticketNumber, customerName = visit.customerName, appointmentWaitingTime = visit.appointmentWaitingTime, serviceName = visit.serviceName }); } return(visits); }