Changeset 185 for trunk/CrypCore


Ignore:
Timestamp:
Jan 7, 2009, 12:16:54 AM (13 years ago)
Author:
Thomas Schmid
Message:
  • changed application startup: init window shows status while creating the GUI
Location:
trunk/CrypCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/CrypCore/Delegates.cs

    r4 r185  
    208208    public delegate void CrypCoreExceptionEventHandler(object sender, PluginManagerEventArgs args);
    209209    public delegate void CrypCoreDebugEventHandler(object sender, PluginManagerEventArgs args);
     210    public delegate void CrypCorePluginLoadedHandler(object sender, PluginLoadedEventArgs args);
    210211}
  • trunk/CrypCore/EventArgs.cs

    r4 r185  
    209209    {
    210210        public readonly Exception Exception;
    211         public readonly string Message;
    212211
    213212        public PluginManagerEventArgs(Exception exception)
     
    218217        public PluginManagerEventArgs(string message)
    219218        {
    220             this.Message = message;
     219           this.Exception = new Exception(message);
    221220        }
    222221    }
     222
     223    public class PluginLoadedEventArgs : EventArgs
     224    {
     225      public readonly int CurrentPluginNumber;
     226      public readonly int NumberPluginsFound;
     227      public readonly string AssemblyName;
     228
     229      public PluginLoadedEventArgs(int currentPluginNumber, int numberPluginsFound, string assemblyName)
     230      {
     231        this.CurrentPluginNumber = currentPluginNumber;
     232        this.NumberPluginsFound = numberPluginsFound;
     233        this.AssemblyName = assemblyName;
     234      }
     235    }
    223236}
  • trunk/CrypCore/PluginManager.cs

    r167 r185  
    215215    {
    216216        /// <summary>
     217        /// Counter for the dll files that were found
     218        /// </summary>
     219        private int availablePluginsApproximation = 0;
     220
     221        /// <summary>
    217222        /// Subdirectory to store plugins
    218223        /// </summary>
     
    228233        /// </summary>
    229234        public event CrypCoreDebugEventHandler OnDebugMessageOccured;
     235
     236        /// <summary>
     237        /// Occurs when a plugin was loaded
     238        /// </summary>
     239        public event CrypCorePluginLoadedHandler OnPluginLoaded;
    230240       
    231241        /// <summary>
     
    289299        /// <returns></returns>
    290300        public Dictionary<string, Type> LoadTypes(AssemblySigningRequirement state)
    291         {           
     301        {
    292302            if (Directory.Exists(globalPluginStore))
    293                 FindAssemblies(new DirectoryInfo(globalPluginStore), state, foundAssemblies);
    294 
    295             if (!Directory.Exists(customPluginStore))
    296                 Directory.CreateDirectory(customPluginStore);
    297 
    298             FindAssemblies(new DirectoryInfo(customPluginStore), state, foundAssemblies);
     303            {
     304              availablePluginsApproximation = AvailablePluginsApproximation(new DirectoryInfo(globalPluginStore));
     305              FindAssemblies(new DirectoryInfo(globalPluginStore), state, foundAssemblies);
     306            }
     307
     308            // custom plugin store is not supported yet
     309            //if (!Directory.Exists(customPluginStore))
     310            //    Directory.CreateDirectory(customPluginStore);
     311            //FindAssemblies(new DirectoryInfo(customPluginStore), state, foundAssemblies);
    299312            LoadTypes(foundAssemblies);
    300313            return this.loadedTypes;
     314        }
     315
     316        private int AvailablePluginsApproximation(DirectoryInfo directory)
     317        {
     318          int count = 0;
     319          foreach (DirectoryInfo subDirectory in directory.GetDirectories())
     320          {
     321            count = AvailablePluginsApproximation(subDirectory);
     322          }
     323          return directory.GetFiles("*.dll").Length;
    301324        }
    302325
     
    314337            }
    315338
     339            int currentPosition = 0;
    316340            foreach (FileInfo fileInfo in directory.GetFiles("*.dll"))
    317341            {
     342                currentPosition++;
    318343                try
    319344                {
    320345                    Assembly asm = Assembly.LoadFile(fileInfo.FullName);
     346                   
    321347                    string key = GetAssemblyKey(asm.FullName, state);
    322348                    if (key == null)
     
    337363
    338364                    if (sendMessage)
     365                    {
    339366                        SendDebugMessage("Loaded Assembly \"" + asm.FullName + "\" from file: " + fileInfo.FullName);
     367                        if (OnPluginLoaded != null)
     368                        {
     369                          OnPluginLoaded(this, new PluginLoadedEventArgs(currentPosition, this.availablePluginsApproximation, asm.GetName().Name + " Version=" + asm.GetName().Version.ToString()));
     370                        }                         
     371                    }
    340372                }
    341373                catch (Exception ex)
     
    366398                      this.loadedTypes.Add(type.FullName, type);
    367399                      if (!this.loadedAssemblies.ContainsKey(assemblyName.Name))
     400                      {
    368401                        this.loadedAssemblies.Add(assemblyName.Name, asm);
     402                      }
    369403                    }
    370404                  }
Note: See TracChangeset for help on using the changeset viewer.