Exemplo n.º 1
0
        public Task Perform(UserViewModel user, IEnumerable <string> arguments = null)
        {
            if (this.IsEnabled)
            {
                if (arguments == null)
                {
                    arguments = new List <string>();
                }

                try
                {
                    if (this.StoreID != Guid.Empty)
                    {
                        if (!CommandBase.commandUses.ContainsKey(this.StoreID))
                        {
                            CommandBase.commandUses[this.StoreID] = 0;
                        }
                        CommandBase.commandUses[this.StoreID]++;
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                this.currentCancellationTokenSource = new CancellationTokenSource();
                this.currentTaskRun = Task.Run(async() =>
                {
                    try
                    {
                        if (!this.Unlocked && !ChannelSession.Settings.UnlockAllCommands)
                        {
                            await this.AsyncSemaphore.WaitAsync();
                        }

                        await SpecialIdentifierStringBuilder.AssignRandomUserSpecialIdentifierGroup(this.ID);
                        foreach (ActionBase action in this.Actions)
                        {
                            action.AssignRandomUserSpecialIdentifierGroup(this.ID);
                        }

                        await this.PerformInternal(user, arguments, this.currentCancellationTokenSource.Token);
                    }
                    catch (TaskCanceledException) { }
                    catch (Exception ex) { Util.Logger.Log(ex); }
                    finally
                    {
                        if (!this.Unlocked && !ChannelSession.Settings.UnlockAllCommands)
                        {
                            this.AsyncSemaphore.Release();
                        }
                    }
                }, this.currentCancellationTokenSource.Token);
            }
            return(Task.FromResult(0));
        }
Exemplo n.º 2
0
        public async Task Perform(UserViewModel user, IEnumerable <string> arguments = null, Dictionary <string, string> extraSpecialIdentifiers = null)
        {
            if (this.IsEnabled)
            {
                if (arguments == null)
                {
                    arguments = new List <string>();
                }

                if (extraSpecialIdentifiers == null)
                {
                    extraSpecialIdentifiers = new Dictionary <string, string>();
                }

                if (!await this.PerformPreChecks(user, arguments, extraSpecialIdentifiers))
                {
                    return;
                }

                try
                {
                    if (this.StoreID != Guid.Empty)
                    {
                        if (!CommandBase.commandUses.ContainsKey(this.StoreID))
                        {
                            CommandBase.commandUses[this.StoreID] = 0;
                        }
                        CommandBase.commandUses[this.StoreID]++;
                    }
                }
                catch (Exception ex) { MixItUp.Base.Util.Logger.Log(ex); }

                ChannelSession.Services.Telemetry.TrackCommand(this.Type, this.IsBasic);

                this.OnCommandStart(this, new EventArgs());

                this.currentCancellationTokenSource = new CancellationTokenSource();
                this.currentTaskRun = Task.Run(async() =>
                {
                    bool waitOccurred = false;
                    try
                    {
                        if (!this.Unlocked && !ChannelSession.Settings.UnlockAllCommands)
                        {
                            await this.AsyncSemaphore.WaitAsync();
                            waitOccurred = true;
                        }

                        await SpecialIdentifierStringBuilder.AssignRandomUserSpecialIdentifierGroup(this.ID);
                        foreach (ActionBase action in this.Actions)
                        {
                            action.AssignRandomUserSpecialIdentifierGroup(this.ID);
                        }

                        await this.PerformInternal(user, arguments, extraSpecialIdentifiers, this.currentCancellationTokenSource.Token);
                    }
                    catch (TaskCanceledException) { }
                    catch (Exception ex) { Util.Logger.Log(ex); }
                    finally
                    {
                        if (waitOccurred)
                        {
                            this.AsyncSemaphore.Release();
                        }
                    }
                }, this.currentCancellationTokenSource.Token);
            }
        }