protected override void OnIncomingHandlableMessage(IRequestMessage message, EntityInteractionRequestPayload payload, IMessageParameters parameters, InstanceClientSession peer) { if (Logger.IsDebugEnabled) { Logger.Debug($"Recieved interaction request for {payload.NetworkGuid.EntityId}."); } if (EntityCollection.ContainsKey(payload.NetworkGuid)) { IWorldInteractable interactable = EntityCollection[payload.NetworkGuid]?.WorldObject?.GetComponent <IWorldInteractable>(); if (interactable == null) { if (Logger.IsWarnEnabled) { Logger.Warn($"Recieved interaction request for entity that can't be interacted with ID: {payload.NetworkGuid.EntityId} Type: {payload.NetworkGuid.EntityType} from NetId: {peer.PeerDetails.ConnectionID}."); } } else { interactable.TryInteract(GuidLookupService.Lookup(peer.PeerDetails.ConnectionID)); } } else if (Logger.IsWarnEnabled) { Logger.Warn($"Recieved interaction request for unknown entity ID: {payload.NetworkGuid.EntityId} Type: {payload.NetworkGuid.EntityType} from NetId: {peer.PeerDetails.ConnectionID}."); } }
/// <summary> /// Retourne l'entité ayant l'id donné. /// </summary> /// <param name="id"></param> /// <returns></returns> public EntityBase GetEntityById(int id) { if (!m_entities.ContainsKey(id)) { return(null); } return(m_entities[id]); }
/// <summary> /// Returns the entity based on the Key. /// </summary> /// <param name="key"></param> /// <returns></returns> public IEntity GetEntity(string key) { if (EntityCollection.ContainsKey(key)) { return(EntityCollection[key]); } return(null); }
public void SetUpTiles() { if (HasSetUpTiles) { return; } foreach (Tile tile in GetComponentsInChildren <Tile>()) { tile.ParentBoard = this; LocalTileCollection[tile.EntityPosition] = tile; WorldTileCollection[tile.GetPosition()] = tile; } // Parse the board and look for the entities using the parser BoardEntities = GetComponentInChildren <EntityParser>(true); if (BoardEntities == null) { Debug.LogWarning("No Entities present on board. This means that the board is a pure open terrain."); return; } foreach (EnemyUnit unit in BoardEntities.GetEnemyUnits()) { unit.SetPosition(new Point(unit.GetPosition().x + (BoardDimensions.x * BoardOffset), 0, unit.GetPosition().z)); if (EnemyCollection.ContainsKey(unit.GetPosition())) { continue; } EnemyCollection.Add(unit.GetPosition(), unit); } foreach (EnviromentalUnit unit in BoardEntities.GetEntities()) { unit.SetUpPosition(BoardOffset, BoardDimensions.x); if (EntityCollection.ContainsKey(unit.GetPosition())) { continue; } EntityCollection.Add(unit.GetPosition(), unit); } HasSetUpTiles = true; }
public void TestCreateAndRemoveAppsInNamespace() { Service service = Connect(); EntityCollection <Application> apps = service.GetApplications(); String appname1 = "sdk-app1"; String appname2 = "sdk-app2"; Assert.IsFalse(apps.ContainsKey(appname1), "Expected app " + appname1 + " to not be in the collection"); Assert.IsFalse(apps.ContainsKey(appname2), "Expected app " + appname2 + " to not be in the collection"); // Create apps SetupApps(apps, appname1, appname2); Assert.IsTrue(apps.ContainsKey(appname1), "Expected app to contain " + appname1); Assert.IsTrue(apps.ContainsKey(appname2), "Expected app to contain " + appname2); // Remove apps CleanupApps(apps, appname1, appname2); Assert.IsFalse(apps.ContainsKey(appname1), "Expected app " + appname1 + " to be removed"); Assert.IsFalse(apps.ContainsKey(appname1), "Expected app " + appname2 + " to be removed"); }
public void ConfCRUD() { Service service; string app = "sdk-tests"; string owner = "nobody"; // Create a fresh app to use as the container for confs that we will // create in this test. There is no way to delete a conf once it's // created so we make sure to create in the context of this test app // and then we delete the app when we are done to make everything go // away. this.CreateApp(app); service = this.Connect(); Assert.IsTrue(service.GetApplications().ContainsKey(app), assertRoot + "#8"); // Create an app specific service instance Args args = new Args(this.SetUp().Opts); args.Add("app", app); args.Add("owner", owner); service = Service.Connect(args); ConfCollection confs = service.GetConfs(); Assert.IsFalse(confs.ContainsKey("testconf"), assertRoot + "#9"); confs.Create("testconf"); Assert.IsTrue(confs.ContainsKey("testconf"), assertRoot + "#10"); EntityCollection <Entity> stanzas = confs.Get("testconf"); Assert.AreEqual(0, stanzas.Size, assertRoot + "#11"); stanzas.Create("stanza1"); stanzas.Create("stanza2"); stanzas.Create("stanza3"); Assert.AreEqual(3, stanzas.Size, assertRoot + "#12"); Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#13"); Assert.IsTrue(stanzas.ContainsKey("stanza2"), assertRoot + "#14"); Assert.IsTrue(stanzas.ContainsKey("stanza3"), assertRoot + "#15"); // Grab the new stanza and check its content Entity stanza1 = stanzas.Get("stanza1"); Assert.IsFalse(stanza1.IsEmpty, "Expected stanza1 to be non-empty"); Assert.AreEqual(5, stanza1.Size, "Expected stanza1 to have 5 elements"); Assert.AreEqual("nobody", stanza1.Get("eai:userName"), assertRoot + "#16"); Assert.AreEqual(app, stanza1.Get("eai:appName"), assertRoot + "#17"); Assert.IsFalse(stanza1.ContainsKey("key1"), assertRoot + "#18"); Assert.IsFalse(stanza1.ContainsKey("key2"), assertRoot + "#19"); Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#20"); // Add a couple of properties args = new Args(); args.Add("key1", "value1"); args.Add("key2", 42); stanza1.Update(args); // Make sure the properties showed up Assert.AreEqual("value1", stanza1.Get("key1"), assertRoot + "#21"); Assert.AreEqual("42", stanza1.Get("key2"), assertRoot + "#22"); Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#23"); // Update an existing property args = new Args(); args.Add("key1", "value2"); stanza1.Update(args); // Make sure the updated property shows up (and no other changes). Assert.AreEqual("value2", stanza1.Get("key1"), assertRoot + "#24"); Assert.AreEqual("42", stanza1.Get("key2"), assertRoot + "#25"); Assert.IsFalse(stanza1.ContainsKey("key3"), assertRoot + "#26"); Assert.IsTrue(stanza1.ContainsValue("value2"), "Expected stanza1 to contain the value value2"); Assert.IsTrue(stanza1.ContainsValue("42"), "Expected stanza1 to contain the value 42"); // Delete the stanzas stanzas.Remove("stanza3"); Assert.AreEqual(2, stanzas.Size, assertRoot + "#27"); Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#28"); Assert.IsTrue(stanzas.ContainsKey("stanza2"), assertRoot + "#29"); Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#30"); stanzas.Remove("stanza2"); Assert.AreEqual(1, stanzas.Size, assertRoot + "#31"); Assert.IsTrue(stanzas.ContainsKey("stanza1"), assertRoot + "#32"); Assert.IsFalse(stanzas.ContainsKey("stanza2"), assertRoot + "#33"); Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#34"); stanzas.Remove("stanza1"); Assert.AreEqual(0, stanzas.Size, assertRoot + "#35"); Assert.IsFalse(stanzas.ContainsKey("stanza1"), assertRoot + "#36"); Assert.IsFalse(stanzas.ContainsKey("stanza2"), assertRoot + "#37"); Assert.IsFalse(stanzas.ContainsKey("stanza3"), assertRoot + "#38"); // Cleanup after ourselves this.RemoveApp(app); }
public void IndexAccessors() { string indexName = "sdk-tests2"; Service service = Connect(); DateTimeOffset offset = new DateTimeOffset(DateTime.Now); string now = DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss") + string.Format("{0}{1} ", offset.Offset.Hours.ToString("D2"), offset.Offset.Minutes.ToString("D2")); ServiceInfo info = service.GetInfo(); // set can_delete if not set, so we can delete events from the index. User user = service.GetUsers().Get("admin"); string[] roles = user.Roles; if (!this.Contains(roles, "can_delete")) { string[] newRoles = new string[roles.Length + 1]; roles.CopyTo(newRoles, 0); newRoles[roles.Length] = "can_delete"; user.Roles = newRoles; user.Update(); } EntityCollection <Index> indexes = service.GetIndexes(); foreach (Index idx in indexes.Values) { int dummyInt; string dummyString; bool dummyBool; DateTime dummyTime; dummyBool = idx.AssureUTF8; dummyString = idx.BlockSignatureDatabase; dummyInt = idx.BlockSignSize; dummyInt = idx.BloomfilterTotalSizeKB; dummyString = idx.ColdPath; dummyString = idx.ColdPathExpanded; dummyString = idx.ColdToFrozenDir; dummyString = idx.ColdToFrozenScript; dummyBool = idx.CompressRawdata; dummyInt = idx.CurrentDBSizeMB; dummyString = idx.DefaultDatabase; dummyBool = idx.EnableRealtimeSearch; dummyInt = idx.FrozenTimePeriodInSecs; dummyString = idx.HomePath; dummyString = idx.HomePathExpanded; dummyString = idx.IndexThreads; dummyTime = idx.LastInitTime; dummyString = idx.MaxBloomBackfillBucketAge; dummyInt = idx.MaxConcurrentOptimizes; dummyString = idx.MaxDataSize; dummyInt = idx.MaxHotBuckets; dummyInt = idx.MaxHotIdleSecs; dummyInt = idx.MaxHotSpanSecs; dummyInt = idx.MaxMemMB; dummyInt = idx.MaxMetaEntries; dummyInt = idx.MaxRunningProcessGroups; dummyTime = idx.MaxTime; dummyInt = idx.MaxTotalDataSizeMB; dummyInt = idx.MaxWarmDBCount; dummyString = idx.MemPoolMB; dummyString = idx.MinRawFileSyncSecs; dummyTime = idx.MinTime; dummyInt = idx.NumBloomfilters; dummyInt = idx.NumHotBuckets; dummyInt = idx.NumWarmBuckets; dummyInt = idx.PartialServiceMetaPeriod; dummyInt = idx.QuarantineFutureSecs; dummyInt = idx.QuarantinePastSecs; dummyInt = idx.RawChunkSizeBytes; dummyInt = idx.RotatePeriodInSecs; dummyInt = idx.ServiceMetaPeriod; dummyString = idx.SuppressBannerList; dummyInt = idx.Sync; dummyBool = idx.SyncMeta; dummyString = idx.ThawedPath; dummyString = idx.ThawedPathExpanded; dummyInt = idx.ThrottleCheckPeriod; dummyInt = idx.TotalEventCount; dummyBool = idx.IsDisabled; dummyBool = idx.IsInternal; } if (!indexes.ContainsKey(indexName)) { indexes.Create(indexName); indexes.Refresh(); } Assert.IsTrue(indexes.ContainsKey(indexName), assertRoot + "#1"); Index index = indexes.Get(indexName); Args indexProperties = GetIndexProperties(index); // use setters to update most index.BlockSignSize = index.BlockSignSize + 1; if (service.VersionCompare("4.3") > 0) { index.EnableOnlineBucketRepair = !index.EnableOnlineBucketRepair; index.MaxBloomBackfillBucketAge = "20d"; } index.FrozenTimePeriodInSecs = index.FrozenTimePeriodInSecs + 1; index.MaxConcurrentOptimizes = index.MaxConcurrentOptimizes + 1; index.MaxDataSize = "auto"; index.MaxHotBuckets = index.MaxHotBuckets + 1; index.MaxHotIdleSecs = index.MaxHotIdleSecs + 1; index.MaxMemMB = index.MaxMemMB + 1; index.MaxMetaEntries = index.MaxMetaEntries + 1; index.MaxTotalDataSizeMB = index.MaxTotalDataSizeMB + 1; index.MaxWarmDBCount = index.MaxWarmDBCount + 1; index.MinRawFileSyncSecs = "disable"; index.PartialServiceMetaPeriod = index.PartialServiceMetaPeriod + 1; index.QuarantineFutureSecs = index.QuarantineFutureSecs + 1; index.QuarantinePastSecs = index.QuarantinePastSecs + 1; index.RawChunkSizeBytes = index.RawChunkSizeBytes + 1; index.RotatePeriodInSecs = index.RotatePeriodInSecs + 1; index.ServiceMetaPeriod = index.ServiceMetaPeriod + 1; index.SyncMeta = !index.SyncMeta; index.ThrottleCheckPeriod = index.ThrottleCheckPeriod + 1; index.Update(); // check, then restore using map method index.Update(indexProperties); index.Refresh(); ClearIndex(service, indexName, index); index.Disable(); Assert.IsTrue(index.IsDisabled); this.SplunkRestart(); service = this.Connect(); index = service.GetIndexes().Get(indexName); user = service.GetUsers().Get("admin"); index.Enable(); Assert.IsFalse(index.IsDisabled); // Restore original roles user.Roles = roles; user.Update(); }
public void Application() { string dummyString; bool dummyBool; int dummyInt; Service service = Connect(); EntityCollection <Application> apps = service.GetApplications(); foreach (Application app in apps.Values) { try { ApplicationSetup applicationSetup = app.Setup(); string setupXml = applicationSetup.SetupXml; } catch (Exception) { // silent exception, if setup doesn't exist, exception occurs } ApplicationArchive applicationArchive = app.Archive(); dummyString = app.Author; dummyBool = app.CheckForUpdates; dummyString = app.Description; dummyString = app.Label; dummyBool = app.Refreshes; dummyString = app.Version; dummyBool = app.IsConfigured; if (service.VersionCompare("5.0") < 0) { dummyBool = app.IsManageable; } dummyBool = app.IsVisible; dummyBool = app.StateChangeRequiresRestart; ApplicationUpdate applicationUpdate = app.AppUpdate(); dummyString = applicationUpdate.Checksum; dummyString = applicationUpdate.ChecksumType; dummyString = applicationUpdate.Homepage; dummyInt = applicationUpdate.UpdateSize; dummyString = applicationUpdate.UpdateName; dummyString = applicationUpdate.AppUrl; dummyString = applicationUpdate.Version; dummyBool = applicationUpdate.IsImplicitIdRequired; } if (apps.ContainsKey("sdk-tests")) { service = this.CleanApp("sdk-tests", service); } apps = service.GetApplications(); Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#1"); Args createArgs = new Args(); createArgs.Add("author", "me"); if (service.VersionCompare("4.2.4") >= 0) { createArgs.Add("configured", false); } createArgs.Add("description", "this is a description"); createArgs.Add("label", "SDKTEST"); if (service.VersionCompare("5.0") < 0) { createArgs.Add("manageable", false); } createArgs.Add("template", "barebones"); createArgs.Add("visible", false); apps.Create("sdk-tests", createArgs); Assert.IsTrue(apps.ContainsKey("sdk-tests"), assertRoot + "#2"); Application app2 = apps.Get("sdk-tests"); dummyBool = app2.CheckForUpdates; Assert.AreEqual("SDKTEST", app2.Label, assertRoot + "#3"); Assert.AreEqual("me", app2.Author, assertRoot + "#4"); Assert.IsFalse(app2.IsConfigured, assertRoot + "#5"); if (service.VersionCompare("5.0") < 0) { Assert.IsFalse(app2.IsManageable, assertRoot + "#6"); } Assert.IsFalse(app2.IsVisible, assertRoot + "#7"); // update the app app2.Author = "not me"; app2.Description = "new description"; app2.Label = "new label"; app2.IsVisible = false; if (service.VersionCompare("5.0") < 0) { app2.IsManageable = false; } app2.Version = "5.0.0"; app2.Update(); // check to see if args took. Assert.AreEqual("not me", app2.Author, assertRoot + "#8"); Assert.AreEqual("new description", app2.Description, assertRoot + "#9"); Assert.AreEqual("new label", app2.Label, assertRoot + "#10"); Assert.IsFalse(app2.IsVisible, assertRoot + "#11"); Assert.AreEqual("5.0.0", app2.Version, assertRoot + "#12"); // archive (package) the application ApplicationArchive appArchive = app2.Archive(); Assert.IsTrue(appArchive.AppName.Length > 0, assertRoot + "#13"); Assert.IsTrue(appArchive.FilePath.Length > 0, assertRoot + "#14"); Assert.IsTrue(appArchive.Url.Length > 0, assertRoot + "#15"); ApplicationUpdate appUpdate = app2.AppUpdate(); Assert.IsTrue(appUpdate.ContainsKey("eai:acl"), assertRoot + "#16"); service = this.CleanApp("sdk-tests", service); apps = service.GetApplications(); Assert.IsFalse(apps.ContainsKey("sdk-tests"), assertRoot + "#17"); }