private static WindowsTimeZoneCollection LoadTimeZonesFromXml() { WindowsTimeZoneCollection tzs = new WindowsTimeZoneCollection(); XmlSerializer ser = new XmlSerializer(tzs.GetType()); using (StreamReader rs = new StreamReader(tzs.GetType().Assembly.GetManifestResourceStream(tzs.GetType().Namespace + ".WindowsTimeZoneCollection.xml"))) { tzs = ser.Deserialize(rs) as WindowsTimeZoneCollection; } return(tzs); }
static WindowsTimeZone() { RegistryPermission permission = new RegistryPermission( RegistryPermissionAccess.Read, "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones"); try { permission.Demand(); timeZones = LoadTimeZonesFromRegistry(); } catch //(Exception ex) //If we can't get into the Registry for any reason, try the fallback... { //SDH: Requires FullTrust //System.Diagnostics.Debug.WriteLine("Error: LoadTimeZonesFromRegistry " + ex.ToString()); timeZones = LoadTimeZonesFromXml(); } }
private static WindowsTimeZoneCollection LoadTimeZonesFromRegistry() { WindowsTimeZoneCollection tzs = new WindowsTimeZoneCollection(); RegistryKey timeZoneListKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", false); string[] timeZoneKeyNames = timeZoneListKey.GetSubKeyNames(); foreach (string timeZoneKeyName in timeZoneKeyNames) { RegistryKey timeZoneKey = timeZoneListKey.OpenSubKey(timeZoneKeyName); WindowsTimeZone windowsTimeZone = new WindowsTimeZone( timeZoneKey.GetValue("Display") as string, timeZoneKey.GetValue("Dlt") as string, timeZoneKey.GetValue("Std") as string, (int)timeZoneKey.GetValue("Index"), timeZoneKey.GetValue("TZI") as byte[]); tzs.Add(windowsTimeZone); } tzs.SortByTimeZoneBias(); return(tzs); }
public Enumerator(WindowsTimeZoneCollection collection) { this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator(); }
private static WindowsTimeZoneCollection LoadTimeZonesFromXml() { WindowsTimeZoneCollection tzs = new WindowsTimeZoneCollection(); XmlSerializer ser = new XmlSerializer(tzs.GetType()); using (StreamReader rs = new StreamReader(tzs.GetType().Assembly.GetManifestResourceStream(tzs.GetType().Namespace + ".WindowsTimeZoneCollection.xml"))) { tzs = ser.Deserialize(rs) as WindowsTimeZoneCollection; } return tzs; }
private static WindowsTimeZoneCollection LoadTimeZonesFromRegistry() { WindowsTimeZoneCollection tzs = new WindowsTimeZoneCollection(); RegistryKey timeZoneListKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Time Zones", false); string[] timeZoneKeyNames = timeZoneListKey.GetSubKeyNames(); foreach (string timeZoneKeyName in timeZoneKeyNames) { RegistryKey timeZoneKey = timeZoneListKey.OpenSubKey(timeZoneKeyName); WindowsTimeZone windowsTimeZone = new WindowsTimeZone( timeZoneKey.GetValue("Display") as string, timeZoneKey.GetValue("Dlt") as string, timeZoneKey.GetValue("Std") as string, (int)timeZoneKey.GetValue("Index" ), timeZoneKey.GetValue("TZI") as byte[] ); tzs.Add( windowsTimeZone ); } tzs.SortByTimeZoneBias(); return tzs; }