예제 #1
0
    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);
        }
    }
예제 #2
0
        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());
                                  }
            }
        }
예제 #3
0
    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;
        }
    }
예제 #5
0
        void Disable()
        {
            if (TimerSub != null)
            {
                TimerSub.Unsubscribe();
                TimerSub = null;
            }

            if (TimerCoroutine != null)
            {
                TimerCoroutine.Abort();
                TimerCoroutine = null;
            }
        }
예제 #6
0
        private void Unsubscribe(ScriptEventData data)
        {
            if (sitSubscribe != null)
            {
                sitSubscribe.Unsubscribe();
                sitSubscribe = null;
            }

            if (standSubscribe != null)
            {
                standSubscribe.Unsubscribe();
                standSubscribe = null;
            }
        }
예제 #7
0
 private void Unsubscribe(ScriptEventData data)
 {
     if (unsubscribes != null)
     {
         unsubscribes();
         unsubscribes = null;
     }
     if (grabSubscribe != null)
     {
         grabSubscribe.Unsubscribe();
     }
     if (releaseSubscribe != null)
     {
         releaseSubscribe.Unsubscribe();
     }
 }
예제 #8
0
 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");
     }
 }
예제 #9
0
        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();
        }
예제 #10
0
    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();
    }
예제 #11
0
        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();
            }
        }
예제 #12
0
        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();
        }
예제 #13
0
    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;
            }
        });
    }
예제 #14
0
        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();
        }
예제 #15
0
    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;
            }
        });
    }
예제 #16
0
 public void Unsubscribe()
 {
     eventSubscription.Unsubscribe();
 }
예제 #17
0
        private static async Task WaitAndStopAsync(IEventSubscription sut)
        {
            await Task.Delay(200);

            sut.Unsubscribe();
        }