Esempio n. 1
0
 public IEnumerable <RoomDataContract> GetRooms(string lat, string lon, string ticket)
 {
     try
     {
         var connector   = GetConnector(ticket);
         var roomsNearby = connector.GetFilteredRooms();
         if (string.IsNullOrEmpty(lat) || string.IsNullOrEmpty(lon))
         {
             var availableRooms = connector.GetAvaialility(roomsNearby).Where(a => a.Availability != TimeInterval.Zero).Take(MaxRoomsInResponse);
             return(availableRooms.Select(Convertions.ToContract));
         }
         else
         {
             double latitude;
             double longitude;
             if (!double.TryParse(lat, out latitude) || !double.TryParse(lon, out longitude))
             {
                 throw new WebFaultException <string>($"Invalid {nameof(lat)} or {nameof(lon)} values", HttpStatusCode.BadRequest);
             }
             var loc = new Location
             {
                 // TODO: real elevation
                 Geometry = new Geometry(latitude, longitude, 120.0)
             };
             var availableRooms = connector.GetAvaialility(LocationResolver.ResolveLocations(roomsNearby));
             availableRooms = LocationResolver.SmartSort(availableRooms, loc).Take(MaxRoomsInResponse);
             return(availableRooms.Select(Convertions.ToContract));
         }
     }
     catch (WebFaultException <string> )
     {
         throw;
     }
     catch (Exception ex)
     {
         throw new WebFaultException <string>(ex.Message, HttpStatusCode.InternalServerError);
     }
 }
Esempio n. 2
0
        private void startButton_Click(object sender, EventArgs e)
        {
            choicesListView.Items.Clear();
            choicesListView.Refresh();

            try
            {
                // TODO: need progress bar

                var roomsNearby        = _connector.GetFilteredRooms();
                var roomsWithLocations = _locations.ResolveLocations(roomsNearby);

                var results = _locations.SmartSort(_connector.GetAvaialility(roomsWithLocations)
                                                   .Where(room => room.Availability != TimeInterval.Zero), _myLocation)
                              .ToArray();

                choicesListView.BeginUpdate();
                foreach (var result in results)
                {
                    var item = choicesListView.Items.Add(new ListViewItem(new[]
                    {
                        result.Room.Name,
                        FormatLocation(result.Room.Location),
                        FormatAvailableIn((int)(result.Availability.Start - DateTime.Now).TotalMinutes),
                        FormatAvailableFor((int)result.Availability.Duration.TotalMinutes)
                    }));
                    item.Tag = result.Room;
                }
                choicesListView.EndUpdate();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                Application.Exit();
            }
        }