@@ -551,22 +551,8 @@ bool ScanAssembly (IProgressStatus monitor, string filePath, AddinScanResult sca
551
551
552
552
// Get the config file from the resources, if there is one
553
553
554
- foreach ( string res in reflector . GetResourceNames ( asm ) ) {
555
- if ( res . EndsWith ( ".addin" ) || res . EndsWith ( ".addin.xml" ) ) {
556
- using ( Stream s = reflector . GetResourceStream ( asm , res ) ) {
557
- AddinDescription ad = AddinDescription . Read ( s , Path . GetDirectoryName ( filePath ) ) ;
558
- if ( config != null ) {
559
- if ( ! config . IsExtensionModel && ! ad . IsExtensionModel ) {
560
- // There is more than one add-in definition
561
- monitor . ReportError ( "Duplicate add-in definition found in assembly: " + filePath , null ) ;
562
- return false ;
563
- }
564
- config = AddinDescription . Merge ( config , ad ) ;
565
- } else
566
- config = ad ;
567
- }
568
- }
569
- }
554
+ if ( ! ScanEmbeddedDescription ( monitor , filePath , reflector , asm , out config ) )
555
+ return false ;
570
556
571
557
if ( config == null || config . IsExtensionModel ) {
572
558
// In this case, only scan the assembly if it has the Addin attribute.
@@ -596,6 +582,29 @@ bool ScanAssembly (IProgressStatus monitor, string filePath, AddinScanResult sca
596
582
}
597
583
}
598
584
585
+ static bool ScanEmbeddedDescription ( IProgressStatus monitor , string filePath , IAssemblyReflector reflector , object asm , out AddinDescription config )
586
+ {
587
+ config = null ;
588
+ foreach ( string res in reflector . GetResourceNames ( asm ) ) {
589
+ if ( res . EndsWith ( ".addin" ) || res . EndsWith ( ".addin.xml" ) ) {
590
+ using ( Stream s = reflector . GetResourceStream ( asm , res ) ) {
591
+ AddinDescription ad = AddinDescription . Read ( s , Path . GetDirectoryName ( filePath ) ) ;
592
+ if ( config != null ) {
593
+ if ( ! config . IsExtensionModel && ! ad . IsExtensionModel ) {
594
+ // There is more than one add-in definition
595
+ monitor . ReportError ( "Duplicate add-in definition found in assembly: " + filePath , null ) ;
596
+ return false ;
597
+ }
598
+ config = AddinDescription . Merge ( config , ad ) ;
599
+ }
600
+ else
601
+ config = ad ;
602
+ }
603
+ }
604
+ }
605
+ return true ;
606
+ }
607
+
599
608
bool ScanDescription ( IProgressStatus monitor , IAssemblyReflector reflector , AddinDescription config , object rootAssembly , AddinScanResult scanResult )
600
609
{
601
610
// First of all scan the main module
@@ -669,14 +678,14 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
669
678
if ( ! config . IsRoot ) {
670
679
foreach ( ModuleDescription mod in config . OptionalModules ) {
671
680
try {
672
- assemblies . Clear ( ) ;
681
+ var asmList = new List < Tuple < string , object > > ( ) ;
673
682
for ( int n = 0 ; n < mod . Assemblies . Count ; n ++ ) {
674
683
string s = mod . Assemblies [ n ] ;
675
684
if ( mod . IgnorePaths . Contains ( s ) )
676
685
continue ;
677
686
string asmFile = Path . Combine ( config . BasePath , s ) ;
678
687
object asm = reflector . LoadAssembly ( asmFile ) ;
679
- assemblies . Add ( asm ) ;
688
+ asmList . Add ( new Tuple < string , object > ( asmFile , asm ) ) ;
680
689
scanResult . AddPathToIgnore ( Path . GetFullPath ( asmFile ) ) ;
681
690
ScanAssemblyImports ( reflector , mod , asm ) ;
682
691
}
@@ -691,9 +700,9 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
691
700
scanResult . AddPathToIgnore ( Path . GetFullPath ( path ) ) ;
692
701
}
693
702
694
- foreach ( object asm in assemblies )
695
- ScanAssemblyContents ( reflector , config , mod , asm , scanResult ) ;
696
-
703
+ foreach ( var asm in asmList )
704
+ ScanSubmodule ( monitor , mod , reflector , config , scanResult , asm . Item1 , asm . Item2 ) ;
705
+
697
706
} catch ( Exception ex ) {
698
707
ReportReflectionException ( monitor , ex , config , scanResult ) ;
699
708
}
@@ -704,6 +713,37 @@ bool ScanDescription (IProgressStatus monitor, IAssemblyReflector reflector, Add
704
713
return true ;
705
714
}
706
715
716
+ bool ScanSubmodule ( IProgressStatus monitor , ModuleDescription mod , IAssemblyReflector reflector , AddinDescription config , AddinScanResult scanResult , string assemblyName , object asm )
717
+ {
718
+ AddinDescription mconfig ;
719
+ ScanEmbeddedDescription ( monitor , assemblyName , reflector , asm , out mconfig ) ;
720
+ if ( mconfig != null ) {
721
+ if ( ! mconfig . IsExtensionModel ) {
722
+ monitor . ReportError ( "Submodules can't define new add-ins: " + assemblyName , null ) ;
723
+ return false ;
724
+ }
725
+ if ( mconfig . OptionalModules . Count != 0 ) {
726
+ monitor . ReportError ( "Submodules can't define nested submodules: " + assemblyName , null ) ;
727
+ return false ;
728
+ }
729
+ if ( mconfig . ConditionTypes . Count != 0 ) {
730
+ monitor . ReportError ( "Submodules can't define condition types: " + assemblyName , null ) ;
731
+ return false ;
732
+ }
733
+ if ( mconfig . ExtensionNodeSets . Count != 0 ) {
734
+ monitor . ReportError ( "Submodules can't define extension node sets: " + assemblyName , null ) ;
735
+ return false ;
736
+ }
737
+ if ( mconfig . ExtensionPoints . Count != 0 ) {
738
+ monitor . ReportError ( "Submodules can't define extension points sets: " + assemblyName , null ) ;
739
+ return false ;
740
+ }
741
+ mod . MergeWith ( mconfig . MainModule ) ;
742
+ }
743
+ ScanAssemblyContents ( reflector , config , mod , asm , scanResult ) ;
744
+ return true ;
745
+ }
746
+
707
747
void ReportReflectionException ( IProgressStatus monitor , Exception ex , AddinDescription config , AddinScanResult scanResult )
708
748
{
709
749
scanResult . AddFileToWithFailure ( config . AddinFile ) ;
0 commit comments