-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathEncryptionViewModel.cs
81 lines (74 loc) · 2.94 KB
/
EncryptionViewModel.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#region Copyright Syncfusion® Inc. 2001-2025.
// Copyright Syncfusion® Inc. 2001-2025. All rights reserved.
// Use of this code is subject to the terms of our license.
// A copy of the current license can be obtained at any time by e-mailing
// licensing@syncfusion.com. Any infringement will be prosecuted under
// applicable laws.
#endregion
using Syncfusion.Windows.Shared;
using System;
using System.IO;
using System.Windows;
using System.Windows.Resources;
namespace syncfusion.pdfviewerdemos.wpf
{
public class EncryptionViewModel
{
private Stream m_documentStream;
private Encryption encryption = null;
/// <summary>
/// Gets or sets the documnet path.
/// </summary>
public Stream DocumentStream
{
get
{
return m_documentStream;
}
set
{
m_documentStream = value;
}
}
/// <summary>
/// Initializes a new instance of the <see cref="MainPageViewModel"/> class.
/// </summary>
public EncryptionViewModel()
{
m_documentStream = GetFileStream("Encrypted Document.pdf");
}
private Stream GetFileStream(string fileName)
{
Uri uriResource = new Uri("/syncfusion.pdfviewerdemos.wpf;component/Assets/" + fileName, UriKind.Relative);
StreamResourceInfo streamResourceInfo = Application.GetResourceStream(uriResource);
return streamResourceInfo.Stream;
}
public void Loaded(object sender, RoutedEventArgs e)
{
encryption = (sender as Encryption).FindName("encryption") as Encryption;
encryption.userpassword.Click += new RoutedEventHandler(Userpassword_Click);
encryption.ownerpassword.Click += new RoutedEventHandler(Ownerpassword_Click);
}
private void Ownerpassword_Click(object sender, RoutedEventArgs e)
{
encryption.userpassword.Visibility = Visibility.Collapsed;
encryption.ownerpassword.Visibility = Visibility.Collapsed;
encryption.pdfviewer1.Visibility = Visibility.Visible;
encryption.pdfviewer1.Load(DocumentStream, "syncfusion");
}
private void Userpassword_Click(object sender, RoutedEventArgs e)
{
encryption.userpassword.Visibility = Visibility.Collapsed;
encryption.ownerpassword.Visibility = Visibility.Collapsed;
encryption.pdfviewer1.Visibility = Visibility.Visible;
encryption.pdfviewer1.Load(DocumentStream, "password");
}
public void Closed(object sender, RoutedEventArgs e)
{
encryption.userpassword.Visibility = Visibility.Visible;
encryption.ownerpassword.Visibility = Visibility.Visible;
encryption.userpassword.Click -= Userpassword_Click;
encryption.ownerpassword.Click -= Ownerpassword_Click;
}
}
}