SignMaster.SigningParameters.ValidateData C# (CSharp) Method

ValidateData() public method

Tests that the signing details do not contain easily-detected errors.
public ValidateData ( ) : void
return void
        public void ValidateData()
        {
            if (PathsOfFilesToSign != null)
            {
                if (PathsOfFilesToSign.Count == 0)
                    throw new Exception("No files specified - nothing to sign!");

                foreach (var path in PathsOfFilesToSign.Where(path => !File.Exists(path)))
                    throw new Exception("File to be signed does not exist: \"" + path + "\"");
            }
            if (CertificatePath != null)
            {
                var driveName = Path.GetPathRoot(CertificatePath);
                var driveInfo = new DriveInfo(driveName);
                while (!driveInfo.IsReady || !File.Exists(CertificatePath))
                {
                    var cause = driveInfo.IsReady ? "The certificate file [" + CertificatePath + "] does not exist."
                        : "The digital certificate CD appears not to be in the drive [" + driveName + "].";

                    if (MessageBox.Show(cause + Environment.NewLine +
                                    "If you wish the file(s) to be signed, insert the CD with access to \"" +
                                    CertificatePath + "\" and press OK."
                                    + Environment.NewLine + Environment.NewLine +
                                    "To continue without signing file(s), press Cancel.",
                                    "SignMaster can't find digital certificate",
                                    MessageBoxButtons.OKCancel) == DialogResult.Cancel)
                    {
                        throw new Exception("Certificate not found - file(s) not signed.");
                    }
                }
            }
        }

Usage Example

Exemplo n.º 1
0
 /// <summary>
 /// Test if we have enough data to do a signing. If not, display a
 /// dialog box asking for the remainder.
 /// </summary>
 /// <returns>false if user canceled, otherwise true.</returns>
 private bool GetAnyNeededUserInput()
 {
     // Test if we have enough data:
     if (m_parameters.IsUserInputNeeded())
     {
         // Show dialog box asking for more details:
         var dlg = new SignMasterForm(ref m_parameters);
         if (dlg.ShowDialog() == DialogResult.Cancel)
         {
             return(false);
         }
     }
     // Make sure the input data is sensible:
     m_parameters.ValidateData();
     return(true);
 }