Skip to content

Commit e032cf7

Browse files
committed
fix snippets errors
1 parent 6f05666 commit e032cf7

File tree

15 files changed

+291
-315
lines changed

15 files changed

+291
-315
lines changed

snippets/csharp/Microsoft.Win32/FileDialog/DefaultExt/Window1.xaml.cs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
using System;
2-
using System.Collections.Generic;
3-
using System.Text;
42
using System.Windows;
53
using System.Windows.Controls;
6-
using System.Windows.Data;
7-
using System.Windows.Documents;
8-
using System.Windows.Input;
9-
using System.Windows.Media;
10-
using System.Windows.Media.Imaging;
11-
using System.Windows.Shapes;
124

135
namespace CSharp
146
{
@@ -74,7 +66,7 @@ void openFileDialog_Click(object sender, RoutedEventArgs e)
7466
Nullable<bool> result = dlg.ShowDialog();
7567

7668
// Process open file dialog box results
77-
if (result)
69+
if (result.Value)
7870
{
7971
// Open document
8072
string filename = dlg.FileName;
@@ -95,7 +87,7 @@ void saveFileDialog_Click(object sender, RoutedEventArgs e)
9587
Nullable<bool> result = dlg.ShowDialog();
9688

9789
// Process save file dialog box results
98-
if (result)
90+
if (result.Value)
9991
{
10092
// Save document
10193
string filename = dlg.FileName;
@@ -115,11 +107,11 @@ void printDialog_Click(object sender, RoutedEventArgs e)
115107
Nullable<bool> result = dlg.ShowDialog();
116108

117109
// Process save file dialog box results
118-
if (result)
110+
if (result.Value)
119111
{
120112
// Print document
121113
}
122114
//</SnippetPrintDialogBoxCODEBEHIND>
123115
}
124116
}
125-
}
117+
}

snippets/csharp/System.IO.Packaging/EncryptedPackageEnvelope/Close/Window1.xaml.cs

Lines changed: 42 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,10 @@
88
using System.Security.RightsManagement;
99
using System.Windows;
1010
using System.Windows.Controls;
11-
using System.Windows.Data;
1211
using System.Windows.Documents;
1312
using System.Windows.Input;
1413
using System.Windows.Markup;
1514
using System.Windows.Xps.Packaging;
16-
using System.Xml;
1715
using WinForms = Microsoft.Win32;
1816

1917
namespace 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();

snippets/csharp/System.IO.Packaging/PackageStore/AddPackage/Window1.xaml.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,12 @@
77
using System.IO.Packaging;
88
using System.Net;
99
using System.Security.RightsManagement;
10-
using System.Text;
1110
using System.Windows;
1211
using System.Windows.Controls;
13-
using System.Windows.Data;
1412
using System.Windows.Documents;
1513
using System.Windows.Input;
1614
using System.Windows.Markup;
1715
using System.Windows.Xps.Packaging;
18-
using System.Xml;
1916
using WinForms = Microsoft.Win32;
2017

2118
namespace SdkSample
@@ -44,14 +41,16 @@ private void OnOpen(object target, ExecutedRoutedEventArgs args)
4441
{
4542
// Create a "File Open" dialog positioned to the
4643
// "Content\" folder containing the sample fixed document.
47-
WinForms.OpenFileDialog dialog = new WinForms.OpenFileDialog();
48-
dialog.InitialDirectory = GetContentFolder();
49-
dialog.CheckFileExists = true;
50-
dialog.Filter = "XPS Document files (*.xps)|*.xps";
44+
WinForms.OpenFileDialog dialog = new WinForms.OpenFileDialog
45+
{
46+
InitialDirectory = GetContentFolder(),
47+
CheckFileExists = true,
48+
Filter = "XPS Document files (*.xps)|*.xps"
49+
};
5150

5251
// Show the "File Open" dialog. If the user picks a file and
5352
// clicks "OK", load and display the specified XPS document.
54-
if (dialog.ShowDialog())
53+
if (dialog.ShowDialog().Value)
5554
{
5655
CloseDocument(); // Close current document if open.
5756
_xpsFile = dialog.FileName; // Save the path and file name.

snippets/csharp/System.Printing/LocalPrintServer/Overview/Window1.xaml.cs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private void WindowLoaded(object sender, RoutedEventArgs e)
7272
public String ContentDir
7373
{
7474
get
75-
{ return _contentDir; }
75+
{ return _contentDir; }
7676
}
7777

7878
#region Button Event Handlers
@@ -133,33 +133,33 @@ private void ButtonHelperPrint(bool async)
133133
switch (currentMode)
134134
{
135135
case eGuiMode.SingleVisual:
136-
{
137-
printHelper.PrintSingleVisual(printQueue, async);
138-
break;
139-
}
136+
{
137+
printHelper.PrintSingleVisual(printQueue, async);
138+
break;
139+
}
140140
case eGuiMode.MultipleVisuals:
141-
{
142-
printHelper.PrintMultipleVisuals(printQueue, async);
143-
break;
144-
}
141+
{
142+
printHelper.PrintMultipleVisuals(printQueue, async);
143+
break;
144+
}
145145
case eGuiMode.SingleFlowDocument:
146-
{
147-
printHelper.PrintSingleFlowContentDocument(
148-
printQueue, async);
149-
break;
150-
}
146+
{
147+
printHelper.PrintSingleFlowContentDocument(
148+
printQueue, async);
149+
break;
150+
}
151151
case eGuiMode.SingleFixedDocument:
152-
{
153-
printHelper.PrintSingleFixedContentDocument(
154-
printQueue, async);
155-
break;
156-
}
152+
{
153+
printHelper.PrintSingleFixedContentDocument(
154+
printQueue, async);
155+
break;
156+
}
157157
case eGuiMode.MultipleFixedDocuments:
158-
{
159-
printHelper.PrintMultipleFixedContentDocuments(
160-
printQueue, async);
161-
break;
162-
}
158+
{
159+
printHelper.PrintMultipleFixedContentDocuments(
160+
printQueue, async);
161+
break;
162+
}
163163
}// end:switch (currentMode)
164164
}// end:ButtonHelperSave()
165165

@@ -180,8 +180,8 @@ private void OnBtnCancelClick(object sender, RoutedEventArgs e)
180180
/// <param name="saveHelper"></param>
181181
/// <param name="asyncInformation">
182182
/// Progress information about the asynchronous save.</param>
183-
private void AsyncPrintEvent(
184-
object printHelper, AsyncPrintEventArgs asyncInformation)
183+
private void AsyncPrintEvent(
184+
object printHelper, AsyncPrintEventArgs asyncInformation)
185185
{
186186
if (asyncInformation.Completed)
187187
{
@@ -217,7 +217,7 @@ private string GetContainerPathFromDialog()
217217
saveFileDialog.Filter = "XPS document files (*.xps)|*.xps";
218218
saveFileDialog.FilterIndex = 1;
219219

220-
if (saveFileDialog.ShowDialog())
220+
if (saveFileDialog.ShowDialog().Value)
221221
{ // The user specified a valid path and filename.
222222
return saveFileDialog.FileName;
223223
}

0 commit comments

Comments
 (0)