Changeset 3289
- Timestamp:
- 04/09/10 01:15:16 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 4 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Core.Views/3.3/Auxiliary.cs
r2916 r3289 23 23 using System.Text; 24 24 using System.Windows.Forms; 25 using HeuristicLab.Core; 25 26 26 27 namespace HeuristicLab.Core.Views { … … 45 46 /// <param name="ex">The exception to display.</param> 46 47 public static void ShowErrorMessageBox(Exception ex) { 47 MessageBox.Show( BuildErrorMessage(ex),48 MessageBox.Show(Log.BuildErrorMessage(ex), 48 49 "Error - " + ex.GetType().Name, 49 50 MessageBoxButtons.OK, 50 51 MessageBoxIcon.Error); 51 52 } 52 /// <summary>53 /// Builds an error message out of an exception and formats it accordingly.54 /// </summary>55 /// <param name="ex">The exception to format.</param>56 /// <returns>The formated message.</returns>57 public static string BuildErrorMessage(Exception ex) {58 string nl = Environment.NewLine;59 StringBuilder sb = new StringBuilder();60 sb.Append("Sorry, but something went wrong!" + nl + ex.Message + nl + ex.StackTrace);61 62 while (ex.InnerException != null) {63 ex = ex.InnerException;64 sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace);65 }66 return sb.ToString();67 }68 53 #endregion 69 54 } -
trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.Designer.cs
r2917 r3289 47 47 this.executionTimeTextBox = new System.Windows.Forms.TextBox(); 48 48 this.executionTimeLabel = new System.Windows.Forms.Label(); 49 this.logTextBox = new System.Windows.Forms.TextBox(); 50 this.logLabel = new System.Windows.Forms.Label(); 49 this.logView = new HeuristicLab.Core.Views.LogView(); 51 50 this.SuspendLayout(); 52 51 // … … 70 69 this.executionTimeLabel.Text = "&Execution Time:"; 71 70 // 72 // log TextBox71 // logView 73 72 // 74 this.log TextBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)73 this.logView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 75 74 | System.Windows.Forms.AnchorStyles.Left) 76 75 | System.Windows.Forms.AnchorStyles.Right))); 77 this.logTextBox.Location = new System.Drawing.Point(0, 39); 78 this.logTextBox.Multiline = true; 79 this.logTextBox.Name = "logTextBox"; 80 this.logTextBox.ReadOnly = true; 81 this.logTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Both; 82 this.logTextBox.Size = new System.Drawing.Size(430, 315); 83 this.logTextBox.TabIndex = 3; 84 this.logTextBox.WordWrap = false; 85 // 86 // logLabel 87 // 88 this.logLabel.AutoSize = true; 89 this.logLabel.Location = new System.Drawing.Point(3, 23); 90 this.logLabel.Name = "logLabel"; 91 this.logLabel.Size = new System.Drawing.Size(28, 13); 92 this.logLabel.TabIndex = 2; 93 this.logLabel.Text = "&Log:"; 76 this.logView.Caption = "LogView"; 77 this.logView.Content = null; 78 this.logView.Location = new System.Drawing.Point(0, 26); 79 this.logView.Name = "logView"; 80 this.logView.Size = new System.Drawing.Size(430, 328); 81 this.logView.TabIndex = 2; 94 82 // 95 83 // EngineView … … 97 85 this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 98 86 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 99 this.Controls.Add(this.logTextBox);100 87 this.Controls.Add(this.executionTimeTextBox); 101 this.Controls.Add(this.logLabel);102 88 this.Controls.Add(this.executionTimeLabel); 89 this.Controls.Add(this.logView); 103 90 this.Name = "EngineView"; 104 91 this.Size = new System.Drawing.Size(430, 354); … … 112 99 protected System.Windows.Forms.TextBox executionTimeTextBox; 113 100 protected System.Windows.Forms.Label executionTimeLabel; 114 protected System.Windows.Forms.TextBox logTextBox; 115 protected System.Windows.Forms.Label logLabel; 101 protected LogView logView; 116 102 117 103 } -
trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs
r3262 r3289 21 21 22 22 using System; 23 using HeuristicLab.Common;24 23 using HeuristicLab.MainForm; 25 24 … … 57 56 /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks> 58 57 protected override void DeregisterContentEvents() { 59 Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);60 58 Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged); 61 Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);62 59 base.DeregisterContentEvents(); 63 60 } … … 69 66 protected override void RegisterContentEvents() { 70 67 base.RegisterContentEvents(); 71 Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);72 68 Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged); 73 Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);74 69 } 75 70 … … 80 75 protected override void OnContentChanged() { 81 76 base.OnContentChanged(); 82 logTextBox.Clear();83 77 if (Content == null) { 84 logTextBox.Enabled = false; 78 logView.Content = null; 79 logView.Enabled = false; 85 80 executionTimeTextBox.Text = "-"; 86 81 executionTimeTextBox.Enabled = false; 87 82 } else { 88 logTextBox.Enabled = true; 83 logView.Content = Content.Log; 84 logView.Enabled = true; 89 85 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 90 86 executionTimeTextBox.Enabled = true; … … 92 88 } 93 89 94 #region Content Events95 protected virtual void Content_ExecutionStateChanged(object sender, EventArgs e) {96 if (InvokeRequired)97 Invoke(new EventHandler(Content_ExecutionStateChanged), sender, e);98 else {99 if (Content.ExecutionState == ExecutionState.Prepared) Log("Engine prepared");100 else if (Content.ExecutionState == ExecutionState.Started) Log("Engine started");101 else if (Content.ExecutionState == ExecutionState.Paused) Log("Engine paused");102 else if (Content.ExecutionState == ExecutionState.Stopped) Log("Engine stopped");103 }104 }105 90 protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) { 106 91 if (InvokeRequired) … … 109 94 executionTimeTextBox.Text = Content.ExecutionTime.ToString(); 110 95 } 111 protected virtual void Content_ExceptionOccurred(object sender, EventArgs<Exception> e) {112 if (InvokeRequired)113 Invoke(new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred), sender, e);114 else115 Log(Auxiliary.BuildErrorMessage(e.Value));116 }117 #endregion118 119 #region Helpers120 protected virtual void Log(string message) {121 if (InvokeRequired)122 Invoke(new Action<string>(Log), message);123 else {124 message = DateTime.Now.ToString() + "\t" + message;125 string[] newLines = message.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);126 string[] lines = new string[logTextBox.Lines.Length + newLines.Length];127 logTextBox.Lines.CopyTo(lines, 0);128 newLines.CopyTo(lines, logTextBox.Lines.Length);129 logTextBox.Lines = lines;130 }131 }132 #endregion133 96 } 134 97 } -
trunk/sources/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj
r3281 r3289 87 87 <ItemGroup> 88 88 <None Include="HeuristicLabCoreViewsPlugin.cs.frame" /> 89 <Compile Include="LogView.cs"> 90 <SubType>UserControl</SubType> 91 </Compile> 92 <Compile Include="LogView.Designer.cs"> 93 <DependentUpon>LogView.cs</DependentUpon> 94 </Compile> 89 95 <Compile Include="VariableValueView.cs"> 90 96 <SubType>UserControl</SubType> -
trunk/sources/HeuristicLab.Core/3.3/Engine.cs
r3288 r3289 30 30 public abstract class Engine : Executable, IEngine { 31 31 [Storable] 32 protected ILog log; 33 public ILog Log { 34 get { return log; } 35 } 36 37 [Storable] 32 38 private Stack<IOperation> executionStack; 33 39 protected Stack<IOperation> ExecutionStack { … … 41 47 protected Engine() 42 48 : base() { 49 log = new Log(); 43 50 executionStack = new Stack<IOperation>(); 51 pausePending = stopPending = false; 52 timer = new System.Timers.Timer(100); 53 timer.AutoReset = true; 54 timer.Elapsed += new System.Timers.ElapsedEventHandler(timer_Elapsed); 55 } 56 [StorableConstructor] 57 protected Engine(bool deserializing) 58 : base(deserializing) { 44 59 pausePending = stopPending = false; 45 60 timer = new System.Timers.Timer(100); … … 51 66 if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState)); 52 67 Engine clone = (Engine)base.Clone(cloner); 68 clone.log = (ILog)cloner.Clone(log); 53 69 IOperation[] contexts = executionStack.ToArray(); 54 70 for (int i = contexts.Length - 1; i >= 0; i--) … … 71 87 OnPrepared(); 72 88 } 89 protected override void OnPrepared() { 90 Log.LogMessage("Engine prepared"); 91 base.OnPrepared(); 92 } 93 73 94 public override void Start() { 74 95 base.Start(); 75 96 ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null); 76 97 } 98 protected override void OnStarted() { 99 Log.LogMessage("Engine started"); 100 base.OnStarted(); 101 } 102 77 103 public override void Pause() { 78 104 base.Pause(); 79 105 pausePending = true; 80 106 } 107 protected override void OnPaused() { 108 Log.LogMessage("Engine paused"); 109 base.OnPaused(); 110 } 111 81 112 public override void Stop() { 82 113 base.Stop(); 83 114 stopPending = true; 84 115 if (ExecutionState == ExecutionState.Paused) OnStopped(); 116 } 117 protected override void OnStopped() { 118 Log.LogMessage("Engine stopped"); 119 base.OnStopped(); 120 } 121 122 protected override void OnExceptionOccurred(Exception exception) { 123 Log.LogException(exception); 124 base.OnExceptionOccurred(exception); 85 125 } 86 126 -
trunk/sources/HeuristicLab.Core/3.3/Executable.cs
r3262 r3289 59 59 executionTime = TimeSpan.Zero; 60 60 } 61 [StorableConstructor] 62 protected Executable(bool deserializing) : base(deserializing) { } 61 63 62 64 public override IDeepCloneable Clone(Cloner cloner) { -
trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj
r3262 r3289 103 103 <Compile Include="Attributes\CreatableAttribute.cs" /> 104 104 <None Include="HeuristicLabCorePlugin.cs.frame" /> 105 <Compile Include="Log.cs" /> 105 106 <Compile Include="Executable.cs" /> 106 107 <Compile Include="ExecutionState.cs" /> 108 <Compile Include="Interfaces\ILog.cs" /> 107 109 <Compile Include="Interfaces\IExecutable.cs" /> 108 110 <Compile Include="Interfaces\IParameterizedNamedItem.cs" /> -
trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs
r3262 r3289 20 20 #endregion 21 21 22 using System;23 using HeuristicLab.Common;24 25 22 namespace HeuristicLab.Core { 26 23 public interface IEngine : IExecutable { 24 ILog Log { get; } 25 27 26 void Prepare(IOperation initialOperation); 28 27 } -
trunk/sources/HeuristicLab.PluginInfrastructure/Main.cs
r3092 r3289 108 108 string nl = Environment.NewLine; 109 109 StringBuilder sb = new StringBuilder(); 110 sb.Append( "Sorry, but something went wrong!" + nl +ex.Message + nl + ex.StackTrace);110 sb.Append(ex.Message + nl + ex.StackTrace); 111 111 112 112 while (ex.InnerException != null) { -
trunk/sources/HeuristicLab.PluginInfrastructure/Starter/StarterForm.cs
r3113 r3289 192 192 } 193 193 private static string BuildErrorMessage(Exception ex) { 194 string nl = Environment.NewLine; 194 195 StringBuilder sb = new StringBuilder(); 195 sb.Append( "Sorry, but something went wrong!\n\n" + ex.Message + "\n\n"+ ex.StackTrace);196 sb.Append(ex.Message + nl + ex.StackTrace); 196 197 197 198 while (ex.InnerException != null) { 198 199 ex = ex.InnerException; 199 sb.Append( "\n\n-----\n\n" + ex.Message + "\n\n"+ ex.StackTrace);200 sb.Append(nl + "-----" + nl + ex.Message + nl + ex.StackTrace); 200 201 } 201 202 return sb.ToString(); -
trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs
r3288 r3289 62 62 Pause(); 63 63 } 64 if (operation.Operator.Breakpoint) 64 if (operation.Operator.Breakpoint) { 65 Log.LogMessage(string.Format("Breakpoint: {0} ({1})", operation.Operator.Name, operation.Operator.ItemName)); 65 66 Pause(); 67 } 66 68 } 67 69 }
Note: See TracChangeset
for help on using the changeset viewer.