Skip to content

Commit 1afb42a

Browse files
committed
Release 1.2.12 - added COM visibility, fixed exceptions in Debug type static initializer, aztomatically added logs directory in web projects hidden by default, documentation generator config
1 parent 8ea1e4d commit 1afb42a

35 files changed

Lines changed: 2725 additions & 111 deletions

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,4 +293,5 @@ __pycache__/
293293
*.user
294294
.vs/
295295
Assets/node_modules
296-
_CreateNewNuGetPackage/*
296+
_CreateNewNuGetPackage/*
297+
docs/*

Attributes/Hidden.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
using System;
1+
using System;
22
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
34

45
namespace Desharp {
56
/// <summary>
@@ -8,6 +9,7 @@ namespace Desharp {
89
/// To print always everything, add to your (App|Web).config:
910
/// &#60;add key="Desharp:DumpCompillerGenerated" value="true" /&#62;
1011
/// </summary>
12+
[ComVisible(true)]
1113
public class HiddenAttribute: Attribute {
1214
}
1315
}

Completers/Detector.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@
44
using System.Collections.Specialized;
55
using System.Data;
66
using System.Reflection;
7+
using System.Runtime.InteropServices;
78

89
namespace Desharp.Completers {
910
/// <summary>
1011
/// Detecting class to check value types to dump them correctly, always internaly used by Desharp, but it should be used for any general purposes.
1112
/// </summary>
13+
[ComVisible(true)]
1214
public class Detector {
1315
/// <summary>
1416
/// True if value is Type object.

Completers/LoadedAssemblies.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Reflection;
44

Core/Dispatcher.cs

Lines changed: 100 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.IO;
66
using System.Linq;
77
using System.Reflection;
8+
using System.Runtime.InteropServices;
89
using System.Runtime.Remoting.Messaging;
910
using System.Threading;
1011
using System.Web;
@@ -37,12 +38,12 @@ internal class Dispatcher {
3738
};
3839

3940
//protected static ReaderWriterLockSlim dispatchersLock = new ReaderWriterLockSlim();
40-
protected static object dispatchersLock = new object { };
41-
protected static volatile Dictionary<string, Dispatcher> dispatchers = new Dictionary<string, Dispatcher>();
41+
internal static object dispatchersLock = new object { };
42+
internal static volatile Dictionary<string, Dispatcher> dispatchers = new Dictionary<string, Dispatcher>();
4243

4344
protected static string callContextKey = typeof(Dispatcher).FullName;
4445
protected static Dictionary<string, Type> webBarRegisteredPanels = new Dictionary<string, Type>();
45-
46+
4647
internal Exception LastError = null;
4748
internal int DumperSequence = 0;
4849
internal string CurrentlyRendererView = "";
@@ -63,66 +64,88 @@ internal class Dispatcher {
6364
protected List<string> webExceptions = null;
6465

6566
static Dispatcher () {
66-
Dispatcher.StaticInitLock.EnterUpgradeableReadLock();
67-
if (Dispatcher.StaticInitialized) {
67+
//try {
68+
Dispatcher.StaticInitLock.EnterUpgradeableReadLock();
69+
if (Dispatcher.StaticInitialized) {
70+
Dispatcher.StaticInitLock.ExitUpgradeableReadLock();
71+
return;
72+
}
73+
Dispatcher.StaticInitLock.EnterWriteLock();
6874
Dispatcher.StaticInitLock.ExitUpgradeableReadLock();
69-
return;
70-
}
71-
Dispatcher.StaticInitLock.EnterWriteLock();
72-
Dispatcher.StaticInitLock.ExitUpgradeableReadLock();
73-
int cfgDepth = Config.GetDepth();
74-
if (cfgDepth > 0) Dispatcher.DumpDepth = cfgDepth;
75-
int cfgMaxLength = Config.GetMaxLength();
76-
if (cfgMaxLength > 0) Dispatcher.DumpMaxLength = cfgMaxLength;
77-
Dispatcher.Levels = Config.GetLevels();
78-
Dispatcher.LogWriteMilisecond = Config.GetLogWriteMilisecond();
79-
Dispatcher.VirtualPathProvider = HostingEnvironment.VirtualPathProvider;
80-
if (HttpRuntime.AppDomainAppId != null && HostingEnvironment.IsHosted) {
81-
Dispatcher.EnvType = EnvType.Web;
82-
Dispatcher.AppRoot = HttpContext.Current.Server.MapPath("~").Replace('\\', '/').TrimEnd('/');
83-
Dispatcher.WebDebugIps = Config.GetDebugIps();
84-
Dispatcher.staticInitWebRegisterPanels(typeof(Panels.Exceptions), typeof(Panels.Dumps));
85-
Dispatcher.staticInitWebRegisterPanels(Config.GetDebugPanels());
86-
Dispatcher.staticInitWebErrorPage(Config.GetErrorPage());
87-
} else {
88-
Dispatcher.EnvType = EnvType.Windows;
89-
Dispatcher.AppRoot = System.IO.Path.GetDirectoryName(
90-
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
91-
).Replace('\\', '/').TrimEnd('/');
92-
AppDomain.CurrentDomain.UnhandledException += delegate (object o, UnhandledExceptionEventArgs e) {
93-
Debug.Log(e.ExceptionObject as Exception);
94-
if (e.IsTerminating) Dispatcher.Disposed();
95-
};
96-
if (Dispatcher.LogWriteMilisecond > 0) {
97-
bool exited = false;
98-
AppDomain.CurrentDomain.ProcessExit += delegate (object o, EventArgs e) {
99-
Dispatcher.Disposed();
100-
exited = true;
101-
};
102-
AppExitWatcher.SetConsoleCtrlHandler(new HandlerRoutine((type) => {
103-
if (exited) return true;
104-
Dispatcher.Disposed();
105-
return true;
106-
}), true);
107-
}
108-
}
109-
if (Tools.IsWindows()) Dispatcher.AppRoot = Dispatcher.AppRoot.Substring(0, 1).ToUpper() + Dispatcher.AppRoot.Substring(1);
110-
if (
111-
Tools.IsWindows() && (
112-
Dispatcher.AppRoot.IndexOf("/bin/Debug") == Dispatcher.AppRoot.Length - 10 ||
113-
Dispatcher.AppRoot.IndexOf("/bin/Release") == Dispatcher.AppRoot.Length - 12
114-
)
115-
) {
116-
Dispatcher.SourcesRoot = System.IO.Path.GetFullPath(Dispatcher.AppRoot + "/../..").Replace('\\', '/');
117-
} else {
118-
Dispatcher.SourcesRoot = "";
119-
}
120-
Dispatcher.staticInitEnabledGlobal();
121-
Dispatcher.staticInitOutputGlobal();
122-
Dispatcher.staticInitDumpCompillerGenerated();
123-
Dispatcher.staticInitDirectory(Config.GetDirectory());
124-
FileLog.StaticInit();
125-
Dispatcher.StaticInitLock.ExitWriteLock();
75+
int cfgDepth = Config.GetDepth();
76+
if (cfgDepth > 0) Dispatcher.DumpDepth = cfgDepth;
77+
int cfgMaxLength = Config.GetMaxLength();
78+
if (cfgMaxLength > 0) Dispatcher.DumpMaxLength = cfgMaxLength;
79+
Dispatcher.Levels = Config.GetLevels();
80+
Dispatcher.LogWriteMilisecond = Config.GetLogWriteMilisecond();
81+
Dispatcher.VirtualPathProvider = HostingEnvironment.VirtualPathProvider;
82+
bool appRootInitialized = false;
83+
if (HttpRuntime.AppDomainAppId != null && HostingEnvironment.IsHosted) {
84+
Dispatcher.EnvType = EnvType.Web;
85+
if (HttpContext.Current != null) {
86+
try {
87+
Dispatcher.AppRoot = HttpContext.Current.Server
88+
.MapPath("~").Replace('\\', '/').TrimEnd('/');
89+
appRootInitialized = true;
90+
} catch (Exception e4) {
91+
}
92+
}
93+
Dispatcher.WebDebugIps = Config.GetDebugIps();
94+
Dispatcher.staticInitWebRegisterPanels(typeof(Panels.Exceptions), typeof(Panels.Dumps));
95+
Dispatcher.staticInitWebRegisterPanels(Config.GetDebugPanels());
96+
Dispatcher.staticInitWebErrorPage(Config.GetErrorPage());
97+
} else {
98+
Dispatcher.EnvType = EnvType.Windows;
99+
try {
100+
Dispatcher.AppRoot = System.IO.Path.GetDirectoryName(
101+
System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
102+
).Replace('\\', '/').TrimEnd('/');
103+
appRootInitialized = true;
104+
} catch (Exception e5) {
105+
}
106+
AppDomain.CurrentDomain.UnhandledException += delegate (object o, UnhandledExceptionEventArgs e1) {
107+
Debug.Log(e1.ExceptionObject as Exception);
108+
if (e1.IsTerminating) Dispatcher.Disposed();
109+
};
110+
if (Dispatcher.LogWriteMilisecond > 0) {
111+
bool exited = false;
112+
AppDomain.CurrentDomain.ProcessExit += delegate (object o, EventArgs e2) {
113+
Dispatcher.Disposed();
114+
exited = true;
115+
};
116+
AppExitWatcher.SetConsoleCtrlHandler(new HandlerRoutine((type) => {
117+
if (exited) return true;
118+
Dispatcher.Disposed();
119+
return true;
120+
}), true);
121+
}
122+
}
123+
bool isWindows = Tools.IsWindows();
124+
if (appRootInitialized && isWindows)
125+
Dispatcher.AppRoot = Dispatcher.AppRoot.Substring(0, 1).ToUpper()
126+
+ Dispatcher.AppRoot.Substring(1);
127+
if (
128+
appRootInitialized && isWindows && (
129+
Dispatcher.AppRoot.IndexOf("/bin/Debug") == Dispatcher.AppRoot.Length - 10 ||
130+
Dispatcher.AppRoot.IndexOf("/bin/Release") == Dispatcher.AppRoot.Length - 12
131+
)
132+
) {
133+
Dispatcher.SourcesRoot = System.IO.Path.GetFullPath(
134+
Dispatcher.AppRoot + "/../.."
135+
).Replace('\\', '/');
136+
} else {
137+
Dispatcher.SourcesRoot = "";
138+
}
139+
Dispatcher.staticInitEnabledGlobal();
140+
Dispatcher.staticInitOutputGlobal();
141+
Dispatcher.staticInitDumpCompillerGenerated();
142+
if (appRootInitialized)
143+
Dispatcher.staticInitDirectory(Config.GetDirectory());
144+
FileLog.StaticInit();
145+
Dispatcher.StaticInitLock.ExitWriteLock();
146+
/*} catch (Exception e3) {
147+
Debug.InitErrors.Add(e3);
148+
}*/
126149
}
127150
internal static Dispatcher GetCurrent (bool createIfNecessary = true) {
128151
string dispatchedKey = Dispatcher.EnvType == EnvType.Web
@@ -378,6 +401,7 @@ internal FireDump GetFireDump () {
378401
return this.FireDump;
379402
}
380403
internal void Configure (DebugConfig cfg) {
404+
return;
381405
if (cfg.EnvType != EnvType.Auto) Dispatcher.EnvType = cfg.EnvType;
382406
if (cfg.Enabled.HasValue) this.Enabled = cfg.Enabled.Value;
383407
if (cfg.LogFormat != LogFormat.Auto) this.Output = cfg.LogFormat;
@@ -437,7 +461,8 @@ internal void Stop () {
437461
if (this.WebRequestState == 0) this.WebRequestBegin();
438462
if (this.WebRequestState == 1) this.WebRequestSessionBegin();
439463
if (this.WebRequestState == 2) this.WebRequestSessionEnd();
440-
this.WebRequestEnd();
464+
this.WebRequestPreSendHeaders();
465+
this.WebRequestPreSendBody();
441466
Dispatcher.Remove();
442467
HttpContext.Current.Response.End();
443468
} else {
@@ -485,7 +510,8 @@ internal void WebRequestSessionEnd () {
485510
}
486511
this.WebRequestState = 3;
487512
}
488-
internal void WebRequestEnd () {
513+
internal void WebRequestPreSendHeaders () {
514+
this.GetFireDump().CloseHeaders();
489515
if (this.Enabled == true) {
490516
if (!this.webRedirect.HasValue) this.webRedirect = Dispatcher.webCheckIfResponseIsRedirect();
491517
// add possible rendered exceptions and debug bar if necessary
@@ -501,6 +527,15 @@ internal void WebRequestEnd () {
501527
}
502528
// manage Content-Security-Policy http header
503529
this.webManageContentSecurityPolicyHeader();
530+
}
531+
} else {
532+
if (this.webTransmitErrorPage && Dispatcher.WebStaticErrorPage.Length > 0)
533+
HtmlResponse.TransmitStaticErrorPagePrepareHeaders();
534+
}
535+
}
536+
internal void WebRequestPreSendBody() {
537+
if (this.Enabled == true) {
538+
if (this.webRenderDesharpBar == 1 && this.webRedirect != true) {
504539
// render debug bar for current request with any previous redirect records from session
505540
List<List<RenderedPanel>> renderedPanels = this.webReqEndSession
506541
?? Dispatcher.webGetSessionStorrage();
@@ -512,7 +547,7 @@ internal void WebRequestEnd () {
512547
}
513548
} else {
514549
if (this.webTransmitErrorPage && Dispatcher.WebStaticErrorPage.Length > 0)
515-
HtmlResponse.TransmitStaticErrorPage();
550+
HtmlResponse.TransmitStaticErrorPageSendContent();
516551
}
517552
}
518553
protected void webManageContentSecurityPolicyHeader () {

Core/Enums/EnvType.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace Desharp {
1+
using System.Runtime.InteropServices;
2+
3+
namespace Desharp {
24
/// <summary>
35
/// Application general environment - should be only defined as web or desktop.
46
/// </summary>
7+
[ComVisible(true)]
58
public enum EnvType {
69
/// <summary>
710
/// Environment will be defined by Desharp assembly at first Desharp call.

Core/Enums/FireDumpType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Runtime.InteropServices;
45
using System.Text;
56

67
namespace Desharp {
78
/// <summary>
89
/// Fire dumper message type to choose in client browser propert console method
910
/// lie console.log(), console.debug(). console.trace() exc...
1011
/// </summary>
12+
[ComVisible(true)]
1113
public enum FireDumpType {
1214
/// <summary>
1315
/// Print value in browser console by: console.debug();

Core/Enums/Level.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace Desharp {
1+
using System.Runtime.InteropServices;
2+
3+
namespace Desharp {
24
/// <summary>
35
/// Application logging levels to define log filename used for Desharp.Debug.Log() calls and to define if log message will be written or not by config settings.
46
/// </summary>
7+
[ComVisible(true)]
58
public enum Level {
69
/// <summary>
710
/// debug.log|debug.html, mostly used as default log file.

Core/Enums/LogFormat.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
namespace Desharp {
1+
using System.Runtime.InteropServices;
2+
3+
namespace Desharp {
24
/// <summary>
35
/// Specify log files format - should be only text or html.
46
/// </summary>
7+
[ComVisible(true)]
58
public enum LogFormat {
69
/// <summary>
710
/// Log format will be determinated automaticly at first Desharp assembly use.

Core/Enums/PanelIconType.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1-
using System;
1+
using System;
2+
using System.Runtime.InteropServices;
23

34
namespace Desharp {
45
/// <summary>
56
/// Panel icon type for custom web debug panel.
67
/// </summary>
78
[Serializable]
9+
[ComVisible(true)]
810
public enum PanelIconType {
911
/// <summary>
1012
/// Debug panels without icon.

0 commit comments

Comments
 (0)