Changeset 2688


Ignore:
Timestamp:
01/27/10 11:11:52 (10 years ago)
Author:
gkronber
Message:

Implemented an enumerable to iterate through all PluginFiles as suggested by swagner, replaced the Assemblies enumerable with an AssemblyName enumerable for internal usage in the plugin infrastructure and replaced Assembly.LoadFrom calls with Assembly.Load() to prevent loading from GAC as far as possible.

#850 (PluginInfrastructure should provide a way to get assemblies associated with a plug-in)

Location:
trunk/sources
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Server.Core/3.2/ClientCommunicator.cs

    r2608 r2688  
    111111              clientAdapter.Update(client);
    112112              HiveLogger.Info(this.ToString() + ": Client " + client.Id + " wasn't offline but hasn't sent heartbeats - Resetting all his jobs");
    113               foreach (Job job in jobAdapter.GetActiveJobsOf(client)) {               
     113              foreach (Job job in jobAdapter.GetActiveJobsOf(client)) {
    114114                jobManager.ResetJobsDependingOnResults(job);
    115115              }
     
    241241    /// <returns></returns>
    242242    public ResponseHB ProcessHeartBeat(HeartBeatData hbData) {
    243      
     243
    244244      ISession session = factory.GetSessionForCurrentThread();
    245245      ITransaction tx = null;
     
    252252          session.GetDataAdapter<ClientInfo, IClientAdapter>();
    253253
    254         IJobAdapter jobAdapter =       
     254        IJobAdapter jobAdapter =
    255255          session.GetDataAdapter<Job, IJobAdapter>();
    256256        HiveLogger.Info(this.ToString() + ": END Fetched Adapters");
     
    268268        if (client.State == State.offline || client.State == State.nullState) {
    269269          response.Success = false;
    270           response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN;         
     270          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN;
    271271          response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage));
    272272
     
    305305        processJobProcess(hbData, jobAdapter, clientAdapter, response);
    306306        HiveLogger.Info(this.ToString() + ": END Processed Heartbeat Jobs");
    307        
     307
    308308        clientAdapter.Update(client);
    309309
     
    331331    /// <param name="response"></param>
    332332    private void processJobProcess(HeartBeatData hbData, IJobAdapter jobAdapter, IClientAdapter clientAdapter, ResponseHB response) {
    333       HiveLogger.Info(this.ToString() + " processJobProcess: Started for Client " + hbData.ClientId);     
    334      
     333      HiveLogger.Info(this.ToString() + " processJobProcess: Started for Client " + hbData.ClientId);
     334
    335335      if (hbData.JobProgress != null && hbData.JobProgress.Count > 0) {
    336336        List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId)));
     
    338338          response.Success = false;
    339339          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
    340           HiveLogger.Error(this.ToString() + " processJobProcess: There is no job calculated by this user " + hbData.ClientId);     
     340          HiveLogger.Error(this.ToString() + " processJobProcess: There is no job calculated by this user " + hbData.ClientId);
    341341          return;
    342342        }
     
    347347            response.Success = false;
    348348            response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
    349             HiveLogger.Error(this.ToString() + " processJobProcess: There is no job calculated by this user " + hbData.ClientId + " Job: " + curJob);     
     349            HiveLogger.Error(this.ToString() + " processJobProcess: There is no job calculated by this user " + hbData.ClientId + " Job: " + curJob);
    350350          } else if (curJob.State == State.abort) {
    351351            // a request to abort the job has been set
     
    376376              if (newAssignedJobs.ContainsKey(currJob.Id)) {
    377377                newAssignedJobs[currJob.Id]--;
    378                 HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL Reduced by one for job: " + currJob + "and is now: " + newAssignedJobs[currJob.Id] + ". User that sucks: " + currJob.Client);                     
     378                HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL Reduced by one for job: " + currJob + "and is now: " + newAssignedJobs[currJob.Id] + ". User that sucks: " + currJob.Client);
    379379                if (newAssignedJobs[currJob.Id] <= 0) {
    380                   HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL reached Zero, Job gets removed: " + currJob + " and set back to offline. User that sucks: " + currJob.Client);                 
     380                  HiveLogger.Error(this.ToString() + " processJobProcess: Job TTL reached Zero, Job gets removed: " + currJob + " and set back to offline. User that sucks: " + currJob.Client);
    381381
    382382                  currJob.State = State.offline;
     
    388388                }
    389389              } else {
    390                 HiveLogger.Error(this.ToString() + " processJobProcess: Job ID wasn't with the heartbeats:  " + currJob);                     
     390                HiveLogger.Error(this.ToString() + " processJobProcess: Job ID wasn't with the heartbeats:  " + currJob);
    391391                currJob.State = State.offline;
    392392                jobAdapter.Update(currJob);
     
    397397
    398398              if (newAssignedJobs.ContainsKey(currJob.Id)) {
    399                 HiveLogger.Info(this.ToString() + " processJobProcess: Job is sending a heart beat, removing it from the newAssignedJobList: " + currJob);                     
     399                HiveLogger.Info(this.ToString() + " processJobProcess: Job is sending a heart beat, removing it from the newAssignedJobList: " + currJob);
    400400                newAssignedJobs.Remove(currJob.Id);
    401401              }
     
    431431          response.Job = computableJob;
    432432          response.Success = true;
    433           HiveLogger.Info(this.ToString() + " SendSerializedJob: Job pulled: " + computableJob.JobInfo + " for user " + clientId);                     
     433          HiveLogger.Info(this.ToString() + " SendSerializedJob: Job pulled: " + computableJob.JobInfo + " for user " + clientId);
    434434          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
    435435          lock (newAssignedJobs) {
     
    438438          }
    439439        } else {
    440           HiveLogger.Info(this.ToString() + " SendSerializedJob: No more Jobs left for " + clientId);                     
     440          HiveLogger.Info(this.ToString() + " SendSerializedJob: No more Jobs left for " + clientId);
    441441          response.Success = false;
    442442          response.Job = null;
     
    481481          response.Job = job2Calculate;
    482482          response.Success = true;
    483           HiveLogger.Info(this.ToString() + " SendSerializedJob: Job pulled: " + job2Calculate + " for user " + clientId);                     
     483          HiveLogger.Info(this.ToString() + " SendSerializedJob: Job pulled: " + job2Calculate + " for user " + clientId);
    484484          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_PULLED;
    485485          lock (newAssignedJobs) {
     
    491491          response.Job = null;
    492492          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOBS_LEFT;
    493           HiveLogger.Info(this.ToString() + " SendSerializedJob: No more Jobs left for " + clientId);                     
     493          HiveLogger.Info(this.ToString() + " SendSerializedJob: No more Jobs left for " + clientId);
    494494        }
    495495
     
    514514
    515515      HiveLogger.Info(this.ToString() + " ProcessJobResult: BEGIN Job received for Storage - main method:");
    516      
     516
    517517      ISession session = factory.GetSessionForCurrentThread();
    518518      ITransaction tx = null;
     
    594594      Exception exception,
    595595      bool finished) {
    596      
     596
    597597      HiveLogger.Info(this.ToString() + " ProcessJobResult: BEGIN Job received for Storage - SUB method: " + jobId);
    598598
    599599      ISession session = factory.GetSessionForCurrentThread();
    600            
     600
    601601      ITransaction tx = null;
    602602
     
    608608        IJobResultsAdapter jobResultAdapter =
    609609          session.GetDataAdapter<JobResult, IJobResultsAdapter>();
    610        
     610
    611611        //should fetch the existing transaction       
    612612        tx = session.BeginTransaction();
     
    628628          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_NO_JOB_WITH_THIS_ID;
    629629          response.JobId = jobId;
    630          
    631           HiveLogger.Error(this.ToString() + " ProcessJobResult: No job with Id " + jobId);                     
    632          
     630
     631          HiveLogger.Error(this.ToString() + " ProcessJobResult: No job with Id " + jobId);
     632
    633633          tx.Rollback();
    634634          return response;
     
    637637          response.Success = false;
    638638          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_WAS_ABORTED;
    639          
    640           HiveLogger.Error(this.ToString() + " ProcessJobResult: Job was aborted! " + job.JobInfo);                     
    641          
     639
     640          HiveLogger.Error(this.ToString() + " ProcessJobResult: Job was aborted! " + job.JobInfo);
     641
    642642          tx.Rollback();
    643643          return response;
     
    648648          response.JobId = jobId;
    649649
    650           HiveLogger.Error(this.ToString() + " ProcessJobResult: Job is not being calculated (client = null)! " + job.JobInfo);                     
     650          HiveLogger.Error(this.ToString() + " ProcessJobResult: Job is not being calculated (client = null)! " + job.JobInfo);
    651651
    652652          tx.Rollback();
     
    658658          response.JobId = jobId;
    659659
    660           HiveLogger.Error(this.ToString() + " ProcessJobResult: Wrong Client for this Job! " + job.JobInfo + ", Sending Client is: " + clientId);                     
     660          HiveLogger.Error(this.ToString() + " ProcessJobResult: Wrong Client for this Job! " + job.JobInfo + ", Sending Client is: " + clientId);
    661661
    662662          tx.Rollback();
     
    668668          response.JobId = jobId;
    669669
    670           HiveLogger.Error(this.ToString() + " ProcessJobResult: Job already finished! " + job.JobInfo + ", Sending Client is: " + clientId);                     
     670          HiveLogger.Error(this.ToString() + " ProcessJobResult: Job already finished! " + job.JobInfo + ", Sending Client is: " + clientId);
    671671
    672672          tx.Rollback();
     
    682682          response.JobId = jobId;
    683683
    684           HiveLogger.Error(this.ToString() + " ProcessJobResult: Wrong Job State, job is: " + job.JobInfo);                     
     684          HiveLogger.Error(this.ToString() + " ProcessJobResult: Wrong Job State, job is: " + job.JobInfo);
    685685
    686686          tx.Rollback();
     
    720720        response.finished = finished;
    721721        response.JobResultId = jobResult.Id;
    722        
     722
    723723        //Removed for Testing
    724724        //tx.Commit();
    725         HiveLogger.Info(this.ToString() + " ProcessJobResult: END Job received for Storage - SUB method: " + jobId);       
     725        HiveLogger.Info(this.ToString() + " ProcessJobResult: END Job received for Storage - SUB method: " + jobId);
    726726        return response;
    727727      }
     
    772772
    773773      HiveLogger.Info("Client logged out " + clientId);
    774      
     774
    775775      ISession session = factory.GetSessionForCurrentThread();
    776776      ITransaction tx = null;
     
    892892            };
    893893
    894             foreach (String assemblyPath in currPlugin.Files) {
    895               currCachedPlugin.PluginFiles.Add(File.ReadAllBytes(assemblyPath));
     894            foreach (string fileName in from file in currPlugin.Files select file.Name) {
     895              currCachedPlugin.PluginFiles.Add(File.ReadAllBytes(fileName));
    896896            }
    897897            response.Plugins.Add(currCachedPlugin);
  • trunk/sources/HeuristicLab.Operators.Programmable/3.2/ProgrammableOperator.cs

    r2681 r2688  
    167167      foreach (var plugin in ApplicationManager.Manager.Plugins) {
    168168        var aList = new List<Assembly>();
    169         foreach (var aName in plugin.Assemblies) {
     169        foreach (var aName in from file in plugin.Files
     170                              where file.Type == PluginFileType.Assembly
     171                              select file.Name) {
    170172          Assembly a;
    171173          locationTable.TryGetValue(aName, out a);
     
    198200            assemblies.Add(a, false);
    199201          }
    200         } catch (NotSupportedException) {
     202        }
     203        catch (NotSupportedException) {
    201204          // NotSupportedException is thrown while accessing
    202205          // the Location property of the anonymously hosted
  • trunk/sources/HeuristicLab.PluginInfrastructure/Advanced/InstallationManager.cs

    r2612 r2688  
    2828using System.ComponentModel;
    2929using HeuristicLab.PluginInfrastructure.UpdateLocationReference;
     30using System.Reflection;
    3031
    3132namespace HeuristicLab.PluginInfrastructure.Advanced {
     
    6768      builder.Append("Build date: ").AppendLine(desc.BuildDate.ToString());
    6869      builder.AppendLine("Files: ");
    69       foreach (string fileName in desc.Files) {
     70      foreach (string fileName in from file in desc.Files select file.Name) {
    7071        builder.AppendLine(fileName);
    7172      }
     
    9596      StringBuilder builder = new StringBuilder();
    9697      var missingFiles = from x in desc.Files
    97                          where !File.Exists(x)
    98                          select x;
     98                         where !File.Exists(x.Name)
     99                         select x.Name;
    99100      if (missingFiles.Count() > 0) {
    100         foreach (string fileName in desc.Files) {
     101        foreach (string fileName in from file in desc.Files select file.Name) {
    101102          if (!File.Exists(fileName)) builder.Append("Missing file: ").AppendLine(fileName);
    102103        }
     
    126127            // or there was a problem loading the assemblies
    127128            builder.AppendLine("There was a problem while loading assemblies: ");
    128             foreach (string assembly in desc.Assemblies) {
    129               builder.AppendLine(assembly);
     129            foreach (AssemblyName assembly in desc.AssemblyNames) {
     130              builder.AppendLine(assembly.FullName);
    130131            }
    131132            return builder.ToString();
     
    196197    public void Remove(IEnumerable<string> pluginNames) {
    197198      var fileNames = from pluginToDelete in PluginDescriptionIterator.IterateDependentsTopDown(GetPluginDescriptions(pluginNames), pluginManager.Plugins)
    198                       from fileName in pluginToDelete.Files
    199                       select Path.Combine(pluginDir, fileName);
     199                      from file in pluginToDelete.Files
     200                      select Path.Combine(pluginDir, file.Name);
    200201      var args = new PluginInfrastructureCancelEventArgs("Deleting", fileNames);
    201202      OnPreDelete(args);
  • trunk/sources/HeuristicLab.PluginInfrastructure/ApplicationManager.cs

    r2686 r2688  
    103103      // load all loadable plugins (all dependencies available) into the execution context
    104104      foreach (var desc in PluginDescriptionIterator.IterateDependenciesBottomUp(plugins.Where(x => x.PluginState != PluginState.Disabled))) {
    105         foreach (string assembly in desc.Assemblies) {
    106           var asm = Assembly.LoadFrom(assembly);
     105        foreach (AssemblyName assemblyName in desc.AssemblyNames) {
     106          var asm = Assembly.Load(assemblyName);
    107107
    108108          // instantiate and load all plugins in this assembly
     
    213213      PluginDescription pluginDesc = (PluginDescription)pluginDescription;
    214214      return from asm in AppDomain.CurrentDomain.GetAssemblies()
    215              where !string.IsNullOrEmpty(asm.Location) &&
    216                    pluginDesc.Assemblies.Any(asmPath =>
    217                      Path.GetFullPath(asmPath).Equals(Path.GetFullPath(asm.Location),
    218                                                       StringComparison.CurrentCultureIgnoreCase))
     215             where pluginDesc.AssemblyNames.Any(asmName => asmName.FullName.Equals(asm.GetName().FullName))
    219216             from t in GetTypes(type, asm, onlyInstantiable)
    220217             select t;
     
    286283    public IPluginDescription GetDeclaringPlugin(Type type) {
    287284      foreach (PluginDescription info in Plugins) {
    288         if (info.Assemblies.Contains(Path.GetFullPath(type.Assembly.Location))) return info;
     285        if (info.AssemblyNames.Contains(type.Assembly.GetName())) return info;
    289286      }
    290287      return null;
  • trunk/sources/HeuristicLab.PluginInfrastructure/HeuristicLab.PluginInfrastructure.csproj

    r2600 r2688  
    101101    <Compile Include="BaseClasses\ApplicationBase.cs" />
    102102    <Compile Include="BaseClasses\PluginBase.cs" />
     103    <Compile Include="Interfaces\IPluginFile.cs" />
    103104    <Compile Include="Interfaces\IApplicationManager.cs" />
    104105    <Compile Include="Interfaces\IApplicationDescription.cs" />
     
    110111    <Compile Include="InvalidPluginException.cs" />
    111112    <Compile Include="Manager\ApplicationDescription.cs" />
     113    <Compile Include="Manager\PluginFile.cs" />
    112114    <Compile Include="Manager\PluginInfrastructureCancelEventArgs.cs" />
    113115    <Compile Include="Manager\PluginDescription.cs" />
  • trunk/sources/HeuristicLab.PluginInfrastructure/Interfaces/IPluginDescription.cs

    r2666 r2688  
    4747    /// Gets the file names of files that are part of the plugin.
    4848    /// </summary>
    49     IEnumerable<string> Files { get; }
    50 
    51     /// <summary>
    52     /// Get a list of assembly names associated with the plugin.
    53     /// </summary>
    54     IEnumerable<string> Assemblies { get; }
     49    IEnumerable<IPluginFile> Files { get; }
    5550  }
    5651}
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginDescription.cs

    r2666 r2688  
    2424using System.Text;
    2525using System.Linq;
     26using System.Reflection;
    2627
    2728namespace HeuristicLab.PluginInfrastructure.Manager {
     
    7778
    7879
    79     private List<string> files = new List<string>();
     80    private List<PluginFile> files = new List<PluginFile>();
    8081    /// <summary>
    8182    /// Gets the names of all files that belong to this plugin.
    8283    /// These files are deleted when the plugin is removed or updated.
    8384    /// </summary>
    84     public IEnumerable<string> Files {
    85       get { return files; }
     85    public IEnumerable<IPluginFile> Files {
     86      get { return files.Cast<IPluginFile>(); }
    8687    }
    8788
    88     internal void AddFiles(IEnumerable<string> fileNames) {
     89    internal void AddFiles(IEnumerable<PluginFile> fileNames) {
    8990      files.AddRange(fileNames);
    9091    }
     
    105106    }
    106107
    107     private List<string> assemblies = new List<string>();
     108    private List<AssemblyName> assemblyNames = new List<AssemblyName>();
    108109    /// <summary>
    109110    /// Gets the names of the assemblies that belong to this plugin.
    110111    /// </summary>
    111     public IEnumerable<string> Assemblies {
    112       get { return assemblies; }
    113       // set { assemblies = value; }
     112    public IEnumerable<AssemblyName> AssemblyNames {
     113      get { return assemblyNames; }
    114114    }
    115115
    116     internal void AddAssemblies(IEnumerable<string> assemblyNames) {
    117       assemblies.AddRange(assemblyNames);
     116    internal void AddAssemblyNames(IEnumerable<AssemblyName> assemblyNames) {
     117      this.assemblyNames.AddRange(assemblyNames);
    118118    }
    119119
  • trunk/sources/HeuristicLab.PluginInfrastructure/Manager/PluginValidator.cs

    r2648 r2688  
    172172      foreach (var desc in pluginDescriptions.Where(x => x.PluginState != PluginState.Disabled)) {
    173173        try {
    174           foreach (var asm in desc.Assemblies) {
    175             Assembly.ReflectionOnlyLoadFrom(asm);
     174          foreach (var asmName in desc.AssemblyNames) {
     175            Assembly.ReflectionOnlyLoad(asmName.FullName);
    176176          }
    177177        }
     
    237237      // get all attributes of that type
    238238      IList<CustomAttributeData> attributes = CustomAttributeData.GetCustomAttributes(pluginType);
    239       List<string> pluginAssemblies = new List<string>();
     239      List<AssemblyName> pluginAssemblyNames = new List<AssemblyName>();
    240240      List<string> pluginDependencies = new List<string>();
    241       List<string> pluginFiles = new List<string>();
     241      List<PluginFile> pluginFiles = new List<PluginFile>();
    242242      string pluginName = null;
    243243      string pluginDescription = null;
     
    254254          string pluginFileName = (string)attributeData.ConstructorArguments[0].Value;
    255255          PluginFileType fileType = (PluginFileType)attributeData.ConstructorArguments[1].Value;
    256           pluginFiles.Add(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)));
     256          pluginFiles.Add(new PluginFile(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)), fileType));
    257257          if (fileType == PluginFileType.Assembly) {
    258             pluginAssemblies.Add(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName)));
     258            pluginAssemblyNames.Add(AssemblyName.GetAssemblyName(Path.GetFullPath(Path.Combine(PluginDir, pluginFileName))));
    259259          }
    260260        }
     
    268268      if (!string.IsNullOrEmpty(pluginName) &&
    269269          pluginFiles.Count > 0 &&
    270           pluginAssemblies.Count > 0 &&
     270          pluginAssemblyNames.Count > 0 &&
    271271          buildDates.Count() == 1) {
    272272        // create a temporary PluginDescription that contains the attribute values
     
    276276        info.Version = pluginType.Assembly.GetName().Version;
    277277        info.BuildDate = DateTime.Parse(buildDates.Single(), System.Globalization.CultureInfo.InvariantCulture);
    278         info.AddAssemblies(pluginAssemblies);
     278        info.AddAssemblyNames(pluginAssemblyNames);
    279279        info.AddFiles(pluginFiles);
    280280
     
    349349                                                                                .Where(x => x.PluginState != PluginState.Disabled))) {
    350350        List<Type> types = new List<Type>();
    351         foreach (string assembly in desc.Assemblies) {
    352           var asm = Assembly.LoadFrom(assembly);
     351        foreach (AssemblyName assemblyName in desc.AssemblyNames) {
     352          var asm = Assembly.Load(assemblyName);
    353353          foreach (Type t in asm.GetTypes()) {
    354354            if (typeof(IPlugin).IsAssignableFrom(t)) {
     
    379379
    380380    private bool CheckPluginFiles(PluginDescription pluginDescription) {
    381       foreach (string filename in pluginDescription.Files) {
     381      foreach (string filename in pluginDescription.Files.Select(x => x.Name)) {
    382382        if (!FileLiesInDirectory(PluginDir, filename) ||
    383383          !File.Exists(filename)) {
Note: See TracChangeset for help on using the changeset viewer.