本文整理汇总了C#中ApplicationConfiguration.SaveToFile方法的典型用法代码示例。如果您正苦于以下问题:C# ApplicationConfiguration.SaveToFile方法的具体用法?C# ApplicationConfiguration.SaveToFile怎么用?C# ApplicationConfiguration.SaveToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ApplicationConfiguration
的用法示例。
在下文中一共展示了ApplicationConfiguration.SaveToFile方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CheckApplicationInstanceCertificate
//.........这里部分代码省略.........
{
if (Utils.FindStringIgnoreCase(certificateDomainNames, serverDomainNames[ii]))
{
continue;
}
if (String.Compare(serverDomainNames[ii], "localhost", StringComparison.OrdinalIgnoreCase) == 0)
{
// check computer name.
string computerName = Utils.GetHostName();
if (Utils.FindStringIgnoreCase(certificateDomainNames, computerName))
{
continue;
}
}
string message = Utils.Format(
"The server is configured to use domain '{0}' which does not appear in the certificate. Create new certificate?",
serverDomainNames[ii]);
createNewCertificate = true;
if (interactive)
{
MessageDlg dialog = new MessageDlg(message, MessageDlgButton.Yes, MessageDlgButton.No);
MessageDlgButton result = await dialog.ShowAsync();
if (result != MessageDlgButton.Yes)
{
createNewCertificate = false;
continue;
}
}
Utils.Trace(message);
break;
}
if (!createNewCertificate)
{
// check if key size matches.
if (keySize == certificate.GetRSAPublicKey().KeySize)
{
await AddToTrustedStore(configuration, certificate);
return certificate;
}
}
}
// prompt user.
if (interactive)
{
if (!createNewCertificate)
{
MessageDlg dialog = new MessageDlg("Application does not have an instance certificate.\n Create one automatically?", MessageDlgButton.Yes, MessageDlgButton.No);
MessageDlgButton result = await dialog.ShowAsync();
if (result != MessageDlgButton.Yes)
{
return null;
}
}
}
// delete existing certificate.
if (certificate != null)
{
await DeleteApplicationInstanceCertificate(configuration);
}
// add the localhost.
if (serverDomainNames.Count == 0)
{
serverDomainNames.Add(Utils.GetHostName());
}
certificate = await Opc.Ua.CertificateFactory.CreateCertificate(
id.StoreType,
id.StorePath,
configuration.ApplicationUri,
configuration.ApplicationName,
null,
serverDomainNames,
keySize,
300);
id.Certificate = certificate;
await AddToTrustedStore(configuration, certificate);
if (updateFile && !String.IsNullOrEmpty(configuration.SourceFilePath))
{
configuration.SaveToFile(configuration.SourceFilePath);
}
await configuration.CertificateValidator.Update(configuration.SecurityConfiguration);
return await configuration.SecurityConfiguration.ApplicationCertificate.LoadPrivateKey(null);
}
return certificate;
}
示例2: CheckApplicationInstanceCertificate
//.........这里部分代码省略.........
}
}
if (found)
{
continue;
}
// check for ip addresses.
for (int jj = 0; jj < entry.AddressList.Length; jj++)
{
if (Utils.FindStringIgnoreCase(certificateDomainNames, entry.AddressList[jj].ToString()))
{
found = true;
break;
}
}
if (found)
{
continue;
}
}
string message = Utils.Format(
"The server is configured to use domain '{0}' which does not appear in the certificate. Update certificate?",
serverDomainNames[ii]);
createNewCertificate = true;
if (interactive)
{
if (MessageBox.Show(message, configuration.ApplicationName, MessageBoxButtons.YesNo) != DialogResult.Yes)
{
createNewCertificate = false;
continue;
}
}
Utils.Trace(message);
break;
}
if (!createNewCertificate)
{
// check if key size matches.
if (keySize == certificate.PublicKey.Key.KeySize)
{
AddToTrustedStore(configuration, certificate);
return certificate;
}
}
}
// prompt user.
if (interactive)
{
if (!createNewCertificate)
{
if (MessageBox.Show("Application does not have an instance certificate. Create one automatically?", configuration.ApplicationName, MessageBoxButtons.YesNo) == DialogResult.No)
{
return null;
}
}
}
// delete existing certificate.
if (certificate != null)
{
DeleteApplicationInstanceCertificate(configuration);
}
// add the localhost.
if (serverDomainNames.Count == 0)
{
serverDomainNames.Add(System.Net.Dns.GetHostName());
}
certificate = Opc.Ua.CertificateFactory.CreateCertificate(
id.StoreType,
id.StorePath,
configuration.ApplicationUri,
configuration.ApplicationName,
null,
serverDomainNames,
keySize,
300);
id.Certificate = certificate;
AddToTrustedStore(configuration, certificate);
if (updateFile && !String.IsNullOrEmpty(configuration.SourceFilePath))
{
configuration.SaveToFile(configuration.SourceFilePath);
}
configuration.CertificateValidator.Update(configuration.SecurityConfiguration);
return configuration.SecurityConfiguration.ApplicationCertificate.LoadPrivateKey(null);
}
示例3: CheckApplicationInstanceCertificate
/// <summary>
/// Synchronous helper implementation of CheckApplicationInstanceCertificate for C++ Proxy
/// </summary>
public static void CheckApplicationInstanceCertificate(ApplicationConfiguration configuration)
{
// create a default certificate id none specified.
CertificateIdentifier id = configuration.SecurityConfiguration.ApplicationCertificate;
if (id == null)
{
id = new CertificateIdentifier();
id.StoreType = Utils.DefaultStoreType;
id.StorePath = Utils.DefaultStorePath;
id.SubjectName = configuration.ApplicationName;
}
// check for certificate with a private key.
X509Certificate2 certificate = null;
Task.Run(async () => certificate = await id.Find(true)).Wait();
if (certificate != null)
{
return;
}
// construct the subject name from the
List<string> hostNames = new List<string>();
hostNames.Add(Utils.GetHostName());
string commonName = Utils.Format("CN={0}", configuration.ApplicationName);
string domainName = Utils.Format("DC={0}", hostNames[0]);
string subjectName = Utils.Format("{0}, {1}", commonName, domainName);
// create a new certificate with a new public key pair.
certificate = CertificateFactory.CreateCertificate(
id.StoreType,
id.StorePath,
configuration.ApplicationUri,
configuration.ApplicationName,
subjectName,
hostNames,
2048,
120,
256);
// update and save the configuration file.
id.Certificate = certificate;
configuration.SaveToFile(configuration.SourceFilePath);
// add certificate to the trusted peer store so other applications will trust it.
ICertificateStore store = configuration.SecurityConfiguration.TrustedPeerCertificates.OpenStore();
try
{
Task.Run(async () =>
{
X509Certificate2Collection certificateCollection = await store.FindByThumbprint(certificate.Thumbprint);
if (certificateCollection != null)
{
await store.Add(certificateCollection[0]);
}
}
).Wait();
}
finally
{
store.Close();
}
// tell the certificate validator about the new certificate.
configuration.CertificateValidator.Update(configuration.SecurityConfiguration);
}