Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,26 @@ public static void Main(String[] args)
}
}




// Verify the signature of an XML file against an asymmetric
// algorithm and return the result.
public static Boolean VerifyXml(XmlDocument Doc, RSA Key)
public static Boolean VerifyXml(XmlDocument xmlDoc, RSA key)
{
// Check arguments.
if (Doc == null)
throw new ArgumentException("Doc");
if (Key == null)
throw new ArgumentException("Key");
if (xmlDoc == null)
throw new ArgumentException("xmlDoc");
if (key == null)
throw new ArgumentException("key");

// Create a new SignedXml object and pass it
// the XML document class.
// <snippet5>
SignedXml signedXml = new SignedXml(Doc);
SignedXml signedXml = new SignedXml(xmlDoc);
// </snippet5>

// Find the "Signature" node and create a new
// XmlNodeList object.
// <snippet6>
XmlNodeList nodeList = Doc.GetElementsByTagName("Signature");
XmlNodeList nodeList = xmlDoc.GetElementsByTagName("Signature");
// </snippet6>

// Throw an exception if no signature was found.
Expand All @@ -100,8 +97,8 @@ public static Boolean VerifyXml(XmlDocument Doc, RSA Key)

// Check the signature and return the result.
// <snippet8>
return signedXml.CheckSignature(Key);
return signedXml.CheckSignature(key);
// </snippet8>
}
}
// </snippet1>
// </snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public TileModeExample()
//
DrawingBrush tileBrushWithFlipYTiling = new DrawingBrush();
tileBrushWithFlipYTiling.Drawing = triangleDrawing;
tileBrushWithFlipYTiling.TileMode = TileMode.FlipX;
tileBrushWithFlipYTiling.TileMode = TileMode.FlipY;

// Specify the brush's Viewport.
tileBrushWithFlipYTiling.Viewport = new Rect(0, 0, 0.5, 0.5);
Expand Down
64 changes: 38 additions & 26 deletions snippets/csharp/framework/migration-guide/versions-installed1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,61 +10,73 @@ public static void Main()

private static void GetVersionFromRegistry()
{
// Opens the registry key for the .NET Framework entry.
using (RegistryKey ndpKey =
RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, "").
// Opens the registry key for the .NET Framework entry.
using (RegistryKey ndpKey =
RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
{
foreach (var versionKeyName in ndpKey.GetSubKeyNames())
{
// As an alternative, if you know the computers you will query are running .NET Framework 4.5
// or later, you can use:
// using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine,
// RegistryView.Registry32).OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP\"))
foreach (string versionKeyName in ndpKey.GetSubKeyNames())
{
// Skip .NET Framework 4.5 version information.
if (versionKeyName == "v4")
{
continue;
}

if (versionKeyName.StartsWith("v"))
{

RegistryKey versionKey = ndpKey.OpenSubKey(versionKeyName);
string name = (string)versionKey.GetValue("Version", "");
string sp = versionKey.GetValue("SP", "").ToString();
string install = versionKey.GetValue("Install", "").ToString();
if (install == "") //no install info, must be later.
Console.WriteLine(versionKeyName + " " + name);
// Get the .NET Framework version value.
var name = (string)versionKey.GetValue("Version", "");
// Get the service pack (SP) number.
var sp = versionKey.GetValue("SP", "").ToString();

// Get the installation flag, or an empty string if there is none.
var install = versionKey.GetValue("Install", "").ToString();
if (string.IsNullOrEmpty(install)) // No install info; it must be in a child subkey.
Console.WriteLine($"{versionKeyName} {name}");
else
{
if (sp != "" && install == "1")
if (!(string.IsNullOrEmpty(sp)) && install == "1")
{
Console.WriteLine(versionKeyName + " " + name + " SP" + sp);
Console.WriteLine($"{versionKeyName} {name} SP{sp}");
}

}
if (name != "")
if (! string.IsNullOrEmpty(name))
{
continue;
}
foreach (string subKeyName in versionKey.GetSubKeyNames())
foreach (var subKeyName in versionKey.GetSubKeyNames())
{
RegistryKey subKey = versionKey.OpenSubKey(subKeyName);
name = (string)subKey.GetValue("Version", "");
if (name != "")
if (! string.IsNullOrEmpty(name))
sp = subKey.GetValue("SP", "").ToString();

install = subKey.GetValue("Install", "").ToString();
if (install == "") //no install info, must be later.
Console.WriteLine(versionKeyName + " " + name);
if (string.IsNullOrEmpty(install)) //No install info; it must be later.
Console.WriteLine($"{versionKeyName} {name}");
else
{
if (sp != "" && install == "1")
if (!(string.IsNullOrEmpty(sp )) && install == "1")
{
Console.WriteLine(" " + subKeyName + " " + name + " SP" + sp);
Console.WriteLine($"{subKeyName} {name} SP{sp}");
}
else if (install == "1")
{
Console.WriteLine(" " + subKeyName + " " + name);
Console.WriteLine($" {subKeyName} {name}");
}
}
}
}
}
}
}
}
}
// The example displays output similar to the following:
// v2.0.50727 2.0.50727.4927 SP2
// v3.0 3.0.30729.4926 SP2
// v3.5 3.5.30729.4926 SP1
// v4.0
// Client 4.0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ public static void Main()
Console.WriteLine($"Version: {Environment.Version}");
}
}
// The example displays output similiar to the following:'
// Version: 4.0.30319.18010
56 changes: 28 additions & 28 deletions snippets/csharp/framework/migration-guide/versions-installed3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,41 +12,41 @@ private static void Get45PlusFromRegistry()
{
const string subkey = @"SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full\";

using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
using (var ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey(subkey))
{
if (ndpKey != null && ndpKey.GetValue("Release") != null) {
Console.WriteLine(".NET Framework Version: " + CheckFor45PlusVersion((int) ndpKey.GetValue("Release")));
}
else {
Console.WriteLine(".NET Framework Version 4.5 or later is not detected.");
}
}
}

// Checking the version using >= will enable forward compatibility.
private static string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 461808)
return "4.7.2 or later";
if (releaseKey >= 461308)
return "4.7.1";
if (releaseKey >= 460798)
return "4.7";
if (releaseKey >= 394802)
return "4.6.2";
if (releaseKey >= 394254)
return "4.6.1";
if (releaseKey >= 393295)
return "4.6";
if (releaseKey >= 379893)
return "4.5.2";
if (releaseKey >= 378675)
return "4.5.1";
if (releaseKey >= 378389)
return "4.5";
// This code should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}

// Checking the version using >= enables forward compatibility.
string CheckFor45PlusVersion(int releaseKey)
{
if (releaseKey >= 461808)
return "4.7.2 or later";
if (releaseKey >= 461308)
return "4.7.1";
if (releaseKey >= 460798)
return "4.7";
if (releaseKey >= 394802)
return "4.6.2";
if (releaseKey >= 394254)
return "4.6.1";
if (releaseKey >= 393295)
return "4.6";
if (releaseKey >= 379893)
return "4.5.2";
if (releaseKey >= 378675)
return "4.5.1";
if (releaseKey >= 378389)
return "4.5";
// This code should never execute. A non-null release key should mean
// that 4.5 or later is installed.
return "No 4.5 or later version detected";
}
}
}
// This example displays output like the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@ Imports System.Security.Cryptography
Imports System.Security.Cryptography.Xml
Imports System.Xml



Module VerifyXML


Sub Main(ByVal args() As String)
Try
' Create a new CspParameters object to specify
Expand Down Expand Up @@ -44,32 +40,27 @@ Module VerifyXML
Catch e As Exception
Console.WriteLine(e.Message)
End Try

End Sub





' Verify the signature of an XML file against an asymmetric
' algorithm and return the result.
Function VerifyXml(ByVal Doc As XmlDocument, ByVal Key As RSA) As [Boolean]
Function VerifyXml(ByVal xmlDoc As XmlDocument, ByVal key As RSA) As [Boolean]
' Check arguments.
If Doc Is Nothing Then
Throw New ArgumentException("Doc")
If xmlDoc Is Nothing Then
Throw New ArgumentException("xmlDoc")
End If
If Key Is Nothing Then
Throw New ArgumentException("Key")
If key Is Nothing Then
Throw New ArgumentException("key")
End If
' Create a new SignedXml object and pass it
' the XML document class.
' <snippet5>
Dim signedXml As New SignedXml(Doc)
Dim signedXml As New SignedXml(xmlDoc)
' </snippet5>
' Find the "Signature" node and create a new
' XmlNodeList object.
' <snippet6>
Dim nodeList As XmlNodeList = Doc.GetElementsByTagName("Signature")
Dim nodeList As XmlNodeList = xmlDoc.GetElementsByTagName("Signature")
' </snippet6>
' Throw an exception if no signature was found.
If nodeList.Count <= 0 Then
Expand All @@ -89,7 +80,7 @@ Module VerifyXML
' </snippet7>
' Check the signature and return the result.
' <snippet8>
Return signedXml.CheckSignature(Key)
Return signedXml.CheckSignature(key)
' </snippet8>
End Function
End Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ Namespace BrushesIntroduction
'
Dim tileBrushWithFlipYTiling As New DrawingBrush()
tileBrushWithFlipYTiling.Drawing = triangleDrawing
tileBrushWithFlipYTiling.TileMode = TileMode.FlipX
tileBrushWithFlipYTiling.TileMode = TileMode.FlipY

' Specify the brush's Viewport.
tileBrushWithFlipYTiling.Viewport = New Rect(0, 0, 0.5, 0.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,50 +8,45 @@ Public Module VersionTest
Private Sub GetVersionFromRegistry()

' Opens the registry key for the .NET Framework entry.
Using ndpKey As RegistryKey = RegistryKey.OpenRemoteBaseKey(RegistryHive.LocalMachine, ""). _
Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).
OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
' As an alternative, if you know the computers you will query are running .NET Framework 4.5
' or later, you can use:

' As an alternative, if you know the computers you will query are running .NET Framework 4.5
' or later, you can use:
' Using ndpKey As RegistryKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, _
' RegistryView.Registry32).OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\")
For Each versionKeyName In ndpKey.GetSubKeyNames()
' Skip .NET Framework 4.5 and later.
If versionKeyName = "v4" Then Continue For

For Each versionKeyName As String In ndpKey.GetSubKeyNames()
If versionKeyName.StartsWith("v") Then
Dim versionKey As RegistryKey = ndpKey.OpenSubKey(versionKeyName)
Dim name As String = DirectCast(versionKey.GetValue("Version", ""), String)
Dim sp As String = versionKey.GetValue("SP", "").ToString()
Dim install As String = versionKey.GetValue("Install", "").ToString()
If install = "" Then
'no install info, ust be later
Console.WriteLine(versionKeyName & " " & name)
' Get the .NET Framework version value.
Dim name = DirectCast(versionKey.GetValue("Version", ""), String)
' Get the service pack (SP) number.
Dim sp = versionKey.GetValue("SP", "").ToString()

Dim install = versionKey.GetValue("Install", "").ToString()
If String.IsNullOrEmpty(install) Then ' No install info; it must be in a child subkey.
Console.WriteLine($"{versionKeyName} {name}")
Else
If sp <> "" AndAlso install = "1" Then
Console.WriteLine(versionKeyName & " " & name & " SP" & sp)

If Not String.IsNullOrEmpty(sp) AndAlso install = "1" Then
Console.WriteLine($"{versionKeyName} {name} SP{sp}")
End If
End If
If name <> "" Then
If Not String.IsNullOrEmpty(name) Then
Continue For
End If
For Each subKeyName As String In versionKey.GetSubKeyNames()
For Each subKeyName In versionKey.GetSubKeyNames()
Dim subKey As RegistryKey = versionKey.OpenSubKey(subKeyName)
name = DirectCast(subKey.GetValue("Version", ""), String)
If name <> "" Then
If Not String.IsNullOrEmpty(name) Then
sp = subKey.GetValue("SP", "").ToString()
End If
install = subKey.GetValue("Install", "").ToString()
If install = "" Then
'no install info, ust be later
Console.WriteLine(versionKeyName & " " & name)
If String.IsNullOrEmpty(install) Then ' No install info; it must be later.
Console.WriteLine($"{versionKeyName} {name}")
Else
If sp <> "" AndAlso install = "1" Then
Console.WriteLine(" " & subKeyName & " " & name & " SP" & sp)
If Not String.IsNullOrEmpty(sp) AndAlso install = "1" Then
Console.WriteLine($"{subKeyName} {name} SP{sp}")
ElseIf install = "1" Then
Console.WriteLine(" " & subKeyName & " " & name)

Console.WriteLine($" {subKeyName} {name}")
End If
End If
Next
Expand All @@ -60,3 +55,9 @@ Public Module VersionTest
End Using
End Sub
End Module
' The example displays output similar to the following:
' v2.0.50727 2.0.50727.4927 SP2
' v3.0 3.0.30729.4926 SP2
' v3.5 3.5.30729.4926 SP1
' v4.0
' Client 4.0.0.0
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ Public Module VersionTest
Console.WriteLine($"Version: {Environment.Version}")
End Sub
End Module
' The example displays output similiar to the following:'
' Version: 4.0.30319.18010

Loading