public static void EnsureField(this FieldCollection flds, string cInternalName, string cFieldTitle, string cFieldDescription, string cGroup) { try { if (!flds.HasField(cFieldTitle, cInternalName)) { flds.AddField(cInternalName, cFieldTitle, cFieldDescription, cGroup); } } catch (Exception ex) { throw new Exception(string.Format("Error in extFieldCollection.EnsureField - {0} - {1}", cFieldTitle, ex.Message), ex); } }
/// <summary> /// 表示名、型を指定して、 /// フィールドを追加します。 /// </summary> /// <param name="this">フィールドコレクション</param> /// <param name="displayName">表示名</param> /// <param name="type">型</param> /// <returns>フィールドを返します。</returns> public static Field AddField(this FieldCollection @this, string displayName, FieldType type) { var xml = new XmlField() { DisplayName = displayName, Type = type.ToString(), }; return(@this.AddField(new XmlField() { DisplayName = displayName, Type = type.ToString(), })); }
public void Write( TzdbDatabase database, WindowsZones cldrWindowsZones, IDictionary<string, string> additionalWindowsNameToIdMappings, Stream stream) { FieldCollection fields = new FieldCollection(); var zones = database.GenerateDateTimeZones().ToList(); var stringPool = CreateOptimizedStringPool(zones, database.ZoneLocations, database.Zone1970Locations, cldrWindowsZones); // First assemble the fields (writing to the string pool as we go) foreach (var zone in zones) { var zoneField = fields.AddField(TzdbStreamFieldId.TimeZone, stringPool); WriteZone(zone, zoneField.Writer); } fields.AddField(TzdbStreamFieldId.TzdbVersion, null).Writer.WriteString(database.Version); // Normalize the aliases var timeZoneMap = new Dictionary<string, string>(); 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); } fields.AddField(TzdbStreamFieldId.TzdbIdMap, stringPool).Writer.WriteDictionary(timeZoneMap); // Windows mappings cldrWindowsZones.Write(fields.AddField(TzdbStreamFieldId.CldrSupplementalWindowsZones, stringPool).Writer); fields.AddField(TzdbStreamFieldId.WindowsAdditionalStandardNameToIdMapping, stringPool).Writer.WriteDictionary (additionalWindowsNameToIdMappings.ToDictionary(pair => pair.Key, pair => cldrWindowsZones.PrimaryMapping[pair.Value])); // Zone locations, if any. var zoneLocations = database.ZoneLocations; if (zoneLocations != null) { var field = fields.AddField(TzdbStreamFieldId.ZoneLocations, stringPool); field.Writer.WriteCount(zoneLocations.Count); foreach (var zoneLocation in zoneLocations) { zoneLocation.Write(field.Writer); } } // Zone 1970 locations, if any. var zone1970Locations = database.Zone1970Locations; if (zone1970Locations != null) { var field = fields.AddField(TzdbStreamFieldId.Zone1970Locations, stringPool); field.Writer.WriteCount(zone1970Locations.Count); foreach (var zoneLocation in zone1970Locations) { zoneLocation.Write(field.Writer); } } var stringPoolField = fields.AddField(TzdbStreamFieldId.StringPool, null); stringPoolField.Writer.WriteCount(stringPool.Count); foreach (string value in stringPool) { stringPoolField.Writer.WriteString(value); } // Now write all the fields out, in the right order. new BinaryWriter(stream).Write(Version); fields.WriteTo(stream); }
public void Write(TzdbDatabase database, WindowsZones cldrWindowsZones) { FieldCollection fields = new FieldCollection(); var zones = database.GenerateDateTimeZones().ToList(); var stringPool = CreateOptimizedStringPool(zones, database.ZoneLocations, cldrWindowsZones); // First assemble the fields (writing to the string pool as we go) foreach (var zone in zones) { var zoneField = fields.AddField(TzdbStreamFieldId.TimeZone, stringPool); WriteZone(zone, zoneField.Writer); } fields.AddField(TzdbStreamFieldId.TzdbVersion, null).Writer.WriteString(database.Version); // Normalize the aliases var timeZoneMap = new Dictionary <string, string>(); 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); } fields.AddField(TzdbStreamFieldId.TzdbIdMap, stringPool).Writer.WriteDictionary(timeZoneMap); // Windows mappings cldrWindowsZones.Write(fields.AddField(TzdbStreamFieldId.CldrSupplementalWindowsZones, stringPool).Writer); fields.AddField(TzdbStreamFieldId.WindowsAdditionalStandardNameToIdMapping, stringPool).Writer.WriteDictionary (PclSupport.StandardNameToIdMap.ToDictionary(pair => pair.Key, pair => cldrWindowsZones.PrimaryMapping[pair.Value])); // Zone locations, if any. var zoneLocations = database.ZoneLocations; if (zoneLocations != null) { var field = fields.AddField(TzdbStreamFieldId.ZoneLocations, stringPool); field.Writer.WriteCount(zoneLocations.Count); foreach (var zoneLocation in zoneLocations) { zoneLocation.Write(field.Writer); } } var stringPoolField = fields.AddField(TzdbStreamFieldId.StringPool, null); stringPoolField.Writer.WriteCount(stringPool.Count); foreach (string value in stringPool) { stringPoolField.Writer.WriteString(value); } // Now write all the fields out, in the right order. new BinaryWriter(stream).Write(Version); fields.WriteTo(stream); stream.Close(); }