88using System . Security . RightsManagement ;
99using System . Windows ;
1010using System . Windows . Controls ;
11- using System . Windows . Data ;
1211using System . Windows . Documents ;
1312using System . Windows . Input ;
1413using System . Windows . Markup ;
1514using System . Windows . Xps . Packaging ;
16- using System . Xml ;
1715using WinForms = Microsoft . Win32 ;
1816
1917namespace SdkSample
@@ -44,7 +42,7 @@ private void OnOpen(object target, ExecutedRoutedEventArgs args)
4442 {
4543 string msg =
4644 "The currently open document needs to be closed before\n " +
47- "opening a new document. Ok to close '" + _xpsDocumentName + "'?" ;
45+ "opening a new document. Ok to close '" + _xpsDocumentName + "'?" ;
4846 MessageBoxResult result =
4947 MessageBox . Show ( msg , "Close Current Document?" ,
5048 MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
@@ -68,7 +66,7 @@ private void OnOpen(object target, ExecutedRoutedEventArgs args)
6866
6967 // Show the "File Open" dialog. If the user picks a file and
7068 // clicks "OK", load and display the specified XPS document.
71- if ( dialog . ShowDialog ( ) )
69+ if ( dialog . ShowDialog ( ) . Value )
7270 OpenDocument ( dialog . FileName ) ;
7371 } // end:OnOpen()
7472
@@ -86,7 +84,7 @@ public bool OpenDocument(string filename)
8684 _xpsDocumentPath = filename ;
8785
8886 // Extract the document filename without the path.
89- _xpsDocumentName = filename . Remove ( 0 , filename . LastIndexOf ( '\\ ' ) + 1 ) ;
87+ _xpsDocumentName = filename . Remove ( 0 , filename . LastIndexOf ( '\\ ' ) + 1 ) ;
9088
9189 _packageUri = new Uri ( filename , UriKind . Absolute ) ;
9290 try
@@ -129,8 +127,8 @@ public bool OpenDocument(string filename)
129127 docViewer . Document = fds ;
130128
131129 // Enable document menu controls.
132- menuFileClose . IsEnabled = true ;
133- menuFilePrint . IsEnabled = true ;
130+ menuFileClose . IsEnabled = true ;
131+ menuFilePrint . IsEnabled = true ;
134132 menuFileRights . IsEnabled = true ;
135133 menuViewIncreaseZoom . IsEnabled = true ;
136134 menuViewDecreaseZoom . IsEnabled = true ;
@@ -185,7 +183,7 @@ private Package GetPackage(string filename)
185183 {
186184 Stream inputPackageStream = webResponse . GetResponseStream ( ) ;
187185 if ( inputPackageStream != null )
188- {
186+ {
189187 // Retrieve the Package from that stream.
190188 inputPackage = Package . Open ( inputPackageStream ) ;
191189 }
@@ -318,7 +316,7 @@ private void OnRights(object sender, EventArgs e)
318316
319317 // Show the "File Open" dialog. If the user picks a file and
320318 // clicks "OK", load and display the specified XPS document.
321- if ( dialog . ShowDialog ( ) )
319+ if ( dialog . ShowDialog ( ) . Value )
322320 OpenXrML ( dialog . FileName ) ;
323321 } // end:OnRights()
324322
@@ -350,7 +348,7 @@ public bool OpenXrML(string filename)
350348
351349 WriteStatus ( "Opened '" + _xrmlFilename + "'" ) ;
352350 WritePrompt ( "Click 'File | Publish...' to publish the document " +
353- "package with the permissions specified in '" + _xrmlFilename + "'." ) ;
351+ "package with the permissions specified in '" + _xrmlFilename + "'." ) ;
354352 rightsBlockTitle . Text = "Rights - " + _xrmlFilename ;
355353 return true ;
356354 } // end:OpenXrML()
@@ -385,23 +383,26 @@ private void OnPublish(object sender, EventArgs e)
385383 {
386384 // Create a "File Save" dialog positioned to the
387385 // "Content\" folder to write the encrypted package to.
388- WinForms . SaveFileDialog dialog = new WinForms . SaveFileDialog ( ) ;
389- dialog . InitialDirectory = GetContentFolder ( ) ;
390- dialog . Title = "Publish Rights Managed Package As" ;
391- dialog . Filter = "Rights Managed XPS package (*-RM.xps)|*-RM.xps" ;
386+ WinForms . SaveFileDialog dialog = new ( )
387+ {
388+ InitialDirectory = GetContentFolder ( ) ,
389+ Title = "Publish Rights Managed Package As" ,
390+ Filter = "Rights Managed XPS package (*-RM.xps)|*-RM.xps" ,
392391
393- // Create a new package filename by prefixing
394- // the document filename extension with "rm".
395- dialog . FileName = _xpsDocumentPath . Insert (
396- _xpsDocumentPath . LastIndexOf ( '.' ) , "-RM" ) ;
392+ // Create a new package filename by prefixing
393+ // the document filename extension with "rm".
394+ FileName = _xpsDocumentPath . Insert (
395+ _xpsDocumentPath . LastIndexOf ( '.' ) , "-RM" )
396+ } ;
397397
398398 // Show the "Save As" dialog. If the user clicks "Cancel", return.
399- if ( ! dialog . ShowDialog ( ) ) return ;
399+ if ( ! dialog . ShowDialog ( ) . Value )
400+ return ;
400401
401402 // Extract the filename without path.
402403 _rmxpsPackagePath = dialog . FileName ;
403404 _rmxpsPackageName = _rmxpsPackagePath . Remove (
404- 0 , _rmxpsPackagePath . LastIndexOf ( '\\ ' ) + 1 ) ;
405+ 0 , _rmxpsPackagePath . LastIndexOf ( '\\ ' ) + 1 ) ;
405406
406407 WriteStatus ( "Publishing '" + _rmxpsPackageName + "'." ) ;
407408 PublishRMPackage ( _xpsDocumentPath , _xrmlFilepath , dialog . FileName ) ;
@@ -425,12 +426,12 @@ public bool PublishRMPackage(
425426 string xrmlString ;
426427
427428 // Extract individual filenames without the path.
428- string packageFilename = packageFile . Remove ( 0 ,
429- packageFile . LastIndexOf ( '\\ ' ) + 1 ) ;
430- string xrmlFilename = xrmlFile . Remove ( 0 ,
431- xrmlFile . LastIndexOf ( '\\ ' ) + 1 ) ;
432- string encryptedFilename = encryptedFile . Remove ( 0 ,
433- encryptedFile . LastIndexOf ( '\\ ' ) + 1 ) ;
429+ string packageFilename = packageFile . Remove ( 0 ,
430+ packageFile . LastIndexOf ( '\\ ' ) + 1 ) ;
431+ string xrmlFilename = xrmlFile . Remove ( 0 ,
432+ xrmlFile . LastIndexOf ( '\\ ' ) + 1 ) ;
433+ string encryptedFilename = encryptedFile . Remove ( 0 ,
434+ encryptedFile . LastIndexOf ( '\\ ' ) + 1 ) ;
434435
435436 try
436437 {
@@ -443,7 +444,7 @@ public bool PublishRMPackage(
443444 }
444445 catch ( Exception ex )
445446 {
446- MessageBox . Show ( "ERROR: '" + xrmlFilename + "' open failed.\n " +
447+ MessageBox . Show ( "ERROR: '" + xrmlFilename + "' open failed.\n " +
447448 "Exception: " + ex . Message , "XrML File Error" ,
448449 MessageBoxButton . OK , MessageBoxImage . Error ) ;
449450 return false ;
@@ -511,7 +512,7 @@ public bool PublishRMPackage(
511512 "XrML UnsignedPublishLicense owner name: " + author . Name ,
512513 "Incorrect Authentication Name" ,
513514 MessageBoxButton . OK , MessageBoxImage . Error ) ;
514- return false ;
515+ return false ;
515516 }
516517
517518 //<SnippetRmPkgPubEncrypt>
@@ -585,9 +586,11 @@ static internal string GetDefaultWindowsUserName()
585586 string [ ] splitUserName = wi . Name . Split ( '\\ ' ) ;
586587
587588 System . DirectoryServices . DirectorySearcher src =
588- new System . DirectoryServices . DirectorySearcher ( ) ;
589- src . SearchRoot = new System . DirectoryServices . DirectoryEntry (
590- "LDAP://" + splitUserName [ 0 ] ) ;
589+ new System . DirectoryServices . DirectorySearcher
590+ {
591+ SearchRoot = new System . DirectoryServices . DirectoryEntry (
592+ "LDAP://" + splitUserName [ 0 ] )
593+ } ;
591594
592595 src . PropertiesToLoad . Add ( "mail" ) ;
593596
@@ -676,7 +679,7 @@ private void OnPrint(object target, ExecutedRoutedEventArgs args)
676679 /// Prints the DocumentViewer's content and annotations.</summary>
677680 public void PrintDocument ( )
678681 {
679- if ( docViewer == null ) return ;
682+ if ( docViewer == null ) return ;
680683 docViewer . Print ( ) ;
681684 } // end:PrintDocument()
682685
@@ -686,20 +689,20 @@ public void PrintDocument()
686689 public DocumentViewer DocViewer
687690 {
688691 get
689- { return docViewer ; } // "docViewer" declared in Window1.xaml
692+ { return docViewer ; } // "docViewer" declared in Window1.xaml
690693 }
691694 #endregion Utilities
692695
693696 #region private fields
694697 private string _xrmlFilepath = null ; // xrml path and filename.
695698 private string _xrmlFilename = null ; // xrml filename without path.
696699 private string _xrmlString = null ; // xrml string.
697- private string _xpsDocumentPath = null ; // XPS doc path and filename.
698- private string _xpsDocumentName = null ; // XPS doc filename without path.
699- private string _rmxpsPackagePath = null ; // RM package path and filename.
700- private string _rmxpsPackageName = null ; // RM package name without path.
701- private Uri _packageUri ; // XPS document path and filename URI.
702- private Package _xpsPackage = null ; // XPS document package.
700+ private string _xpsDocumentPath = null ; // XPS doc path and filename.
701+ private string _xpsDocumentName = null ; // XPS doc filename without path.
702+ private string _rmxpsPackagePath = null ; // RM package path and filename.
703+ private string _rmxpsPackageName = null ; // RM package name without path.
704+ private Uri _packageUri ; // XPS document path and filename URI.
705+ private Package _xpsPackage = null ; // XPS document package.
703706 private XpsDocument _xpsDocument ; // XPS document within the package.
704707 private static SecureEnvironment _secureEnv = null ;
705708 private static String _currentUserId = GetDefaultWindowsUserName ( ) ;
0 commit comments