private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // dispose managed state (managed objects).
                    if (_Client != null)
                    {
                        _Client.Dispose();
                        _Client = null;
                    }
                    if (_Signer != null)
                    {
                        _Signer.Dispose();
                        _Signer = null;
                    }
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                disposedValue = true;
            }
        }
Exemplo n.º 2
0
        private async void loadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var account = cmbAccounts.SelectedItem as Account;

            if (account == null)
            {
                log.Error("not account.");
                await Task.FromResult(0);

                return;
            }

            RS256Signer signer = null;
            AcmeClient  client = null;

            try
            {
                signer = account.Signer;

                client = new AcmeClient(new Uri(account.uri), new AcmeServerDirectory(), signer);
                client.Init();
                log.Info("\nGetting AcmeServerDirectory");
                client.GetDirectory(true);

                client.Registration = account.Registration;

                this.client  = client;
                this.account = account;
                log.Info("load done.");
                labInfo.Text = account.ToString();
                btnRefreshDomains.PerformClick();
            }
            catch (Exception ex)
            {
                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }

                if (signer != null)
                {
                    signer.Dispose();
                    signer = null;
                }

                var acmeWebException = ex as AcmeClient.AcmeWebException;
                if (acmeWebException != null)
                {
                    log.Error(acmeWebException.Message);
                    log.Error("ACME Server Returned:");
                    log.Error(acmeWebException.Response.ContentAsString);
                }
                else
                {
                    log.Error(ex);
                }
            }
        }
Exemplo n.º 3
0
        private bool TryLoad(bool force = false)
        {
            if (force == false && this.client != null)
            {
                return(true);
            }

            RS256Signer signer = null;
            AcmeClient  client = null;

            try
            {
                signer = account.Signer;

                client = new AcmeClient(new Uri(account.uri), new AcmeServerDirectory(), signer);
                client.Init();
                log.Info("\nGetting AcmeServerDirectory");
                client.GetDirectory(true);

                client.Registration = account.Registration;

                this.client = client;
                log.Info("load done.");
                labInfo.Text = account.ToString();
                //
                return(true);
            }
            catch (Exception ex)
            {
                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }

                if (signer != null)
                {
                    signer.Dispose();
                    signer = null;
                }

                var acmeWebException = ex as AcmeClient.AcmeWebException;
                if (acmeWebException != null)
                {
                    log.Error(acmeWebException.Message);
                    log.Error("ACME Server Returned:");
                    log.Error(acmeWebException.Response.ContentAsString);
                }
                else
                {
                    log.Error(ex);
                }
            }
            return(false);
        }
Exemplo n.º 4
0
 public void Dispose()
 {
     _client.Dispose();
 }
Exemplo n.º 5
0
 public void Dispose()
 {
     _acmeClient?.Dispose();
 }
 /// <inheritdoc />
 public void Dispose()
 {
     _signer.Dispose();
     _client.Dispose();
 }
        private async void btnCreate_Click(object sender, EventArgs e)
        {
            Working(true);
            var ok = CheckInput();

            if (ok == false)
            {
                Working(false);
                await Task.FromResult(0);

                return;
            }

            var c = db.Accounts.Find(o => o.email == txtEmail.Text && o.uri == cmbUrl.Text)
                    .Count();

            if (c > 0)
            {
                log.Warn($"该账号已存在。");
                return;
            }
            RS256Signer signer = null;

            try
            {
                signer = new RS256Signer();
                signer.Init();

                client = new AcmeClient(new Uri(cmbUrl.Text), new AcmeServerDirectory(), signer);

                client.Init();
                log.Info("Getting AcmeServerDirectory");
                client.GetDirectory(true);

                var email = txtEmail.Text;

                var contacts = new string[] { };
                if (!String.IsNullOrEmpty(email))
                {
                    email    = "mailto:" + email;
                    contacts = new string[] { email };
                }
                log.Info("Calling Register");
                var registration = client.Register(contacts);

                log.Info("Updating Registration");
                client.UpdateRegistration(true, true);

                log.Info("Saving Registration");

                account = new Account()
                {
                    email        = txtEmail.Text,
                    Registration = client.Registration,
                    Signer       = signer,
                    uri          = cmbUrl.Text,
                };
                if (string.IsNullOrWhiteSpace(txtTokens.Text) == false)
                {
                    var m = txtTokens.Text.Split("\r\n".ToArray(), StringSplitOptions.RemoveEmptyEntries)
                            .Select(o => o.Trim())
                            .Distinct().ToList();
                    account.dnspod_tokens = m.Where(o => Dnspod.DnspodApi.TokenRegex.IsMatch(o)).ToList();
                }
                db.Accounts.Insert(account);
                Working(false);
                log.Info("register done.");
                this.DialogResult = DialogResult.OK;
            }
            catch (Exception ex)
            {
                var acmeWebException = ex as AcmeClient.AcmeWebException;
                if (acmeWebException != null)
                {
                    log.Error(acmeWebException.Message);
                    log.Error("ACME Server Returned:");
                    log.Error(acmeWebException.Response.ContentAsString);
                }
                else
                {
                    log.Error(e);
                }
                if (client != null)
                {
                    client.Dispose();
                    client = null;
                }

                if (signer != null)
                {
                    signer.Dispose();
                    signer = null;
                }
                account = null;
                Working(false);
                return;
            }
        }