@@ -24,8 +24,9 @@ public static void Main()
2424                if  ( DataClassificationSupported ( connection ) ) 
2525                { 
2626                    // 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 ) ; 
2930                } 
3031            } 
3132            finally 
@@ -65,7 +66,8 @@ public static bool DataClassificationSupported(SqlConnection connection)
6566    /// Creates a temporary table for this sample program and sets tags for Sensitivity Classification. 
6667    /// </summary> 
6768    /// <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 ) 
6971    { 
7072        SqlCommand  command  =  new  SqlCommand ( null ,  connection ) ; 
7173
@@ -81,43 +83,67 @@ private static void CreateTable(SqlConnection connection)
8183            +  "[Fax] [nvarchar](30) MASKED WITH (FUNCTION = 'default()') NULL)" ; 
8284        command . ExecuteNonQuery ( ) ; 
8385
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 ( ) ; 
8892
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 ( ) ; 
9296
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 ( ) ; 
96100
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+         }         
100124    } 
101125
102126    /// <summary> 
103127    /// Run query to fetch result set from target table. 
104128    /// </summary> 
105129    /// <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 ) 
107132    { 
108133        SqlCommand  command  =  new  SqlCommand ( null ,  connection ) ; 
109134        command . CommandText  =  $ "SELECT * FROM { tableName } "; 
110135        using  ( SqlDataReader  reader  =  command . ExecuteReader ( ) ) 
111136        { 
112-             PrintSensitivityClassification ( reader ) ; 
137+             PrintSensitivityClassification ( reader ,   rankEnabled ) ; 
113138        } 
114139    } 
115140
116141    /// <summary> 
117142    /// Prints Sensitivity Classification data as received in the result set. 
118143    /// </summary> 
119144    /// <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 ) 
121147    { 
122148        if  ( reader . SensitivityClassification  !=  null ) 
123149        { 
@@ -140,8 +166,11 @@ private static void PrintSensitivityClassification(SqlDataReader reader)
140166                        Console . WriteLine ( $ "Information Type: { sp . InformationType . Name } ") ; 
141167                        Console . WriteLine ( ) ; 
142168                    } 
169+ 
170+                     Console . WriteLine ( $ "Sensitivity Rank: { sp . SensitivityRank . ToString ( ) } ") ; 
143171                } 
144172            } 
173+             Console . Writeline ( $ "reader.SensitivityClassification.SensitivityRank : { reader . SensitivityClassification . SensitivityRank . ToString ( ) } ") ; 
145174        } 
146175    } 
147176
0 commit comments