Beispiel #1
0
        /// <summary>
        /// Scans the specified directories for components not already present in cache.
        /// </summary>
        /// <param name="directories">The directories.</param>
        /// <param name="workspaceTypeDirectories">The workspace type directories.</param>
        /// <param name="cachedFiles">Components already loaded in the cache.</param>
        /// <param name="results">.</param>
        /// <returns>
        /// True or False depending on the success of the scanning operation.
        /// </returns>
        public static bool Scan(IEnumerable <string> directories, IEnumerable <string> workspaceTypeDirectories,
                                ISet <string> cachedFiles, ComponentScanResults results)
        {
            bool success = true;

            AppDomain newDomain = null;

            try
            {
                var libraryHelper = new LibraryHelper(workspaceTypeDirectories);

                newDomain = libraryHelper.CreateDomain("ComponentScanner", false);
                newDomain.Load(Assembly.GetExecutingAssembly().GetName());

                // Preload the workspace types so that the component scanner won't barf when a component references a workspace type.
                libraryHelper.PreloadWorkspaceTypes(newDomain);

                ComponentScanner scanner = (ComponentScanner)newDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(ComponentScanner).FullName, false, BindingFlags.Instance | BindingFlags.NonPublic, null, null, null, null);

                if (!RuntimeInfo.IsRunInMono)
                {
                    scanner.Scan(directories, cachedFiles);
                }
                else
                {
                    scanner.Scan(directories, new List <string>(cachedFiles));
                }

                results.NewFilesLoaded = new List <FileDescriptor>(scanner.NewFilesLoaded);
                results.RequestedFiles = new List <string>(scanner.FilesToGetFromCache);

                results.Errors = new List <string>(scanner.Errors);
            }
            catch (Exception e)
            {
                success = false;

                results.NewFilesLoaded      = new List <FileDescriptor>();
                results.RequestedFiles      = new List <string>();
                results.OldGuidToNewGuidMap = new Dictionary <string, string>();

                results.Errors = results.Errors ?? new List <string>();
                results.Errors.Add(e.Message);
            }
            finally
            {
                if (newDomain != null)
                {
#if !MONO_DEV
                    //appdomain unload crashes mono.exe process when running directly from
                    //Mono Develop, possibly because attached debugger. When run normally works fine.
                    //use MONO_DEV compiler symbol when developing
                    AppDomain.Unload(newDomain);
#endif
                }
            }

            return(success);
        }
Beispiel #2
0
 /// <summary>
 /// Processes the ComponentScanResults by extracting the new files read during scanning and
 /// by adding the requested MetadataDefinition to the results.
 /// </summary>
 /// <param name="results">The results from scanning.</param>
 public void ProcessComponentScanResults(ComponentScanResults results)
 {
     foreach (string filePath in results.RequestedFiles)
     {
         try
         {
             FileDescriptor file = this.m_componentFiles[filePath];
             if (file is AssemblyFileDescriptor)
             {
                 AssemblyFileDescriptor assembly = (AssemblyFileDescriptor)file;
                 foreach (ComponentMetadataDefinition metadata in assembly.MetadataCollection)
                 {
                     if (!results.Components.Contains(metadata.ID))
                     {
                         results.Components.Add(metadata);
                         string GuidID;
                         if (assembly.NewGuidToOldGuid.TryGetValue(metadata.ID, out GuidID))
                         {
                             results.OldGuidToNewGuidMap.Add(GuidID, metadata.ID);
                         }
                     }
                     else
                     {
                         MetadataDefinition oldMetadata = results.Components[metadata.ID];
                         string             msg         = String.Format(Messages.SameComponents, oldMetadata.Classname, oldMetadata.Assembly,
                                                                        metadata.Classname, metadata.Assembly);
                         NLog.LogManager.GetCurrentClassLogger().Warn(msg);
                         results.Errors.Add(msg);
                     }
                 }
             }
             else if (file is CompositeComponentFileDescriptor)
             {
                 CompositeComponentFileDescriptor component = (CompositeComponentFileDescriptor)file;
                 if (!results.CompositeComponents.Contains(component.MetadataDefinition.ID))
                 {
                     results.CompositeComponents.Add(component.MetadataDefinition);
                 }
                 else
                 {
                     MetadataDefinition oldMetadata = results.CompositeComponents[component.MetadataDefinition.ID];
                     string             msg         = String.Format(Messages.SameComponents, oldMetadata.Classname, oldMetadata.Assembly,
                                                                    component.MetadataDefinition.Classname, component.MetadataDefinition.Assembly);
                     NLog.LogManager.GetCurrentClassLogger().Warn(msg);
                     results.Errors.Add(msg);
                 }
             }
         }
         catch (KeyNotFoundException)
         {
         }
     }
 }
Beispiel #3
0
        /// <summary>
        /// Scans the specified directories for components not already present in cache.
        /// </summary>
        /// <param name="directories">The directories.</param>
        /// <param name="workspaceTypeDirectories">The workspace type directories.</param>
        /// <param name="cachedFiles">Components already loaded in the cache.</param>
        /// <param name="results">.</param>
        /// <returns>
        /// True or False depending on the success of the scanning operation.
        /// </returns>
        public static bool Scan(IEnumerable<string> directories, IEnumerable<string> workspaceTypeDirectories,
            ISet<string> cachedFiles, ComponentScanResults results)
        {
            bool success = true;

            AppDomain newDomain = null;

            try
            {
                var libraryHelper = new LibraryHelper(workspaceTypeDirectories);

                newDomain = libraryHelper.CreateDomain("ComponentScanner", false);
                newDomain.Load(Assembly.GetExecutingAssembly().GetName());

                // Preload the workspace types so that the component scanner won't barf when a component references a workspace type.
                libraryHelper.PreloadWorkspaceTypes(newDomain);

                ComponentScanner scanner = (ComponentScanner)newDomain.CreateInstanceAndUnwrap(Assembly.GetExecutingAssembly().FullName, typeof(ComponentScanner).FullName, false, BindingFlags.Instance | BindingFlags.NonPublic, null, null, null, null);

                if (!RuntimeInfo.IsRunInMono)
                {
                    scanner.Scan(directories, cachedFiles);
                }
                else
                {
                    scanner.Scan(directories, new List<string>(cachedFiles));
                }

                results.NewFilesLoaded = new List<FileDescriptor>(scanner.NewFilesLoaded);
                results.RequestedFiles = new List<string>(scanner.FilesToGetFromCache);

                results.Errors = new List<string>(scanner.Errors);
            }
            catch (Exception e)
            {
                success = false;

                results.NewFilesLoaded = new List<FileDescriptor>();
                results.RequestedFiles = new List<string>();
                results.OldGuidToNewGuidMap = new Dictionary<string, string>();

                results.Errors = results.Errors ?? new List<string>();
                results.Errors.Add(e.Message);
            }
            finally
            {
                if (newDomain != null)
                {
#if !MONO_DEV
                    //appdomain unload crashes mono.exe process when running directly from 
                    //Mono Develop, possibly because attached debugger. When run normally works fine.
                    //use MONO_DEV compiler symbol when developing
                    AppDomain.Unload(newDomain);
#endif
                }
            }

            return success;
        }