public void TestParseCoordinateDecimalDegree() { String coordinateString = " 13.7628° N 100.478100° E"; GeoPoint geoPoint = new GeoPoint(coordinateString); var expected = new GeoPoint(13.7628, 100.478100); Assert.IsTrue(expected.Equals(geoPoint), String.Format("Expected {0}, returned {1}", expected, geoPoint)); }
public void TestParseCoordinateDegMinSec() { String coordinateString = " 13°45'46.08\" N 100°28'41.16\" E"; GeoPoint geoPoint = new GeoPoint(coordinateString); var expected = new GeoPoint(13.7628, 100.478100); Assert.IsTrue(expected.Equals(geoPoint), String.Format("Expected {0}, returned {1}", expected, geoPoint)); }
public void TestDatumConversion() { // example as of http://www.colorado.edu/geography/gcraft/notes/datum/gif/molodens.gif GeoPoint point = new GeoPoint(30, -100, 232, GeoDatum.DatumNorthAmerican27MeanConus()); point.Datum = GeoDatum.DatumWGS84(); GeoPoint expected = new GeoPoint(30.0002239, -100.0003696, 194.816, GeoDatum.DatumWGS84()); Assert.IsTrue(expected.Equals(point)); }
public void TestGeoPointCopyConstructor() { GeoPoint basePoint = new GeoPoint(_LatitudeBangkok, _LongitudeBangkok, _AltitudeBangkok, GeoDatum.DatumWGS84()); GeoPoint clonePoint = new GeoPoint(basePoint); Assert.IsTrue(basePoint.Equals(clonePoint)); // Assert.AreEqual<GeoPoint>(lClonePoint, lBasePoint); // does not use the IEquatable }
public void TestGeoHashToGeo() { GeoPoint geoPoint = new GeoPoint(); geoPoint.GeoHash = _BangkokGeoHash; GeoPoint expected = new GeoPoint(_LatitudeBangkok, _LongitudeBangkok); Assert.IsTrue(expected.Equals(geoPoint)); }
public void TestMaidenheadToGeo() { GeoPoint geoPoint = new GeoPoint(); geoPoint.Maidenhead = _BangkokMaidenhead; GeoPoint expected = new GeoPoint(_LatitudeBangkok, _LongitudeBangkok); Assert.IsTrue(expected.Equals(geoPoint), String.Format("Expected {0}, returned {1}", expected, geoPoint)); }
public void TestUTMToGeo() { // Dresden according to Wikipedia : 13° 44' 29"E 51° 02' 55"N = UTM 33U 0411777 5655984 UtmPoint utmPoint = new UtmPoint("33U 0411777 5655984"); GeoPoint geoPoint = new GeoPoint(utmPoint, GeoDatum.DatumWGS84()); GeoPoint expected = new GeoPoint(51.0 + 02.0 / 60.0 + 55.0 / 3600.0, 13.0 + 44.0 / 60.0 + 29.0 / 3600.0); Assert.IsTrue(expected.Equals(geoPoint)); }
public void Equals_WithEqualValues_ReturnsFalse() { // Arrange var point1 = new GeoPoint(-43.2126812, -22.951911); var point2 = new GeoPoint(-43.2126812, -22.951911); // Act var result = point1.Equals((object)point2); // Assert Assert.True(result); }
public void Equals_WithDifferentValues_ReturnsFalse() { // Arrange var point1 = new GeoPoint(-43.2126812, -22.951911); var point2 = new GeoPoint(-43.1589638, -22.9492483); // Act var result = point1.Equals((object)point2); // Assert Assert.False(result); }
public void Equality() { GeoPoint g1 = new GeoPoint(1.5, 2.5); // Equal GeoPoint g2 = new GeoPoint(1.5, 2.5); // Difference in latitude GeoPoint g3 = new GeoPoint(2.5, 2.5); // Difference in longitude GeoPoint g4 = new GeoPoint(1.5, 3.5); // Equals(GeoPoint) Assert.True(g1.Equals(g2)); Assert.False(g1.Equals(g3)); Assert.False(g1.Equals(g4)); // Equals(object) Assert.True(g1.Equals((object)g2)); Assert.False(g1.Equals((object)g3)); Assert.False(g1.Equals((object)g4)); Assert.True(g1 == g2); Assert.False(g1 == g3); Assert.False(g1 == g4); Assert.False(g1 == null); Assert.False(g1 != g2); Assert.True(g1 != g3); Assert.True(g1 != g4); Assert.True(g1 != null); Assert.Equal(g1.GetHashCode(), g2.GetHashCode()); Assert.NotEqual(g1.GetHashCode(), g3.GetHashCode()); Assert.NotEqual(g1.GetHashCode(), g4.GetHashCode()); }
/** * @return true if the first and the last GeoPoint of this polygonal chain are equal, false otherwise. */ public bool isClosed () { lock (this.GeoPoints) { int numberOfGeoPoints = this.GeoPoints.Count; if (numberOfGeoPoints < 2) { return false; } GeoPoint GeoPointFirst = this.GeoPoints[0]; GeoPoint GeoPointLast = this.GeoPoints[numberOfGeoPoints - 1]; return GeoPointFirst.Equals(GeoPointLast); } }
private int InsertOrGetId(GeoPoint item, IDbConnection db) { string latitude = item.Latitude.ToString().Replace(",", "."); string longitude = item.Longitude.ToString().Replace(",", "."); string sql = @"SELECT * FROM GeoPoints " + $"WHERE Latitude = {latitude} AND Longitude = {longitude};" + @"SELECT CAST(SCOPE_IDENTITY() as int);"; var point = db.Query <GeoPoint>(sql).SingleOrDefault(); if (item.Equals(point)) { return(point.Id); } else { return(Insert(item, db)); } }
public async Task <IActionResult> Run( [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] HttpRequest req, ILogger logger, CancellationToken token) { return(await req.Wrap <ReindeerRescueRequest>(logger, async request => { if (request == null) { return new BadRequestErrorMessageResult("Request is empty."); } if (string.IsNullOrWhiteSpace(request.Id)) { return new BadRequestErrorMessageResult($"Missing required value for property '{nameof(ReindeerRescueRequest.Id)}'."); } if (!Guid.TryParse(request.Id, out Guid id)) { return new BadRequestErrorMessageResult($"Value for property '{nameof(ReindeerRescueRequest.Id)}' is not a valid ID or has an invalid format (example of valid value and format for Unique Identifier (GUID): '135996C9-3090-4399-85DB-1F5041DF1DDD')."); } Attempt attempt = await _attemptService.Get(id, 2, token); if (attempt == null) { return new NotFoundResult(); } if (!attempt.SantaRescueAt.HasValue) { return new BadRequestErrorMessageResult($"It looks like you're reusing an old ID from a previous failed attempt created {attempt.Created} - you need to start all over again - remember not to hard code any IDs in your application."); } if (attempt.ReindeerInZones == null) { throw new InvalidOperationException($"Missing value for '{nameof(attempt.ReindeerInZones)}' on attempt with Id '{attempt.Id}'."); } var messages = new List <string>(); if (request.Locations == null) { messages.Add($"Missing required value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}'."); } else if (request.Locations.Length > attempt.ReindeerInZones.Length) { messages.Add($"Invalid value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}'. Expected a maximum number of locations to be {attempt.ReindeerInZones.Length} - but was {request.Locations.Length}."); } else { for (int i = 0; i < attempt.ReindeerInZones.Length; i++) { ReindeerInZone zone = attempt.ReindeerInZones[i]; ReindeerRescueRequest.ReindeerLocation locationInRequest = request.Locations?.ElementAtOrDefault(i); if (locationInRequest == null) { messages.Add($"Missing required value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}]'."); } else if (string.IsNullOrWhiteSpace(locationInRequest.Name)) { messages.Add($"Missing required value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}].{nameof(ReindeerRescueRequest.ReindeerLocation.Name).WithFirstCharToLowercase()}'"); } else if (locationInRequest.Name.Length >= 100) { messages.Add($"Invalid value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}].{nameof(ReindeerRescueRequest.ReindeerLocation.Name).WithFirstCharToLowercase()}' - length exceeds maximum of 100 characters."); } else if (!string.Equals(locationInRequest.Name, zone.Reindeer.ToString())) { messages.Add($"Expected name of Reindeer for '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}].{nameof(ReindeerRescueRequest.ReindeerLocation.Name).WithFirstCharToLowercase()}' to be '{zone.Reindeer}' - but was '{locationInRequest.Name}'."); } else if (locationInRequest.Position == null) { messages.Add($"Missing required value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}].{nameof(ReindeerRescueRequest.ReindeerLocation.Position).WithFirstCharToLowercase()}'"); } else { Point center = new Point(zone.Center.Lon, zone.Center.Lat); double radiusInMeter = zone.Radius.InMeter(); string name = zone.Reindeer.ToString(); var feedOptions = new FeedOptions { PartitionKey = new PartitionKey(zone.CountryCode), MaxItemCount = 1 }; ObjectInLocationForCosmosDb actualReindeer = _documentClient .CreateDocumentQuery <ObjectInLocationForCosmosDb>(UriFactory.CreateDocumentCollectionUri("World", "Objects"), feedOptions) .Where(u => u.Name == name && center.Distance(u.Location) <= radiusInMeter) .AsEnumerable() .FirstOrDefault(); if (actualReindeer == null) { throw new InvalidOperationException($"Reindeer '{name}' not found for zone {zone.Center}, Country {zone.CountryCode}."); } GeoPoint actualPosition = actualReindeer.GetLocation(); if (!actualPosition.Equals(locationInRequest.Position)) { messages.Add($"Invalid value for property '{nameof(ReindeerRescueRequest.Locations).WithFirstCharToLowercase()}[{i}].{nameof(ReindeerRescueRequest.ReindeerLocation.Position).WithFirstCharToLowercase()}'. Reindeer '{zone.Reindeer}' was not found at {locationInRequest.Position} - actual position is {actualPosition}."); } } } } if (messages.Count > 0) { attempt.InvalidReindeerRescue = messages.ToArray(); await _attemptService.Save(attempt, 3, token); return new BadRequestErrorMessageResult($@"Unfortunately one or more reindeer was not at the specified locations. Below is the detailed rescue report from the extraction team: {string.Join(Environment.NewLine, messages.Select(x => $"\t - {x}"))} Please try again - and remember since the reindeer has probably moved their locations by now, you'll have to start all over again."); } attempt.ReindeersRescueAt = DateTimeOffset.UtcNow; Uri problemUri = await _toyDistributionProblemRepository.Save(attempt, ToyDistributionProblem.Create(), token); await _attemptService.Save(attempt, 3, token); return new OkObjectResult(new ReindeerRescueResponse(problemUri)); })); }
/// <summary> /// 根据提供的组id获取设备信息,id为-1表示获取所有 /// </summary> /// <param name="devices">out 设备集合</param> /// <param name="groupid">组id</param> public static void GetDevices(out List <Device> devices, int groupid = -1, string geoid = null, string deviceid = null) { LogHelper.MainLog("GetDevices1 time:" + DateTime.Now.TimeOfDay); devices = new List <Device>(); var points = new List <GeoPoint>(); DataSet set; #region sql语句 StringBuilder sqlBuilder = new StringBuilder(); sqlBuilder.Append("SELECT * FROM (SELECT A.DeviceID,A.DeviceName,A.DeviceType,"); sqlBuilder.Append("A.DeviceRegCode,A.FactoryNum,A.PhoneLevel,A.DeviceTypeInfo,"); sqlBuilder.Append("A.DeviceIP,A.DevicePort,A.SoftVersion,A.HardVersion,A.Manufacturer,A.GeoId,A.GroupID,"); sqlBuilder.Append("B.ExtensionID AS ExtenID,B.ExtensionNo AS ExtenNO,B.StateID AS StateID,B.PhoneState,B.PanelNum "); sqlBuilder.Append("FROM ipvt_deviceinfotable AS A left join ipvt_extensionmessagetable AS B "); sqlBuilder.Append("on A.ExtensionID=B.ExtensionID where 1=1"); if (groupid != -1) { sqlBuilder.Append(" AND A.GroupID=" + groupid); } if (!string.IsNullOrEmpty(geoid)) { sqlBuilder.Append(" AND (A.GroupID=" + geoid + " or A.DeviceIP='" + deviceid + "' )"); } sqlBuilder.Append(") AS C "); sqlBuilder.Append(@" LEFT JOIN ipvt_geoinfotable AS D ON C.GeoId=D.GeoID LEFT JOIN ipvt_panelinfotable as E on C.ExtenID=E.ExtensionID ORDER BY ExtenID,E.PanelNum"); #endregion #region 获取设备集 try { set = CustomMySqlHelper.ExecuteDataSet(sqlBuilder.ToString()); if (set.Tables.Count > 0) { DataRowCollection rows = set.Tables[0].Rows; foreach (DataRow row in rows) { int id = EvaluationHelper.ObjectToInt(row["DeviceID"]); if (!devices.Exists(m => m.Id == id)) { var device = new Device(); device.Name = EvaluationHelper.ObjectToString(row["DeviceName"]); device.Id = EvaluationHelper.ObjectToInt(row["DeviceID"]); device.Type = EvaluationHelper.ObjectToInt(row["DeviceType"]); device.Ip = EvaluationHelper.ObjectToString(row["DeviceIP"]); device.PhoneLevel = EvaluationHelper.ObjectToInt(row["PhoneLevel"]); device.RegistCode = EvaluationHelper.ObjectToString(row["DeviceRegCode"]); device.SoftVersion = EvaluationHelper.ObjectToString(row["SoftVersion"]); device.HardVersion = EvaluationHelper.ObjectToString(row["HardVersion"]); device.DeviceTypeInfo = EvaluationHelper.ObjectToString(row["DeviceTypeInfo"]); if (string.IsNullOrEmpty(device.DeviceTypeInfo) || device.DeviceTypeInfo == "IP-Center" || device.DeviceTypeInfo == "IP-Phone") { device.Generation = 1; } else { device.Generation = 2; } device.ColorString = GetColor(device.DeviceTypeInfo); if (row["GroupID"] != DBNull.Value) { device.GroupId = EvaluationHelper.ObjectToInt(row["GroupID"]); } device.Port = EvaluationHelper.ObjectToInt(row["DevicePort"]); device.Extension = new Extension { Number = EvaluationHelper.ObjectToString(row["ExtenNO"]), Id = EvaluationHelper.ObjectToInt(row["ExtenID"]), State = StateManager.GetState(EvaluationHelper.ObjectToInt(row["StateID"])), PhoneState = EvaluationHelper.ObjectToInt(row["PhoneState"]) == 0 ? State.STAT_INVALID : State.STAT_DEVICE_TALKING, PanelNum = EvaluationHelper.ObjectToString(row["PanelNum"]) }; if (string.IsNullOrEmpty(device.Name)) //如果名称为空给设备添加默认名称=分机号 { device.Name = EvaluationHelper.ObjectToString(row["ExtenNO"]); } GeoPoint pnt = new GeoPoint(); if (row["GeoId"] != DBNull.Value) { pnt.Id = EvaluationHelper.ObjectToInt(row["GeoId"]); bool flag = false; foreach (var p in points) { if (pnt.Equals(p)) { pnt = p; flag = true; break; } } if (!flag) { pnt.Id = EvaluationHelper.ObjectToInt(row["GeoID"]); pnt.Name = EvaluationHelper.ObjectToString(row["Name"]); pnt.Address = EvaluationHelper.ObjectToString(row["FormattedAddress"]); pnt.Phone = EvaluationHelper.ObjectToString(row["phone"]); pnt.Latitude = EvaluationHelper.ObjectToDouble(row["Latitude"]); pnt.Longitude = EvaluationHelper.ObjectToDouble(row["Longitude"]); pnt.Note = EvaluationHelper.ObjectToString(row["Note"]); } } device.GeoPoint = pnt; device.Manufacturer = EvaluationHelper.ObjectToString(row["Manufacturer"]); if (!string.IsNullOrEmpty(EvaluationHelper.ObjectToString(row["PanelID"]))) { var panel = new PanelDevice(); //面板对象 panel.Id = EvaluationHelper.ObjectToInt(row["PanelID"]); //面板号 panel.Number = EvaluationHelper.ObjectToInt(row["PanelNum1"]); //面板号 int stateNum = EvaluationHelper.ObjectToInt(row["PanelState"]); //面板状态号 switch (stateNum) { case 0: panel.LineState = State.STAT_DEVICE_ONLINE; //在线 break; case 1: panel.LineState = State.STAT_DEVICE_OFFLINE; //离线 break; } int alarmState = EvaluationHelper.ObjectToInt(row["TamperAlarm"]); if (alarmState == 2) { panel.State = State.STAT_ANTI_DISMANTLE_ALARM; //防拆警报 } else { panel.State = panel.LineState; } panel.Name = EvaluationHelper.ObjectToString(row["PanelName"]); //面板名 if (string.IsNullOrEmpty(panel.Name)) { panel.Name = string.Format("面板{0}", panel.Number); } if (device.Extension.State == State.STAT_DEVICE_OFFLINE) { panel.State = State.STAT_DEVICE_OFFLINE; } else if (panel.State == State.STAT_ANTI_DISMANTLE_ALARM) { device.Extension.AlarmState = State.STAT_ANTI_DISMANTLE_ALARM; } device.Panels.Add(panel); } devices.Add(device); } else { if (!string.IsNullOrEmpty(EvaluationHelper.ObjectToString(row["PanelID"]))) { Device device = devices.Find(m => m.Id == id); var panel = new PanelDevice(); //面板对象 panel.Id = EvaluationHelper.ObjectToInt(row["PanelID"]); //面板号 panel.Number = EvaluationHelper.ObjectToInt(row["PanelNum1"]); //面板号 int stateNum = EvaluationHelper.ObjectToInt(row["PanelState"]); //面板状态号 switch (stateNum) { case 0: panel.LineState = State.STAT_DEVICE_ONLINE; //在线 break; case 1: panel.LineState = State.STAT_DEVICE_OFFLINE; //离线 break; } int alarmState = EvaluationHelper.ObjectToInt(row["TamperAlarm"]); if (alarmState == 2) { panel.State = State.STAT_ANTI_DISMANTLE_ALARM; //防拆警报 } else { panel.State = panel.LineState; } panel.Name = EvaluationHelper.ObjectToString(row["PanelName"]); //面板名 if (string.IsNullOrEmpty(panel.Name)) { panel.Name = string.Format("面板{0}", panel.Number); } if (device.Extension.State == State.STAT_DEVICE_OFFLINE) { panel.State = State.STAT_DEVICE_OFFLINE; } else if (panel.State == State.STAT_ANTI_DISMANTLE_ALARM) { device.Extension.AlarmState = State.STAT_ANTI_DISMANTLE_ALARM; } device.Panels.Add(panel); } } } } } catch (Exception ex) { LogHelper.MainLog("error int GetDevices!" + ex); } #endregion LogHelper.MainLog("GetDevices2 time:" + DateTime.Now.TimeOfDay); //#region 获取设备的面板信息 //foreach (Device dev in devices) //{ // List<PanelDevice> list; // GetPanels(dev.Extension.Id, out list); // //LogHelper.MainLog(string.Format("GetDevices(int groupid = -1),ExtensionNumber:{1} --- PanelNum:{0}", list.Count, dev.Extension.Number)); // foreach (PanelDevice panel in list) // { // if (dev.Extension.State == State.STAT_DEVICE_OFFLINE) // { // panel.State = State.STAT_DEVICE_OFFLINE; // } // else if (panel.State == State.STAT_ANTI_DISMANTLE_ALARM) // { // dev.Extension.AlarmState = State.STAT_ANTI_DISMANTLE_ALARM; // } // dev.Panels.Add(panel); // } //} //#endregion //LogHelper.MainLog("GetDevices3 time:" + DateTime.Now.TimeOfDay); //#region 获取转移信息 //foreach (Device dev in devices) //{ // if (dev.Type == 0) //刷选寻呼话筒 // { // List<Transfer> trans; // TransferTableManager.GetTransferTableByExtension(out trans, dev.Extension); //转移信息集合 // foreach (Transfer tran in trans) // { // dev.TransferTable.Add(tran); // } // } //} //#endregion //LogHelper.MainLog("GetDevices4 time:" + DateTime.Now.TimeOfDay); points.Clear(); }