/// <summary> /// Get source agrument if not present /// </summary> /// <param name="args">Command line argments</param> /// <returns>Arguments</returns> private static bool GetSourceIfNotPresent(ref string[] args) { try { if (CertificateHelper.LoadFromResource(DEFAULT_CERTIFICATE_RESOURCE_NAME) != null) { return(true); } if (args.Length == 1) { return(true); } else if (args.Length < 1) { var name = GetDnsNameFromExecutableFileName(); if (name != null) { args = new string[1]; args[0] = name; return(true); } var inputHelperForm = new InputHelperForm(); if (inputHelperForm.ShowDialog() == DialogResult.OK) { args = new string[1]; args[0] = inputHelperForm.toolStripTextBox1.Text; return(true); } } else { throw new ArgumentOutOfRangeException(nameof(args) + ".Length", args.Length, "> 1"); } } catch (Exception ex) { MessageBox.Show(ex.ToString(), nameof(GetSourceIfNotPresent) + " Error ", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }
/// <summary> /// Load certificate from file, http server or resource /// </summary> /// <param name="args">Command line arguments</param> /// <param name="certificate">Certificate</param> /// <returns>Load is success?</returns> private static bool LoadCertificate(string[] args, out X509Certificate2 certificate) { certificate = null; try { certificate = CertificateHelper.LoadFromResource(DEFAULT_CERTIFICATE_RESOURCE_NAME); if (certificate != null) { return(true); } if (args.Length == 1) { string name = args[0]; if (File.Exists(name)) { certificate = CertificateHelper.LoadFromFile(name); return(true); } else { certificate = CertificateHelper.LoadFromTcpHost(name); return(true); } } } catch (Exception ex) { MessageBox.Show(ex.ToString(), nameof(LoadCertificate) + " Error ", MessageBoxButtons.OK, MessageBoxIcon.Error); } return(false); }