private Task Show(SwalOption option)
    {
        IsAutoHide = option.IsAutoHide;
        Delay      = option.Delay;

        option.Dialog = ModalContainer;
        var parameters = option.ToAttributes();

        parameters.Add(nameof(ModalDialog.OnClose), new Func <Task>(async() =>
        {
            if (IsAutoHide && DelayToken != null)
            {
                DelayToken.Cancel();
                DelayToken = null;
            }
            DialogParameter = null;
            await ModalContainer.CloseOrPopDialog();
            StateHasChanged();
        }));

        parameters.Add(nameof(ModalDialog.BodyTemplate), BootstrapDynamicComponent.CreateComponent <SweetAlertBody>(SweetAlertBody.Parse(option)).Render());

        DialogParameter = parameters;
        IsShowDialog    = true;
        StateHasChanged();
        return(Task.CompletedTask);
    }
Пример #2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         DelayToken?.Dispose();
         DelayToken = null;
         SwalService.UnRegister(this);
     }
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="disposing"></param>
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposing)
            {
                DelayToken?.Dispose();
                DelayToken = null;
                SwalService.UnRegister(this);
            }
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="disposing"></param>
 protected virtual void Dispose(bool disposing)
 {
     if (disposing)
     {
         if (DelayToken != null)
         {
             DelayToken.Cancel();
             DelayToken.Dispose();
             DelayToken = null;
         }
         SwalService.UnRegister(this);
     }
 }
Пример #5
0
        private async Task DelayReadyAsync(IGatewayApiClient shard, ReadyEventArgs e)
        {
            if (_delays.TryGetValue(shard.Id, out var delay))
            {
                // If a disconnection happened cancel the already existing delay.
                delay.Tcs.Cancel();
                shard.Logger.LogWarning("The ready delay was overwritten by a new session.");
            }

            var sw = Stopwatch.StartNew();

            using (delay = new DelayToken(shard.StoppingToken))
            {
                _delays[shard.Id] = delay;
                try
                {
                    await delay.Tcs.Task.ConfigureAwait(false);

                    // The task finished meaning all pending guilds were received.
                    // Now depending on the mode we either fire ready straight away or do chunking.
                    _delays.Remove(shard.Id);
                    switch (Dispatcher.ReadyEventDelayMode)
                    {
                    case ReadyEventDelayMode.Guilds:
                    {
                        shard.Logger.LogInformation("Ready. Received all pending guilds in {0}ms.", sw.ElapsedMilliseconds);
                        await InvokeEventAsync(e).ConfigureAwait(false);

                        break;
                    }

                        // TODO: some chunking design...?
                    }

                    if (InitialReadys.TryGetValue(shard.Id, out var readyTcs))
                    {
                        readyTcs.Complete();
                    }
                }
                catch (OperationCanceledException)
                { }
            }
        }