-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathXmlConnector.ashx.cs
3331 lines (2893 loc) · 152 KB
/
XmlConnector.ashx.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
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
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.CodeDom;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Mime;
using System.Resources;
using System.Runtime.Remoting.Contexts;
using System.Text;
using System.Web;
using System.Web.Management;
using System.Xml;
using DotNetNuke.Entities.Portals;
using DotNetNuke.Entities.Users;
using NBrightCore;
using NBrightCore.common;
using NBrightCore.images;
using NBrightCore.render;
using NBrightDNN;
using NBrightMod.common;
using DataProvider = DotNetNuke.Data.DataProvider;
using System.Web.Script.Serialization;
using System.Web.UI.WebControls;
using DotNetNuke.Common;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Tabs;
using DotNetNuke.Services.Localization;
using DotNetNuke.UI.WebControls;
using DotNetNuke.Entities.Modules;
using DotNetNuke.Security.Permissions;
using DotNetNuke.Security.Roles;
using Nevoweb.DNN.NBrightMod.Components;
namespace Nevoweb.DNN.NBrightMod
{
/// <summary>
/// Summary description for XMLconnector
/// </summary>
public class XmlConnector : IHttpHandler
{
private readonly JavaScriptSerializer _js = new JavaScriptSerializer();
private String _lang = "";
private String _itemid = "";
public void ProcessRequest(HttpContext context)
{
#region "Initialize"
var strOut = "";
var moduleidparam = Utils.RequestQueryStringParam(context, "mid");
var paramCmd = Utils.RequestQueryStringParam(context, "cmd");
var lang = Utils.RequestQueryStringParam(context, "lang");
var language = Utils.RequestQueryStringParam(context, "language");
_itemid = Utils.RequestQueryStringParam(context, "itemid");
var secure = Utils.RequestQueryStringParam(context, "secure");
bool encryptfilename = secure == "1";
#region "setup language"
// Ajax can break context with DNN, so reset the context language to match the client.
// NOTE: "genxml/hidden/lang" should be set in the template for langauge to work OK.
SetContextLangauge(context);
System.Threading.Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.CreateSpecificCulture(_lang);
#endregion
#endregion
#region "Do processing of command"
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var moduleid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/moduleid");
if (moduleid <= 0 && Utils.IsNumeric(moduleidparam))
{
moduleid = Convert.ToInt32(moduleidparam);
}
strOut = "** No Action **";
switch (paramCmd)
{
case "test":
strOut = "<root>" + UserController.Instance.GetCurrentUserInfo().Username + "</root>";
break;
case "getsettings":
strOut = GetSettings(context, true);
break;
case "gettheme":
strOut = GetSettings(context);
break;
case "savesettings":
if (LocalUtils.CheckRights(moduleid)) strOut = SaveSettings(context);
break;
case "resetsettings":
if (LocalUtils.CheckRights(moduleid)) strOut = ResetSettings(context);
break;
case "saveconfig":
if (LocalUtils.CheckRights(moduleid)) strOut = SaveConfig(context);
break;
case "getdetail":
strOut = GetData(context);
break;
case "getselectlangdata":
strOut = GetData(context);
break;
case "getlist":
strOut = GetData(context);
break;
case "getlistheader":
strOut = GetData(context);
break;
case "getimagelist":
strOut = GetData(context);
break;
case "addnew":
if (LocalUtils.CheckRights(moduleid)) strOut = GetData(context, true);
break;
case "deleterecord":
if (LocalUtils.CheckRights(moduleid)) strOut = DeleteData(context);
break;
case "savedata":
if (LocalUtils.CheckRights(moduleid))
{
SaveImages(context);
SaveDocs(context);
strOut = SaveData(context);
}
break;
case "savelistdata":
strOut = SaveListData(context);
break;
case "savelistdataheader":
strOut = SaveHeaderData(context);
break;
case "selectlang":
// DO NOT save on langauge changem this will always create the version records.
//if (LocalUtils.CheckRights(moduleid))
//{
// SaveImages(context);
// SaveDocs(context);
// strOut = SaveData(context);
//}
break;
case "fileupload":
if (LocalUtils.CheckRights(moduleid)) FileUpload(context, moduleidparam);
break;
case "clientfileupload":
UploadWholeFile(context, moduleidparam, false, false, 60);
break;
case "fileuploadsecure":
if (LocalUtils.CheckRights(moduleid)) FileUpload(context, moduleidparam, false, true);
break;
case "addselectedfiles":
if (LocalUtils.CheckRights(moduleid)) AddSelectedFiles(context);
break;
case "replaceselectedfiles":
if (LocalUtils.CheckRights(moduleid)) ReplaceSelectedFiles(context);
break;
case "deleteselectedfiles":
if (LocalUtils.CheckRights(moduleid)) DeleteSelectedFiles(context);
break;
case "getfiles":
strOut = GetFiles(context, true);
break;
case "getfolderfiles":
strOut = GetFolderFiles(context, true);
break;
case "savetheme":
if (LocalUtils.CheckRights(moduleid)) strOut = SaveTheme(context);
break;
case "exporttheme":
if (LocalUtils.CheckRights(moduleid))
{
var zipfile = DoThemeExport(context);
strOut = "<a href='/DesktopModules/NBright/NBrightMod/XmlConnector.ashx?cmd=downloadfile&filename=/NBrightTemp/" + Path.GetFileName(zipfile) + "'>Download Theme</a>";
}
break;
case "importtheme":
if (LocalUtils.CheckRights(moduleid))
{
var fname1 = FileUpload(context, moduleidparam, true);
strOut = DoThemeImport(fname1);
LocalUtils.ClearRazorCache(moduleidparam);
}
break;
case "downloadfile":
var fileindex = Utils.RequestQueryStringParam(context, "fileindex");
var itemid = Utils.RequestQueryStringParam(context, "itemid");
var filename = Utils.RequestQueryStringParam(context, "filename");
if (Utils.IsNumeric(itemid) && Utils.IsNumeric(fileindex))
{
var objCtrl = new NBrightDataController();
var nbi = objCtrl.GetData(Convert.ToInt32(itemid));
var fpath = nbi.GetXmlProperty("genxml/docs/genxml[" + fileindex + "]/hidden/docpath");
var downloadname = Utils.RequestQueryStringParam(context, "downloadname");
if (downloadname == "") downloadname = Path.GetFileName(fpath);
UpdateDownloadCount(Convert.ToInt32(itemid), fileindex, 1);
LocalUtils.ClearRazorCache(nbi.ModuleId.ToString());
Utils.ForceDocDownload(fpath, downloadname, context.Response);
}
else
{
if (filename != "")
{
var fpath = PortalSettings.Current.HomeDirectoryMapPath.TrimEnd('\\') + "\\" + filename;
var downloadname = Utils.RequestQueryStringParam(context, "downloadname");
if (downloadname == "") downloadname = Path.GetFileName(fpath);
Utils.ForceDocDownload(fpath, downloadname, context.Response);
}
}
strOut = "File Download Error, filename: " + filename + ", itemid: " + itemid + ", fileindex: " + fileindex + " ";
break;
case "sendemail":
strOut = SendEmail(context);
break;
case "doportalvalidation":
if (LocalUtils.CheckRights(moduleid))
{
LocalUtils.ResetValidationFlag();
LocalUtils.ValidateModuleData();
strOut = "Portal Validation Ativated";
}
break;
case "createtemplate":
if (LocalUtils.CheckRights(moduleid))
{
CreatePortalTemplates(context);
strOut = "OK";
}
break;
case "makethemesys":
if (LocalUtils.CheckRights(moduleid))
{
strOut = MoveThemeToSystem(context);
}
break;
case "gettemplatemenu":
if (LocalUtils.CheckRights(moduleid))
{
strOut = GetTemplateMenu(context);
}
break;
case "savetemplatedata":
if (LocalUtils.CheckRights(moduleid))
{
strOut = SaveTemplateMenu(context);
}
break;
case "deleteportalresx":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DeletePortalResx(context);
}
break;
case "deleteportaltempl":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DeletePortalTemplate(context);
}
break;
case "deletemoduletempl":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DeleteModuleTemplate(context);
}
break;
case "deletetheme":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DeleteTheme(context);
}
break;
case "clonemodule":
if (LocalUtils.CheckRights(moduleid))
{
strOut = CloneModule(context);
}
break;
case "attachroles":
if (LocalUtils.CheckRights(moduleid))
{
strOut = AttachRolesToModule(context);
}
break;
case "resetlanguage":
if (LocalUtils.CheckRights(moduleid))
{
strOut = ResetLanguage(context);
}
break;
case "downloadthemes":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DownloadThemes(context);
}
break;
case "displayserverthemes":
if (LocalUtils.CheckRights(moduleid))
{
strOut = DisplayAllThemes(context);
}
break;
case "savenotes":
if (LocalUtils.CheckRights(moduleid))
{
strOut = SaveNotes(context);
}
break;
}
if (strOut == "** No Action **")
{
var settings = LocalUtils.GetSettings(moduleid.ToString(""));
if (settings.GetXmlProperty("genxml/textbox/assembly").Trim(' ') != "" && settings.GetXmlProperty("genxml/textbox/namespace").Trim(' ') != "")
{
var handle = Activator.CreateInstance(settings.GetXmlProperty("genxml/textbox/assembly"), settings.GetXmlProperty("genxml/textbox/namespace"));
var objProvider = (AjaxInterface)handle.Unwrap();
strOut = objProvider.ProcessCommand(paramCmd, context, Utils.GetCurrentCulture());
}
}
#endregion
#region "return results"
//send back xml as plain text
context.Response.Clear();
context.Response.ContentType = "text/plain";
context.Response.Write(strOut);
context.Response.End();
#endregion
}
public bool IsReusable
{
get
{
return false;
}
}
#region "Methods"
private void SetContextLangauge(HttpContext context)
{
var ajaxInfo = LocalUtils.GetAjaxFields(context);
SetContextLangauge(ajaxInfo); // Ajax breaks context with DNN, so reset the context language to match the client.
}
private void SetContextLangauge(NBrightInfo ajaxInfo = null)
{
// NOTE: "genxml/hidden/lang" should be set in the template for langauge to work OK.
// set langauge if we have it passed.
if (ajaxInfo == null) ajaxInfo = new NBrightInfo(true);
var lang = ajaxInfo.GetXmlProperty("genxml/hidden/currentlang");
if (lang == "") lang = Utils.RequestParam(HttpContext.Current, "langauge"); // fallbacl
if (lang == "") lang = ajaxInfo.GetXmlProperty("genxml/hidden/lang"); // fallbacl
if (lang == "") lang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
if (lang == "") lang = Utils.GetCurrentCulture(); // fallback, but very often en-US on ajax call
if (lang != "") _lang = lang;
// set the context culturecode, so any DNN functions use the correct culture
if (_lang != "" && _lang != System.Threading.Thread.CurrentThread.CurrentCulture.ToString()) System.Threading.Thread.CurrentThread.CurrentCulture = new CultureInfo(_lang);
}
private String GetSettings(HttpContext context, bool clearCache = false)
{
try
{
var strOut = "";
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
var razortemplate = ajaxInfo.GetXmlProperty("genxml/hidden/razortemplate");
if (razortemplate == "") razortemplate = "settings.cshtml";
if (moduleid == "") moduleid = "-1";
if (clearCache) LocalUtils.ClearRazorCache(moduleid);
// do edit field data if a itemid has been selected
var obj = LocalUtils.GetSettings(moduleid);
obj.ModuleId = Convert.ToInt32(moduleid); // assign for new records
strOut = LocalUtils.RazorTemplRender(razortemplate, moduleid, "settings", obj, _lang);
return strOut;
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String SaveConfig(HttpContext context)
{
try
{
var objCtrl = new NBrightDataController();
var nbiconfig = LocalUtils.GetConfig(false);
// update record with ajax data
var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
nbiconfig.UpdateAjax(strIn);
objCtrl.Update(nbiconfig);
return "";
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String SaveNotes(HttpContext context)
{
try
{
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
if (Utils.IsNumeric(moduleid))
{
// get DB record
var nbi = LocalUtils.GetSettings(moduleid);
if (nbi.ModuleId == 0) // new setting record
{
nbi = CreateSettingsInfo(moduleid, nbi);
}
nbi.SetXmlProperty("genxml/textbox/notes", ajaxInfo.GetXmlProperty("genxml/textbox/notes"));
LocalUtils.UpdateSettings(nbi);
LocalUtils.ClearRazorCache(nbi.ModuleId.ToString(""));
LocalUtils.ClearRazorSateliteCache(nbi.ModuleId.ToString(""));
}
return "";
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String SaveSettings(HttpContext context)
{
try
{
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
if (Utils.IsNumeric(moduleid))
{
// get DB record
var nbi = LocalUtils.GetSettings(moduleid);
if (nbi.ModuleId == 0) // new setting record
{
nbi = CreateSettingsInfo(moduleid, nbi);
}
// get data passed back by ajax
var strIn = HttpUtility.UrlDecode(Utils.RequestParam(context, "inputxml"));
// update record with ajax data
nbi.UpdateAjax(strIn);
// look for datasource moduleid and use xrefitemid to persist it, this is so we can clear cache of satelite modules.
var datasourceref = nbi.GetXmlProperty("genxml/dropdownlist/datasourceref");
if (datasourceref != nbi.GUIDKey && datasourceref != "")
{
var objCtrl = new NBrightDataController();
var satnbi = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, "SETTINGS", datasourceref);
if (satnbi != null)
{
nbi.XrefItemId = satnbi.ItemID;
nbi.SetXmlProperty("genxml/hidden/moduleiddatasource", satnbi.ModuleId.ToString());
}
}
// check for special processing on guidkeys (unique key persists on export/import)
if (nbi.GetXmlProperty("genxml/dropdownlist/targetpage") != "")
{
var guidkey = nbi.GetXmlProperty("genxml/dropdownlist/targetpage");
var t = (from kvp in TabController.GetTabsBySortOrder(PortalSettings.Current.PortalId) where kvp.UniqueId.ToString() == guidkey select kvp.TabID);
if (t.Any())
{
nbi.SetXmlProperty("genxml/dropdownlist/targetpagetabid", t.First().ToString());
}
}
else
{
nbi.RemoveXmlNode("genxml/dropdownlist/targetpagetabid");
}
if (nbi.GetXmlProperty("genxml/hidden/modref") == "")
{
if (nbi.GUIDKey != "")
{
nbi.SetXmlProperty("genxml/hidden/modref", nbi.GUIDKey);
}
else
{
var gid = "_" + Utils.GetUniqueKey(10); // prefix with "_", so export can identify module level templates.
nbi.SetXmlProperty("genxml/hidden/modref", gid);
nbi.GUIDKey = gid;
}
}
if (nbi.TextData == "") nbi.TextData = "NBrightMod";
// update module description for identifying module.
var objModule = DnnUtils.GetModuleinfo(Convert.ToInt32(moduleid));
nbi.SetXmlProperty("genxml/ident", nbi.GetXmlProperty("genxml/dropdownlist/themefolder") + ": " + objModule.ParentTab.TabName + " " + objModule.PaneName + " [" + nbi.GUIDKey + "]");
nbi = LocalUtils.CreateRequiredUploadFolders(nbi);
LocalUtils.UpdateSettings(nbi);
LocalUtils.ClearRazorCache(nbi.ModuleId.ToString(""));
LocalUtils.ClearRazorSateliteCache(nbi.ModuleId.ToString(""));
}
return "";
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String ResetSettings(HttpContext context)
{
try
{
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
if (Utils.IsNumeric(moduleid) && Convert.ToInt32(moduleid) > 0)
{
// remove module level templates (before removal of data records)
var settings = LocalUtils.GetSettings(moduleid, false);
if (settings != null)
{
var theme = settings.GetXmlProperty("genxml/dropdownlist/themefolder");
if (theme != "")
{
var themeFolderName = PortalSettings.Current.HomeDirectoryMapPath.TrimEnd('\\') + "\\NBrightMod\\Themes\\" + theme;
if (Directory.Exists(themeFolderName))
{
var flist = Directory.GetFiles(themeFolderName, "*.*", SearchOption.AllDirectories);
foreach (var f in flist)
{
var fname = Path.GetFileName(f);
if (fname != null && fname.StartsWith(settings.GUIDKey)) File.Delete(f);
}
}
}
}
LocalUtils.ClearRazorCache(moduleid);
LocalUtils.ClearRazorSateliteCache(moduleid);
DnnUtils.ClearPortalCache(PortalSettings.Current.PortalId);
// remove all data linked to module.
LocalUtils.DeleteAllDataRecords(Convert.ToInt32(moduleid));
}
return "";
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String SaveTheme(HttpContext context)
{
try
{
var objCtrl = new NBrightDataController();
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context, true, false);
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
if (Utils.IsNumeric(moduleid))
{
// get DB record
var nbi = LocalUtils.GetSettings(moduleid);
if (nbi.ModuleId <= 0) // new setting record
{
nbi = CreateSettingsInfo(moduleid, nbi);
}
if (nbi.ModuleId > 0)
{
nbi.UpdateAjax(LocalUtils.GetAjaxData(context), "", true, false);
objCtrl.Update(nbi);
LocalUtils.ClearRazorCache(nbi.ModuleId.ToString(""));
}
}
return "";
}
catch (Exception ex)
{
return ex.ToString();
}
}
private NBrightInfo CreateSettingsInfo(String moduleid, NBrightInfo settings)
{
var modref = Utils.GetUniqueKey(10);
//rebuild xml
settings.PortalId = PortalSettings.Current.PortalId;
settings = LocalUtils.CreateRequiredUploadFolders(settings);
settings.ModuleId = Convert.ToInt32(moduleid);
settings.TypeCode = "SETTINGS";
settings.Lang = "";
settings.GUIDKey = modref;
return settings;
}
private String GetData(HttpContext context, bool clearCache = false)
{
try
{
var entitytype = "NBrightModDATA";
var objCtrl = new NBrightDataController();
var strOut = "";
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context);
var itemid = ajaxInfo.GetXmlProperty("genxml/hidden/itemid");
var newitem = ajaxInfo.GetXmlProperty("genxml/hidden/newitem");
var selecteditemid = ajaxInfo.GetXmlProperty("genxml/hidden/selecteditemid");
var moduleid = ajaxInfo.GetXmlProperty("genxml/hidden/moduleid");
var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
var displayreturn = ajaxInfo.GetXmlProperty("genxml/hidden/displayreturn");
var uploadtype = ajaxInfo.GetXmlProperty("genxml/hidden/uploadtype");
var modref = ajaxInfo.GetXmlProperty("genxml/hidden/modref");
if (editlang == "") editlang = _lang;
if (moduleid == "") moduleid = "-1";
if (clearCache) LocalUtils.ClearRazorCache(moduleid);
var strTemplate = "editlist.cshtml";
if (Utils.IsNumeric(selecteditemid)) strTemplate = "editfields.cshtml";
switch (displayreturn.ToLower())
{
case "list":
// removed selected itemid if we want to return to the list.
strTemplate = "editlist.cshtml";
selecteditemid = "";
break;
case "listheader":
// removed selected itemid if we want to return to the list.
strTemplate = "editlistheader.cshtml";
selecteditemid = "";
entitytype = "NBrightModHEADER";
var headerdataitem = objCtrl.GetByGuidKey(PortalSettings.Current.PortalId, -1, entitytype, modref);
if (headerdataitem != null)
{
selecteditemid = headerdataitem.ItemID.ToString("");
}
break;
}
if (newitem == "new")
{
selecteditemid = "new"; // return list on new record
AddNew(moduleid, entitytype,modref);
}
if (Utils.IsNumeric(selecteditemid))
{
// do edit field data if a itemid has been selected
var obj = objCtrl.Get(Convert.ToInt32(selecteditemid), editlang);
if (obj != null)
{
// check we have a base data record, if so create langauge record.
var lnode = obj.XMLDoc.SelectSingleNode("genxml/lang");
if (lnode == null)
{
LocalUtils.CreateLangaugeDataRecord(obj.ItemID, Convert.ToInt32(moduleid), editlang,"", entitytype, modref);
obj = objCtrl.Get(Convert.ToInt32(selecteditemid), editlang);
}
// get any version data.
if (obj.XrefItemId > 0 && obj.TypeCode.StartsWith(entitytype))
{
var nbi = objCtrl.GetData(obj.XrefItemId, "v" + entitytype + "LANG", obj.Lang, true);
if (nbi == null)
{
// found invalid itemid, clean it up.
var nbiClean = objCtrl.Get(obj.ItemID);
nbiClean.XrefItemId = 0;
objCtrl.Update(nbiClean);
obj.XrefItemId = 0;
}
else
{
if (nbi.GetXmlPropertyBool("genxml/versiondelete"))
{
obj = null;
}
else
{
obj = nbi;
}
}
}
}
strOut = LocalUtils.RazorTemplRender(strTemplate, moduleid, _lang + itemid + editlang + selecteditemid, obj, editlang);
}
else
{
// preprocess razor template to get meta data for data select into cache.
var cachedlist = LocalUtils.RazorPreProcessTempl(strTemplate, moduleid, Utils.GetCurrentCulture());
var orderby = "";
if (cachedlist != null && cachedlist.ContainsKey("orderby")) orderby = cachedlist["orderby"];
var settings = LocalUtils.GetSettings(moduleid);
var isVersion = false;
// Return list of items
var returnlimit = settings.GetXmlPropertyInt("genxml/textbox/returnlimit");
var l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), entitytype, "", orderby, returnlimit, 0, 0, 0, editlang);
if (l.Any())
{
// check we have a base data recxord, if so create langauge record.
var nolang = false;
foreach (var nbi in l)
{
var lnode = nbi.XMLDoc.SelectSingleNode("genxml/lang");
if (lnode == null)
{
LocalUtils.CreateLangaugeDataRecord(nbi.ItemID, Convert.ToInt32(moduleid), editlang, "", entitytype, modref);
nolang = true;
}
}
if (nolang) // reload if we found invalid data list
{
l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), entitytype, "", orderby, returnlimit, 0, 0, 0, editlang);
}
// get any version data.
var length = l.Count;
var removeList = new List<int>();
for (int i = 0; i < length; i++)
{
var nbi = l[i];
if (nbi.XrefItemId > 0)
{
isVersion = true;
if (nbi.GetXmlPropertyBool("genxml/versiondelete"))
{
removeList.Add(nbi.ItemID);
}
else
{
var vnbi = objCtrl.GetData(nbi.XrefItemId, nbi.Lang);
if (vnbi == null)
{
// found invalid itemid, clean it up.
var nbiClean = objCtrl.Get(nbi.ItemID);
nbiClean.XrefItemId = 0;
objCtrl.Update(nbiClean);
nbi.XrefItemId = 0;
}
else
{
l[i] = vnbi;
}
}
}
}
// remove deleted record.
for (int i = length - 1; i >= 0; i--)
{
if (removeList.Contains(l[i].ItemID))
{
l.RemoveAt(i);
}
}
}
// get any "added" version records
var l2 = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), "a" + entitytype, "", orderby, returnlimit, 0, 0, 0, editlang);
foreach (var nbi in l2)
{
l.Add(nbi);
isVersion = true;
}
if (isVersion && !String.IsNullOrWhiteSpace(orderby) && l.Count > 1)
{
// need to put the sort correct, but must be done at SQL level, because we have dynamic sort defined.
var filter2 = " and ( ";
foreach (var nbi in l)
{
filter2 += " NB1.ItemId = " + nbi.ItemID + " or ";
}
filter2 = filter2.Substring(0, filter2.Length - 3) + ") ";
l = objCtrl.GetList(PortalSettings.Current.PortalId, Convert.ToInt32(moduleid), "", filter2, orderby, returnlimit, 0, 0, 0, editlang);
}
strOut = LocalUtils.RazorTemplRenderList(strTemplate, moduleid, _lang + editlang, l, editlang);
}
// debug data out by writing out to file (REMOVE FOR PROUCTION)
//Utils.SaveFile(PortalSettings.Current.HomeDirectoryMapPath + "\\debug_NBrightMod_getData.txt", strOut);
return strOut;
}
catch (Exception ex)
{
return ex.ToString();
}
}
private String GetTemplateMenu(HttpContext context)
{
#region "init params from ajax"
var strOut = "";
//get uploaded params
var ajaxInfo = LocalUtils.GetAjaxFields(context, true, false);
var themefolder = ajaxInfo.GetXmlProperty("genxml/dropdownlist/themefolder");
var newname = ajaxInfo.GetXmlProperty("genxml/textbox/newname");
var updatetype = ajaxInfo.GetXmlProperty("genxml/hidden/updatetype");
if (updatetype == "new") themefolder = newname; // if we are creating a new theme, use the new name to save.
var razortemplname = "config.edittheme.cshtml";
var editlang = ajaxInfo.GetXmlProperty("genxml/hidden/editlang");
var templfilename = ajaxInfo.GetXmlProperty("genxml/hidden/templfilename");
var resxfilename = ajaxInfo.GetXmlProperty("genxml/hidden/resxfilename");
var currentedittab = ajaxInfo.GetXmlProperty("genxml/hidden/currentedittab");
var modulelevel = ajaxInfo.GetXmlPropertyBool("genxml/hidden/modulelevel");
var moduleid = ajaxInfo.GetXmlPropertyInt("genxml/hidden/moduleid");
var moduleref = "";
var modInfo = new NBrightInfo();
var templData = new NBrightInfo(true);
// for module level template we need to add the modref to the start of the template
if (Utils.IsNumeric(moduleid))
{
var objCtrl = new NBrightDataController();
// assign module themefolder.
modInfo = objCtrl.GetByType(PortalSettings.Current.PortalId, moduleid, "SETTINGS");
if (modInfo != null)
{
themefolder = modInfo.GetXmlProperty("genxml/dropdownlist/themefolder");
moduleref = modInfo.GetXmlProperty("genxml/hidden/modref");
}
else
{
modInfo = new NBrightInfo();
}
}
if (modulelevel)
{
templfilename = moduleref + templfilename; // module level templates prefixed with moduleref
templData.SetXmlProperty("genxml/modulelevel", "True", TypeCode.String, true, true, false);
}
else
{
modInfo = new NBrightInfo(); // we're editing portal level, clear module info so we pickup only portal level templates.
templData.SetXmlProperty("genxml/modulelevel", "False", TypeCode.String, true, true, false);
}
var fulltemplfilename = themefolder + "." + ajaxInfo.GetXmlProperty("genxml/hidden/templfilename");
#endregion
var templfullpath = "";
var templrelpath = "";
var razorTempl2 = "";
if (templfilename.EndsWith(".cshtml"))
{
razorTempl2 = LocalUtils.GetTemplateData(fulltemplfilename, editlang, modInfo.ToDictionary());
}
else
{
var sourceportal = PortalSettings.Current.HomeDirectoryMapPath.Trim('\\') + "\\NBrightMod\\Themes\\" + themefolder + "\\" + Path.GetExtension(templfilename).Replace(".", "");
var sourceroot = HttpContext.Current.Server.MapPath("/DesktopModules/NBright/NBrightMod/Themes/" + themefolder + "/" + Path.GetExtension(templfilename).Replace(".", ""));
razorTempl2 = Utils.ReadFile(sourceportal + "\\" + templfilename);
if (razorTempl2 == "")
{
// we have no portal level module template, so take system level
razorTempl2 = Utils.ReadFile(sourceroot + "\\" + ajaxInfo.GetXmlProperty("genxml/hidden/templfilename"));
}
else
{
// we have a portal level, so get paths
templfullpath = sourceportal + "\\" + templfilename;
templrelpath = "/" + PortalSettings.Current.HomeDirectory.Trim('/') + "/NBrightMod/Themes/" + themefolder + "/" + Path.GetExtension(templfilename).Replace(".", "") + "/" + templfilename;
}
}
// get resxdata for theme.ascx.**-**.resx
var sourcesystemresx = HttpContext.Current.Server.MapPath("/DesktopModules/NBright/NBrightMod/Themes/" + themefolder + "/resx");
resxfilename = "theme.ascx." + editlang + ".resx";
if (editlang == "none" || editlang == "") resxfilename = "theme.ascx.resx";
var resxfilenameread = resxfilename;
if (!File.Exists(sourcesystemresx + "\\" + resxfilenameread)) resxfilenameread = "theme.ascx.resx";
var resxdata = "<genxml>";
if (File.Exists(sourcesystemresx + "\\" + resxfilenameread))
{
ResXResourceReader rsxr = new ResXResourceReader(sourcesystemresx + "\\" + resxfilenameread);
var resxlist = new List<DictionaryEntry>();
foreach (DictionaryEntry d in rsxr)
{
resxlist.Add(d);
resxdata += "<item><key>" + d.Key + "</key><value>" + d.Value + "</value></item>";
}
rsxr.Close();
}
resxdata += "</genxml>";
templData.SetXmlProperty("genxml/resxdata", "");
templData.AddXmlNode(resxdata, "genxml", "genxml/resxdata");
templData.Lang = _lang;
templData.SetXmlProperty("genxml/editlang", editlang);
templData.SetXmlProperty("genxml/templtext", razorTempl2);
templData.SetXmlProperty("genxml/templfullpath", templfullpath);
templData.SetXmlProperty("genxml/templrelpath", templrelpath);
templData.SetXmlProperty("genxml/templfilename", templfilename);
var displayname = templfilename;
if (moduleref != "") displayname = templfilename.Replace(moduleref, "");
templData.SetXmlProperty("genxml/displayfilename", displayname);
templData.SetXmlProperty("genxml/resxfilename", resxfilename);
templData.SetXmlProperty("genxml/hidden/currentedittab", currentedittab);
templData.SetXmlProperty("genxml/themefolder", themefolder);
// get template files
templData.RemoveXmlNode("genxml/files");
templData.AddSingleNode("files", "", "genxml");
templData.RemoveXmlNode("genxml/portalfiles");
templData.AddSingleNode("portalfiles", "", "genxml");
templData.RemoveXmlNode("genxml/modulefiles");
templData.AddSingleNode("modulefiles", "", "genxml");
templData = GetListOfTemplateFiles(templData, themefolder, "default", moduleref);
templData = GetListOfTemplateFiles(templData, themefolder, "css", moduleref);
templData = GetListOfTemplateFiles(templData, themefolder, "js", moduleref);
templData = GetListOfTemplateFiles(templData, themefolder, "resx", moduleref);
strOut = LocalUtils.RazorTemplRender(razortemplname, "-1", "", templData, _lang, true);
return strOut;
}
private NBrightInfo GetListOfTemplateFiles(NBrightInfo templData, String themefolder, String themesubfolder, String modref)
{
var sourceRoot = HttpContext.Current.Server.MapPath("/DesktopModules/NBright/NBrightMod/Themes/" + themefolder + "/" + themesubfolder);
var systemtheme = "True";
if (!System.IO.Directory.Exists(sourceRoot))