##// END OF EJS Templates
sync
cin -
r133:6c49d02a9a05 v2
parent child
Show More
@@ -23,10 +23,10 namespace Implab.Diagnostics {
23
23
24 for (int i = 0; i < text.indent; i++)
24 for (int i = 0; i < text.indent; i++)
25 msg.Append(" ");
25 msg.Append(" ");
26 msg.AppendFormat("[{0}]:{1}: {2}", args.ThreadId, channel, text.content);
26 msg.AppendFormat("[{0}]: {1}", args.ThreadId, text.content);
27
27
28 lock (_consoleLock) {
28 lock (_consoleLock) {
29 //Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1);
29 Console.ForegroundColor = (ConsoleColor)(args.ThreadId % 15 + 1);
30 Console.WriteLine(msg);
30 Console.WriteLine(msg);
31 }
31 }
32 }
32 }
@@ -41,10 +41,10 namespace Implab.Diagnostics {
41 }
41 }
42
42
43 public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) {
43 public void EnterLogicalOperation(LogicalOperation operation, bool takeOwnership) {
44 var prev = CurrentOperation;
44 //var prev = CurrentOperation;
45 m_stack.Push(m_current);
45 m_stack.Push(m_current);
46 m_current = new OperationContext(operation, takeOwnership);
46 m_current = new OperationContext(operation, takeOwnership);
47 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name)));
47 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(takeOwnership ? TraceEventType.Attach : TraceEventType.Enter, String.Format("{0} -> {1}",prev.Name, operation.Name)));
48 }
48 }
49
49
50 public void StartLogicalOperation(string name) {
50 public void StartLogicalOperation(string name) {
@@ -63,16 +63,16 namespace Implab.Diagnostics {
63
63
64 public LogicalOperation DetachLogicalOperation() {
64 public LogicalOperation DetachLogicalOperation() {
65 var prev = m_current.DetachLogicalOperation();
65 var prev = m_current.DetachLogicalOperation();
66 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name)));
66 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Detach, String.Format("{0} -> {1}",prev.Name, CurrentOperation.Name)));
67 return prev;
67 return prev;
68 }
68 }
69
69
70 public void Leave() {
70 public void Leave() {
71 if (m_stack.Count > 0) {
71 if (m_stack.Count > 0) {
72 m_current.Leave();
72 m_current.Leave();
73 var prev = CurrentOperation;
73 //var prev = CurrentOperation;
74 m_current = m_stack.Pop();
74 m_current = m_stack.Pop();
75 LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name)));
75 //LogChannel<TraceEvent>.Default.LogEvent(new TraceEvent(TraceEventType.Leave, String.Format("{0} -> {1}", prev.Name, CurrentOperation.Name)));
76 } else {
76 } else {
77 TraceLog.TraceWarning("Attempt to leave the last operation context");
77 TraceLog.TraceWarning("Attempt to leave the last operation context");
78 m_current = OperationContext.EMPTY;
78 m_current = OperationContext.EMPTY;
@@ -18,7 +18,8 namespace Implab.Diagnostics {
18 }
18 }
19
19
20 public override string ToString() {
20 public override string ToString() {
21 return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);
21 /*return EventType == TraceEventType.Information ? Message : String.Format("{0}: {1}", EventType, Message);*/
22 return Message;
22 }
23 }
23
24
24 public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
25 public static TraceEvent Create(TraceEventType type, string format, params object[] args) {
@@ -89,15 +89,19 namespace Implab
89 public static IPromise InvokePromise(Func<IPromise> action) {
89 public static IPromise InvokePromise(Func<IPromise> action) {
90 ArgumentNotNull(action, "action");
90 ArgumentNotNull(action, "action");
91
91
92 var p = new Promise();
93 try {
92 try {
94 action();
93 var p = action();
95 p.Resolve();
94 if (p == null) {
95 var d = new Promise();
96 d.Reject(new Exception("The action returned null"));
97 p = d;
98 }
99 return p;
96 } catch (Exception err) {
100 } catch (Exception err) {
101 var p = new Promise();
97 p.Reject(err);
102 p.Reject(err);
103 return p;
98 }
104 }
99
100 return p;
101 }
105 }
102
106
103 [DebuggerStepThrough]
107 [DebuggerStepThrough]
General Comments 0
You need to be logged in to leave comments. Login now