Example #1
0
                additionalConditionFuncs) ConfigureBuilder(IMessageEvent @event, VersaCommand command)
        {
            //TODO:the serviceprovider attached to the event may get disposed. Must ensure that a working backup can be returned.

            var services = @event.Services;
            IHubContext <THub> context;

            try
            {
                context = services.GetRequiredService <IHubContext <THub> >();
            }
            catch (ObjectDisposedException)
            {
                services = backupProvider;
                context  = services.GetRequiredService <IHubContext <THub> >();
            }

            var          authenticator = services.GetRequiredService <AuthTranslator <string> >();
            IVersaWriter useTerm;

            try
            {
                var tsk1 = authenticator.GetExternalID(@event.GetPlayerID());
                tsk1.Wait();
                useTerm = new VersaSignalRWriter(@event.GetPlayerID(),
                                                 context.Clients.User(tsk1.Result), functionName, services.GetRequiredService <HtmlEncoder>());
            }
            catch
            {
                try
                {
                    var tsk1 = authenticator.GetExternalID(@event.GetPlayerID());
                    tsk1.Wait();
                    useTerm = new VersaSignalRWriter(@event.GetPlayerID(),
                                                     context.Clients.Client(tsk1.Result), functionName,
                                                     services.GetRequiredService <HtmlEncoder>());
                }
                catch
                {
                    useTerm = broadcaster;
                }
            }

            IPlayer playerHandlerFunction(VersaCommsID id)
            {
                IPlayer player;

                if (players.Any(t => t.VersaID == @event.GetPlayerID()))
                {
                    player = players.First(t => @event.GetPlayerID() == t.VersaID);
                }
                else
                {
                    player = new Player(@event.GetPlayerID());
                    players.Add(player);
                }

                return(player);
            }

            var b = new CommandContext.Builder
            {
                Message    = @event.FullMessage,
                GMTerm     = broadcaster, //TODO: fix this later on to ensure that the system checks if it's in a scenario.
                UserTerm   = useTerm,
                OriginTerm =
                    @event.Terminal.As(new VersaCommsID(0)) == default ?
                    new VersaSignalRWriter(@event.Terminal.As <VersaCommsID>(default), context.Clients.User(new Func <string>(() =>