public int Execute(WindowsMapperCompilerOptions options) { log.Info("Starting compilation of {0}", options.SourceFileName); DateTimeZone.SetUtcOnly(true); var inputFile = new FileInfo(options.SourceFileName); if (!inputFile.Exists) { log.Error("Source file {0} does not exist", inputFile.FullName); return 2; } var mappings = ReadInput(inputFile); using (var output = new ResourceOutput(WindowsToPosixResource.WindowToPosixMapBase, options.OutputType)) { log.Info("Compiling to {0}", output.OutputFileName); output.WriteDictionary(WindowsToPosixResource.WindowToPosixMapKey, mappings); } log.Info("Finished compiling.", options.SourceFileName); return 0; }
/// <summary> /// Generates the date time zones from the given parsed time zone information object. /// </summary> /// <remarks> /// <para> /// First we go through the list of time zones and generate an <see cref="DateTimeZone" /> /// object for each one. We create a mapping between the time zone name and itself (for /// writing out later). Then we write out the time zone as a resource to the current writer. /// </para> /// <para> /// Second we go through all of the alias mappings and find the actual time zone that they /// map to. we do this by redirecting through aliases until there are no more aliases. This /// allows for on alias to refer to another. We add the alias mapping to the time zone /// mapping created in the first step. When done, we write out the entire mapping as a /// resource. The keys of the mapping can be used as the list of valid time zone ids /// supported by this resource file. /// </para> /// </remarks> /// <param name="database">The database of parsed zone info records.</param> /// <param name="output">The output file <see cref="ResourceOutput" />.</param> private static void GenerateDateTimeZones(TzdbDatabase database, ResourceOutput output) { var timeZoneMap = new Dictionary<string, string>(); foreach (var zoneList in database.Zones) { var timeZone = CreateTimeZone(zoneList, database.Rules); timeZoneMap.Add(timeZone.Id, timeZone.Id); output.WriteTimeZone(timeZone.Id, timeZone); } foreach (var key in database.Aliases.Keys) { var value = database.Aliases[key]; while (database.Aliases.ContainsKey(value)) { value = database.Aliases[value]; } timeZoneMap.Add(key, value); } output.WriteDictionary(DateTimeZoneResourceProvider.IdMapKey, timeZoneMap); }