forked from J8K3-zz/speventreceiverman
/
CopyDialog.cs
211 lines (175 loc) · 6.92 KB
/
CopyDialog.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.SharePoint;
using System.Reflection;
using System.Text;
namespace SPEventReceiverManager
{
public partial class CopyDialog : Form
{
#region Fields
private readonly spevthkman m_ParentForm;
private SPSite m_DestinationSite;
private SPWeb m_DestinationWeb;
private SPList m_DestinationList;
#endregion
#region Constructors
public CopyDialog(spevthkman parentForm, SPWeb web, ISecurableObject selectedObject)
: base()
{
this.m_ParentForm = parentForm;
InitializeComponent();
this.Web = web;
this.SelectedObject = selectedObject;
}
#endregion
#region Properties
internal SPWeb Web
{
get;
private set;
}
internal ISecurableObject SelectedObject
{
get;
private set;
}
#endregion
#region Methods
private void HandleException(Exception ex)
{
MessageBox.Show(this, ex.ToString(), "An unexpected errror has occured!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void CopyDialog_Load(object sender, EventArgs e)
{
try
{
this.SourceSiteLabel.Text = this.Web.Site.Url;
this.SourceWebLabel.Text = this.Web.Title;
SPList list = this.SelectedObject as SPList;
this.SourceListLabel.Text = list.Title;
foreach (SPEventReceiverDefinition def in list.EventReceivers)
{
this.EventReceiverCheckedListBox.Items.Add(def, true);
}
Utility.GetSitesOnLocalServer(this.SiteComboBox.Items);
}
catch (Exception ex)
{
this.HandleException(ex);
}
}
private void SiteComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
SiteItem siteItem = this.SiteComboBox.SelectedItem as SiteItem;
if (siteItem != null)
{
this.m_DestinationSite = new SPSite(siteItem.SiteId);
this.WebComboBox.Items.Clear();
foreach (SPWeb web in this.m_DestinationSite.AllWebs)
{
this.WebComboBox.Items.Add(new SiteItem((web.IsRootWeb ? "[Root Web]" : web.Name), web.ID));
}
}
}
catch (UnauthorizedAccessException)
{
MessageBox.Show(this, "You do not have permission to access the selected site.", "Unauthorized Access", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
}
catch (Exception ex)
{
this.HandleException(ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void WebComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
SiteItem webItem = this.WebComboBox.SelectedItem as SiteItem;
this.m_DestinationWeb = this.m_DestinationSite.OpenWeb(webItem.SiteId);
foreach (SPList list in this.m_DestinationWeb.Lists)
{
this.ListComboBox.Items.Add(new SecurableObjectItem(list.Title, list.ID));
}
}
catch (UnauthorizedAccessException)
{
MessageBox.Show(this, "You do not have permission to access the selected site.", "Unauthorized Access", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
}
catch (Exception ex)
{
this.HandleException(ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void ListComboBox_SelectedIndexChanged(object sender, EventArgs e)
{
try
{
this.Cursor = Cursors.WaitCursor;
SecurableObjectItem listItem = this.ListComboBox.SelectedItem as SecurableObjectItem;
this.m_DestinationList = this.m_DestinationWeb.Lists[listItem.ObjectId];
}
catch (UnauthorizedAccessException)
{
MessageBox.Show(this, "You do not have permission to access the selected site.", "Unauthorized Access", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1);
}
catch (Exception ex)
{
this.HandleException(ex);
}
finally
{
this.Cursor = Cursors.Default;
}
}
private void OkButton_Click(object sender, EventArgs e)
{
try
{
foreach (SPEventReceiverDefinition definition in this.EventReceiverCheckedListBox.CheckedItems)
{
MethodInfo hook = Utility.ResolveEventHook(definition.Assembly, definition.Class, definition.Type);
if (hook == null)
{
StringBuilder message = new StringBuilder();
message.AppendLine("The event receiver listed below cannot be copied because the referenced assembly or type cannot be resolved.");
message.AppendFormat("[{0}, {1}] [{2}]", definition.Class, definition.Assembly, definition.ContextItemUrl);
MessageBox.Show(this, message.ToString(), "Invalid Event hook Search Result", MessageBoxButtons.OK);
}
else
{
Utility.ProcessEventHookAction(this, this.m_DestinationList, definition.Type.ToString(), hook.Module.Assembly, hook.ReflectedType, true);
}
}
this.DialogResult = System.Windows.Forms.DialogResult.OK;
this.Close();
}
catch (Exception ex)
{
this.HandleException(ex);
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
}
private void CancelButton_Click(object sender, EventArgs e)
{
this.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.Close();
}
#endregion
}
}