RE: [nant-dev] ResourceUtil rewind
> > Greco Giuseppe wrote: > > >what's about something like that? Giving the following resource files > > > > Global.resx > > Another.resx > > ... .resx > > > > > >we could have a separate resource manager for each resource file, > > > > > This means storing *all* the resources in a single assembly > > I don't quite understand how your implementation is supposed to work. > The static constructor will only be called once so: > > static ResourceUtils() { > Assembly assembly = Assembly.GetCallingAssembly(); > Global = new > ResourceManager(assembly.GetName().Name + GlobalResx, assembly); > Another = new > ResourceManager(assembly.GetName().Name + AnotherResx, assembly); > ... > > } > > will only allow the loading of resources whatever the calling > assembly is at type initialization time ( probably > NAnt.Core.dll ? ). This means that we would have to store > *all* resources for *all* asemblies in NAnt.Core. I thought > we agreed that it would be better to have each assembly store > its own localised resources ? > No, that was just a way to have more than one *.resx file per assembly. > > >solving also the problem with VS.NET: > > > > > > > it has no bearing on the vs.net problem. That issue only > related to the > naming of the embedded resource structure - so Another.resx > still maps > to .Another.resource in the final assembly ( when > built by vs.net ). > Exactly, meaning that in the example above we would have something like MyNamespace.Global.resource MyNamespace.Another.resoruce ... > > > I think that a variation on your register assemblies proposal > could work > well and be more flexible going forward: > > public sealed class ResourceUtils { > private static ResourceManager _sharedResourceManager; > private static Hashtable _resourceManagerDictionary = new > Hashtable(); > > ... > ... > private static void RegisterAssembly(Assembly assembly) { > lock (_resourceManagerDictionary) { > > _resourceManagerDictionary.Add(assembly.GetName().Name, > new > ResourceManager(assembly.GetName().Name, assembly)); > } > } > private static void RegisterSharedAssembly(Assembly assembly) { > lock (_sharedResourceManager) { > _sharedResourceManager = new > ResourceManager(assembly.GetName().Name, assembly); > } > } > I think the RegisterSharedAssembly() method is not necessary; we could just always use the RegisterAssembly() method (adding also the shared resource manager to the hashtable). In any case the problem related to the naming of the embedded resource structure still remains... In the code above you assume this name always corresponds to the assembly name... but it does not (e.g. MyNamespace.Another.resources). > public static string GetString(string name, CultureInfo culture) { > string localizedString = null; > ResourceManager resourceManager = null; > Assembly assembly = Assembly.GetCallingAssembly(); > > if ( ! > _resourceManagerDictionary.Contains(assembly.GetName().Name ) ) { > lock (_resourceManagerDictionary) { > RegisterAssembly(assembly); > } > } > // get the required Manager > resourceManager = > _resourceManagerDictionary[assembly.GetName().Name] as > ResourceManager; > localizedString = resourceManager.GetString(name, > culture); > > // try the shared resources if we didn't find it in the > specific resource manager > if ( localizedString == null && _sharedResourceManager != > null) { > return _sharedResourceManager.GetString(name, > culture); > } > > return localizedString; > } > > } > > Since there are only 2 cases. > - load resource from the current assembly > - load the resource from the shared resource assembly > > and somewhere in NAnt startup sequence we'd call: > > ResourceUtils:RegisterSharedAssembly( Assembly.LoadFrom( > "NAnt.SharedResources.dll" ) ); ResourceUtils.RegisterAssembly(Assembly.LoadFrom("NAnt.SharedResources.d ll")); would be enought... isn't it? j3d. > > > Ian > -- DISCLAIMER -- This message (including any attachments) is confidential and may be privileged. If you have received it by mistake please notify the sender by return e-mail and delete this message from your system.Any unauthorised use or dissemination of this message in whole or in part is strictly prohibited. Please note that e-mails are susceptible to change. Banca del Gottardo (including its group companies) shall not be liable for the improper or incomplete transmission of the information contained in this communicati
Re: [nant-dev] ResourceUtils
On Wed, 23 Feb 2005 10:36:40 +0100, Giuseppe Greco <[EMAIL PROTECTED]> wrote: > On Tue, 2005-02-22 at 09:41 +0800, Troy Laurin wrote: > > > [DCL] > Would you suggest something like this? > > sealed class ResourceUtils > { > private ResourceUtils() {} > public static readonly ResourceUtils Instance = new ResourceUtils(); > ... > } > > ... > > string errorMessage = ResourceUtils.Instance.GetString("NA1001"); > > That works fine too, but looking at > http://msdn.microsoft.com/library/default.asp?url=/library/en- > us/dnbda/html/singletondespatt.asp, on .NET the result is > exactly the same as with the double-checked locking pattern That is exactly what I would suggest. Note that the result is exactly the same as with double-checked locking, but the implementation is very different: Using DCL, you have to guard against multiple threads attempting to construct your object at about the same time, and you need a memory barrier (or a volatile field) to ensure that the object created by the first thread is visible to the others. Using inline initialisation, you are guaranteeing that the object will be completely constructed before anyone tries to access it, and a side-effect of this guarantee means you no longer need memory barriers to effect visibility. Or rather, the memory barrier you have to pass to access the class definition (exactly once, the first time you access the class) also suffices for the member. > Oh no! Java? Pfui!!! I come from C/C++... and my bibles were > "Effective C++" and "More Effective C++" by Scott Meyers... There's no need to get that way, if you believe in good programming as well as effective programming. There's a lot of (worthwhile) things that you can do in C++ that are impossible (or at least don't make sense) in Java, but not all that many projects need to do that kind of thing. Anyway, there's no reason why a Java programmer can't understand what's going on beneath the covers, too :-) I think of myself as a Java programmer, but I cut my teeth on C. (Actually, I cut my teeth on Basic, then moved onto Pascal at school, then worked in C after that... but you get my point) > > j3d. Peace, -- Troy --- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ___ nant-developers mailing list nant-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-developers
[nant-dev] [ nant-Bugs-1154339 ] less than sign not allowed in ${}
Bugs item #1154339, was opened at 2005-03-01 10:19 Message generated for change (Comment added) made by johnwebbcole You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1154339&group_id=31650 Category: Core Group: None Status: Closed Resolution: Invalid Priority: 5 Submitted By: John Cole (johnwebbcole) Assigned to: Gert Driesen (drieseng) Summary: less than sign not allowed in ${} Initial Comment: The < sign fails with the following error when inside ${} braces: Error loading buildfile. '<', hexadecimal value 0x3C, is an invalid attribute character. Line 12, position 17. This would not be that odd, except that the greater than sign (>) does work. Here is an example build script: Shouldn't both < and > work or not work similarly? -- >Comment By: John Cole (johnwebbcole) Date: 2005-03-02 09:11 Message: Logged In: YES user_id=892481 Ok, I went to the xml spec and found my misconception. I was under the impression that both < and > were not allowed in xml attributes (with specific exceptions). Only the < sign is not allowed and MUST be escaped as < while the > sign MAY be escaped with > unless it appears in "]]>" when it is not ending a CDATA block. I was wondering how NAnt was allowing the > sign in the first place :-) -- Comment By: Gert Driesen (drieseng) Date: 2005-03-02 07:43 Message: Logged In: YES user_id=707851 The XML error says it all: the less than character is not allowed in attributes. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1154339&group_id=31650 --- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ___ nant-developers mailing list nant-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-developers
Re: [nant-dev] ResourceUtil rewind
Greco Giuseppe wrote: what's about something like that? Giving the following resource files Global.resx Another.resx ... .resx we could have a separate resource manager for each resource file, This means storing *all* the resources in a single assembly I don't quite understand how your implementation is supposed to work. The static constructor will only be called once so: static ResourceUtils() { Assembly assembly = Assembly.GetCallingAssembly(); Global = new ResourceManager(assembly.GetName().Name + GlobalResx, assembly); Another = new ResourceManager(assembly.GetName().Name + AnotherResx, assembly); ... } will only allow the loading of resources whatever the calling assembly is at type initialization time ( probably NAnt.Core.dll ? ). This means that we would have to store *all* resources for *all* asemblies in NAnt.Core. I thought we agreed that it would be better to have each assembly store its own localised resources ? solving also the problem with VS.NET: it has no bearing on the vs.net problem. That issue only related to the naming of the embedded resource structure - so Another.resx still maps to .Another.resource in the final assembly ( when built by vs.net ). I think that a variation on your register assemblies proposal could work well and be more flexible going forward: public sealed class ResourceUtils { private static ResourceManager _sharedResourceManager; private static Hashtable _resourceManagerDictionary = new Hashtable(); ... ... private static void RegisterAssembly(Assembly assembly) { lock (_resourceManagerDictionary) { _resourceManagerDictionary.Add(assembly.GetName().Name, new ResourceManager(assembly.GetName().Name, assembly)); } } private static void RegisterSharedAssembly(Assembly assembly) { lock (_sharedResourceManager) { _sharedResourceManager = new ResourceManager(assembly.GetName().Name, assembly); } } public static string GetString(string name, CultureInfo culture) { string localizedString = null; ResourceManager resourceManager = null; Assembly assembly = Assembly.GetCallingAssembly(); if ( ! _resourceManagerDictionary.Contains(assembly.GetName().Name ) ) { lock (_resourceManagerDictionary) { RegisterAssembly(assembly); } } // get the required Manager resourceManager = _resourceManagerDictionary[assembly.GetName().Name] as ResourceManager; localizedString = resourceManager.GetString(name, culture); // try the shared resources if we didn't find it in the specific resource manager if ( localizedString == null && _sharedResourceManager != null) { return _sharedResourceManager.GetString(name, culture); } return localizedString; } } Since there are only 2 cases. - load resource from the current assembly - load the resource from the shared resource assembly and somewhere in NAnt startup sequence we'd call: ResourceUtils:RegisterSharedAssembly( Assembly.LoadFrom( "NAnt.SharedResources.dll" ) ); Ian --- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ___ nant-developers mailing list nant-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-developers
[nant-dev] [ nant-Bugs-1154339 ] less than sign not allowed in ${}
Bugs item #1154339, was opened at 2005-03-01 17:19 Message generated for change (Comment added) made by drieseng You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1154339&group_id=31650 >Category: Core Group: None >Status: Closed >Resolution: Invalid Priority: 5 Submitted By: John Cole (johnwebbcole) >Assigned to: Gert Driesen (drieseng) Summary: less than sign not allowed in ${} Initial Comment: The < sign fails with the following error when inside ${} braces: Error loading buildfile. '<', hexadecimal value 0x3C, is an invalid attribute character. Line 12, position 17. This would not be that odd, except that the greater than sign (>) does work. Here is an example build script: Shouldn't both < and > work or not work similarly? -- >Comment By: Gert Driesen (drieseng) Date: 2005-03-02 14:43 Message: Logged In: YES user_id=707851 The XML error says it all: the less than character is not allowed in attributes. -- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=402868&aid=1154339&group_id=31650 --- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ___ nant-developers mailing list nant-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-developers
Re: [nant-dev] ResourceUtil rewind
Greco Giuseppe wrote: what's about something like that? Giving the following resource files Global.resx Another.resx ... .resx we could have a separate resource manager for each resource file, This means storing *all* the resources in a single assembly I don't quite understand how your implementation is supposed to work. The static constructor will only be called once so: static ResourceUtils() { Assembly assembly = Assembly.GetCallingAssembly(); Global = new ResourceManager(assembly.GetName().Name + GlobalResx, assembly); Another = new ResourceManager(assembly.GetName().Name + AnotherResx, assembly); ... } will only allow the loading of resources whatever the calling assembly is at type initialization time ( probably NAnt.Core.dll ? ). This means that we would have to store *all* resources for *all* asemblies in NAnt.Core. I thought we agreed that it would be better to have each assembly store its own localised resources ? No, that was just a way to have more than one *.resx file per assembly. aah ok - I'm not sure that its necessary though - one Strings.resx for localized strings per assembly is probably sufficent. Besides, creating the two resourcemanagers in the static constructor doesn't solve the problem as its only called a single time. You would need to store a more complicated structure with 'x' ResourceManagers per assembly - ie 1 for each embedded resource file. solving also the problem with VS.NET: it has no bearing on the vs.net problem. That issue only related to the naming of the embedded resource structure - so Another.resx still maps to .Another.resource in the final assembly ( when built by vs.net ). Exactly, meaning that in the example above we would have something like MyNamespace.Global.resource MyNamespace.Another.resoruce ... I think that a variation on your register assemblies proposal could work well and be more flexible going forward: public sealed class ResourceUtils { private static ResourceManager _sharedResourceManager; private static Hashtable _resourceManagerDictionary = new Hashtable(); ... ... private static void RegisterAssembly(Assembly assembly) { lock (_resourceManagerDictionary) { _resourceManagerDictionary.Add(assembly.GetName().Name, new ResourceManager(assembly.GetName().Name, assembly)); } } private static void RegisterSharedAssembly(Assembly assembly) { lock (_sharedResourceManager) { _sharedResourceManager = new ResourceManager(assembly.GetName().Name, assembly); } } I think the RegisterSharedAssembly() method is not necessary; we could just always use the RegisterAssembly() method (adding also the shared resource manager to the hashtable). sure - thats fine. Except- how would you know to use that one as the fallback if the resource isn't found in the current assembly's ResourceManager ? We don't want to try all of them. Hardcode the name "NAnt.SharedResources" in the GetString() method ? In any case the problem related to the naming of the embedded resource structure still remains... In the code above you assume this name always corresponds to the assembly name... but it does not (e.g. MyNamespace.Another.resources). sure but if we assume strings.resx and namespace == assemblyname then we always get: MyNamespace.Strings.resources doh ! -- except the namespace doesn't equal the assembly name - for example NAnt.DotNet => NAnt.DotNetTasks.dll. Ok - another way around this is to just change the vs.net project files to have *no* default namespace and set the prefix manually on each resx file. I don't think we should be working to hard to workaround vs.net't busted build system especially since the official build is the 'built by nant' one. Since there are only 2 cases. - load resource from the current assembly - load the resource from the shared resource assembly and somewhere in NAnt startup sequence we'd call: ResourceUtils:RegisterSharedAssembly( Assembly.LoadFrom( "NAnt.SharedResources.dll" ) ); ResourceUtils.RegisterAssembly(Assembly.LoadFrom("NAnt.SharedResources.d ll")); would be enought... isn't it? yep - if we can identify the shared resourcemaneger to use as a fallback. Ian --- SF email is sponsored by - The IT Product Guide Read honest & candid reviews on hundreds of IT Products from real users. Discover which products truly live up to the hype. Start reading now. http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click ___ nant-developers mailing list nant-developers@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-developers