Esempio n. 1
0
		private void MainForm_Load(object sender, EventArgs e)
		{
			try
			{
				var props = Properties.Settings.Default;
				_connector = new ExchangeConnector.ExchangeConnector(props.email);

				string currentSite = props.currentSite;
				_locations = new LocationResolver();
				_locations.Load("locationMap.csv");
				_connector.LocationFilter = _locations.OfSite(currentSite).ToArray(); // filter locations by site
				_connector.Connect();

				_myLocation = new Location
				{
					Site =  props.currentSite,
					Building = props.currentBuilding,
					Floor = props.currentFloor
				};
			}
			catch (Exception ex)
			{
				MessageBox.Show(ex.Message);
				Application.Exit();
			}
		}
Esempio n. 2
0
		private static Location CreateLocation(string[] items)
		{
			var location = new Location
			{
				Site = items[1],
				Building = items[2],
				Floor = items[3]
			};
			if (items.Length == 7)
			{
				location.Geometry = new Geometry(
					float.Parse(items[4]), float.Parse(items[5]), float.Parse(items[6]));
			}
			return location;
		}
Esempio n. 3
0
		public void DistanceTest()
		{
			var locs = new[]
			{
				new Geometry(37.324761, -121.999824, 120.0),
				new Geometry(37.324761, -121.999824, 140.0),
				new Geometry(37.325322, -121.997707, 140.0),
				new Geometry(37.326043, -121.998811, 120.0),
				new Geometry(37.326043, -121.998811, 140.0),
				new Geometry(37.325911, -122.000898, 120.0),
				new Geometry(37.325911, -122.000898, 140.0),
				new Geometry(37.324953, -121.998867, 120.0),
				new Geometry(37.324953, -121.998867, 140.0)
			};

			var me = new Location { Geometry = new Geometry(37.324761, -121.999824, 120.0) };

			foreach (var loc in locs)
			{
				Debug.WriteLine(Distance.Calculate(me, new Location { Geometry = loc }));
			}
		}
Esempio n. 4
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. 5
0
		private static readonly double DefaultDistanceBetweenRooms = 20.0; // 20 m

		public static double Calculate(Location from, Location to)
		{
			if (from == null || to == null)
			{
				return DefaultDistanceBetweenSites;
			}
			if (from.Geometry == null || to.Geometry == null)
			{
				if (from.Site != to.Site)
				{
					return DefaultDistanceBetweenSites;
				}
				if (from.Building != to.Building)
				{
					return DefaultDistanceBetweenBuildings;
				}
				if (from.Floor != to.Floor)
				{
					return DefaultDistanceBetweenFloors;
				}
				return DefaultDistanceBetweenRooms;
			}
			return CalculateP(from.Geometry, to.Geometry) + Math.Abs(from.Geometry.Elevation - to.Geometry.Elevation);
		}
Esempio n. 6
0
		public SmartSearch(Location location)
		{
			_comparer = new SmartRoomComparer(location);
		}
Esempio n. 7
0
		private static string FormatLocation(Location location)
		{
			return $"{location.Building} {location.Floor}";
		}
Esempio n. 8
0
		public IEnumerable<RoomAvailabilityInfo> SmartSort(IEnumerable<RoomAvailabilityInfo> rooms, Location myLocation)
		{
			return new SmartSearch(myLocation).Sort(rooms);
		}