8
8
using System . Security . RightsManagement ;
9
9
using System . Windows ;
10
10
using System . Windows . Controls ;
11
- using System . Windows . Data ;
12
11
using System . Windows . Documents ;
13
12
using System . Windows . Input ;
14
13
using System . Windows . Markup ;
15
14
using System . Windows . Xps . Packaging ;
16
- using System . Xml ;
17
15
using WinForms = Microsoft . Win32 ;
18
16
19
17
namespace SdkSample
@@ -44,7 +42,7 @@ private void OnOpen(object target, ExecutedRoutedEventArgs args)
44
42
{
45
43
string msg =
46
44
"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 + "'?" ;
48
46
MessageBoxResult result =
49
47
MessageBox . Show ( msg , "Close Current Document?" ,
50
48
MessageBoxButton . OKCancel , MessageBoxImage . Question ) ;
@@ -68,7 +66,7 @@ private void OnOpen(object target, ExecutedRoutedEventArgs args)
68
66
69
67
// Show the "File Open" dialog. If the user picks a file and
70
68
// clicks "OK", load and display the specified XPS document.
71
- if ( dialog . ShowDialog ( ) )
69
+ if ( dialog . ShowDialog ( ) . Value )
72
70
OpenDocument ( dialog . FileName ) ;
73
71
} // end:OnOpen()
74
72
@@ -86,7 +84,7 @@ public bool OpenDocument(string filename)
86
84
_xpsDocumentPath = filename ;
87
85
88
86
// Extract the document filename without the path.
89
- _xpsDocumentName = filename . Remove ( 0 , filename . LastIndexOf ( '\\ ' ) + 1 ) ;
87
+ _xpsDocumentName = filename . Remove ( 0 , filename . LastIndexOf ( '\\ ' ) + 1 ) ;
90
88
91
89
_packageUri = new Uri ( filename , UriKind . Absolute ) ;
92
90
try
@@ -129,8 +127,8 @@ public bool OpenDocument(string filename)
129
127
docViewer . Document = fds ;
130
128
131
129
// Enable document menu controls.
132
- menuFileClose . IsEnabled = true ;
133
- menuFilePrint . IsEnabled = true ;
130
+ menuFileClose . IsEnabled = true ;
131
+ menuFilePrint . IsEnabled = true ;
134
132
menuFileRights . IsEnabled = true ;
135
133
menuViewIncreaseZoom . IsEnabled = true ;
136
134
menuViewDecreaseZoom . IsEnabled = true ;
@@ -185,7 +183,7 @@ private Package GetPackage(string filename)
185
183
{
186
184
Stream inputPackageStream = webResponse . GetResponseStream ( ) ;
187
185
if ( inputPackageStream != null )
188
- {
186
+ {
189
187
// Retrieve the Package from that stream.
190
188
inputPackage = Package . Open ( inputPackageStream ) ;
191
189
}
@@ -318,7 +316,7 @@ private void OnRights(object sender, EventArgs e)
318
316
319
317
// Show the "File Open" dialog. If the user picks a file and
320
318
// clicks "OK", load and display the specified XPS document.
321
- if ( dialog . ShowDialog ( ) )
319
+ if ( dialog . ShowDialog ( ) . Value )
322
320
OpenXrML ( dialog . FileName ) ;
323
321
} // end:OnRights()
324
322
@@ -350,7 +348,7 @@ public bool OpenXrML(string filename)
350
348
351
349
WriteStatus ( "Opened '" + _xrmlFilename + "'" ) ;
352
350
WritePrompt ( "Click 'File | Publish...' to publish the document " +
353
- "package with the permissions specified in '" + _xrmlFilename + "'." ) ;
351
+ "package with the permissions specified in '" + _xrmlFilename + "'." ) ;
354
352
rightsBlockTitle . Text = "Rights - " + _xrmlFilename ;
355
353
return true ;
356
354
} // end:OpenXrML()
@@ -385,23 +383,26 @@ private void OnPublish(object sender, EventArgs e)
385
383
{
386
384
// Create a "File Save" dialog positioned to the
387
385
// "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" ,
392
391
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
+ } ;
397
397
398
398
// Show the "Save As" dialog. If the user clicks "Cancel", return.
399
- if ( ! dialog . ShowDialog ( ) ) return ;
399
+ if ( ! dialog . ShowDialog ( ) . Value )
400
+ return ;
400
401
401
402
// Extract the filename without path.
402
403
_rmxpsPackagePath = dialog . FileName ;
403
404
_rmxpsPackageName = _rmxpsPackagePath . Remove (
404
- 0 , _rmxpsPackagePath . LastIndexOf ( '\\ ' ) + 1 ) ;
405
+ 0 , _rmxpsPackagePath . LastIndexOf ( '\\ ' ) + 1 ) ;
405
406
406
407
WriteStatus ( "Publishing '" + _rmxpsPackageName + "'." ) ;
407
408
PublishRMPackage ( _xpsDocumentPath , _xrmlFilepath , dialog . FileName ) ;
@@ -425,12 +426,12 @@ public bool PublishRMPackage(
425
426
string xrmlString ;
426
427
427
428
// 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 ) ;
434
435
435
436
try
436
437
{
@@ -443,7 +444,7 @@ public bool PublishRMPackage(
443
444
}
444
445
catch ( Exception ex )
445
446
{
446
- MessageBox . Show ( "ERROR: '" + xrmlFilename + "' open failed.\n " +
447
+ MessageBox . Show ( "ERROR: '" + xrmlFilename + "' open failed.\n " +
447
448
"Exception: " + ex . Message , "XrML File Error" ,
448
449
MessageBoxButton . OK , MessageBoxImage . Error ) ;
449
450
return false ;
@@ -511,7 +512,7 @@ public bool PublishRMPackage(
511
512
"XrML UnsignedPublishLicense owner name: " + author . Name ,
512
513
"Incorrect Authentication Name" ,
513
514
MessageBoxButton . OK , MessageBoxImage . Error ) ;
514
- return false ;
515
+ return false ;
515
516
}
516
517
517
518
//<SnippetRmPkgPubEncrypt>
@@ -585,9 +586,11 @@ static internal string GetDefaultWindowsUserName()
585
586
string [ ] splitUserName = wi . Name . Split ( '\\ ' ) ;
586
587
587
588
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
+ } ;
591
594
592
595
src . PropertiesToLoad . Add ( "mail" ) ;
593
596
@@ -676,7 +679,7 @@ private void OnPrint(object target, ExecutedRoutedEventArgs args)
676
679
/// Prints the DocumentViewer's content and annotations.</summary>
677
680
public void PrintDocument ( )
678
681
{
679
- if ( docViewer == null ) return ;
682
+ if ( docViewer == null ) return ;
680
683
docViewer . Print ( ) ;
681
684
} // end:PrintDocument()
682
685
@@ -686,20 +689,20 @@ public void PrintDocument()
686
689
public DocumentViewer DocViewer
687
690
{
688
691
get
689
- { return docViewer ; } // "docViewer" declared in Window1.xaml
692
+ { return docViewer ; } // "docViewer" declared in Window1.xaml
690
693
}
691
694
#endregion Utilities
692
695
693
696
#region private fields
694
697
private string _xrmlFilepath = null ; // xrml path and filename.
695
698
private string _xrmlFilename = null ; // xrml filename without path.
696
699
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.
703
706
private XpsDocument _xpsDocument ; // XPS document within the package.
704
707
private static SecureEnvironment _secureEnv = null ;
705
708
private static String _currentUserId = GetDefaultWindowsUserName ( ) ;
0 commit comments