@@ -24,8 +24,9 @@ public static void Main()
24
24
if ( DataClassificationSupported ( connection ) )
25
25
{
26
26
// Create the temporary table and retrieve its Data Discovery and Classification information.
27
- CreateTable ( connection ) ;
28
- RunTests ( connection ) ;
27
+ // Set rankEnabled to be true if testing with rank information.
28
+ CreateTable ( connection , rankEnabled : true ) ;
29
+ RunTests ( connection , rankEnabled : true ) ;
29
30
}
30
31
}
31
32
finally
@@ -65,7 +66,8 @@ public static bool DataClassificationSupported(SqlConnection connection)
65
66
/// Creates a temporary table for this sample program and sets tags for Sensitivity Classification.
66
67
/// </summary>
67
68
/// <param name="connection">The SqlConnection to work with.</param>
68
- private static void CreateTable ( SqlConnection connection )
69
+ /// <param name="rankEnabled">True if rank information is enabled and false otherwise</param>
70
+ private static void CreateTable ( SqlConnection connection , bool rankEnabled = false )
69
71
{
70
72
SqlCommand command = new SqlCommand ( null , connection ) ;
71
73
@@ -81,43 +83,67 @@ private static void CreateTable(SqlConnection connection)
81
83
+ "[Fax] [nvarchar](30) MASKED WITH (FUNCTION = 'default()') NULL)" ;
82
84
command . ExecuteNonQuery ( ) ;
83
85
84
- // Set Sensitivity Classification tags for table columns.
85
- command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
86
- + ".CompanyName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Company Name', INFORMATION_TYPE_ID='COMPANY')" ;
87
- command . ExecuteNonQuery ( ) ;
86
+ if ( rankEnabled )
87
+ {
88
+ // Set Sensitivity Classification tags for table columns with rank information
89
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
90
+ + ".CompanyName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Company Name', INFORMATION_TYPE_ID='COMPANY', RANK=LOW)" ;
91
+ command . ExecuteNonQuery ( ) ;
88
92
89
- command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
90
- + ".ContactName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Person Name', INFORMATION_TYPE_ID='NAME')" ;
91
- command . ExecuteNonQuery ( ) ;
93
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
94
+ + ".ContactName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Person Name', INFORMATION_TYPE_ID='NAME', RANK=LOW )" ;
95
+ command . ExecuteNonQuery ( ) ;
92
96
93
- command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
94
- + ".Phone WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT')" ;
95
- command . ExecuteNonQuery ( ) ;
97
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
98
+ + ".Phone WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT', RANK=MEDIUM )" ;
99
+ command . ExecuteNonQuery ( ) ;
96
100
97
- command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
98
- + ".Fax WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT')" ;
99
- command . ExecuteNonQuery ( ) ;
101
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
102
+ + ".Fax WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT', RANK=MEDIUM)" ;
103
+ command . ExecuteNonQuery ( ) ;
104
+ }
105
+ else
106
+ {
107
+ // Set Sensitivity Classification tags for table columns without rank information
108
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
109
+ + ".CompanyName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Company Name', INFORMATION_TYPE_ID='COMPANY')" ;
110
+ command . ExecuteNonQuery ( ) ;
111
+
112
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
113
+ + ".ContactName WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Person Name', INFORMATION_TYPE_ID='NAME')" ;
114
+ command . ExecuteNonQuery ( ) ;
115
+
116
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
117
+ + ".Phone WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT')" ;
118
+ command . ExecuteNonQuery ( ) ;
119
+
120
+ command . CommandText = $ "ADD SENSITIVITY CLASSIFICATION TO { tableName } "
121
+ + ".Fax WITH (LABEL='PII', LABEL_ID='L1', INFORMATION_TYPE='Contact Information', INFORMATION_TYPE_ID='CONTACT')" ;
122
+ command . ExecuteNonQuery ( ) ;
123
+ }
100
124
}
101
125
102
126
/// <summary>
103
127
/// Run query to fetch result set from target table.
104
128
/// </summary>
105
129
/// <param name="connection">The SqlConnection to work with.</param>
106
- private static void RunTests ( SqlConnection connection )
130
+ /// <param name="rankEnabled">True if rank information is enabled and false otherwise</param>
131
+ private static void RunTests ( SqlConnection connection , bool rankEnabled = false )
107
132
{
108
133
SqlCommand command = new SqlCommand ( null , connection ) ;
109
134
command . CommandText = $ "SELECT * FROM { tableName } ";
110
135
using ( SqlDataReader reader = command . ExecuteReader ( ) )
111
136
{
112
- PrintSensitivityClassification ( reader ) ;
137
+ PrintSensitivityClassification ( reader , rankEnabled ) ;
113
138
}
114
139
}
115
140
116
141
/// <summary>
117
142
/// Prints Sensitivity Classification data as received in the result set.
118
143
/// </summary>
119
144
/// <param name="reader">The SqlDataReader to work with.</param>
120
- private static void PrintSensitivityClassification ( SqlDataReader reader )
145
+ /// <param name="rankEnabled">True if rank information is enabled and false otherwise</param>
146
+ private static void PrintSensitivityClassification ( SqlDataReader reader , bool rankEnabled = false )
121
147
{
122
148
if ( reader . SensitivityClassification != null )
123
149
{
@@ -140,8 +166,11 @@ private static void PrintSensitivityClassification(SqlDataReader reader)
140
166
Console . WriteLine ( $ "Information Type: { sp . InformationType . Name } ") ;
141
167
Console . WriteLine ( ) ;
142
168
}
169
+
170
+ Console . WriteLine ( $ "Sensitivity Rank: { sp . SensitivityRank . ToString ( ) } ") ;
143
171
}
144
172
}
173
+ Console . Writeline ( $ "reader.SensitivityClassification.SensitivityRank : { reader . SensitivityClassification . SensitivityRank . ToString ( ) } ") ;
145
174
}
146
175
}
147
176
0 commit comments