void NewUser(UserData newUser) { Client client = ScenePrivate.FindAgent(newUser.User).Client; // CommandReceived will be called every time the command it triggered on the client // CommandCanceled will be called if the subscription fails if (SubscribeCommand != "") { client.SubscribeToCommand(SubscribeCommand, CommandAction.Pressed, (data) => { if (subscription == null) { Log.Write(GetType().Name, $"[{SubscribeCommand}] Subscribing to {ActionCommand}."); subscription = client.SubscribeToCommand(ActionCommand, CommandAction.All, CommandReceived, CommandCanceled); } }, CommandCanceled); } if (UnsubscribeCommand != "") { client.SubscribeToCommand(UnsubscribeCommand, CommandAction.Pressed, (data) => { if (subscription != null) { Log.Write(GetType().Name, $"[{UnsubscribeCommand}] Unsubscribing to {ActionCommand}."); subscription.Unsubscribe(); subscription = null; } }, CommandCanceled); } }
void AddUser(UserData data) { try { AgentPrivate newUser = ScenePrivate.FindAgent(data.User); if (IsBanned(newUser)) { Wait(TimeSpan.FromSeconds(2)); bool admin = IsAdmin(newUser); IEventSubscription timerEvent = Timer.Create(TimeSpan.FromSeconds(admin? 300 : 10), () => { Bannish(newUser); }); WaitFor(newUser.Client.UI.ModalDialog.Show, "You are banned." + (admin ? "\n( ;) )" : ""), admin ? "You can't ban me!" : "Okay", "Bye"); if (timerEvent.Active) { timerEvent.Unsubscribe(); } if (newUser.Client.UI.ModalDialog.Response == "You can't ban me!") { Banned.Remove(newUser.AgentInfo.Handle.ToLower()); return; } Bannish(newUser); } } catch (NullReferenceException nre) { if (DebugSpam) { Log.Write("AddUser", nre.Message); } } // ignore exceptions for not found agents. catch (Exception e) { if (DebugSpam) { Log.Write("AddUser", e.ToString()); } } }
private void getBeatBlockcfg(ScriptEventData gotBlockcfg) { SendBlockNamescfg sendBlockcfg = gotBlockcfg.Data.AsInterface <SendBlockNamescfg>(); BeatBlockName = sendBlockcfg.SendBlockArraycfg[0]; beats = sendBlockcfg.SendBlockArraycfg[1]; BlockGenre = sendBlockcfg.SendBlockArraycfg[2]; BeatBlockConfigSub.Unsubscribe(); }
private void RemoveUser(UserData data) { trackedEvents.Remove(data.User); if (trackedEvents.Count == 0) { timer.Unsubscribe(); timer = null; } }
void Disable() { if (TimerSub != null) { TimerSub.Unsubscribe(); TimerSub = null; } if (TimerCoroutine != null) { TimerCoroutine.Abort(); TimerCoroutine = null; } }
private void Unsubscribe(ScriptEventData data) { if (sitSubscribe != null) { sitSubscribe.Unsubscribe(); sitSubscribe = null; } if (standSubscribe != null) { standSubscribe.Unsubscribe(); standSubscribe = null; } }
private void Unsubscribe(ScriptEventData data) { if (unsubscribes != null) { unsubscribes(); unsubscribes = null; } if (grabSubscribe != null) { grabSubscribe.Unsubscribe(); } if (releaseSubscribe != null) { releaseSubscribe.Unsubscribe(); } }
private void stopYt(bool blank) { if (ytTimer != null) { ytTimer.Unsubscribe(); ytTimer = null; } else { Log.Write(LogLevel.Warning, GetType().Name, $"No ytTimer Active"); } if (blank) { ScenePrivate.OverrideMediaSource("about:blank"); } }
public async Task Should_reopen_subscription_once_if_exception_is_retrieved() { await OnErrorAsync(eventSubscription, new InvalidOperationException()); await Task.Delay(1000); sut.Unsubscribe(); A.CallTo(() => eventSubscription.Unsubscribe()) .MustHaveHappened(2, Times.Exactly); A.CallTo(() => eventStore.CreateSubscription(A <IEventSubscriber> ._, A <string> ._, A <string> ._)) .MustHaveHappened(2, Times.Exactly); A.CallTo(() => eventSubscriber.OnErrorAsync(eventSubscription, A <Exception> ._)) .MustNotHaveHappened(); }
private void getSamplescfg(ScriptEventData gotSamplescfg) { if (gotSamplescfg.Data == null) { Log.Write(LogLevel.Warning, Script.ID.ToString(), "Expected non-null event data"); return; } SendSamplescfg sendSamplescfg = gotSamplescfg.Data.AsInterface <SendSamplescfg>(); if (sendSamplescfg == null) { Log.Write(LogLevel.Error, Script.ID.ToString(), "Unable to create interface, check logs for missing member(s)"); return; } //Log.Write("Raver: Sample Count: " + sendSamplescfg.SendSampleLibrarycfg.Count()); Sample1 = sendSamplescfg.SendSampleLibrarycfg.ElementAt(0); BeatBlockSampleConfigSub.Unsubscribe(); }
private async Task <IReadOnlyList <StoredEvent>?> QueryWithSubscriptionAsync(string streamFilter, Func <Task>?action = null, bool fromBeginning = false) { var subscriber = new EventSubscriber(); IEventSubscription?subscription = null; try { subscription = Sut.CreateSubscription(subscriber, streamFilter, fromBeginning ? null : subscriptionPosition); if (action != null) { await action(); } using (var cts = new CancellationTokenSource(30000)) { while (!cts.IsCancellationRequested) { subscription.WakeUp(); await Task.Delay(500, cts.Token); if (subscriber.Events.Count > 0) { subscriptionPosition = subscriber.LastPosition; return(subscriber.Events); } } cts.Token.ThrowIfCancellationRequested(); return(null); } } finally { subscription?.Unsubscribe(); } }
public async Task Should_stop_subscription_if_stopped() { await sut.ActivateAsync(consumerName); await sut.ActivateAsync(); await sut.StopAsync(); await sut.StopAsync(); await sut.CompleteAsync(); AssertGrainState(isStopped: true, position: initialPosition); A.CallTo(() => grainState.WriteAsync()) .MustHaveHappenedOnceExactly(); A.CallTo(() => eventSubscription.Unsubscribe()) .MustHaveHappenedOnceExactly(); }
public override void Init() { if (!ObjectPrivate.TryGetFirstComponent(out _rb)) { Log.Write(LogLevel.Error, "HeldObjectCommandScript can't find a RigidBodyComponent!"); return; } if (!_rb.GetCanGrab()) { Log.Write(LogLevel.Error, "HeldObjectCommandScript isn't on a grabbable object!"); return; } // Subscribe to the "PrimaryAction" action when the object is picked up _rb.SubscribeToHeldObject(HeldObjectEventType.Grab, (HeldObjectData holdData) => { AgentPrivate agent = ScenePrivate.FindAgent(holdData.HeldObjectInfo.SessionId); if (agent != null && agent.IsValid) { _commandSubscription = agent.Client.SubscribeToCommand("PrimaryAction", CommandAction.Pressed, (CommandData command) => { Log.Write(agent.AgentInfo.Name + " pressed the button while holding the object!"); }, (canceledData) => { }); } }); // Unsubscribe from the "PrimaryAction" action when the object is dropped _rb.SubscribeToHeldObject(HeldObjectEventType.Release, (HeldObjectData holdData) => { if (_commandSubscription != null) { _commandSubscription.Unsubscribe(); _commandSubscription = null; } }); }
public async Task Should_stop_subscription_when_stopped() { await sut.ActivateAsync(consumerName); await sut.ActivateAsync(); await sut.StopAsync(); await sut.StopAsync(); await sut.CompleteAsync(); AssetGrainState(new EventConsumerState { IsStopped = true, Position = initialPosition, Error = null }); A.CallTo(() => grainState.WriteAsync()) .MustHaveHappenedOnceExactly(); A.CallTo(() => eventSubscription.Unsubscribe()) .MustHaveHappenedOnceExactly(); }
public override void Init() { if (!ObjectPrivate.TryGetFirstComponent(out _rb)) { Log.Write(LogLevel.Error, "FlashlightScript can't find a RigidBodyComponent!"); return; } if (!ObjectPrivate.TryGetFirstComponent(out _light) || _light.IsScriptable) { } _rb.SubscribeToHeldObject(HeldObjectEventType.Grab, (HeldObjectData holdData) => { AgentPrivate agent = ScenePrivate.FindAgent(holdData.HeldObjectInfo.SessionId); if (agent != null && agent.IsValid) { _commandSubscription = agent.Client.SubscribeToCommand("PrimaryAction", CommandAction.Pressed, (CommandData command) => { // Do }, (canceledData) => { }); } } _rb.SubscribeToHeldObject(HeldObjectEventType.Release, (HeldObjectData holdData) => { if (_commandSubscription != null) { _commandSubscription.Unsubscribe(); _commandSubscription = null; } }); }
public void Unsubscribe() { eventSubscription.Unsubscribe(); }
private static async Task WaitAndStopAsync(IEventSubscription sut) { await Task.Delay(200); sut.Unsubscribe(); }