Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6230


Ignore:
Timestamp:
05/17/11 18:56:06 (12 years ago)
Author:
ascheibe
Message:

#1233

  • don't set every view as default in slave ui
  • fixed bug in PluginCache where files got accessed by multiple threads
Location:
branches/HeuristicLab.Hive-3.4/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/AboutView.cs

    r6225 r6230  
    2828namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
    2929  [View("AboutView: Show some information about HeursticLab Hive")]
    30   [Content(typeof(Item), IsDefaultView = true)]
     30  [Content(typeof(Item), IsDefaultView = false)]
    3131  public partial class AboutView : ItemView {
    3232    public new Item Content {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave.Views/3.4/LogView.cs

    r6225 r6230  
    2929namespace HeuristicLab.Clients.Hive.SlaveCore.Views {
    3030  [View("LogView: Displays logged messages from the slave core.")]
    31   [Content(typeof(SlaveItem), IsDefaultView = true)]
     31  [Content(typeof(SlaveItem), IsDefaultView = false)]
    3232  public partial class LogView : ItemView {
    3333    public new SlaveItem Content {
  • branches/HeuristicLab.Hive-3.4/sources/HeuristicLab.Clients.Hive.Slave/3.4/PluginCache.cs

    r6178 r6230  
    2525using System.Linq;
    2626using System.Reflection;
    27 using System.Runtime.CompilerServices;
    2827using System.Runtime.Serialization;
    2928using System.Runtime.Serialization.Formatters.Binary;
     
    7473    private void DoUpdateRun() {
    7574      SafelyCreateDirectory(PluginCacheDir);
    76       foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
    77         cachedPluginsGuids.Add(Guid.Parse(GetFilenameFromPath(dir)));
    78       }
    79     }
    80 
    81     [MethodImpl(MethodImplOptions.Synchronized)]
     75      lock (cachedPluginsGuids) {
     76        cachedPluginsGuids.Clear();
     77        foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
     78          cachedPluginsGuids.Add(Guid.Parse(GetFilenameFromPath(dir)));
     79        }
     80      }
     81    }
     82
    8283    public void CopyPluginsForJob(List<Plugin> requests, Guid jobId, out string configFileName) {
    83       lock (locker) {
    84         configFileName = string.Empty;
    85         String targetDir = Path.Combine(PluginTempBaseDir, jobId.ToString());
    86 
    87         RecreateDirectory(targetDir);
    88 
    89         foreach (Plugin requestedPlugin in requests) {
    90           var filePaths = GetPluginFilePaths(requestedPlugin.Id);
    91           foreach (string filePath in filePaths) {
    92             File.Copy(filePath, Path.Combine(targetDir, Path.GetFileName(filePath)));
    93           }
    94 
    95           if (requestedPlugin.Name == "Configuration") {
    96             configFileName = Path.Combine(targetDir, Path.GetFileName(filePaths.SingleOrDefault())); // configuration plugin consists only of 1 file (usually the "HeuristicLab X.X.exe.config")
    97           }
    98         }
    99 
    100         // copy files from PluginInfrastructure (which are not declared in any plugins)
    101         string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
    102         CopyFile(baseDir, targetDir, "HeuristicLab.PluginInfrastructure-3.3.dll");
    103         CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib.dll");
    104         CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib License.txt");
    105 
    106         // copy slave plugins, otherwise its not possible to register the UnhandledException handler to the appdomain       
    107         CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive.SlaveCore-3.4.dll");
    108         CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive-3.4.dll");
    109         //CopyFile(baseDir, targetDir, "HeuristicLab.Services.Hive.Common-3.4.dll");
    110         CopyFile(baseDir, targetDir, "HeuristicLab.Hive-3.4.dll");
    111         CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Common-3.3.dll");
    112       }
     84      configFileName = string.Empty;
     85      String targetDir = Path.Combine(PluginTempBaseDir, jobId.ToString());
     86
     87      RecreateDirectory(targetDir);
     88
     89      foreach (Plugin requestedPlugin in requests) {
     90        var filePaths = GetPluginFilePaths(requestedPlugin.Id);
     91        foreach (string filePath in filePaths) {
     92          File.Copy(filePath, Path.Combine(targetDir, Path.GetFileName(filePath)));
     93        }
     94
     95        if (requestedPlugin.Name == "Configuration") {
     96          configFileName = Path.Combine(targetDir, Path.GetFileName(filePaths.SingleOrDefault())); // configuration plugin consists only of 1 file (usually the "HeuristicLab X.X.exe.config")
     97        }
     98      }
     99
     100      // copy files from PluginInfrastructure (which are not declared in any plugins)
     101      string baseDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
     102      CopyFile(baseDir, targetDir, "HeuristicLab.PluginInfrastructure-3.3.dll");
     103      CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib.dll");
     104      CopyFile(baseDir, targetDir, "ICSharpCode.SharpZipLib License.txt");
     105
     106      // copy slave plugins, otherwise its not possible to register the UnhandledException handler to the appdomain       
     107      CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive.SlaveCore-3.4.dll");
     108      CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Hive-3.4.dll");
     109      //CopyFile(baseDir, targetDir, "HeuristicLab.Services.Hive.Common-3.4.dll");
     110      CopyFile(baseDir, targetDir, "HeuristicLab.Hive-3.4.dll");
     111      CopyFile(baseDir, targetDir, "HeuristicLab.Clients.Common-3.3.dll");
     112
    113113    }
    114114
     
    150150        List<Guid> missingGuids = new List<Guid>();
    151151        List<Plugin> neededPlugins = new List<Plugin>();
    152         foreach (Guid pluginId in myJob.PluginsNeededIds) {
    153           Plugin plugin = WcfService.Instance.GetPlugin(pluginId);
    154           if (plugin != null) {
    155             neededPlugins.Add(plugin);
    156           }
    157 
    158           if (!cachedPluginsGuids.Contains(pluginId)) {
    159             missingGuids.Add(pluginId);
     152        lock (cachedPluginsGuids) {
     153          foreach (Guid pluginId in myJob.PluginsNeededIds) {
     154            Plugin plugin = WcfService.Instance.GetPlugin(pluginId);
     155            if (plugin != null) {
     156              neededPlugins.Add(plugin);
     157            }
     158
     159            if (!cachedPluginsGuids.Contains(pluginId)) {
     160              missingGuids.Add(pluginId);
     161            }
    160162          }
    161163        }
     
    172174          }
    173175
    174           DoUpdateRun();
     176          if (missingGuids.Count > 0) {
     177            DoUpdateRun();
     178          }
    175179          CopyPluginsForJob(neededPlugins, myJob.Id, out configFileName);
    176180        } else {
    177181          configFileName = "";
    178182        }
    179 
    180183        SlaveClientCom.Instance.ClientCom.LogMessage("Fetched " + missingGuids.Count + " plugins for job " + myJob.Id);
    181184      }
     
    203206    /// </summary>   
    204207    private void WriteDateLastUsed(string path) {
    205       FileStream fs = new FileStream(Path.Combine(path, lastUsedFileName), FileMode.Create);
    206       BinaryFormatter formatter = new BinaryFormatter();
    207 
     208      FileStream fs = null;
    208209      try {
     210        fs = new FileStream(Path.Combine(path, lastUsedFileName), FileMode.Create);
     211        BinaryFormatter formatter = new BinaryFormatter();
    209212        formatter.Serialize(fs, DateTime.Now);
     213      }
     214      catch (IOException) {
     215        SlaveClientCom.Instance.ClientCom.LogMessage(string.Format("No used date written in path {0}.", path));
    210216      }
    211217      catch (SerializationException) {
     
    214220      }
    215221      finally {
    216         fs.Close();
     222        if (fs != null) {
     223          fs.Close();
     224        }
    217225      }
    218226    }
     
    245253
    246254      if (Directory.Exists(PluginCacheDir)) {
    247         foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
    248           try {
    249             fs = new FileStream(Path.Combine(dir, lastUsedFileName), FileMode.Open);
    250             BinaryFormatter formatter = new BinaryFormatter();
    251             luDate = (DateTime)formatter.Deserialize(fs);
    252             fs.Close();
    253 
    254             if (luDate.AddDays(maxAge) < DateTime.Now) {
     255        lock (locker) {
     256          foreach (string dir in Directory.EnumerateDirectories(PluginCacheDir)) {
     257            try {
     258              fs = new FileStream(Path.Combine(dir, lastUsedFileName), FileMode.Open);
     259              BinaryFormatter formatter = new BinaryFormatter();
     260              luDate = (DateTime)formatter.Deserialize(fs);
     261              fs.Close();
     262
     263              if (luDate.AddDays(maxAge) < DateTime.Now) {
     264                Directory.Delete(dir, true);
     265                changed = true;
     266              }
     267            }
     268            catch (FileNotFoundException) {
     269              //nerver used
    255270              Directory.Delete(dir, true);
    256271              changed = true;
    257272            }
    258           }
    259           catch (SerializationException) {
    260             fs.Close();
    261             throw;
    262           }
    263           catch (System.IO.FileNotFoundException) {
    264             //nerver used
    265             Directory.Delete(dir, true);
    266             changed = true;
    267           }
    268           catch (Exception) {
    269             throw;
    270           }
    271         }
    272       }
    273       if (changed)
    274         DoUpdateRun();
    275     }
    276 
     273            catch (Exception ex) {
     274              if (fs != null) {
     275                fs.Close();
     276              }
     277              SlaveClientCom.Instance.ClientCom.LogMessage(string.Format("CleanPluginCache threw exception: {0}", ex.ToString()));
     278            }
     279          }
     280
     281          if (changed)
     282            DoUpdateRun();
     283        }
     284      }
     285    }
    277286
    278287    internal void DeletePluginsForJob(Guid id) {
     
    288297            Thread.Sleep(1000);
    289298            tries--;
    290             if (tries == 0) throw;// TODO: don't know what do do
     299            if (tries == 0) throw;// TODO: don't know what to do
    291300          }
    292301        }
Note: See TracChangeset for help on using the changeset viewer.