internal override bool Validate(TypeInfo type, Collection<String> warnings)
        {
            _potentialHAVs = FindBaseTypesAndInterfaces(type);
            
            if (_potentialHAVs.Length == 0)
            {
                return false;
            }

            foreach (MiniConstructorInfo ci in type.GetConstructors(true))
            {
                MiniParameterInfo[] pars = ci.GetParameters();
                if (pars.Length != 1)
                {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterUnusableCtorMultipleParams, type.AssemblyQualifiedName));
                    continue;
                }

                TypeInfo paramType = pars[0].ParameterType;
                bool success = false;
                try
                {
                    if (paramType.IsInterface && (paramType.Implements(typeofIContract)))
                    {
                        _constructors.Add(paramType);
                        success = true;
                    }
                }
                catch (FileNotFoundException) { }
                catch (FileLoadException)
                {
                    // Can happen for a constructor taking a type that isn't in mscorlib nor System.AddIn.Contract, and
                    // also isn't in any of the directories that we would probe.
                }
                if (!success)
                {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterUnusableCtorBadParam, type.AssemblyQualifiedName, paramType.FullName));
                    continue;
                }
            }
            if (_constructors.Count == 0)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterNoValidCtors, type.AssemblyQualifiedName));
                return false;
            }

            return base.Validate(type, warnings);
        }
        internal override bool Validate(TypeInfo type, Collection <String> warnings)
        {
            _potentialHAVs = FindBaseTypesAndInterfaces(type);

            if (_potentialHAVs.Length == 0)
            {
                return(false);
            }

            foreach (MiniConstructorInfo ci in type.GetConstructors(true))
            {
                MiniParameterInfo[] pars = ci.GetParameters();
                if (pars.Length != 1)
                {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterUnusableCtorMultipleParams, type.AssemblyQualifiedName));
                    continue;
                }

                TypeInfo paramType = pars[0].ParameterType;
                bool     success   = false;
                try
                {
                    if (paramType.IsInterface && (paramType.Implements(typeofIContract)))
                    {
                        _constructors.Add(paramType);
                        success = true;
                    }
                }
                catch (FileNotFoundException) { }
                catch (FileLoadException)
                {
                    // Can happen for a constructor taking a type that isn't in mscorlib nor System.AddIn.Contract, and
                    // also isn't in any of the directories that we would probe.
                }
                if (!success)
                {
                    warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterUnusableCtorBadParam, type.AssemblyQualifiedName, paramType.FullName));
                    continue;
                }
            }
            if (_constructors.Count == 0)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.HostAdapterNoValidCtors, type.AssemblyQualifiedName));
                return(false);
            }

            return(base.Validate(type, warnings));
        }
Beispiel #3
0
        //Validate the addin. Also fill in the base class and interfaces.
        internal override bool Validate(TypeInfo type, Collection<String> warnings)
        {
            Type addInAttributeType = typeof(AddInAttribute);
            // Get the AddInAttribute, if available.  It is not required in the FindAddIn case.
            MiniCustomAttributeInfo[] attributes = type.GetCustomAttributeInfos(addInAttributeType);
            if (attributes.Length > 0)
            {
                MiniCustomAttributeInfo addInAttribute = attributes[0];

                _unlocalized.Name = (String)addInAttribute.FixedArgs[0].Value;
                foreach (MiniCustomAttributeNamedArgInfo namedArg in addInAttribute.NamedArgs)
                {
                    switch (namedArg.Name)
                    {
                        case "Description":
                            _unlocalized.Description = (String)namedArg.Value;
                        break;
                        case "Version":
                            _version = (String)namedArg.Value;
                        break;
                        case "Publisher":
                            _unlocalized.Publisher = (String)namedArg.Value;
                        break;
                        default:
                            warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.UnknownNamedAddInAttributeParameter, namedArg.Name, type.FullName, type.Assembly.ModuleName));
                        break;
                    }
                }
            }
            
            if (String.IsNullOrEmpty(_unlocalized.Name))
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInMustSpecifyName, type.FullName, type.Assembly.ModuleName));
                return false;
            }

            /* 
            // Parse and validate the custom attribute on this type.
            foreach (CustomAttributeData attr in CustomAttributeData.GetCustomAttributes(type)) {
                if (attr.Constructor.DeclaringType == PipelineComponent.AddInAttributeInReflectionLoaderContext) {
                    if (attr.ConstructorArguments.Count == 1) {
                        _unlocalized.Name = (String)attr.ConstructorArguments[0].Value;
                        if (String.IsNullOrEmpty(_unlocalized.Name)) {
                            warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInMustSpecifyName, type.FullName, type.Assembly.Location));
                            return false;
                        }
                    }
#if LOCALIZABLE_ADDIN_ATTRIBUTE
                    else if (attr.ConstructorArguments.Count == 2) {
                        _resMgrBaseName = (String)attr.ConstructorArguments[0].Value;
                        _nameResource = (String)attr.ConstructorArguments[1].Value;
                        if (String.IsNullOrEmpty(_resMgrBaseName)) {
                            warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.MustSpecifyResMgrBaseName, type.FullName, type.Assembly.Location));
                            return false;
                        }
                        if (String.IsNullOrEmpty(_nameResource)) {
                            warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.MustSpecifyResourceName, type.FullName, type.Assembly.Location));
                            return false;
                        }
                    }
#endif  // LOCALIZABLE_ADDIN_ATTRIBUTE
                    else {
                        System.Diagnostics.Contracts.Contract.Assert(false, "Unknown number of custom attribute constructor parameters");
                    }
                    foreach (CustomAttributeNamedArgument arg in attr.NamedArguments) {
                        if (arg.MemberInfo.Name == "Publisher")
                            _unlocalized.Publisher = (String)arg.TypedValue.Value;
                        else if (arg.MemberInfo.Name == "Version")
                            _version = (String)arg.TypedValue.Value;
                        else if (arg.MemberInfo.Name == "Description")
                            _unlocalized.Description = (String)arg.TypedValue.Value;
#if LOCALIZABLE_ADDIN_ATTRIBUTE
                        else if (arg.MemberInfo.Name == "PublisherResourceName")
                            _publisherResource = (String)arg.TypedValue.Value;
                        else if (arg.MemberInfo.Name == "DescriptionResourceName")
                            _descriptionResource = (String)arg.TypedValue.Value;
#endif
                        else {
                            System.Diagnostics.Contracts.Contract.Assert(false, "Unknown named parameter to AddInAttribute: " + arg.MemberInfo.Name);
                            warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.UnknownNamedAddInAttributeParameter, arg.MemberInfo.Name, type.FullName, type.Assembly.Location));
                            // Let's ignore this - this shouldn't be fatal.
                        }
                    }
                    break;
                }
            }
            */

            // Check for a public default constructor
            bool found = false;
            foreach (MiniConstructorInfo ci in type.GetConstructors()) {
                MiniParameterInfo[] pars = ci.GetParameters();
                if (pars.Length == 0) {
                    found = true;
                    break;
                }
            }
            
            if (!found)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.NoDefaultConstructor, type.FullName, type.Assembly.ModuleName));
                return false;
            }

            _potentialAddinBases = FindBaseTypesAndInterfaces(type);
            
            if(_potentialAddinBases.Length == 0)
            {
                return false;
            }


#if LOCALIZABLE_ADDIN_ATTRIBUTE
            if (ContainsLocalizableStrings) {
                _localizedResources = ResourceProvider.LookupResourcesInCurrentDomain(_fullPathToAddIn,
                    _resMgrBaseName, _nameResource, _publisherResource, _descriptionResource);
            }
#endif
            return base.Validate(type, warnings);
        }
Beispiel #4
0
        //Validate the addin. Also fill in the base class and interfaces.
        internal override bool Validate(TypeInfo type, Collection <String> warnings)
        {
            Type addInAttributeType = typeof(AddInAttribute);

            // Get the AddInAttribute, if available.  It is not required in the FindAddIn case.
            MiniCustomAttributeInfo[] attributes = type.GetCustomAttributeInfos(addInAttributeType);
            if (attributes.Length > 0)
            {
                MiniCustomAttributeInfo addInAttribute = attributes[0];

                _unlocalized.Name = (String)addInAttribute.FixedArgs[0].Value;
                foreach (MiniCustomAttributeNamedArgInfo namedArg in addInAttribute.NamedArgs)
                {
                    switch (namedArg.Name)
                    {
                    case "Description":
                        _unlocalized.Description = (String)namedArg.Value;
                        break;

                    case "Version":
                        _version = (String)namedArg.Value;
                        break;

                    case "Publisher":
                        _unlocalized.Publisher = (String)namedArg.Value;
                        break;

                    default:
                        warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.UnknownNamedAddInAttributeParameter, namedArg.Name, type.FullName, type.Assembly.ModuleName));
                        break;
                    }
                }
            }

            if (String.IsNullOrEmpty(_unlocalized.Name))
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInMustSpecifyName, type.FullName, type.Assembly.ModuleName));
                return(false);
            }

            /*
             * // Parse and validate the custom attribute on this type.
             * foreach (CustomAttributeData attr in CustomAttributeData.GetCustomAttributes(type)) {
             *  if (attr.Constructor.DeclaringType == PipelineComponent.AddInAttributeInReflectionLoaderContext) {
             *      if (attr.ConstructorArguments.Count == 1) {
             *          _unlocalized.Name = (String)attr.ConstructorArguments[0].Value;
             *          if (String.IsNullOrEmpty(_unlocalized.Name)) {
             *              warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.AddInMustSpecifyName, type.FullName, type.Assembly.Location));
             *              return false;
             *          }
             *      }
             #if LOCALIZABLE_ADDIN_ATTRIBUTE
             *      else if (attr.ConstructorArguments.Count == 2) {
             *          _resMgrBaseName = (String)attr.ConstructorArguments[0].Value;
             *          _nameResource = (String)attr.ConstructorArguments[1].Value;
             *          if (String.IsNullOrEmpty(_resMgrBaseName)) {
             *              warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.MustSpecifyResMgrBaseName, type.FullName, type.Assembly.Location));
             *              return false;
             *          }
             *          if (String.IsNullOrEmpty(_nameResource)) {
             *              warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.MustSpecifyResourceName, type.FullName, type.Assembly.Location));
             *              return false;
             *          }
             *      }
             #endif  // LOCALIZABLE_ADDIN_ATTRIBUTE
             *      else {
             *          System.Diagnostics.Contracts.Contract.Assert(false, "Unknown number of custom attribute constructor parameters");
             *      }
             *      foreach (CustomAttributeNamedArgument arg in attr.NamedArguments) {
             *          if (arg.MemberInfo.Name == "Publisher")
             *              _unlocalized.Publisher = (String)arg.TypedValue.Value;
             *          else if (arg.MemberInfo.Name == "Version")
             *              _version = (String)arg.TypedValue.Value;
             *          else if (arg.MemberInfo.Name == "Description")
             *              _unlocalized.Description = (String)arg.TypedValue.Value;
             #if LOCALIZABLE_ADDIN_ATTRIBUTE
             *          else if (arg.MemberInfo.Name == "PublisherResourceName")
             *              _publisherResource = (String)arg.TypedValue.Value;
             *          else if (arg.MemberInfo.Name == "DescriptionResourceName")
             *              _descriptionResource = (String)arg.TypedValue.Value;
             #endif
             *          else {
             *              System.Diagnostics.Contracts.Contract.Assert(false, "Unknown named parameter to AddInAttribute: " + arg.MemberInfo.Name);
             *              warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.UnknownNamedAddInAttributeParameter, arg.MemberInfo.Name, type.FullName, type.Assembly.Location));
             *              // Let's ignore this - this shouldn't be fatal.
             *          }
             *      }
             *      break;
             *  }
             * }
             */

            // Check for a public default constructor
            bool found = false;

            foreach (MiniConstructorInfo ci in type.GetConstructors())
            {
                MiniParameterInfo[] pars = ci.GetParameters();
                if (pars.Length == 0)
                {
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                warnings.Add(String.Format(CultureInfo.CurrentCulture, Res.NoDefaultConstructor, type.FullName, type.Assembly.ModuleName));
                return(false);
            }

            _potentialAddinBases = FindBaseTypesAndInterfaces(type);

            if (_potentialAddinBases.Length == 0)
            {
                return(false);
            }


#if LOCALIZABLE_ADDIN_ATTRIBUTE
            if (ContainsLocalizableStrings)
            {
                _localizedResources = ResourceProvider.LookupResourcesInCurrentDomain(_fullPathToAddIn,
                                                                                      _resMgrBaseName, _nameResource, _publisherResource, _descriptionResource);
            }
#endif
            return(base.Validate(type, warnings));
        }