Beispiel #1
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 #2
0
        internal PipelineComponent(TypeInfo typeInfo, String assemblyLocation)
        {
            if (typeInfo == null)
            {
                throw new ArgumentNullException("typeInfo");
            }
            if (assemblyLocation == null)
            {
                throw new ArgumentNullException("assemblyLocation");
            }
            System.Diagnostics.Contracts.Contract.EndContractBlock();

            _typeInfo = typeInfo;
            if (Path.IsPathRooted(assemblyLocation))
            {
                // For FindAddIn case, we know the full location;
                _location             = assemblyLocation;
                _haveSetRootDirectory = true;
            }
            else
            {
                _relativeLocation = assemblyLocation;
            }

            // load the qualification data, either from reflection or minireflection, as appropriate
            if (_typeInfo.HasReflectionType)
            {
                IList <CustomAttributeData> cas        = CustomAttributeData.GetCustomAttributes(_typeInfo.ReflectionType);
                Dictionary <String, String> dictionary = new Dictionary <String, String>();
                foreach (CustomAttributeData ca in cas)
                {
                    if (Object.ReferenceEquals(ca.Constructor.DeclaringType, s_QualificationDataAttrInReflectionLoaderContext))
                    {
                        IList <CustomAttributeTypedArgument> args = ca.ConstructorArguments;
                        String key = (String)args[0].Value;
                        String val = (String)args[1].Value;
                        dictionary[key] = val;
                    }
                }
                _qualificationData = dictionary.Count == 0 ? s_emptyDictionary :
                                     new ReadOnlyDictionary <String, String>(dictionary);
            }
            else
            {
                Type qualificationDataAttribute        = typeof(QualificationDataAttribute);
                MiniCustomAttributeInfo[]   cas        = typeInfo.GetCustomAttributeInfos(qualificationDataAttribute);
                Dictionary <String, String> dictionary = new Dictionary <String, String>();
                if (cas != null && cas.Length > 0)
                {
                    foreach (MiniCustomAttributeInfo ca in cas)
                    {
                        MiniCustomAttributeFixedArgInfo[] fai = ca.FixedArgs;
                        String key = (String)fai[0].Value;
                        String val = (String)fai[1].Value;
                        dictionary[key] = val;
                    }
                }
                _qualificationData = dictionary.Count == 0 ? s_emptyDictionary :
                                     new ReadOnlyDictionary <String, String>(dictionary);
            }
        }
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));
        }
        internal PipelineComponent(TypeInfo typeInfo, String assemblyLocation)
        {
            if (typeInfo == null)
                throw new ArgumentNullException("typeInfo");
            if (assemblyLocation == null)
                throw new ArgumentNullException("assemblyLocation");
            System.Diagnostics.Contracts.Contract.EndContractBlock();
            
            _typeInfo = typeInfo;
            if (Path.IsPathRooted(assemblyLocation)) {
                // For FindAddIn case, we know the full location;
                _location = assemblyLocation;
                _haveSetRootDirectory = true;
            }
            else {
                _relativeLocation = assemblyLocation;
            }

            // load the qualification data, either from reflection or minireflection, as appropriate
            if (_typeInfo.HasReflectionType)
            {
                IList<CustomAttributeData> cas =CustomAttributeData.GetCustomAttributes(_typeInfo.ReflectionType); 
                Dictionary<String, String> dictionary = new Dictionary<String, String>();
                foreach (CustomAttributeData ca in cas)
                {
                    if (Object.ReferenceEquals(ca.Constructor.DeclaringType, s_QualificationDataAttrInReflectionLoaderContext))
                    {
                        IList<CustomAttributeTypedArgument> args = ca.ConstructorArguments;
                        String key = (String)args[0].Value;
                        String val = (String)args[1].Value;
                        dictionary[key] = val;
                    }
                }
                _qualificationData = dictionary.Count == 0 ? s_emptyDictionary : 
                    new ReadOnlyDictionary<String, String>(dictionary);
            }
            else
            {
                Type qualificationDataAttribute = typeof (QualificationDataAttribute);
                MiniCustomAttributeInfo[] cas = typeInfo.GetCustomAttributeInfos(qualificationDataAttribute);
                Dictionary<String, String> dictionary = new Dictionary<String, String>();
                if (cas != null && cas.Length > 0)
                {
                    foreach (MiniCustomAttributeInfo ca in cas)
                    {
                        MiniCustomAttributeFixedArgInfo[] fai = ca.FixedArgs;
                        String key = (String)fai[0].Value;
                        String val = (String)fai[1].Value;
                        dictionary[key] = val;
                    }
                }
                _qualificationData = dictionary.Count == 0 ? s_emptyDictionary : 
                    new ReadOnlyDictionary<String, String>(dictionary);
            }
        }