forked from AricieConseil/Aricie.PortalKeeper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeeperConfig.ascx.vb
663 lines (523 loc) · 31 KB
/
KeeperConfig.ascx.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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
Imports System.Diagnostics
Imports System.Collections.Generic
Imports System.Reflection
Imports System.Web.Compilation
Imports System.Xml
Imports DotNetNuke.Common
Imports DotNetNuke.UI.Skins.Controls
Imports DotNetNuke.Services.Exceptions
Imports DotNetNuke.Services.Localization
Imports DotNetNuke.UI.Skins
Imports DotNetNuke.UI.WebControls
Imports Aricie.Collections
Imports Aricie.Services
Imports Aricie.DNN.UI.Controls
Imports Aricie.DNN.Settings
Imports Aricie.DNN.Security.Trial
Imports Aricie.DNN.Configuration
Imports Aricie.DNN.Services
Imports Aricie.DNN.Diagnostics
Imports Aricie.DNN.Services.Workers
Imports Aricie.DNN.TestSurrogates
Imports Aricie.DNN.UI.WebControls
Imports Aricie.Web
Namespace Aricie.DNN.Modules.PortalKeeper.UI
Partial Class KeeperConfig
Inherits AriciePortalModuleBase
Public Sub New()
MyBase.New()
#If DEBUG Then
'the following mechansim illustrates bringing a compiled coding section into edit and continue domain within this code behind file
AddHandler DnnContext.Current.Debug, AddressOf Me.OnDebug
RegisterDebugSurrogates()
#End If
End Sub
Private _KeeperConfig As PortalKeeperConfig
Private _KeeperSettings As FirewallSettings
Protected ReadOnly Property KeeperConfig() As PortalKeeperConfig
Get
If _KeeperConfig Is Nothing Then
If Me.IsPostBack AndAlso Me.UserInfo.IsSuperUser Then
_KeeperConfig = DirectCast(Session("KeeperConfig"), PortalKeeperConfig)
If _KeeperConfig Is Nothing Then
_KeeperConfig = ReflectionHelper.CloneObject(Of PortalKeeperConfig)(PortalKeeperConfig.Instance)
'Session("KeeperConfig") = _KeeperConfig (moved in prerender to support datasource changes)
End If
Else
dim existing as PortalKeeperConfig = TryCast(Session("KeeperConfig"), PortalKeeperConfig)
If existing IsNot Nothing Then
Session.Remove("KeeperConfig")
End If
Dim objConfig As PortalKeeperConfig = PortalKeeperConfig.Instance
_KeeperConfig = objConfig
If Me.UserInfo.IsSuperUser Then
Dim cloningJob As New SessionCloningJob(Of PortalKeeperConfig)(Me.Session, objConfig, "KeeperConfig")
cloningJob.Enqueue()
End If
End If
End If
Return _KeeperConfig
End Get
End Property
Protected ReadOnly Property KeeperSettings() As FirewallSettings
Get
If _KeeperSettings Is Nothing Then
If Not Me.IsPostBack OrElse Session("KeeperSettings") Is Nothing Then
Session("KeeperSettings") = SettingsController.GetModuleSettings(Of FirewallSettings)(SettingsScope.PortalSettings, NukeHelper.PortalId)
End If
_KeeperSettings = DirectCast(Session("KeeperSettings"), FirewallSettings)
End If
Return _KeeperSettings
End Get
End Property
Private _UserBotSettings As UserBotSettings(Of ScheduleEvent)
Protected ReadOnly Property UserBotSettings As UserBotSettings(Of ScheduleEvent)
Get
If _UserBotSettings Is Nothing Then
Me.KeeperConfig.SchedulerFarm.AvailableUserBots.TryGetValue(Me.KeeperModuleSettings.UserBotName, _UserBotSettings)
End If
Return _UserBotSettings
End Get
End Property
Private _UserBot As UserBotInfo
Public Property UserBot() As UserBotInfo
Get
If _UserBot Is Nothing Then
If Me.UserBotSettings IsNot Nothing Then
Dim key As String = "UserBot" & Me.UserBotSettings.Name
If Not Me.IsPostBack OrElse Session(key) Is Nothing Then
Session(key) = Me.UserBotSettings.GetUserBotInfo(Me.UserInfo, True)
End If
_UserBot = DirectCast(Session(key), UserBotInfo)
If Me.KeeperModuleSettings.DisplayRankings Then
Dim objRankings As List(Of ProbeRanking) = Me.UserBotSettings.GetRankings()
If objRankings IsNot Nothing Then
_UserBot.Rankings = objRankings
End If
End If
End If
End If
Return _UserBot
End Get
Set(value As UserBotInfo)
Dim userSettings As UserBotSettings(Of ScheduleEvent) = Nothing
If Me.KeeperConfig.SchedulerFarm.AvailableUserBots.TryGetValue(Me.KeeperModuleSettings.UserBotName, userSettings) Then
userSettings.SetUserBotInfo(Me.UserInfo, Me.PortalId, value)
Dim key As String = "UserBot" & userSettings.Name
Session.Remove(key)
_UserBot = Nothing
End If
End Set
End Property
Protected ReadOnly Property KeeperModuleSettings() As KeeperModuleSettings
Get
Return Me.GetModuleSettings(Of KeeperModuleSettings)()
End Get
End Property
#Region "Event Handlers"
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Try
AddHandler Me.KC.Debug, AddressOf Me.OnDebug
If Not Me.IsPostBack Then
AssertInstalled()
#If DEBUG Then
Me.divDebug.Visible = True
#End If
End If
EnforceFreeVersion()
BindSettings()
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Private Sub EnforceFreeVersion()
Dim tc As Aricie.DNN.Security.Trial.TrialController = Aricie.DNN.Security.Trial.TrialController.Instance(New TrialProvider())
Dim objTrialStatus As TrialStatusInfo = tc.LimitModule(Me, True)
Me.KC.TrialStatus = objTrialStatus
Me.KS.TrialStatus = objTrialStatus
End Sub
Private Sub Page_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreRender
Try
If Me.IsPostBack AndAlso Me.KC.DataSource IsNot Nothing Then
If TypeOf Me.KC.DataSource Is SubPathContainer Then
_KeeperConfig = DirectCast( DirectCast( KC.DataSource, SubPathContainer).OriginalEntity, PortalKeeperConfig)
Else
_KeeperConfig = DirectCast( KC.DataSource, PortalKeeperConfig)
End If
Session("KeeperConfig") = _KeeperConfig
End If
If Not Me.IsPostBack Then
ManageVisibility()
End If
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
'Private Sub cmdSaveConfig_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSaveConfig.Click
' Try
' If Me.UserInfo.IsSuperUser AndAlso Me.KC.IsValid Then
' Dim objSettings As PortalKeeperConfig = DirectCast(Me.KC.DataSource, PortalKeeperConfig)
' PortalKeeperConfig.Save(objSettings)
' Skin.AddModuleMessage(Me, Localization.GetString("HostConfigSaved.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess)
' Else
' Skin.AddModuleMessage(Me, Localization.GetString("HostConfigInvalid.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning)
' End If
' Catch ex As Exception
' ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
Protected Sub cmdSave_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdSave.Click
Try
If Me.IsAdmin AndAlso Me.KS.IsValid Then
Dim objSettings As FirewallSettings = DirectCast(Me.KS.DataSource, FirewallSettings)
SettingsController.SetModuleSettings(Of FirewallSettings)(SettingsScope.PortalSettings, Me.PortalId, objSettings)
Skin.AddModuleMessage(Me, Localization.GetString("ConfigSaved.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess)
Else
Skin.AddModuleMessage(Me, Localization.GetString("ConfigInvalid.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning)
End If
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
'Protected Sub cmdRunBots_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdRunBots.Click
' Try
' 'Dim flowid As String = Guid.NewGuid.ToString
' 'If PortalKeeperConfig.Instance.SchedulerFarm.EnableLogs Then
' ' Dim objStep As New StepInfo(Debug.PKPDebugType, "Manual Run Start", _
' ' WorkingPhase.InProgress, False, False, -1, flowid)
' ' PerformanceLogger.Instance.AddDebugInfo(objStep)
' 'End If
' 'Dim nbRuns As Integer = PortalKeeperConfig.Instance.SchedulerFarm.RunBots(PortalKeeperSchedule.ScheduleEventList, True, Guid.NewGuid.ToString)
' 'If PortalKeeperConfig.Instance.SchedulerFarm.EnableLogs Then
' ' Dim objStep As New StepInfo(Debug.PKPDebugType, "Manual Run End", _
' ' WorkingPhase.InProgress, True, False, -1, flowid)
' ' PerformanceLogger.Instance.AddDebugInfo(objStep)
' 'End If
' 'Skin.AddModuleMessage(Me, String.Format(Localization.GetString("ManualRun.Message", Me.LocalResourceFile), nbRuns), ModuleMessage.ModuleMessageType.GreenSuccess)
' PortalKeeperConfig.Instance.SchedulerFarm.RunForcedBots(Me)
' Me.BindSettings()
' Catch ex As Exception
' ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
Protected Sub cmdInstall_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdInstall.Click
Try
Configuration.ConfigHelper.ProcessModuleUpdate(Configuration.ConfigActionType.Install, New PortalKeeperConfigUpdate)
Response.Redirect(NavigateURL())
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Protected Sub cmdUninstall_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdUninstall.Click
Try
Dim uninstallProcedure As IUpdateProvider
Dim errorsUpdater As IUpdateProvider = KeeperConfig.ApplicationSettings.CustomErrorsConfig.GetUpdateProvider()
If ConfigHelper.IsInstalled(errorsUpdater, True) Then
uninstallProcedure = New MultiUpdateProvider(errorsUpdater, New PortalKeeperConfigUpdate)
Else
uninstallProcedure = New PortalKeeperConfigUpdate
End If
ConfigHelper.ProcessModuleUpdate(Configuration.ConfigActionType.Uninstall, uninstallProcedure)
Response.Redirect(Me.Request.Url.AbsoluteUri)
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Private Sub cmdClearProbes_Click(sender As Object, e As System.EventArgs) Handles cmdClearProbes.Click
Try
CacheHelper.RemoveCache("PKPProbes")
Skin.AddModuleMessage(Me, Localization.GetString("ProbesCleared.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess)
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Protected Sub cmdDebug_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdDebug.Click
Try
DnnContext.Current.OnDebug()
'To remove the context routing replace with:
'Me.OnCmdDebug()
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
Private Sub cmdCancelSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancelSettings.Click
Try
Me.Response.Redirect(NavigateURL)
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
'Private Sub cmdCancelUserBot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdCancelUserBot.Click
' Try
' Me.Response.Redirect(NavigateURL)
' Catch ex As Exception
' ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
'Private Sub cmdSaveUserBot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdSaveUserBot.Click
' Try
' If Me.ctUserBotEntities.IsValid Then
' Dim userSettings As UserBotSettings(Of ScheduleEvent) = Nothing
' If Me.KeeperConfig.SchedulerFarm.AvailableUserBots.TryGetValue(Me.KeeperModuleSettings.UserBotName, userSettings) Then
' Dim userBotEntity As UserBotInfo = DirectCast(Me.ctUserBotEntities.DataSource, UserBotInfo)
' Dim readOnlyUserBot As UserBotInfo = userSettings.GetUserBotInfo(Me.KeeperConfig.SchedulerFarm, Me.UserInfo, Me.PortalId, True)
' userBotEntity.RevertReadonlyParameters(readOnlyUserBot)
' Me.UserBot = userBotEntity
' Me.BindSettings()
' Skin.AddModuleMessage(Me, Localization.GetString("UserBotSaved.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess)
' End If
' End If
' Catch ex As Exception
' ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
'Private Sub cmdDeleteUserBot_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdDeleteUserBot.Click
' Try
' Dim userSettings As UserBotSettings(Of ScheduleEvent) = Nothing
' If Me.KeeperConfig.SchedulerFarm.AvailableUserBots.TryGetValue(Me.KeeperModuleSettings.UserBotName, userSettings) Then
' Me.UserBot = Nothing
' Me.BindSettings()
' Skin.AddModuleMessage(Me, Localization.GetString("UserBotDeleted.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.GreenSuccess)
' End If
' Catch ex As Exception
' ProcessModuleLoadException(Me, ex)
' End Try
'End Sub
#End Region
#Region "Private methods"
Private Sub BindSettings()
If Me.UserInfo.IsSuperUser Then
Me.divUserBot.Controls.Clear()
Me.KC.LocalResourceFile = Me.SharedResourceFile
Me.KC.DataSource = Me.KeeperConfig
Me.KC.DataBind()
Else
Me.divHostConfig.Controls.Clear()
If Me.KeeperConfig.SchedulerFarm.EnableUserBots AndAlso Not String.IsNullOrEmpty(Me.KeeperModuleSettings.UserBotName) Then
If Me.KeeperModuleSettings.UserBot IsNot Nothing AndAlso Me.KeeperModuleSettings.UserBot.Bot IsNot Nothing Then
Dim userSettings As UserBotSettings(Of ScheduleEvent) = Nothing
If Me.KeeperConfig.SchedulerFarm.AvailableUserBots.TryGetValue(Me.KeeperModuleSettings.UserBotName, userSettings) Then
If Me.KeeperModuleSettings.EnableActionCommands AndAlso Me.KeeperModuleSettings.UserBot.ActionCommands.Count > 0 Then
Me.divActionCommands.Visible = True
If Me.divActionCommands.Controls.Count = 0 Then
For Each objActionCommand As ActionCommand In Me.KeeperModuleSettings.UserBot.ActionCommands
Dim cb As New CommandButton()
Me.divActionCommands.Controls.Add(cb)
cb.ID = "cmd" & objActionCommand.Name
cb.Text = objActionCommand.Name
If Not String.IsNullOrEmpty(objActionCommand.ResxKey) Then
cb.ResourceKey = objActionCommand.ResxKey
End If
cb.ImageUrl = objActionCommand.IconPath
cb.CommandName = objActionCommand.Name
AddHandler cb.Click, AddressOf ActionCommandClick
Next
End If
End If
Me.ctUserBotEntities.LocalResourceFile = Me.SharedResourceFile
Me.ctUserBotEntities.DataSource = Me.UserBot
Me.ctUserBotEntities.DataBind()
If Me.KeeperModuleSettings.DisplayBotConfig Then
Me.lblBotDefinition.Visible = True
Me.ctlUserBot.LocalResourceFile = Me.SharedResourceFile.Replace("SharedResources", Me.KeeperModuleSettings.UserBot.ResourceFile)
Me.ctlUserBot.EditMode = DotNetNuke.UI.WebControls.PropertyEditorMode.View
Me.ctlUserBot.DataSource = Me.KeeperModuleSettings.UserBot.Bot
Me.ctlUserBot.DataBind()
Else
Me.lblBotDefinition.Visible = False
End If
End If
End If
Else
Me.divUserBot.Controls.Clear()
End If
End If
If Me.KeeperConfig.FirewallConfig.EnablePortalLevelSettings AndAlso Me.IsAdmin Then
Me.KS.LocalResourceFile = Me.SharedResourceFile
Me.KS.DataSource = Me.KeeperSettings
Me.KS.DataBind()
Else
Me.divPortalSettings.Controls.Clear()
End If
End Sub
Private Sub ActionCommandClick(sender As Object, e As EventArgs)
Dim cb As CommandButton = DirectCast(sender, CommandButton)
Dim commandName As String = cb.CommandName
For Each objActionCommand As ActionCommand In Me.KeeperModuleSettings.UserBot.ActionCommands
If objActionCommand.Name = commandName Then
Try
Dim resultContext As New PortalKeeperContext(Of ScheduleEvent)
resultContext.Init(Me.UserBotSettings.Bot)
resultContext.InitParams(Me.UserBot.GetParameterValues(Me.UserInfo))
resultContext.Init(objActionCommand)
objActionCommand.BatchRun(PortalKeeperSchedule.ScheduleEventList, resultContext)
'Dim resultVars As SerializableDictionary(Of String, Object) = resultContext.ComputeDynamicExpressions(objActionCommand.ComputedVars, True)
Dim objDumpSettings As New DumpSettings()
objDumpSettings.EnableDump = True
objDumpSettings.DumpAllVars = False
objDumpSettings.DumpVariables = objActionCommand.ComputedVars
objDumpSettings.SkipNull = False
Dim resultVars As SerializableDictionary(Of String, Object) = resultContext.GetDump(objDumpSettings)
If resultVars.Count > 0 Then
UserBot.ComputedEntities = resultVars
End If
Me.BindSettings()
Catch ex As Exception
Aricie.Services.ExceptionHelper.LogException(ex)
End Try
End If
Next
End Sub
Private Sub AssertInstalled()
'HttpContext.Current.Response.Write("test")
If Me.UserInfo.IsSuperUser Then
Me.divInstall.Visible = True
Configuration.ConfigHelper.AssertIsInstalled(Me, New PortalKeeperConfigUpdate, Me.cmdInstall, New Control() {Me.cmdUninstall, Me.divConfig})
Me.AddConfirm(Me.cmdUninstall)
Else
Me.divInstall.Visible = False
End If
End Sub
Private Sub ManageVisibility()
If Me.UserInfo.IsSuperUser Then
Me.divHostConfig.Visible = True
Me.divPortalSettings.Visible = Me.KeeperConfig.FirewallConfig.EnablePortalLevelSettings
Else
Me.divHostConfig.Visible = False
If Me.IsAdmin Then
If Not Me.KeeperConfig.FirewallConfig.EnablePortalLevelSettings Then
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("PortalLevelSettingsDisabled.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning)
Else
Me.divPortalSettings.Visible = True
End If
End If
If Me.KeeperConfig.SchedulerFarm.EnableUserBots AndAlso Not String.IsNullOrEmpty(Me.KeeperModuleSettings.UserBotName) Then
If Me.KeeperModuleSettings.UserBot IsNot Nothing Then
Me.divUserBot.Visible = True
If Not DotNetNuke.Security.Permissions.ModulePermissionController.HasModulePermission(Me.ModuleConfiguration.ModulePermissions, "EDIT") Then
Me.ctUserBotEntities.EditMode = DotNetNuke.UI.WebControls.PropertyEditorMode.View
Me.divUserBotCmds.Visible = False
Else
Me.ctUserBotEntities.EditMode = DotNetNuke.UI.WebControls.PropertyEditorMode.Edit
Me.divUserBotCmds.Visible = True
End If
Else
DotNetNuke.UI.Skins.Skin.AddModuleMessage(Me, Localization.GetString("NoUserBot.Message", Me.LocalResourceFile), ModuleMessage.ModuleMessageType.YellowWarning)
End If
End If
End If
End Sub
#End Region
#Region "Debug"
Private Sub OnCmdDebug()
Dim sw As New Stopwatch()
sw.Start()
DemonstrateSurrogates()
DnnContext.Instance.AddModuleMessage(String.Format("Time Elapsed: {0}", Common.FormatTimeSpan(sw.Elapsed)), ModuleMessage.ModuleMessageType.GreenSuccess)
End Sub
'Public Shared Function CompileCodeDirectory(directoryName As String) As System.Reflection.Assembly
' Dim buildManagerType As Type = GetType(BuildManager)
' Dim assemblyName As String = "App_SubCode_" & directoryName
' Dim compileMethod As MethodInfo = buildManagerType.GetMethod("CompileCodeDirectory", BindingFlags.Instance Or BindingFlags.NonPublic)
' Dim theBuildManager As Object = buildManagerType.GetField("_theBuildManager", BindingFlags.Static Or BindingFlags.NonPublic).GetValue(Nothing)
' Dim topAssemblies As List(Of System.Reflection.Assembly) = DirectCast(buildManagerType.GetField("_topLevelReferencedAssemblies", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(theBuildManager), List(Of System.Reflection.Assembly))
' For Each objCodeAssembly As System.Reflection.Assembly In New ArrayList(topAssemblies)
' If objCodeAssembly.GetName().Name.StartsWith(assemblyName) Then
' topAssemblies.Remove(objCodeAssembly)
' End If
' Next
' Dim codeAssemblies As ArrayList = DirectCast(buildManagerType.GetField("_codeAssemblies", BindingFlags.Instance Or BindingFlags.NonPublic).GetValue(theBuildManager), ArrayList)
' For Each objCodeAssembly As System.Reflection.Assembly In New ArrayList(codeAssemblies)
' If objCodeAssembly.GetName().Name.StartsWith(assemblyName) Then
' codeAssemblies.Remove(objCodeAssembly)
' End If
' Next
' assemblyName = assemblyName & DateTime.UtcNow.ToFileTimeUtc().ToString()
' Dim appVirtualPath As Object = GetType(HttpRuntime).GetProperty("CodeDirectoryVirtualPath", BindingFlags.Static Or BindingFlags.NonPublic).GetValue(Nothing, Nothing)
' Dim virtualPathType As Type = appVirtualPath.GetType()
' Dim targetVirtualDir As Object = virtualPathType.GetMethod("SimpleCombineWithDir", BindingFlags.Instance Or BindingFlags.NonPublic).Invoke(appVirtualPath, {directoryName})
' Dim typeCodeDirectoryType As Type = compileMethod.GetParameters()(1).ParameterType 'BuildManager.GetType("System.Web.Compilation.CodeDirectoryType, System.Web", False)
' Dim objCodeDirectoryType As Object = [Enum].Parse(typeCodeDirectoryType, "SubCode")
' Dim toReturn As System.Reflection.Assembly = DirectCast(compileMethod.Invoke(theBuildManager, {targetVirtualDir, objCodeDirectoryType, assemblyName, Nothing}), System.Reflection.Assembly)
' DotNetNuke.Common.Utilities.DataCache.ClearCache()
' Return toReturn
'End Function
Private Sub OnDebug(sender As Object, e As DebugEventArgs)
Try
DnnContext.Instance.AddModuleMessage("Event routed from DNN Context", ModuleMessage.ModuleMessageType.GreenSuccess)
OnCmdDebug()
Catch ex As Exception
ProcessModuleLoadException(Me, ex)
End Try
End Sub
'Private Function TestReddit() As String
' Dim objReddit As New RedditSharp.Reddit(RedditSharp.WebAgent.RateLimitMode.Burst)
' 'objReddit.User = objReddit.LogIn("Jessynoo", "cetia540", True)
' Dim toreturn As String = ""
' Dim botName As String = "Alfred_Centworth"
' objReddit.User = objReddit.LogIn(botName, "cetia540", True)
' Dim messages As IEnumerable(Of Comment) = objReddit.GetUser("Jessynoo").Comments.Take(5)
' 'Dim messages As IEnumerable(Of Comment) = objReddit.User.Inbox()
' For Each objMessage In messages
' Dim answered As Boolean = objMessage.Comments.Any(Function(tmpMessage) tmpMessage.Author.AuthorName = botName)
' If Not answered Then
' toreturn += HttpUtility.HtmlEncode(ReflectionHelper.Serialize(messages).Beautify())
' End If
' 'objMessage.Reply("")
' Next
' Return toreturn
'End Function
Private Sub RegisterDebugSurrogates()
ReflectionHelper.RegisterDebugSurrogate(AddressOf Me.SurrogateCallback, True)
End Sub
Public Function SurrogateCallback(objType As Type) As Object
Dim toReturn As Object = Nothing
Select Case objType.FullName
Case GetType(TestSurrogateOriginal).FullName
toReturn = New TestSurrogateReplacement()
End Select
Return toReturn
End Function
Private Sub DemonstrateSurrogates()
Dim message As String
'We first instantiate the original Type. It can be a static or a dynamic Type
Dim testSurrogate As New TestSurrogateOriginal()
message = testSurrogate.TestFunction()
DnnContext.Instance.AddModuleMessage(String.Format("Debug: {0}", message.ToString()), ModuleMessage.ModuleMessageType.GreenSuccess)
'We then use the surrogate mechanism through the CreateObject method. The surrogate was registered in the user control constructor
testSurrogate = ReflectionHelper.CreateObject(Of TestSurrogateOriginal)()
message = testSurrogate.TestFunction()
DnnContext.Instance.AddModuleMessage(String.Format("Debug: {0}", message.ToString()), ModuleMessage.ModuleMessageType.GreenSuccess)
'We then use the Automatic Surrogate mechanism through the CreateType method. Adding Debug to the Namespace of an original Type let you define a surrogate either in App_Code or in the calling dynamic code file
'Note this will work if the corresponding application action is enabled or by setting:
'ReflectionHelper.EnableAutoDebugSurrogates = True
testSurrogate = ReflectionHelper.CreateObject(Of TestSurrogateOriginal)(ReflectionHelper.CreateType(GetType(TestSurrogateOriginal).AssemblyQualifiedName, False))
message = testSurrogate.TestFunction()
DnnContext.Instance.AddModuleMessage(String.Format("Debug: {0}", message.ToString()), ModuleMessage.ModuleMessageType.GreenSuccess)
End Sub
#End Region
End Class
End Namespace
#Region "Surrogates Demonstration"
Namespace Aricie.DNN.TestSurrogates
Public Class TestSurrogateOriginal
Public Overridable Function TestFunction() As String
Return "Hello World from original: " & Me.GetType.AssemblyQualifiedName
End Function
End Class
Public Class TestSurrogateReplacement
Inherits TestSurrogateOriginal
Public Overrides Function TestFunction() As String
Return "Hello World from explicit surrogate: " & Me.GetType.AssemblyQualifiedName
End Function
End Class
End Namespace
Namespace Aricie.DNN.TestSurrogates.Debug
Public Class TestSurrogateReplacement
Inherits Aricie.DNN.TestSurrogates.TestSurrogateReplacement
Public Overrides Function TestFunction() As String
Return "Hello World from automatic surrogate to explicit surrogate: " & Me.GetType.AssemblyQualifiedName
End Function
End Class
End Namespace
#End Region