-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathucUsers.vb
182 lines (122 loc) · 5.86 KB
/
ucUsers.vb
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
Imports System.Data.SqlClient
Imports System.DirectoryServices
Imports DNNTool.Entities
Imports System.ComponentModel
Imports DNNTool.Services
Imports DNNTool.Services.Args
Public Class ucUsers
#Region "Private Members"
Private _srcConnectionString As String = ""
Private _srcSiteName As String = ""
Private _srcSiteAlias As String = ""
Private _srcSitePath As String = ""
Private _srcDatabaseName As String = ""
Private _srcSitePort As Integer = 80
Private _connection As SqlConnection = Nothing
#End Region
#Region "Event Handlers"
Private Sub drpSiteForUserCreation_SelectedIndexChanged(sender As Object, e As EventArgs) Handles drpSiteForUserCreation.SelectedIndexChanged
BindSite()
End Sub
Private Sub btnCreateAccountStart_Click(sender As Object, e As EventArgs) Handles btnCreateAccountStart.Click
If Not _connection Is Nothing Then
If UserCreateProcess.IsBusy <> True Then
Dim args As New UserCreateArgs
args.Accounts = Convert.ToInt32(ctlNumberofAcounts.Value)
args.CleanUpFirst = chkCleanFirst.Checked
args.PortalId = Convert.ToInt32(ctlPortalId.Value)
args.Connection = _connection
btnCreateAccountCancel.Enabled = True
btnCreateAccountStart.Enabled = False
lblCreateResult.Text = "Processing request..."
UserCreateProcess.RunWorkerAsync(args)
Else
MsgBox("Another process is still busy. Please wait...")
End If
Else
MsgBox("Could not connect to database!")
End If
End Sub
Private Sub btnCreateAccountCancel_Click(sender As Object, e As EventArgs) Handles btnCreateAccountCancel.Click
If UserCreateProcess.WorkerSupportsCancellation Then
UserCreateProcess.CancelAsync()
btnCreateAccountCancel.Enabled = False
ctlAccountsProgress.Value = 0
End If
End Sub
Private Sub UserCreateProcess_DoWork(sender As Object, e As System.ComponentModel.DoWorkEventArgs) Handles UserCreateProcess.DoWork
e.Result = Services.UserCreator.Work(CType(sender, BackgroundWorker), e)
End Sub
Private Sub UserCreateProcess_ProgressChanged(sender As Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles UserCreateProcess.ProgressChanged
ctlAccountsProgress.Value = e.ProgressPercentage
lblCreateResult.Text = e.ProgressPercentage.ToString
End Sub
Private Sub UserCreateProcess_RunWorkerCompleted(sender As Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles UserCreateProcess.RunWorkerCompleted
' First, handle the case where an exception was thrown.
If (e.Error IsNot Nothing) Then
MessageBox.Show(e.Error.Message)
ElseIf e.Cancelled Then
' Next, handle the case where the user canceled the
' operation.
' Note that due to a race condition in
' the DoWork event handler, the Cancelled
' flag may not have been set, even though
' CancelAsync was called.
lblCreateResult.Text = "Canceled"
Else
' Finally, handle the case where the operation succeeded.
lblCreateResult.Text = e.Result.ToString()
End If
' Enable the Start button.
btnCreateAccountStart.Enabled = True
' Disable the Cancel button.
btnCreateAccountCancel.Enabled = False
ctlAccountsProgress.Value = 0
End Sub
Private Sub ucUsers_Load(sender As Object, e As EventArgs) Handles Me.Load
BindSites()
End Sub
#End Region
#Region "Private Methods"
Private Sub BindSites()
drpSiteForUserCreation.Items.Clear()
Dim IISServer As New DirectoryEntry("IIS://localhost/W3SVC")
For Each e As DirectoryEntry In IISServer.Children
If e.SchemaClassName.ToLower = "iiswebserver" Then
Dim siteName As String = e.Properties("ServerComment")(0).ToString
Dim siteId As String = e.Name
If Common.Utilities.IsDNN(siteId) Then
drpSiteForUserCreation.Items.Add(New SiteItem(siteId, siteName))
End If
End If
Next
End Sub
Private Sub BindSite()
_srcSiteName = CType(drpSiteForUserCreation.SelectedItem, SiteItem).SiteName
Dim site As IISWebsite = IISWebsite.OpenWebsite(_srcSiteName)
If Not site Is Nothing Then
_srcSitePath = site.Root.Path()
_srcSiteAlias = site.Hostheader
_srcSitePort = site.Port
If System.IO.Directory.Exists(_srcSitePath) Then
Dim path As String = _srcSitePath
path += ("\bin\dotnetnuke.dll").Replace("\\", "\")
Dim dnnVersionInfo As FileVersionInfo = FileVersionInfo.GetVersionInfo(path)
If Not dnnVersionInfo Is Nothing Then
_srcConnectionString = Common.Utilities.GetConnectionStringFromConfig(_srcSitePath)
If Not String.IsNullOrEmpty(_srcConnectionString) Then
_connection = Common.Utilities.GetDatabaseConnection(_srcConnectionString)
End If
lblDNNVersion.Text = String.Format("DNN {0}.{1}.{2}", dnnVersionInfo.FileMajorPart.ToString, dnnVersionInfo.FileMinorPart.ToString, dnnVersionInfo.FileBuildPart.ToString)
lblAlias.Text = _srcSiteAlias
lblConnectionString.Text = _srcConnectionString
lblDatabasename.Text = _srcDatabaseName
lblPort.Text = _srcSitePort.ToString
lblSitePath.Text = _srcSitePath
btnCreateAccountStart.Enabled = True
End If
End If
End If
End Sub
#End Region
End Class