Beispiel #1
0
        private async void Test()
        {
            var config = new ConfigClass
            {
                DomainName         = "where.now.im",
                Email              = "*****@*****.**",
                WanIface           = "ether1-wan",
                MikroTikAddress    = "10.0.0.1",
                MikroTikPort       = 8728,
                FtpLogin           = "******",
                FtpPassword        = "",
                MikroTikLogin      = "******",
                MikroTikPassword   = "",
                UseAlpn            = true,
                Force              = true,
                LetsEncryptAddress = LeUri.StagingV2,
            };

            var p = new LetsEncryptMikroTik.Core.Program(config);

            try
            {
                await Task.Run(() => p.RunAsync(false, new LogSink(this)));
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
            }
        }
        static int Main(string[] args)
        {
            var configurationBuilder = new ConfigurationBuilder()
                                       .SetBasePath(Directory.GetCurrentDirectory())
                                       .AddJsonFile("appsettings.json", optional: true, reloadOnChange: false)
                                       .AddJsonFile("appsettings.local.json", optional: true);

            var configuration = configurationBuilder.Build();
            var config        = configuration.Get <ConfigClass>();

            var p = new LetsEncryptMikroTik.Core.Program(config);

            try
            {
                p.RunAsync().GetAwaiter().GetResult();
            }
            catch (Exception)
            {
                return(1);
            }

            if (Environment.UserInteractive)
            {
                // Press Any Key
                Console.Write("Для завершения нажмите любую клавишу...");
                Console.ReadKey(intercept: true);
            }
            return(0);
        }
        private async void Button_Start_Click(object sender, EventArgs e)
        {
            string mtLogin    = textBox_MtLogin.Text.Trim();
            string mtPassword = textBox_mtPassword.Text;

            string ftpLogin;
            string ftpPassword;

            if (checkBox1.Checked)
            {
                ftpLogin    = textBox_ftpLogin.Text.Trim();
                ftpPassword = textBox_ftpPassword.Text;
            }
            else
            {
                ftpLogin    = mtLogin;
                ftpPassword = mtPassword;
            }

            var config = new Core.ConfigClass
            {
                MikroTikAddress    = textBox_MtAddress.Text.Trim(),
                MikroTikPort       = int.Parse(textBox_mtPort.Text),
                MikroTikLogin      = mtLogin,
                MikroTikPassword   = mtPassword,
                FtpLogin           = ftpLogin,
                FtpPassword        = ftpPassword,
                DomainName         = textBox_domainName.Text.Trim(),
                Email              = textBox_email.Text.Trim(),
                WanIface           = textBox_wan.Text.Trim(),
                Force              = checkBox_force.Checked,
                LetsEncryptAddress = (Core.LeUri)(Uri) comboBox_lec.SelectedValue,
                SaveFile           = checkBox_saveFile.Checked,
                UseAlpn            = radioButton_alpn.Checked,
            };

            var program = new Core.Program(config);

            //AllocConsole();
            //AttachConsole(ATTACH_PARENT_PROCESS);

            button_start.Enabled = false;
            groupBox_mt.Enabled  = false;
            groupBox_ftp.Enabled = false;
            textBox_wan.Enabled  = false;
            groupBox_lec.Enabled = false;
            richTextBox1.Clear();
            try
            {
                await Task.Run(() => program.RunAsync(logToFile: true, logSink: new InMemorySinkLog(this)));
            }
            catch (Exception ex)
            {
                MessageBox.Show(this, ex.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                button_start.Enabled = true;
                groupBox_mt.Enabled  = true;
                groupBox_ftp.Enabled = true;
                textBox_wan.Enabled  = true;
                groupBox_lec.Enabled = true;
                //FreeConsole();
            }
        }