Free cookie consent management tool by TermsFeed Policy Generator

Changeset 3289


Ignore:
Timestamp:
04/09/10 01:15:16 (15 years ago)
Author:
swagner
Message:

Implemented logs of engines (#963).

Location:
trunk/sources
Files:
4 added
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Core.Views/3.3/Auxiliary.cs

    r2916 r3289  
    2323using System.Text;
    2424using System.Windows.Forms;
     25using HeuristicLab.Core;
    2526
    2627namespace HeuristicLab.Core.Views {
     
    4546    /// <param name="ex">The exception to display.</param>
    4647    public static void ShowErrorMessageBox(Exception ex) {
    47       MessageBox.Show(BuildErrorMessage(ex),
     48      MessageBox.Show(Log.BuildErrorMessage(ex),
    4849                      "Error - " + ex.GetType().Name,
    4950                      MessageBoxButtons.OK,
    5051                      MessageBoxIcon.Error);
    5152    }
    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     }
    6853    #endregion
    6954  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.Designer.cs

    r2917 r3289  
    4747      this.executionTimeTextBox = new System.Windows.Forms.TextBox();
    4848      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();
    5150      this.SuspendLayout();
    5251      //
     
    7069      this.executionTimeLabel.Text = "&Execution Time:";
    7170      //
    72       // logTextBox
     71      // logView
    7372      //
    74       this.logTextBox.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)
    7574                  | System.Windows.Forms.AnchorStyles.Left)
    7675                  | 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;
    9482      //
    9583      // EngineView
     
    9785      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
    9886      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
    99       this.Controls.Add(this.logTextBox);
    10087      this.Controls.Add(this.executionTimeTextBox);
    101       this.Controls.Add(this.logLabel);
    10288      this.Controls.Add(this.executionTimeLabel);
     89      this.Controls.Add(this.logView);
    10390      this.Name = "EngineView";
    10491      this.Size = new System.Drawing.Size(430, 354);
     
    11299    protected System.Windows.Forms.TextBox executionTimeTextBox;
    113100    protected System.Windows.Forms.Label executionTimeLabel;
    114     protected System.Windows.Forms.TextBox logTextBox;
    115     protected System.Windows.Forms.Label logLabel;
     101    protected LogView logView;
    116102
    117103  }
  • trunk/sources/HeuristicLab.Core.Views/3.3/EngineView.cs

    r3262 r3289  
    2121
    2222using System;
    23 using HeuristicLab.Common;
    2423using HeuristicLab.MainForm;
    2524
     
    5756    /// <remarks>Calls <see cref="ViewBase.RemoveItemEvents"/> of base class <see cref="ViewBase"/>.</remarks>
    5857    protected override void DeregisterContentEvents() {
    59       Content.ExecutionStateChanged -= new EventHandler(Content_ExecutionStateChanged);
    6058      Content.ExecutionTimeChanged -= new EventHandler(Content_ExecutionTimeChanged);
    61       Content.ExceptionOccurred -= new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
    6259      base.DeregisterContentEvents();
    6360    }
     
    6966    protected override void RegisterContentEvents() {
    7067      base.RegisterContentEvents();
    71       Content.ExecutionStateChanged += new EventHandler(Content_ExecutionStateChanged);
    7268      Content.ExecutionTimeChanged += new EventHandler(Content_ExecutionTimeChanged);
    73       Content.ExceptionOccurred += new EventHandler<EventArgs<Exception>>(Content_ExceptionOccurred);
    7469    }
    7570
     
    8075    protected override void OnContentChanged() {
    8176      base.OnContentChanged();
    82       logTextBox.Clear();
    8377      if (Content == null) {
    84         logTextBox.Enabled = false;
     78        logView.Content = null;
     79        logView.Enabled = false;
    8580        executionTimeTextBox.Text = "-";
    8681        executionTimeTextBox.Enabled = false;
    8782      } else {
    88         logTextBox.Enabled = true;
     83        logView.Content = Content.Log;
     84        logView.Enabled = true;
    8985        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    9086        executionTimeTextBox.Enabled = true;
     
    9288    }
    9389
    94     #region Content Events
    95     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     }
    10590    protected virtual void Content_ExecutionTimeChanged(object sender, EventArgs e) {
    10691      if (InvokeRequired)
     
    10994        executionTimeTextBox.Text = Content.ExecutionTime.ToString();
    11095    }
    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       else
    115         Log(Auxiliary.BuildErrorMessage(e.Value));
    116     }
    117     #endregion
    118 
    119     #region Helpers
    120     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     #endregion
    13396  }
    13497}
  • trunk/sources/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj

    r3281 r3289  
    8787  <ItemGroup>
    8888    <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>
    8995    <Compile Include="VariableValueView.cs">
    9096      <SubType>UserControl</SubType>
  • trunk/sources/HeuristicLab.Core/3.3/Engine.cs

    r3288 r3289  
    3030  public abstract class Engine : Executable, IEngine {
    3131    [Storable]
     32    protected ILog log;
     33    public ILog Log {
     34      get { return log; }
     35    }
     36
     37    [Storable]
    3238    private Stack<IOperation> executionStack;
    3339    protected Stack<IOperation> ExecutionStack {
     
    4147    protected Engine()
    4248      : base() {
     49      log = new Log();
    4350      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) {
    4459      pausePending = stopPending = false;
    4560      timer = new System.Timers.Timer(100);
     
    5166      if (ExecutionState == ExecutionState.Started) throw new InvalidOperationException(string.Format("Clone not allowed in execution state \"{0}\".", ExecutionState));
    5267      Engine clone = (Engine)base.Clone(cloner);
     68      clone.log = (ILog)cloner.Clone(log);
    5369      IOperation[] contexts = executionStack.ToArray();
    5470      for (int i = contexts.Length - 1; i >= 0; i--)
     
    7187      OnPrepared();
    7288    }
     89    protected override void OnPrepared() {
     90      Log.LogMessage("Engine prepared");
     91      base.OnPrepared();
     92    }
     93
    7394    public override void Start() {
    7495      base.Start();
    7596      ThreadPool.QueueUserWorkItem(new WaitCallback(Run), null);
    7697    }
     98    protected override void OnStarted() {
     99      Log.LogMessage("Engine started");
     100      base.OnStarted();
     101    }
     102
    77103    public override void Pause() {
    78104      base.Pause();
    79105      pausePending = true;
    80106    }
     107    protected override void OnPaused() {
     108      Log.LogMessage("Engine paused");
     109      base.OnPaused();
     110    }
     111
    81112    public override void Stop() {
    82113      base.Stop();
    83114      stopPending = true;
    84115      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);
    85125    }
    86126
  • trunk/sources/HeuristicLab.Core/3.3/Executable.cs

    r3262 r3289  
    5959      executionTime = TimeSpan.Zero;
    6060    }
     61    [StorableConstructor]
     62    protected Executable(bool deserializing) : base(deserializing) { }
    6163
    6264    public override IDeepCloneable Clone(Cloner cloner) {
  • trunk/sources/HeuristicLab.Core/3.3/HeuristicLab.Core-3.3.csproj

    r3262 r3289  
    103103    <Compile Include="Attributes\CreatableAttribute.cs" />
    104104    <None Include="HeuristicLabCorePlugin.cs.frame" />
     105    <Compile Include="Log.cs" />
    105106    <Compile Include="Executable.cs" />
    106107    <Compile Include="ExecutionState.cs" />
     108    <Compile Include="Interfaces\ILog.cs" />
    107109    <Compile Include="Interfaces\IExecutable.cs" />
    108110    <Compile Include="Interfaces\IParameterizedNamedItem.cs" />
  • trunk/sources/HeuristicLab.Core/3.3/Interfaces/IEngine.cs

    r3262 r3289  
    2020#endregion
    2121
    22 using System;
    23 using HeuristicLab.Common;
    24 
    2522namespace HeuristicLab.Core {
    2623  public interface IEngine : IExecutable {
     24    ILog Log { get; }
     25
    2726    void Prepare(IOperation initialOperation);
    2827  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Main.cs

    r3092 r3289  
    108108      string nl = Environment.NewLine;
    109109      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);
    111111
    112112      while (ex.InnerException != null) {
  • trunk/sources/HeuristicLab.PluginInfrastructure/Starter/StarterForm.cs

    r3113 r3289  
    192192    }
    193193    private static string BuildErrorMessage(Exception ex) {
     194      string nl = Environment.NewLine;
    194195      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);
    196197
    197198      while (ex.InnerException != null) {
    198199        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);
    200201      }
    201202      return sb.ToString();
  • trunk/sources/HeuristicLab.SequentialEngine/3.3/SequentialEngine.cs

    r3288 r3289  
    6262          Pause();
    6363        }
    64         if (operation.Operator.Breakpoint)
     64        if (operation.Operator.Breakpoint) {
     65          Log.LogMessage(string.Format("Breakpoint: {0} ({1})", operation.Operator.Name, operation.Operator.ItemName));
    6566          Pause();
     67        }
    6668      }
    6769    }
Note: See TracChangeset for help on using the changeset viewer.