-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathGXApplication.cs
More file actions
4338 lines (4051 loc) · 115 KB
/
GXApplication.cs
File metadata and controls
4338 lines (4051 loc) · 115 KB
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
namespace GeneXus.Application
{
using System;
using System.Collections;
using System.IO;
using System.Reflection;
using GeneXus.Data;
using GeneXus.XML;
using GeneXus.Utils;
#if !NETCORE
using System.Web.UI;
using GeneXus.WebControls;
using System.Messaging;
using System.ServiceModel.Web;
using GeneXus.UserControls;
using System.Net.Http.Headers;
#else
using Microsoft.AspNetCore.Http;
using GxClasses.Helpers;
using Experimental.System.Messaging;
#endif
using GeneXus.Configuration;
using GeneXus.Metadata;
#if !NETCORE
using Jayrock.Json;
#endif
using GeneXus.Http;
using System.Collections.Specialized;
using System.Collections.Generic;
using System.Text;
using GeneXus.Data.NTier;
using GeneXus.Resources;
using System.Net;
using TZ4Net;
using System.Globalization;
using System.Diagnostics;
using System.Text.RegularExpressions;
using System.Web;
using GeneXus.Http.Server;
using GeneXus.Mime;
using GeneXus.Printer;
using System.Drawing;
using System.Collections.Concurrent;
#if NETCORE
using Microsoft.AspNetCore.Http.Features;
#endif
using NodaTime;
using System.Threading;
using System.Security.Claims;
using System.Security;
using Microsoft.Net.Http.Headers;
using System.Threading.Tasks;
using GeneXus.Data.ADO;
public interface IGxContext
{
void disableOutput();
void enableOutput();
bool isOutputEnabled();
void setPortletMode();
void setAjaxCallMode();
void setAjaxEventMode();
void setFullAjaxMode();
void AddDeferredFrags();
bool isPortletMode();
bool isAjaxCallMode();
bool isAjaxRequest();
bool isSpaRequest();
bool isSpaRequest(bool ignoreFlag);
bool isAjaxEventMode();
bool isPopUpObject();
bool isFullAjaxMode();
bool isMultipartRequest();
void DisableSpaRequest();
String AjaxCmpContent { get; set; }
bool isCloseCommand { get; }
[Obsolete("GetOlsonTimeZone is deprecated. Use GetTimeZone() instead", false)]
OlsonTimeZone GetOlsonTimeZone();
String GetTimeZone();
Boolean SetTimeZone(String sTZ);
HttpAjaxContext httpAjaxContext { get; }
GxHttpContextVars httpContextVars { get; set; }
T ReadSessionKey<T>(string key) where T : class;
bool WriteSessionKey<T>(string key, T value) where T : class;
List<string[]> userStyleSheetFiles { get; }
void DoAfterInit();
void PushCurrentUrl();
bool isSmartDevice();
bool IsMultipartRequest { get; }
void PushAjaxCmpContent(String Content);
int CmpDrawLvl { get; set; }
bool isEnabled { get; set; }
HttpContext HttpContext { get; set; }
HtmlTextWriter OutputWriter { get; set; }
ArrayList DataStores { get; }
string Gx_ope { get; set; }
int Gx_dbe { get; set; }
string Gx_dbt { get; set; }
string Gx_etb { get; set; }
short Gx_eop { get; set; }
short Gx_err { get; set; }
string Gx_dbsqlstate { get; set; }
string ClientID { get; set; }
GxErrorHandlerInfo ErrorHandlerInfo { get; }
string Gxuserid { get; set; }
string Gxpasswrd { get; set; }
string Gxdbname { get; set; }
string Gxdbsrv { get; set; }
string wjLoc { get; set; }
int wjLocDisableFrm { get; set; }
short wbHandled { get; set; }
short wbGlbDoneStart { get; set; }
msglist GX_msglist { get; set; }
short nUserReturn { get; set; }
string sCallerURL { get; set; }
GXXMLWriter GX_xmlwrt { get; }
FileIO FileIOInstance { get; }
FtpService FtpInstance { get; }
short nLocRead { get; set; }
GxLocationCollection colLocations { get; set; }
int nSOAPErr { get; set; }
string sSOAPErrMsg { get; set; }
string CleanAbsoluteUri { get; }
string BaseUrl { get; set; }
string ConfigSection { get; set; }
IReportHandler reportHandler { get; set; }
int handle { get; set; }
bool isRedirected { get; }
bool ResponseCommited { get; set; }
bool DrawingGrid { get; set; }
bool HtmlHeaderClosed { get; }
bool DrawGridsAtServer { get; set; }
void AddDataStore(IGxDataStore datastore);
IGxDataStore GetDataStore(string id);
void CloseConnections();
void CommitDataStores();
void Disconnect();
void RollbackDataStores();
void CommitDataStores(string callerName);
void RollbackDataStores(string callerName);
void CommitDataStores(string callerName, IDataStoreProvider dataStore);
void RollbackDataStores(string callerName, IDataStoreProvider dataStore);
string getCurrentLocation();
string GetRemoteAddress();
string GetServerName();
int GetServerPort();
string GetScriptPath();
string GetPhysicalPath();
string GetContextPath();
string GetBuildNumber(int buildN);
byte DeleteFile(string fileName);
byte FileExists(string fileName);
string GetDynUrl();
int GetSoapErr();
string GetSoapErrMsg();
bool isRemoteGXDB();
DateTime ServerNow(string dataSource);
DateTime ServerNowMs(string dataSource);
string ServerVersion(string dataSource);
string DataBaseName(string dataSource);
void SetProperty(string key, string value);
string GetProperty(string key);
void SetContextProperty(string key, object value);
object GetContextProperty(string key);
string PathToRelativeUrl(string name);
string PathToRelativeUrl(string name, bool relativeToServer);
string PathToUrl(string name);
string GetContentType(string name);
bool ExecuteBeforeConnect(IGxDataStore datastore);
bool ExecuteAfterConnect(String datastoreName);
int GetButtonType();
string GetCssProperty(string propName, string propValue);
string GetLanguage();
string GetLanguageProperty(String propName);
string FileToBase64(string filePath);
string FileFromBase64(string b64);
byte[] FileToByteArray(string filePath);
string FileFromByteArray(byte[] bArray);
IGxContext UtlClone();
string GetRequestMethod();
string GetRequestQueryString();
void DeleteReferer(int popupLevel);
void DeleteReferer();
void PopReferer();
string GetReferer();
int GetBrowserType();
bool IsLocalStorageSupported();
bool ExposeMetadata();
string GetBrowserVersion();
short GetHttpSecure();
string GetCookie(string name);
short SetCookie(string name, string value, string path, DateTime expires, string domain, int secure, bool httponly);
short SetCookie(string name, string value, string path, DateTime expires, string domain, int secure);
byte ResponseContentType(string sContentType);
byte RespondFile(string name);
byte SetHeader(string name, string value);
string GetHeader(string name);
bool IsForward();
void Redirect(String jumpUrl);
void Redirect(String jumpUrl, bool bSkipPushUrl);
void PopUp(String url);
void PopUp(String url, Object[] returnParms);
void WindowClosed();
void NewWindow(GXWindow win);
void DispatchAjaxCommands();
void DoAjaxRefresh();
void DoAjaxRefreshForm();
void DoAjaxRefreshCmp(String sPrefix);
#if !NETCORE
void DoAjaxLoad(int SId, GXWebRow row);
#endif
void DoAjaxAddLines(int SId, int lines);
void DoAjaxSetFocus(string ControlName);
string BuildHTMLColor(int lColor);
string BuildHTMLFont(String type, int size, String color);
GxXmlContext Xml { get; }
GxHttpResponse GX_webresponse { get; }
HttpCookieCollection localCookies { get; set; }
MessageQueueTransaction MQTransaction { get; set; }
void AddJavascriptSource(string jsSrc, string urlBuildNumber);
void AddJavascriptSource(string jsSrc, string urlBuildNumber, bool userDefined, bool inlined);
void AddDeferredJavascriptSource(string jsSrc, string urlBuildNumber);
void AddStyleSheetFile(string styleSheet);
void AddWebAppManifest();
bool JavascriptSourceAdded(string jsSrc);
bool StyleSheetAdded(string styleSheet);
void StatusMessage(string message);
void AddComponentObject(string cmpCtx, string objName);
void PrintReportAtClient(string reportFile, string printerRule);
void SaveComponentMsgList(string cmpCtx);
void SendComponentObjects();
void SendServerCommands();
void CloseHtmlHeader();
void WriteHtmlText(string sText);
void WriteHtmlTextNl(string sText);
void skipLines(long lines);
string convertURL(string file);
string GetCompleteURL(string file);
string GetImagePath(string id, string KBId, string theme);
string GetImageSrcSet(string baseImage);
void SetDefaultTheme(string theme);
string GetTheme();
void SetDefaultTheme(string theme, bool isDSO);
bool GetThemeisDSO();
int SetTheme(string theme);
bool CheckContentType(string contentKey, string contentType, string fullPath);
string ExtensionForContentType(string contentType);
void SetSubmitInitialConfig(IGxContext context);
string GetMessage(string id);
string GetMessage(string id, object[] args);
string GetMessage(string id, string language);
int SetLanguage(string id);
void SetWrapped(bool wrapped);
bool GetWrapped();
bool isCrawlerRequest();
void SendWebValue(string sText);
void SendWebAttribute(string sText);
void SendWebValueSpace(string sText);
void SendWebValueEnter(string sText);
void SendWebValueComplete(string sText);
void RenderUserControl(string controlType, string internalName, string htmlId, GxDictionary propbag);
void ajax_rsp_command_close();
void ajax_rsp_clear();
void setWebReturnParms(Object[] retParms);
void setWebReturnParmsMetadata(Object[] retParms);
String getWebReturnParmsJS();
String getWebReturnParmsMetadataJS();
String getJSONResponse();
LocalUtil localUtil { get; }
IGxSession GetSession();
CookieContainer GetCookieContainer(string url, bool includeCookies = true);
bool WillRedirect();
GXSOAPContext SoapContext { get; set; }
void UpdateSessionCookieContainer();
string GetCacheInvalidationToken();
string GetURLBuildNumber(string resourcePath, string urlBuildNumber);
}
#if NETCORE
internal static class AppContext
{
static IHttpContextAccessor _httpContextAccessor { get; set; }
internal static HttpContext Current => _httpContextAccessor != null ? new GxHttpContextAccesor(_httpContextAccessor) : null;
internal static void Configure(IHttpContextAccessor accessor)
{
_httpContextAccessor = accessor;
}
}
public class GxHttpContextAccesor : HttpContext
{
IHttpContextAccessor ctxAccessor;
public GxHttpContextAccesor(IHttpContextAccessor ctxAccessor)
{
this.ctxAccessor = ctxAccessor;
}
public override ConnectionInfo Connection => ctxAccessor?.HttpContext?.Connection;
public override IFeatureCollection Features => ctxAccessor?.HttpContext?.Features;
public override IDictionary<object, object> Items
{
get => ctxAccessor?.HttpContext?.Items ?? new Dictionary<object, object>();
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.Items = value; }
}
public override HttpRequest Request => ctxAccessor?.HttpContext?.Request;
public override CancellationToken RequestAborted
{
get => ctxAccessor?.HttpContext?.RequestAborted ?? CancellationToken.None;
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.RequestAborted = value; }
}
public override IServiceProvider RequestServices
{
get => ctxAccessor?.HttpContext?.RequestServices;
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.RequestServices = value; }
}
public override HttpResponse Response => ctxAccessor?.HttpContext?.Response;
public override ISession Session
{
get => ctxAccessor?.HttpContext?.Session;
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.Session = value; }
}
public override string TraceIdentifier
{
get => ctxAccessor?.HttpContext?.TraceIdentifier;
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.TraceIdentifier = value; }
}
public override ClaimsPrincipal User
{
get => ctxAccessor?.HttpContext?.User;
set { if (ctxAccessor?.HttpContext != null) ctxAccessor.HttpContext.User = value; }
}
public override WebSocketManager WebSockets => ctxAccessor?.HttpContext?.WebSockets;
public override void Abort()
{
ctxAccessor?.HttpContext?.Abort();
}
}
#endif
internal class GxApplication
{
internal static GxContext MainContext { get; set; }
}
[Serializable]
public class GxContext : IGxContext, IDisposable
{
private static IGXLogger log = null;
[NonSerialized]
private bool _disposed;
internal static string GX_SPA_REQUEST_HEADER = "X-SPA-REQUEST";
internal static string GX_SPA_REDIRECT_URL = "X-SPA-REDIRECT-URL";
internal const string GXLanguage = "GXLanguage";
internal const string GXTheme = "GXTheme";
internal const string SERVER_VAR_HTTP_HOST = "HTTP_HOST";
internal const string CURRENT_GX_CONTEXT = "CURRENT_GX_CONTEXT";
[NonSerialized]
HttpContext _HttpContext;
[NonSerialized]
HtmlTextWriter _outputWriter;
[NonSerialized]
NameValueCollection _httpHeaders;
ArrayList _DataStores;
[NonSerialized]
GxXmlContext _XMLContext;
[NonSerialized]
GxErrorHandlerInfo _errorHandlerInfo;
[NonSerialized]
private List<string[]> _userStyleSheetFiles = new List<string[]>();
public List<string[]> userStyleSheetFiles
{
get { return _userStyleSheetFiles; }
}
string _gxUserId;
string _clientId = string.Empty;
string _gxPasswrd;
string _gxDbName;
string _gxDbSrv;
short _wbHandled;
short _wbGlbDoneStart;
[NonSerialized]
msglist _gxMsgList;
short _nUserReturn;
string _sCallerURL;
[NonSerialized]
FileIO _fileIoInstance;
[NonSerialized]
FtpService _ftpInstance;
short _nLocRead;
[NonSerialized]
GxLocationCollection _colLocations;
int _nSOAPErr;
string _sSOAPErrMsg;
string _currentLocation = "";
string _configSection = "";
int _handle = -1;
object beforeCommitObj, afterCommitObj, beforeRollbackObj, afterRollbackObj, beforeConnectObj, afterConnectObj;
bool inBeforeCommit;
bool inAfterCommit;
bool inBeforeRollback;
bool inAfterRollback;
bool SkipPushUrl;
[NonSerialized]
Hashtable _properties;
[NonSerialized]
IReportHandler _reportHandler;
string _theme = "";
bool _theme_isDSO = false;
[NonSerialized]
ArrayList _reportHandlerToClose;
private bool configuredEventHandling;
private static string _physicalPath;
[NonSerialized]
private LocalUtil _localUtil;
private bool _responseCommited;
private bool _refreshAsGET;
private bool wrapped;
public bool IsCrawlerRequest { get; set; }
private int drawGridsAtServer = -1;
public bool HtmlHeaderClosed { private set; get; }
public bool DrawingGrid { set; get; }
public GxHttpContextVars httpContextVars { set; get; }
[NonSerialized]
private IGxSession _session;
private bool _isSumbited;
[NonSerialized]
private OlsonTimeZone _currentTimeZone;
[NonSerialized]
private String _currentTimeZoneId;
[NonSerialized]
MessageQueueTransaction _mqTransaction;
bool _mqTransactionNull = true;
[NonSerialized]
HttpCookieCollection _localCookies;
string _HttpRequestMethod;
[System.Diagnostics.CodeAnalysis.SuppressMessage("GxFxCopRules", "CR1000:EnforceThreadSafeType")]
[NonSerialized]
Dictionary<string, CookieContainer> cookieContainers;
static string COOKIE_CONTAINER = "GX_COOKIECONTAINER";
private bool _ignoreSpa;
private const string _serviceWorkerFileName = "service-worker.js";
private bool? _isServiceWorkerDefined = null;
private const string _webAppManifestFileName = "manifest.json";
private bool? _isWebAppManifestDefined = null;
private static string CACHE_INVALIDATION_TOKEN;
private bool IsServiceWorkerDefined
{
get
{
if (_isServiceWorkerDefined == null)
{
_isServiceWorkerDefined = CheckFileExists(_serviceWorkerFileName);
}
return _isServiceWorkerDefined == true;
}
}
private bool IsWebAppManifestDefined
{
get
{
if (_isWebAppManifestDefined == null)
{
_isWebAppManifestDefined = CheckFileExists(_webAppManifestFileName);
}
return _isWebAppManifestDefined == true;
}
}
public static GxContext CreateDefaultInstance()
{
GxContext context = new GxContext();
DataStoreUtil.LoadDataStores(context);
string theme = Preferences.GetDefaultTheme();
if (!string.IsNullOrEmpty(theme))
context.SetDefaultTheme(theme);
return context;
}
static IGXLogger Logger
{
get
{
if (Config.configLoaded)
{
if (log == null)
{
log = GXLoggerFactory.GetLogger<GeneXus.Application.GxContext>();
return log;
}
return log;
}
else
return null;
}
}
public GxContext()
{
_DataStores = new ArrayList(2);
LocalInitialize();
_errorHandlerInfo = new GxErrorHandlerInfo();
setContext(this);
httpContextVars = new GxHttpContextVars();
GXLogging.Debug(Logger, "GxContext.Ctr Default handle:", () => _handle.ToString());
if (GxApplication.MainContext == null && !(IsHttpContext || GxContext.IsRestService))
GxApplication.MainContext = this;
}
public GxContext(int handle, string location)
{
_DataStores = new ArrayList(2);
_currentLocation = location;
_handle = handle;
_errorHandlerInfo = new GxErrorHandlerInfo();
setContext(this);
httpContextVars = new GxHttpContextVars();
}
public GxContext(String location)
{
GXLogging.Debug(Logger, "GxContext.Ctr, parameters location=", location);
_DataStores = new ArrayList(2);
_errorHandlerInfo = new GxErrorHandlerInfo();
setContext(this);
httpContextVars = new GxHttpContextVars();
GXLogging.Debug(Logger, "Return GxContext.Ctr");
}
public GxContext(int handle, ArrayList dataStores, HttpContext httpContext)
{
_DataStores = dataStores;
_HttpContext = httpContext;
_HttpRequestMethod = "";
_handle = handle;
_errorHandlerInfo = new GxErrorHandlerInfo();
setContext(this);
httpContextVars = new GxHttpContextVars();
}
#if NETCORE
private Dictionary<string, IEnumerable<Cookie>> ToSerializableCookieContainer(Dictionary<string, CookieContainer> cookies)
{
if (cookies == null)
return null;
Dictionary<string, IEnumerable<Cookie>> serializableCookies = new Dictionary<string, IEnumerable<Cookie>>();
foreach (string key in cookies.Keys)
{
serializableCookies[key] = cookies[key].GetCookies();
}
return serializableCookies;
}
#endif
private Dictionary<string, CookieContainer> FromSerializableCookieContainer(Dictionary<string, IEnumerable<Cookie>> cookies)
{
if (cookies == null)
return null;
Dictionary<string, CookieContainer> serializableCookies = new Dictionary<string, CookieContainer>();
foreach (string key in cookies.Keys)
{
CookieCollection cookieco = new CookieCollection();
IEnumerable<Cookie> cookiesEnum = cookies[key];
foreach (Cookie c in cookiesEnum)
{
cookieco.Add(c);
}
CookieContainer cc = new CookieContainer();
cc.Add(cookieco);
serializableCookies[key] = cc;
}
return serializableCookies;
}
public void UpdateSessionCookieContainer()
{
IGxSession tempStorage = GetSession();
#if NETCORE
tempStorage.Set(COOKIE_CONTAINER, ToSerializableCookieContainer(cookieContainers));
#else
tempStorage.Set(COOKIE_CONTAINER, cookieContainers);
#endif
}
public CookieContainer GetCookieContainer(string url, bool includeCookies = true)
{
try
{
CookieContainer container = null;
IGxSession tempStorage = GetSession();
#if NETCORE
cookieContainers = FromSerializableCookieContainer(tempStorage.Get<Dictionary<string, IEnumerable<Cookie>>>(COOKIE_CONTAINER));
#else
cookieContainers = tempStorage.Get<Dictionary<string, CookieContainer>>(COOKIE_CONTAINER);
#endif
if (cookieContainers == null)
{
cookieContainers = new Dictionary<string, CookieContainer>();
#if NETCORE
tempStorage.Set(COOKIE_CONTAINER, ToSerializableCookieContainer(cookieContainers));
#else
tempStorage.Set(COOKIE_CONTAINER, cookieContainers);
#endif
}
string domain = (new Uri(url)).GetLeftPart(UriPartial.Authority);
if (cookieContainers.TryGetValue(domain, out container) && includeCookies)
{
return container;
}
else
{
container = new CookieContainer();
cookieContainers[domain] = container;
}
return container;
}
catch (Exception ex)
{
GXLogging.Debug(Logger, ex, "GetCookieContainer error url:", url);
}
return new CookieContainer();
}
[NonSerialized]
static GxContext _currentBatchGxContext;
static public GxContext Current
{
get
{
#if !NETCORE
if (HttpContext.Current != null)
{
GxContext currCtx = (GxContext)HttpContext.Current.Items[CURRENT_GX_CONTEXT];
if (currCtx != null)
return currCtx;
}
else
{
return _currentBatchGxContext;
}
return null;
#else
if (AppContext.Current != null)
{
if (AppContext.Current.Items.TryGetValue(CURRENT_GX_CONTEXT, out object ctxObj) && ctxObj is GxContext currCtx)
return currCtx;
}
else
{
return _currentBatchGxContext;
}
return null;
#endif
}
}
static void setContext(GxContext ctx)
{
#if !NETCORE
if (HttpContext.Current != null)
HttpContext.Current.Items[CURRENT_GX_CONTEXT] = ctx;
#else
if (AppContext.Current != null)
AppContext.Current.Items[CURRENT_GX_CONTEXT] = ctx;
#endif
else if (!IsHttpContext)
_currentBatchGxContext = ctx;
}
public LocalUtil localUtil
{
get
{
if (_localUtil == null) _localUtil = GXResourceManager.GetLocalUtil(GetLanguage());
return _localUtil;
}
}
public bool ResponseCommited
{
get
{
return _responseCommited;
}
set
{
_responseCommited = value;
}
}
private bool bCloseCommand;
public void ajax_rsp_command_close()
{
bCloseCommand = true;
try
{
JObject closeParms = new JObject();
closeParms.Put("values", HttpAjaxContext.GetParmsJArray(this.returnParms));
closeParms.Put("metadata", HttpAjaxContext.GetParmsJArray(this.returnParmsMetadata));
httpAjaxContext.appendAjaxCommand("close", closeParms);
}
catch (Exception)
{
}
}
public void ajax_rsp_clear()
{
httpAjaxContext.ajax_rsp_clear();
}
public bool isCloseCommand { get { return bCloseCommand; } }
[NonSerialized]
private Object[] returnParms = Array.Empty<Object>();
private Object[] returnParmsMetadata = Array.Empty<Object>();
public void setWebReturnParms(Object[] retParms)
{
this.returnParms = retParms;
}
public void setWebReturnParmsMetadata(Object[] retParmsMetadata)
{
this.returnParmsMetadata = retParmsMetadata;
}
public static string GetHttpRequestPostedFileType(HttpContext httpContext, string varName)
{
try
{
HttpPostedFile pf = httpContext.Request.GetFile(varName);
if (pf != null)
return FileUtil.GetFileType(pf.FileName);
}
catch { }
return string.Empty;
}
public static string GetHttpRequestPostedFileName(HttpContext httpContext, string varName)
{
try
{
HttpPostedFile pf = httpContext.Request.GetFile(varName);
if (pf != null)
return FileUtil.GetFileName(pf.FileName);
}
catch { }
return string.Empty;
}
public static bool GetHttpRequestPostedFile(IGxContext gxContext, string varName, out string fileToken)
{
var httpContext = gxContext.HttpContext;
fileToken = null;
if (httpContext != null)
{
HttpPostedFile pf = httpContext.Request.GetFile(varName);
if (pf != null && pf.ContentLength > 0)
{
string tempDir = Preferences.getTMP_MEDIA_PATH();
string ext = Path.GetExtension(pf.FileName);
if (ext != null)
ext = ext.TrimStart('.');
string filePath = FileUtil.getTempFileName(tempDir);
GXLogging.Debug(Logger, "cgiGet(" + varName + "), fileName:" + filePath);
GxFile file = new GxFile(tempDir, filePath, GxFileType.PrivateAttribute);
filePath = file.Create(pf.InputStream);
string fileGuid = GxUploadHelper.GetUploadFileGuid();
fileToken = GxUploadHelper.GetUploadFileId(fileGuid);
GxUploadHelper.CacheUploadFile(fileGuid, Path.GetFileName(pf.FileName), ext, file, gxContext);
return true;
}
}
return false;
}
public String getWebReturnParmsJS()
{
return HttpAjaxContext.GetParmsJArray(this.returnParms).ToString();
}
public String getWebReturnParmsMetadataJS()
{
return HttpAjaxContext.GetParmsJArray(this.returnParmsMetadata).ToString();
}
[NonSerialized]
HttpAjaxContext _httpAjaxContext;
public HttpAjaxContext httpAjaxContext
{
get
{
if (_httpAjaxContext == null)
_httpAjaxContext = new HttpAjaxContext();
return _httpAjaxContext;
}
}
private String sAjaxCmpContent = String.Empty;
public String AjaxCmpContent
{
get { return sAjaxCmpContent; }
set { sAjaxCmpContent = value; }
}
public void PushAjaxCmpContent(String Content)
{
sAjaxCmpContent += Content;
}
private bool bIsEnabled = true;
public bool isEnabled
{
get { return bIsEnabled; }
set { bIsEnabled = value; }
}
public bool isOutputEnabled()
{
return this.isEnabled;
}
public void disableOutput()
{
this.isEnabled = false;
}
public void enableOutput()
{
this.isEnabled = true;
}
private int nCmpDrawLvl;
public int CmpDrawLvl
{
get { return nCmpDrawLvl; }
set { nCmpDrawLvl = value; }
}
protected bool PortletMode;
protected bool AjaxCallMode;
protected bool AjaxEventMode;
protected bool FullAjaxMode;
public void setPortletMode()
{ PortletMode = true; }
public void setAjaxCallMode()
{ AjaxCallMode = true; }
public void setAjaxEventMode()
{ AjaxEventMode = true; }
public void setFullAjaxMode()
{ FullAjaxMode = true; }
public bool isPortletMode()
{ return PortletMode; }
public bool isAjaxCallMode()
{ return AjaxCallMode; }
public bool isAjaxEventMode()
{ return AjaxEventMode; }
public bool isAjaxRequest()
{ return isAjaxCallMode() || isAjaxEventMode() || isPortletMode(); }
public bool isFullAjaxMode()
{ return FullAjaxMode; }
public bool isSpaRequest(bool ignoreFlag)
{
if (!ignoreFlag && _ignoreSpa)
{
return false;
}
return GetRequestMethod() == "GET" && !isAjaxRequest() && HttpContext.Request.Headers[GX_SPA_REQUEST_HEADER] == "1";
}
public bool isSpaRequest()
{
return isSpaRequest(false);
}
public bool isMultipartRequest()
{ return IsMultipartRequest; }
public void DisableSpaRequest()
{
_ignoreSpa = true;
}
private StringCollection deferredFragments = new StringCollection();
private StringCollection javascriptSources = new StringCollection();
private StringCollection styleSheets = new StringCollection();
private HashSet<string> deferredJavascriptSources = new HashSet<string>();
public void AddJavascriptSource(string jsSrc, string urlBuildNumber)
{
AddJavascriptSource(jsSrc, urlBuildNumber, false, true);
}
public void ClearJavascriptSources()
{
javascriptSources.Clear();
}
public void AddDeferredFrags()
{
foreach (string each_fragment in deferredFragments)
{
WriteHtmlText(each_fragment);
}
}
public void AddJavascriptSource(string jsSrc, string urlBuildNumber, bool userDefined, bool isInlined)
{
if (!string.IsNullOrWhiteSpace(jsSrc) && !JavascriptSourceAdded(jsSrc))
{
javascriptSources.Add(jsSrc);
string queryString = GetURLBuildNumber(jsSrc, urlBuildNumber);
string attributes = "";
if (userDefined)
{
queryString = "";
attributes = "data-gx-external-script";
}
string fragment = "<script type=\"text/javascript\" src=\"" + GetCompleteURL(jsSrc) + queryString + "\" " + attributes + "></script>";
if (isAjaxRequest() || isInlined || jsSrc == "jquery.js" || jsSrc == "gxcore.js")
{
WriteHtmlText(fragment);
}
else
{
deferredFragments.Add(fragment);
}
// After including jQuery, include all the deferred Javascript files
if (jsSrc == "jquery.js")
{
foreach (string deferredJsSrc in deferredJavascriptSources)
{
AddJavascriptSource(deferredJsSrc, "", false, true);
}
}
// After including gxgral, set the Service Worker Url if one is defined
if (jsSrc == "gxgral.js" && IsServiceWorkerDefined)
{
WriteHtmlText($"<script>gx.serviceWorkerUrl = \"{GetCompleteURL(_serviceWorkerFileName)}\";</script>");
}
}
}
[Obsolete("AddJavascriptSource with 1 argument is deprecated", false)]
public void AddJavascriptSource(string jsSrc)
{
AddJavascriptSource(jsSrc, string.Empty);
}
public void AddDeferredJavascriptSource(string jsSrc, string urlBuildNumber)
{