Click here to Skip to main content
15,902,114 members
Home / Discussions / C#
   

C#

 
Generaltrap state changes (standbye, hibernate, etc) Pin
vista2719-Jul-04 11:31
vista2719-Jul-04 11:31 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
Heath Stewart19-Jul-04 11:45
protectorHeath Stewart19-Jul-04 11:45 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
vista2719-Jul-04 13:57
vista2719-Jul-04 13:57 
GeneralRe: trap state changes (standbye, hibernate, etc) Pin
Heath Stewart20-Jul-04 3:40
protectorHeath Stewart20-Jul-04 3:40 
GeneralCultureInfo for unsupported Culture Pin
Colin Angus Mackay19-Jul-04 11:25
Colin Angus Mackay19-Jul-04 11:25 
GeneralRe: CultureInfo for unsupported Culture Pin
Heath Stewart19-Jul-04 11:40
protectorHeath Stewart19-Jul-04 11:40 
GeneralRe: CultureInfo for unsupported Culture Pin
Colin Angus Mackay20-Jul-04 2:39
Colin Angus Mackay20-Jul-04 2:39 
GeneralRe: CultureInfo for unsupported Culture Pin
Heath Stewart20-Jul-04 3:56
protectorHeath Stewart20-Jul-04 3:56 
This code gets a manifest resource stream (identitied by the const StreamResource) from a satellite assembly. Unfortunately, you'll still need a valid CultureInfo (sorry, it's been a while since I wrote this; it might still help, though):
public static Stream GetZipResourceStream(CultureInfo culture)
{
  // Get a reference to this assembly.
  Assembly asm = typeof(SiteBuilder).Assembly;

  // Get the neutral resources language, if any.
  CultureInfo neutral = GetNeutralResourcesLanguage(asm);
  if (culture == null || !culture.Equals(neutral))
  {
    // Get the satellite contract version, or use this assembly's version.
    Version v = GetSatelliteContractVersion(asm);
    if (v == null) v = asm.GetName().Version;

    try
    {
      // Now get the satellite assembly for the culture and version.
      asm = asm.GetSatelliteAssembly(culture, v);
    }
    catch
    {
      // Try to get the invariant culture's satellite assembly and version.
      try
      {
        asm = asm.GetSatelliteAssembly(culture.Parent, v);
      }
      catch {}
    }
  }

  // Get the manifest resource stream.
  Stream s = asm.GetManifestResourceStream(SiteResource);
  return s;
}

internal static CultureInfo GetNeutralResourcesLanguage(Assembly a)
{
  if (a == null) throw new ArgumentNullException("a");

  // If the assembly is 'mscorlib.dll', return an invariant culture.
  if (a == typeof(object).Assembly)
    return CultureInfo.InvariantCulture;

  // Try to find the NeutralResourcesLanguageAttribute.
  NeutralResourcesLanguageAttribute[] attrs =
    (NeutralResourcesLanguageAttribute[])
    a.GetCustomAttributes(typeof(NeutralResourcesLanguageAttribute), false);

  // If the attribute wasn't found, return an invariant culture.
  if (attrs.Length == 0) return CultureInfo.InvariantCulture;

  try
  {
    // If the name is valid, return a CultureInfo from it.
    return new CultureInfo(attrs[0].CultureName);
  }
  catch (ThreadAbortException)
  {
    throw;
  }
  catch (Exception ex)
  {
    throw new ArgumentException(
	  BLR.FormatString("InvalidNeutralResourcesLanguageCulture",
      a.ToString(), attrs[0].CultureName), "a", ex);
  }
}

internal static Version GetSatelliteContractVersion(Assembly a)
{
  if (a == null) throw new ArgumentNullException("a");

  // If the assembly is 'mscorlib.dll', return null.
  if (a == typeof(object).Assembly)
    return null;

  SatelliteContractVersionAttribute[] attrs =
    (SatelliteContractVersionAttribute[])
    a.GetCustomAttributes(typeof(SatelliteContractVersionAttribute), false);

  // If the attribute wasn't found, return null.
  if (attrs.Length == 0) return null;

  try
  {
    // If the version is valid, return a Version from it.
    return new Version(attrs[0].Version);
  }
  catch (Exception ex)
  {
    throw new ArgumentException(
	  BLR.FormatString("InvalidSatelliteContractVersion",
      a.ToString(), attrs[0].Version), "a", ex);
  }
}


 

Microsoft MVP, Visual C#
My Articles
GeneralRe: CultureInfo for unsupported Culture Pin
Colin Angus Mackay20-Jul-04 10:45
Colin Angus Mackay20-Jul-04 10:45 
GeneralVery simple search on a form Pin
janigorse19-Jul-04 10:59
janigorse19-Jul-04 10:59 
GeneralRe: Very simple search on a form Pin
Heath Stewart19-Jul-04 11:23
protectorHeath Stewart19-Jul-04 11:23 
Generalintegrate context menu with shell Pin
goooooooogle19-Jul-04 9:52
goooooooogle19-Jul-04 9:52 
GeneralRe: integrate context menu with shell Pin
Nick Parker19-Jul-04 10:40
protectorNick Parker19-Jul-04 10:40 
GeneralRe: integrate context menu with shell Pin
Dave Kreskowiak19-Jul-04 15:24
mveDave Kreskowiak19-Jul-04 15:24 
GeneralRichTextBox Question Pin
bneacetp19-Jul-04 9:44
bneacetp19-Jul-04 9:44 
GeneralRe: RichTextBox Question Pin
leppie19-Jul-04 11:12
leppie19-Jul-04 11:12 
GeneralRe: RichTextBox Question Pin
Heath Stewart19-Jul-04 11:31
protectorHeath Stewart19-Jul-04 11:31 
GeneralRe: RichTextBox Question Pin
bneacetp19-Jul-04 11:40
bneacetp19-Jul-04 11:40 
GeneralPrint button with SSRS Pin
clydeJones19-Jul-04 8:51
clydeJones19-Jul-04 8:51 
GeneralDynamic Help Using HtmlHelp API and COM Interfaces Pin
JimmyG1319-Jul-04 7:57
JimmyG1319-Jul-04 7:57 
GeneralKeyDown event is not firing while draging node on treeview Pin
god4k19-Jul-04 6:51
god4k19-Jul-04 6:51 
GeneralRe: KeyDown event is not firing while draging node on treeview Pin
leppie19-Jul-04 6:59
leppie19-Jul-04 6:59 
GeneralRe: KeyDown event is not firing while draging node on treeview Pin
Heath Stewart19-Jul-04 9:10
protectorHeath Stewart19-Jul-04 9:10 
GeneralReturning a filtered DataTable Pin
Andy H19-Jul-04 6:44
Andy H19-Jul-04 6:44 
GeneralRe: Returning a filtered DataTable Pin
Werdna19-Jul-04 8:58
Werdna19-Jul-04 8:58 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.