/// <summary> /// Checks if the region exists. /// </summary> /// <param name="region">The name of the region that needs to be checked.</param> /// <returns>If the region exists or not.</returns> public virtual bool ContainsRegion(string region) { lock (_mutex) { return(Regions.ContainsKey(region)); } }
private Region LoadOrGenerateRegion(Coordinates2D coordinates, bool generate = true) { if (Regions.ContainsKey(coordinates)) { return((Region)Regions[coordinates]); } if (!generate) { return(null); } Region region; if (BaseDirectory != null) { var file = Path.Combine(BaseDirectory, Region.GetRegionFileName(coordinates)); if (File.Exists(file)) { region = new Region(coordinates, this, file); } else { region = new Region(coordinates, this); } } else { region = new Region(coordinates, this); } lock (Regions) Regions[coordinates] = region; return(region); }
void LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { CLLocation lastLocation = e.Locations[e.Locations.Length - 1]; SetLastKnownLocation(lastLocation); if (Regions.Count > 20 && locationManager.MonitoredRegions.Count == 20) { RecalculateRegions(); } else { //Check any current monitored regions not in loaded persistent regions and stop monitoring them foreach (CLCircularRegion region in locationManager.MonitoredRegions) { if (!Regions.ContainsKey(region.Identifier)) { locationManager.StopMonitoring(region); string message = string.Format("{0} - Stopped monitoring region {1} wasn't in persistent loaded regions", CrossGeofence.Id, region.Identifier); System.Diagnostics.Debug.WriteLine(message); } } } System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2},{3}", CrossGeofence.Id, "Location update", lastLocation.Coordinate.Latitude, lastLocation.Coordinate.Longitude)); }
void OnRegionLeft(CLRegion region) { if (!mGeofenceResults.ContainsKey(region.Identifier)) { mGeofenceResults.Add(region.Identifier, new GeofenceResult() { RegionId = region.Identifier }); } if (LastKnownLocation != null) { mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude; mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude; mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy; } else { mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude; mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude; mGeofenceResults[region.Identifier].Accuracy = region.Radius; } mGeofenceResults[region.Identifier].LastExitTime = DateTime.Now; mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Exited; CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]); if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowExitNotification) { CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationExitMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationExitMessage); } }
public Region LookupRegion(string name) { var n = name.NormalizeId(); if (Regions.ContainsKey(n)) { return(Regions[n]); } return(null); }
public void UnloadChunk(Coordinates2D coordinates) { var regionPosition = ChunkCoordinatesToRegion(coordinates); if (!Regions.ContainsKey(regionPosition)) { throw new ArgumentOutOfRangeException("coordinates"); } Regions[regionPosition].UnloadChunk(new Coordinates2D(coordinates.X - regionPosition.X * 32, coordinates.Z - regionPosition.Z * 32)); }
/// <summary> /// Gets the region depending on the region position. /// </summary> /// <returns>The region.</returns> /// <param name="regionPosition">Region position.</param> public Region GetRegion(RegionPosition regionPosition) { if (Regions.ContainsKey(regionPosition)) { return(Regions[regionPosition]); } var region = new Region(regionPosition); return(region); }
public Chunk GetChunkWithoutGeneration(Coordinates2D coordinates) { var regionPosition = ChunkCoordinatesToRegion(coordinates); if (!Regions.ContainsKey(regionPosition)) { return(null); } return(Regions[regionPosition].GetChunkWithoutGeneration( new Coordinates2D(coordinates.X - regionPosition.X * 32, coordinates.Z - regionPosition.Z * 32))); }
public void SendFKPM(FKPMGene fkp) { if (Genes.ContainsKey(fkp.gene)) { Genes [fkp.gene].SendFKPM(fkp.fkpm); } if (Regions.ContainsKey(fkp.gene)) { Regions [fkp.gene].SendFKPM(fkp.fkpm); } }
public void UnloadChunk(Coordinates2D coordinates) { int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0); int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0); var regionPosition = new Coordinates2D(regionX, regionZ); if (!Regions.ContainsKey(regionPosition)) { throw new ArgumentOutOfRangeException("coordinates"); } Regions[regionPosition].UnloadChunk(new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32)); }
void OnRegionEntered(CLRegion region) { if (GeofenceResults.ContainsKey(region.Identifier) && GeofenceResults[region.Identifier].Transition == GeofenceTransition.Entered) { return; } if (!mGeofenceResults.ContainsKey(region.Identifier)) { mGeofenceResults.Add(region.Identifier, new GeofenceResult() { RegionId = region.Identifier }); } if (LastKnownLocation != null) { mGeofenceResults[region.Identifier].Latitude = LastKnownLocation.Latitude; mGeofenceResults[region.Identifier].Longitude = LastKnownLocation.Longitude; mGeofenceResults[region.Identifier].Accuracy = LastKnownLocation.Accuracy; } else { mGeofenceResults[region.Identifier].Latitude = region.Center.Latitude; mGeofenceResults[region.Identifier].Longitude = region.Center.Longitude; mGeofenceResults[region.Identifier].Accuracy = region.Radius; } mGeofenceResults[region.Identifier].LastEnterTime = DateTime.Now; mGeofenceResults[region.Identifier].LastExitTime = null; mGeofenceResults[region.Identifier].Transition = GeofenceTransition.Entered; if (mRegions.ContainsKey(region.Identifier)) { region.NotifyOnEntry = mRegions[region.Identifier].NotifyOnEntry; } if (region.NotifyOnEntry) { CrossGeofence.GeofenceListener.OnRegionStateChanged(mGeofenceResults[region.Identifier]); if (Regions.ContainsKey(region.Identifier) && Regions[region.Identifier].ShowNotification && Regions[region.Identifier].ShowEntryNotification) { CreateNotification(ViewAction, string.IsNullOrEmpty(Regions[region.Identifier].NotificationEntryMessage) ? GeofenceResults[region.Identifier].ToString() : Regions[region.Identifier].NotificationEntryMessage); } } Task.Factory.StartNew(async() => { //Checks if device has stayed asynchronously await CheckIfStayed(region.Identifier); }); }
public Chunk GetChunkWithoutGeneration(Coordinates2D coordinates) { int regionX = coordinates.X / Region.Width - ((coordinates.X < 0) ? 1 : 0); int regionZ = coordinates.Z / Region.Depth - ((coordinates.Z < 0) ? 1 : 0); var regionPosition = new Coordinates2D(regionX, regionZ); if (!Regions.ContainsKey(regionPosition)) { return(null); } return(Regions[regionPosition].GetChunkWithoutGeneration( new Coordinates2D(coordinates.X - regionX * 32, coordinates.Z - regionZ * 32))); }
/// <summary> /// Creates a region. /// </summary> /// <param name="region">The name of the region that is created.</param> /// <returns>If the region has been created successfully or not. Should the region already exist, this method will return false.</returns> public virtual bool CreateRegion(string region) { lock (_mutex) { if (!Regions.ContainsKey(region)) { Regions[region] = new DataRegion <TObject>(); return(true); } } return(false); }
public void Deserialize(GenericReader reader) { var version = reader.GetVersion(); switch (version) { case 0: { Deleted = reader.ReadBool(); Name = reader.ReadString(); Season = reader.ReadInt(); Rules = reader.ReadFlag <MapRules>(); InstanceRegions = reader.ReadBlockList(r => { var t = r.ReadType(); var name = r.ReadString(); var area = r.ReadArray(r1 => r1.ReadRect3D()); if (Regions.ContainsKey(name)) { var reg = Regions[name]; if (!(reg is InstanceRegion ir) || !reg.TypeEquals(t, false) || !reg.Area.ContentsEqual(area, true)) { reg.Unregister(); Regions.Remove(name); } else { ir.Deserialize(r); return(ir); } } return(t.CreateInstanceSafe <InstanceRegion>(name, this, area, r)); }, InstanceRegions); BounceInfo = reader.ReadBlockDictionary(r => { var k = r.ReadMobile <PlayerMobile>(); var v = r.ReadLocation(); return(new KeyValuePair <PlayerMobile, MapPoint>(k, v)); }, BounceInfo); }
public Region getRegion(Vector2 vector2) { vector2 = Game1.getWithinField(vector2); vector2.X -= vector2.X % RegionSize; vector2.Y -= vector2.Y % RegionSize; if (Regions.ContainsKey(vector2)) { return(Regions[vector2]); } else { return(null); } }
public Map AddRegion(Region region) { if (!Regions.ContainsKey(region.Id)) { foreach (var city in region.Cities) { if (Cities.ContainsKey(city.Key)) { throw new Exception("Found city duplicates on the map"); } } //region.MapRef = this; Regions.Add(region.Id, region); } return(this); }
public void SendComponent(string _id, int _start, int _end, Sense sn) { char[] chrs = { '#' }; string[] strs = _id.Split(chrs, 3); if (Genes.ContainsKey(strs [0])) { Genes [strs [0]].AddFileElement(strs [1], _start, _end); } else if (Regions.ContainsKey(strs [0])) { Regions [strs [0]].AddFileElement(strs [1], _start, _end); } else { AddRegion(strs [0], strs [1], _start, _end, sn); } }
/// <summary> /// Returns the chunk at the specific position, but does not generate /// a new chunk if it doesn't already exist. /// </summary> /// <param name="position">Position in chunk coordinates</param> public Chunk GetChunkWithoutGeneration(Vector3 position) { //In chunks var x = (int)position.X; var z = (int)position.Z; //In regions int regionX = x / Region.Width - ((x < 0) ? 1 : 0); int regionZ = z / Region.Depth - ((z < 0) ? 1 : 0); var regionPosition = new Vector3(regionX, 0, regionZ); if (!Regions.ContainsKey(regionPosition)) { return(null); } return(Regions[regionPosition].GetChunkWithoutGeneration(new Vector3(x - regionX * 32, 0, z - regionZ * 32))); }
public void UnloadChunk(int x, int z, bool save) { //In regions int regionX = x / Region.Width - ((x < 0) ? 1 : 0); int regionZ = z / Region.Depth - ((z < 0) ? 1 : 0); var position = new Vector3(regionX, 0, regionZ); if (!Regions.ContainsKey(position)) { return; } var region = Regions[position]; if (save) { region.Save(); } region.UnloadChunk(new Vector3(x - regionX * 32, 0, z - regionZ * 32)); }
private Region CreateOrLoadRegion(Vector3 position) { lock (Regions) { if (!Regions.ContainsKey(position)) { if (Directory == null) { Regions.Add(position, new Region(position, this)); } else { Regions.Add(position, new Region(position, this, Path.Combine(Directory, Region.GetRegionFileName(position)))); } } return(Regions[position]); } }
public bool ContainsTexture(string textureName) { return(Regions.ContainsKey(textureName)); }
/// <summary> /// Geofence plugin iOS implementation /// </summary> public GeofenceImplementation() { mGeofenceResults = new Dictionary <string, GeofenceResult>(); using (var pool = new NSAutoreleasePool()) { pool.InvokeOnMainThread(() => { locationManager = new CLLocationManager(); locationManager.DidStartMonitoringForRegion += DidStartMonitoringForRegion; locationManager.RegionEntered += RegionEntered; locationManager.RegionLeft += RegionLeft; locationManager.Failed += OnFailure; locationManager.DidDetermineState += DidDetermineState; locationManager.LocationsUpdated += LocationsUpdated; }); } string priorityType = "Balanced Power"; switch (CrossGeofence.GeofencePriority) { case GeofencePriority.HighAccuracy: priorityType = "High Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyBest; break; case GeofencePriority.AcceptableAccuracy: priorityType = "Acceptable Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters; break; case GeofencePriority.MediumAccuracy: priorityType = "Medium Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyHundredMeters; break; case GeofencePriority.LowAccuracy: priorityType = "Low Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyKilometer; break; case GeofencePriority.LowestAccuracy: priorityType = "Lowest Accuracy"; locationManager.DesiredAccuracy = CLLocation.AccuracyThreeKilometers; break; default: locationManager.DesiredAccuracy = CLLocation.AccurracyBestForNavigation; break; } System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2}", CrossGeofence.Id, "Location priority set to", priorityType)); if (CrossGeofence.SmallestDisplacement > 0) { locationManager.DistanceFilter = CrossGeofence.SmallestDisplacement; System.Diagnostics.Debug.WriteLine(string.Format("{0} - {1}: {2} meters", CrossGeofence.Id, "Location smallest displacement set to", CrossGeofence.SmallestDisplacement)); } if (locationManager.MonitoredRegions.Count > 0 && IsMonitoring) { NSSet monitoredRegions = locationManager.MonitoredRegions; foreach (CLCircularRegion region in monitoredRegions) { //If not on regions remove on startup since that region was set not persistent if (!Regions.ContainsKey(region.Identifier)) { locationManager.StopMonitoring(region); } else { locationManager.RequestState(region); } } locationManager.StartMonitoringSignificantLocationChanges(); string message = string.Format("{0} - {1} {2} region(s)", CrossGeofence.Id, "Actually monitoring", locationManager.MonitoredRegions.Count); System.Diagnostics.Debug.WriteLine(message); } SetLastKnownLocation(locationManager.Location); }
public async Task TestGenerateInsertScript_DifferentColumnTypes_DefaultFormats() { // Arrange const string tableName = "dbo.Test01"; tableToDrop = tableName; string createTableScript = $"create table {tableName} (" + "Id int identity(1,1) not null, " + "SomeUniqueId uniqueidentifier not null, " + "SomeGuid varchar(64) not null, " + "Country varchar(128) not null, " + "RegionName nvarchar(128) not null, " + "City nvarchar(128) not null, " + "AddressLine1 varchar(256) not null, " + "AddressLine2 varchar(256) not null, " + "LatitudeLongitude varchar(32) not null, " + "SomeTextColumn varchar(128) not null, " + "PersonFullName varchar(16) not null, " + "Email varchar(64) not null, " + "Telephone varchar(16) not null, " + "PassportNo varchar(16) not null, " + "PostalCode varchar(12) not null, " + "WholeValue int not null, " + "DecimalValue decimal not null, " + "FloatValue float not null, " + "BoolValue bit not null, " + "DateTimeValue datetime not null, " + ") on [primary];"; InsertScriptGenerationOptions generationOptions = new InsertScriptGenerationOptions { RowCount = 10 }; IDataGenStrategy strategy = CreateSqlServerDataGenStrategy(); // Act TableInfo tableInfo = await strategy.GetTableInfoAsync(createTableScript); string insertScript = await strategy.GenerateInsertScriptAsync(tableInfo, generationOptions); // Assert Log(createTableScript); Log(insertScript); Assert.IsTrue(tableInfo.Columns.Count > 0); string createInsertScript = createTableScript + Environment.NewLine + insertScript; ExecuteNonQuery(createInsertScript); using (SqlCommand cmd = new SqlCommand($"select * from {tableName}", Connection)) { cmd.CommandType = CommandType.Text; using (SqlDataReader reader = cmd.ExecuteReader()) { int col = 0; int colId = col++; int colGuid = col++; int colGuidString = col++; int colCountry = col++; int colRegion = col++; int colCity = col++; int colAddressLine1 = col++; int colAddressLine2 = col++; int colLatitudeLongitude = col++; int colRandomText = col++; int colFullName = col++; int colEmail = col++; int colPhone = col++; int colPassport = col++; int colPostalCode = col++; int colInt = col++; int colDecimal = col++; int colFloat = col++; int colBoolean = col++; int colDateTime = col++; Assert.AreEqual(col, reader.FieldCount); Assert.AreEqual("int", reader.GetDataTypeName(colId)); Assert.AreEqual("uniqueidentifier", reader.GetDataTypeName(colGuid)); Assert.AreEqual("varchar", reader.GetDataTypeName(colGuidString)); Assert.AreEqual("varchar", reader.GetDataTypeName(colCountry)); Assert.AreEqual("nvarchar", reader.GetDataTypeName(colRegion)); Assert.AreEqual("nvarchar", reader.GetDataTypeName(colCity)); Assert.AreEqual("varchar", reader.GetDataTypeName(colAddressLine1)); Assert.AreEqual("varchar", reader.GetDataTypeName(colAddressLine2)); Assert.AreEqual("varchar", reader.GetDataTypeName(colLatitudeLongitude)); Assert.AreEqual("varchar", reader.GetDataTypeName(colRandomText)); Assert.AreEqual("varchar", reader.GetDataTypeName(colFullName)); Assert.AreEqual("varchar", reader.GetDataTypeName(colEmail)); Assert.AreEqual("varchar", reader.GetDataTypeName(colPhone)); Assert.AreEqual("varchar", reader.GetDataTypeName(colPassport)); Assert.AreEqual("varchar", reader.GetDataTypeName(colPostalCode)); Assert.AreEqual("int", reader.GetDataTypeName(colInt)); Assert.AreEqual("decimal", reader.GetDataTypeName(colDecimal)); Assert.AreEqual("float", reader.GetDataTypeName(colFloat)); Assert.AreEqual("bit", reader.GetDataTypeName(colBoolean)); Assert.AreEqual("datetime", reader.GetDataTypeName(colDateTime)); int rowCount = 0; while (reader.Read()) { for (int i = 0; i < col; i++) { Assert.IsFalse(reader.IsDBNull(i)); } rowCount++; Assert.AreEqual(rowCount, reader.GetInt32(colId)); Guid guid = reader.GetGuid(colGuid); Assert.AreNotEqual(Guid.Empty, guid); string guidString = reader.GetString(colGuidString); Guid guidFromString = Guid.Parse(guidString); Assert.AreNotEqual(Guid.Empty, guidFromString); Assert.AreNotEqual(guid, guidFromString); string country = reader.GetString(colCountry); Assert.IsTrue(Countries.ContainsKey(country), $"Country not found: {country}"); string region = reader.GetString(colRegion); Assert.IsTrue(Regions.ContainsKey(region), $"Region not found: {region}. (Country: {country})"); string city = reader.GetString(colCity); Assert.IsTrue(Cities.ContainsKey(city), $"City not found: {city}. (Country: {country}, Region: {region})"); string addressLine1 = reader.GetString(colAddressLine1); Assert.IsFalse(string.IsNullOrWhiteSpace(addressLine1)); string addressLine2 = reader.GetString(colAddressLine2); Assert.IsFalse(string.IsNullOrWhiteSpace(addressLine2)); string latitudeLongitude = reader.GetString(colLatitudeLongitude); Assert.IsFalse(string.IsNullOrWhiteSpace(latitudeLongitude)); string randomText = reader.GetString(colRandomText); Assert.IsFalse(string.IsNullOrWhiteSpace(randomText)); string fullName = reader.GetString(colFullName); Assert.AreEqual(1, fullName.Count(c => c == ' '), $"Generated Full name: {fullName}"); string email = reader.GetString(colEmail); Assert.IsTrue(IsValidEmail(email), $"Generated Email: {email}"); string phone = reader.GetString(colPhone); Regex regex = new Regex(@"[\d\s]+"); Assert.IsTrue(regex.IsMatch(phone), $"Generated Phone: {phone}"); string passport = reader.GetString(colPassport); regex = new Regex(@"[\d\s]+"); Assert.IsTrue(regex.IsMatch(passport), $"Generated Passport: {passport}"); string postalCode = reader.GetString(colPostalCode); regex = new Regex(@"[\d]+"); Assert.IsTrue(regex.IsMatch(postalCode), $"Generated Postal code: {postalCode}"); int intValue = reader.GetInt32(colInt); Assert.IsTrue(intValue >= 0); decimal decimalNumber = reader.GetDecimal(colDecimal); Assert.IsTrue(decimalNumber >= 0); double floatNumber = reader.GetDouble(colFloat); Assert.IsTrue(floatNumber >= 0); bool boolValue = reader.GetBoolean(colBoolean); Assert.IsTrue(boolValue || !boolValue); DateTime dateTime = reader.GetDateTime(colDateTime); Assert.IsTrue(dateTime > DateTime.Now.AddYears(-10)); Assert.IsTrue(dateTime < DateTime.Now.AddYears(10)); } Assert.AreEqual(generationOptions.RowCount, rowCount); } } }