public ResourceState Lookup(String addInAssemblyFileName, String resMgrBaseName, String nameResource, String publisherResource, String descriptionResource) { Contract.Requires(Path.IsPathRooted(addInAssemblyFileName)); // @TODO: This should be using ReflectionOnlyLoadFrom to ensure we // don't run into potential security issues with module constructors, // but the V2 ResourceManager uses normal reflection to get the custom // attributes on an assembly, so this throws an exception on V2. // In V3, we can change the ResourceManager to call // GetCustomAttributeData instead, and use ReflectionOnlyLoadFrom here. Assembly addIn = Assembly.LoadFrom(addInAssemblyFileName); ResourceManager resMgr = new ResourceManager(resMgrBaseName, addIn); CultureInfo culture = Thread.CurrentThread.CurrentUICulture; ResourceState resState = new ResourceState(); resState.CultureName = culture.Name; if (nameResource != null) { resState.Name = resMgr.GetString(nameResource, culture); } if (publisherResource != null) { resState.Publisher = resMgr.GetString(publisherResource, culture); } if (descriptionResource != null) { resState.Description = resMgr.GetString(descriptionResource, culture); } return(resState); }
public ResourceState Lookup(String addInAssemblyFileName, String resMgrBaseName, String nameResource, String publisherResource, String descriptionResource) { Contract.Requires(Path.IsPathRooted(addInAssemblyFileName)); // @ Assembly addIn = Assembly.LoadFrom(addInAssemblyFileName); ResourceManager resMgr = new ResourceManager(resMgrBaseName, addIn); CultureInfo culture = Thread.CurrentThread.CurrentUICulture; ResourceState resState = new ResourceState(); resState.CultureName = culture.Name; if (nameResource != null) { resState.Name = resMgr.GetString(nameResource, culture); } if (publisherResource != null) { resState.Publisher = resMgr.GetString(publisherResource, culture); } if (descriptionResource != null) { resState.Description = resMgr.GetString(descriptionResource, culture); } return(resState); }
internal static ResourceState LookupResourcesInCurrentDomain(String addInAssemblyFileName, String resMgrBaseName, String nameResource, String publisherResource, String descriptionResource) { ResourceLookupWorker worker = new ResourceLookupWorker(); ResourceState state = worker.Lookup(addInAssemblyFileName, resMgrBaseName, nameResource, publisherResource, descriptionResource); return(state); }
internal AddIn(TypeInfo typeInfo, String assemblyLocation, String fullPathToAddin, String assemblyName) : base(typeInfo, assemblyLocation) { System.Diagnostics.Contracts.Contract.Requires(Path.IsPathRooted(fullPathToAddin)); _fullPathToAddIn = fullPathToAddin; _assemblyName = assemblyName; _unlocalized = new ResourceState(); }
internal AddIn(TypeInfo typeInfo, String assemblyLocation, String fullPathToAddin, String assemblyName) : base(typeInfo, assemblyLocation) { System.Diagnostics.Contracts.Contract.Requires(Path.IsPathRooted(fullPathToAddin)); _fullPathToAddIn = fullPathToAddin; _assemblyName = assemblyName; _unlocalized = new ResourceState(); }
internal ResourceState GetLocalizedResources() { if (!ContainsLocalizableStrings) { return(_unlocalized); } ResourceState resState = _localizedResources; if (Thread.CurrentThread.CurrentUICulture.Name == resState.CultureName) { return(resState); } // Cache this set of resources, in case someone asks for another from // the same culture. _localizedResources = ResourceProvider.LookupResourcesInNewDomain(Location, _resMgrBaseName, _nameResource, _publisherResource, _descriptionResource); return(_localizedResources); }
public ResourceState Lookup(String addInAssemblyFileName, String resMgrBaseName, String nameResource, String publisherResource, String descriptionResource) { Contract.Requires(Path.IsPathRooted(addInAssemblyFileName)); // @ Assembly addIn = Assembly.LoadFrom(addInAssemblyFileName); ResourceManager resMgr = new ResourceManager(resMgrBaseName, addIn); CultureInfo culture = Thread.CurrentThread.CurrentUICulture; ResourceState resState = new ResourceState(); resState.CultureName = culture.Name; if (nameResource != null) resState.Name = resMgr.GetString(nameResource, culture); if (publisherResource != null) resState.Publisher = resMgr.GetString(publisherResource, culture); if (descriptionResource != null) resState.Description = resMgr.GetString(descriptionResource, culture); return resState; }
public ResourceState Lookup(String addInAssemblyFileName, String resMgrBaseName, String nameResource, String publisherResource, String descriptionResource) { Contract.Requires(Path.IsPathRooted(addInAssemblyFileName)); // @TODO: This should be using ReflectionOnlyLoadFrom to ensure we // don't run into potential security issues with module constructors, // but the V2 ResourceManager uses normal reflection to get the custom // attributes on an assembly, so this throws an exception on V2. // In V3, we can change the ResourceManager to call // GetCustomAttributeData instead, and use ReflectionOnlyLoadFrom here. Assembly addIn = Assembly.LoadFrom(addInAssemblyFileName); ResourceManager resMgr = new ResourceManager(resMgrBaseName, addIn); CultureInfo culture = Thread.CurrentThread.CurrentUICulture; ResourceState resState = new ResourceState(); resState.CultureName = culture.Name; if (nameResource != null) resState.Name = resMgr.GetString(nameResource, culture); if (publisherResource != null) resState.Publisher = resMgr.GetString(publisherResource, culture); if (descriptionResource != null) resState.Description = resMgr.GetString(descriptionResource, culture); return resState; }
//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 ResourceState GetLocalizedResources() { if (!ContainsLocalizableStrings) return _unlocalized; ResourceState resState = _localizedResources; if (Thread.CurrentThread.CurrentUICulture.Name == resState.CultureName) return resState; // Cache this set of resources, in case someone asks for another from // the same culture. _localizedResources = ResourceProvider.LookupResourcesInNewDomain(Location, _resMgrBaseName, _nameResource, _publisherResource, _descriptionResource); return _localizedResources; }
//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)); }