public void ReplaceIfNull()
        {
            var bd1 = new BooleanDisposable();
            var bd2 = new BooleanDisposable();

            var field = default(IDisposable);

            Assert.True(DisposableHelper.ReplaceIfNull(ref field, bd1));

            Assert.False(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            Assert.False(DisposableHelper.ReplaceIfNull(ref field, bd2));

            Assert.False(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            Assert.True(DisposableHelper.Dispose(ref field));

            Assert.True(bd1.IsDisposed());
            Assert.False(bd2.IsDisposed());

            var bd3 = new BooleanDisposable();

            Assert.False(DisposableHelper.SetIfNull(ref field, bd3));

            Assert.True(bd3.IsDisposed());
        }
 public void Cancel()
 {
     Interlocked.Exchange(ref latest, Final);
     upstream.Cancel();
     DisposableHelper.Dispose(ref timer);
     worker.Dispose();
 }
Example #3
0
 public override void Cancel()
 {
     Interlocked.Exchange(ref index, long.MaxValue);
     upstream = SubscriptionHelper.Cancelled;
     base.Cancel();
     DisposableHelper.Dispose(ref timer);
     worker.Dispose();
 }
Example #4
0
 public void OnComplete()
 {
     if (Interlocked.Exchange(ref index, long.MaxValue) != long.MaxValue)
     {
         DisposableHelper.Dispose(ref timer);
         actual.OnComplete();
         worker.Dispose();
     }
 }
Example #5
0
 public void OnError(Exception cause)
 {
     if (Interlocked.Exchange(ref index, long.MaxValue) != long.MaxValue)
     {
         DisposableHelper.Dispose(ref timer);
         actual.OnError(cause);
         worker.Dispose();
     }
 }
Example #6
0
 public void Cancel()
 {
     Volatile.Write(ref cancelled, true);
     DisposableHelper.Dispose(ref upstream);
     if (Interlocked.Increment(ref wip) == 1)
     {
         queue.Clear();
     }
 }
Example #7
0
            protected void CancelOthers()
            {
                var array = subscribers;
                int n     = this.n;

                for (int i = 0; i < n; i++)
                {
                    DisposableHelper.Dispose(ref array[i]);
                }
            }
            public void OnError(Exception e)
            {
                if (Interlocked.Exchange(ref index, long.MaxValue) != long.MaxValue)
                {
                    DisposableHelper.Dispose(ref d);

                    actual.OnError(e);
                }
                else
                {
                    ExceptionHelper.OnErrorDropped(e);
                }
            }
            public void Cancel()
            {
                if (Volatile.Read(ref cancelled))
                {
                    return;
                }
                Volatile.Write(ref cancelled, true);
                DisposableHelper.Dispose(ref d);

                if (QueueDrainHelper.Enter(ref wip))
                {
                    entry = null;
                }
            }
            bool Emit(Entry curr)
            {
                long e = emitted;

                if (Volatile.Read(ref requested) != e)
                {
                    emitted = e + 1;
                    actual.OnNext(curr.item);
                    return(true);
                }
                Interlocked.Exchange(ref latest, Final);
                actual.OnError(new InvalidOperationException("Could not emit value due to lack of requests"));
                DisposableHelper.Dispose(ref timer);
                worker.Dispose();
                return(false);
            }
 public void Cancel()
 {
     DisposableHelper.Dispose(ref cancel);
 }
 public void OnComplete()
 {
     DisposableHelper.Dispose(ref timer);
     worker.Schedule(() => Timeout(-1L));
 }
Example #13
0
 public void Cancel()
 {
     DisposableHelper.Dispose(ref upstream);
 }
 public void Cancel()
 {
     DisposableHelper.Dispose(ref d);
     arbiter.Cancel();
 }
 public void OnError(Exception cause)
 {
     Interlocked.Exchange(ref latest, Final);
     DisposableHelper.Dispose(ref timer);
     worker.Dispose();
 }
 public virtual void Cancel()
 {
     DisposableHelper.Dispose(ref disposable);
 }
 public void Cancel()
 {
     DisposableHelper.Dispose(ref task);
 }
 public override void Cancel()
 {
     base.Cancel();
     DisposableHelper.Dispose(ref task);
 }
 public override void Cancel()
 {
     DisposableHelper.Dispose(ref d);
 }
        public static Task <int> Invoke(CancellationToken token, OutputFormat output, IConsole console)
        {
            GeneratedJwtKey newJwt = GeneratedJwtKey.Create();

            StringBuilder outputBldr = new StringBuilder();

            outputBldr.AppendLine(Strings.Message_GenerateApiKey);
            outputBldr.AppendLine();
            outputBldr.AppendLine(string.Format(Strings.Message_GeneratedAuthorizationHeader, HeaderNames.Authorization, AuthConstants.ApiKeySchema, newJwt.Token));
            outputBldr.AppendLine();

            RootOptions opts = new()
            {
                Authentication = new AuthenticationOptions()
                {
                    MonitorApiKey = new MonitorApiKeyOptions()
                    {
                        Subject   = newJwt.Subject,
                        PublicKey = newJwt.PublicKey,
                    }
                }
            };

            outputBldr.AppendFormat(CultureInfo.CurrentCulture, Strings.Message_SettingsDump, output);
            outputBldr.AppendLine();
            switch (output)
            {
            case OutputFormat.Json:
            {
                // Create configuration from object model.
                MemoryConfigurationSource source = new();
                source.InitialData = opts.ToConfigurationValues();
                ConfigurationBuilder builder = new();
                builder.Add(source);
                IConfigurationRoot configuration = builder.Build();

                try
                {
                    // Write configuration into stream
                    using MemoryStream stream = new();
                    using (ConfigurationJsonWriter writer = new(stream))
                    {
                        writer.Write(configuration, full: true, skipNotPresent: true);
                    }

                    // Write stream content as test into builder.
                    stream.Position           = 0;
                    using StreamReader reader = new(stream);
                    outputBldr.AppendLine(reader.ReadToEnd());
                }
                finally
                {
                    DisposableHelper.Dispose(configuration);
                }
            }
            break;

            case OutputFormat.Text:
                outputBldr.AppendLine(string.Format(Strings.Message_GeneratekeySubject, newJwt.Subject));
                outputBldr.AppendLine(string.Format(Strings.Message_GeneratekeyPublicKey, newJwt.PublicKey));
                break;

            case OutputFormat.Cmd:
            case OutputFormat.PowerShell:
            case OutputFormat.Shell:
                IDictionary <string, string> optList = opts.ToEnvironmentConfiguration();
                foreach ((string name, string value) in optList)
                {
                    outputBldr.AppendFormat(CultureInfo.InvariantCulture, GetFormatString(output), name, value);
                    outputBldr.AppendLine();
                }
                break;
            }

            outputBldr.AppendLine();
            console.Out.Write(outputBldr.ToString());

            return(Task.FromResult(0));
        }