Free cookie consent management tool by TermsFeed Policy Generator

Changeset 242


Ignore:
Timestamp:
05/13/08 20:24:46 (17 years ago)
Author:
gkronber
Message:

added support for "service" applications that are restarted automatically when they crash with an exception. (related to #149)

Location:
trunk/sources
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationInfo.cs

    r2 r242  
    4646    }
    4747
     48    private bool autoRestart;
     49    public bool AutoRestart {
     50      get { return autoRestart; }
     51      set { autoRestart = value; }
     52    }
     53
    4854    private string pluginAssembly;
    4955    /// <summary>
    5056    /// Name of the assembly that contains the IApplication type.
    51     /// NEEDED?
    5257    /// </summary>
    5358    public string PluginAssembly {
     
    5964    /// <summary>
    6065    /// Name of the type that implements the interface IApplication.
    61     /// NEEDED?
    6266    /// </summary>
    6367    public string PluginType {
  • trunk/sources/HeuristicLab.PluginInfrastructure/BaseClasses/ApplicationBase.cs

    r8 r242  
    3030    private Version version;
    3131    private string description;
    32    
     32    private bool autoRestart;
     33
    3334    public ApplicationBase() {
    3435      ReadAttributes();
     
    4546      // after the assertion we are sure that the array access will not fail
    4647      ClassInfoAttribute pluginAttribute = (ClassInfoAttribute)pluginAttributes[0];
     48      if(pluginAttribute != null) {
     49        // if the plugin name is not explicitly set in the attribute then the default plugin name is the FullName of the type
     50        if(pluginAttribute.Name != null) {
     51          this.name = pluginAttribute.Name;
     52        } else {
     53          this.name = this.GetType().FullName;
     54        }
    4755
    48       // if the plugin name is not explicitly set in the attribute then the default plugin name is the FullName of the type
    49       if(pluginAttribute != null && pluginAttribute.Name != null) {
    50         this.name = pluginAttribute.Name;
    51       } else {
    52         this.name = this.GetType().FullName;
    53       }
     56        // if the version is not explicitly set in the attribute then the version of the assembly is used as default
     57        if(pluginAttribute.Version != null) {
     58          this.version = new Version(pluginAttribute.Version);
     59        } else {
     60          this.version = this.GetType().Assembly.GetName().Version;
     61        }
    5462
    55       // if the version is not explicitly set in the attribute then the version of the assembly is used as default
    56       if(pluginAttribute != null && pluginAttribute.Version != null) {
    57         this.version = new Version(pluginAttribute.Version);
    58       } else {
    59         this.version = this.GetType().Assembly.GetName().Version;
    60       }
     63        // if the description is not explicitly set in the attribute then the name of name of the application is used as default
     64        if(pluginAttribute.Description != null) {
     65          this.description = pluginAttribute.Description;
     66        } else {
     67          this.description = name;
     68        }
    6169
    62       // if the description is not explicitly set in the attribute then the name of name of the application is used as default
    63       if(pluginAttribute != null && pluginAttribute.Description != null) {
    64         this.description = pluginAttribute.Description;
    65       } else {
    66         this.description = name;
     70        this.autoRestart = pluginAttribute.AutoRestart;
    6771      }
    6872    }
     
    8387    }
    8488
    85     public abstract void Run() ;
     89    public bool AutoRestart {
     90      get { return autoRestart; }
     91    }
     92
     93    public abstract void Run();
    8694
    8795    #endregion
  • trunk/sources/HeuristicLab.PluginInfrastructure/ClassInfoAttribute.cs

    r91 r242  
    5252    }
    5353
     54    private bool autoRestart;
     55    public bool AutoRestart {
     56      get { return autoRestart; }
     57      set { autoRestart = value; }
     58    }
     59
    5460    public ClassInfoAttribute() {}
    5561  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Interfaces/IApplication.cs

    r2 r242  
    2929    Version Version { get; }
    3030    string Description { get;}
     31    bool AutoRestart { get; }
    3132    void Run();
    3233  }
  • trunk/sources/HeuristicLab.PluginInfrastructure/Loader.cs

    r91 r242  
    120120        info.Version = application.Version;
    121121        info.Description = application.Description;
     122        info.AutoRestart = application.AutoRestart;
    122123        info.PluginAssembly = application.GetType().Assembly.GetName().Name;
    123124        info.PluginType = application.GetType().Namespace + "." + application.GetType().Name;
  • trunk/sources/HeuristicLab/MainForm.cs

    r241 r242  
    9494          PluginManager.Manager.Action += new PluginManagerActionEventHandler(splashScreen.Manager_Action);
    9595          Thread t = new Thread(delegate() {
    96             try {
    97               PluginManager.Manager.Run(app);
    98             } catch(Exception ex) {
    99               ShowErrorMessageBox(ex);
    100             }
     96            bool stopped = false;
     97            do {
     98              try {
     99                PluginManager.Manager.Run(app);
     100                stopped = true;
     101              } catch(Exception ex) {
     102                stopped = false;
     103                ThreadPool.QueueUserWorkItem(delegate(object exception) { ShowErrorMessageBox((Exception)exception); }, ex);
     104                Thread.Sleep(5000); // sleep 5 seconds before autorestart
     105              }
     106            } while(!stopped && app.AutoRestart);
    101107          });
    102108          t.SetApartmentState(ApartmentState.STA); // needed for the AdvancedOptimizationFrontent
Note: See TracChangeset for help on using the changeset viewer.