Changeset 1565 for trunk/sources
- Timestamp:
- 04/16/09 12:43:01 (16 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence.GUI/3.3/PersistenceConfigurationForm.cs
r1542 r1565 9 9 using System.Text; 10 10 using HeuristicLab.Persistence.Default.Decomposers; 11 using HeuristicLab.PluginInfrastructure; 11 12 12 13 namespace HeuristicLab.Persistence.GUI { … … 15 16 16 17 private readonly Dictionary<string, IFormatter> formatterTable; 18 private readonly Dictionary<string, bool> simpleFormatterTable; 17 19 private readonly Dictionary<IFormatter, string> reverseFormatterTable; 18 20 private readonly Dictionary<string, Type> typeNameTable; … … 22 24 InitializeComponent(); 23 25 formatterTable = new Dictionary<string, IFormatter>(); 26 simpleFormatterTable = new Dictionary<string, bool>(); 24 27 reverseFormatterTable = new Dictionary<IFormatter, string>(); 25 28 typeNameTable = new Dictionary<string, Type>(); 26 reverseTypeNameTable = new Dictionary<Type, string>(); 27 initializeConfigPages(); 29 reverseTypeNameTable = new Dictionary<Type, string>(); 30 InitializeNameTables(); 31 initializeConfigPages(); 28 32 UpdateFromConfigurationService(); 29 33 } … … 68 72 69 73 private void UpdateFromConfigurationService() { 70 foreach ( IFormat format in ConfigurationService.Instance.Formatters.Keys) {71 Configuration config = ConfigurationService.Instance.GetConfiguration(format); 74 foreach ( IFormat format in ConfigurationService.Instance.Formats ) { 75 Configuration config = ConfigurationService.Instance.GetConfiguration(format); 72 76 UpdateFormatterGrid( 73 77 (DataGridView)GetControlsOnPage(format.Name, "GridView"), … … 80 84 81 85 private void initializeConfigPages() { 82 configurationTabs.TabPages.Clear(); 83 foreach ( var formats in ConfigurationService.Instance.Formatters ) { 84 TabPage page = new TabPage(formats.Key.Name) { 85 Name = formats.Key.Name, 86 Tag = formats.Key, 86 configurationTabs.TabPages.Clear(); 87 foreach ( IFormat format in ConfigurationService.Instance.Formats ) { 88 List<IFormatter> formatters = ConfigurationService.Instance.Formatters[format.SerialDataType]; 89 TabPage page = new TabPage(format.Name) { 90 Name = format.Name, 91 Tag = format, 87 92 }; 88 93 configurationTabs.TabPages.Add(page); … … 103 108 DataGridView gridView = createGridView(); 104 109 verticalSplit.Panel2.Controls.Add(gridView); 105 fillDataGrid(gridView, format s.Value);110 fillDataGrid(gridView, formatters); 106 111 ListBox checkBox = new ListBox { 107 112 Name = "CheckBox", … … 171 176 } 172 177 173 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 174 updateNameTables(formatters); 178 private void fillDataGrid(DataGridView gridView, IEnumerable<IFormatter> formatters) { 175 179 Dictionary<string, List<string>> formatterMap = createFormatterMap(formatters); 176 180 foreach ( var formatterMapping in formatterMap ) { … … 196 200 foreach (var formatter in formatters) { 197 201 string formatterName = reverseFormatterTable[formatter]; 198 string typeName = reverseTypeNameTable[formatter. Type];202 string typeName = reverseTypeNameTable[formatter.SourceType]; 199 203 if (!formatterMap.ContainsKey(typeName)) 200 204 formatterMap.Add(typeName, new List<string>()); … … 204 208 } 205 209 206 private void updateNameTables(IEnumerable<IFormatter> formatters) { 207 foreach (var formatter in formatters) { 208 string formatterName = formatter.GetType().Name; 209 if (formatterTable.ContainsKey(formatterName)) { 210 IFormatter otherFormatter = formatterTable[formatterName]; 211 formatterTable.Remove(formatterName); 212 reverseFormatterTable.Remove(otherFormatter); 213 formatterTable.Add(otherFormatter.GetType().VersionInvariantName(), otherFormatter); 214 reverseFormatterTable.Add(otherFormatter, otherFormatter.GetType().VersionInvariantName()); 215 formatterName = formatter.GetType().VersionInvariantName(); 210 private void InitializeNameTables() { 211 foreach (var serialDataType in ConfigurationService.Instance.Formatters.Keys) { 212 foreach (var formatter in ConfigurationService.Instance.Formatters[serialDataType]) { 213 string formatterName = formatter.GetType().Name; 214 if (simpleFormatterTable.ContainsKey(formatterName)) { 215 IFormatter otherFormatter = formatterTable[formatterName]; 216 formatterTable.Remove(formatterName); 217 reverseFormatterTable.Remove(otherFormatter); 218 formatterTable.Add(otherFormatter.GetType().VersionInvariantName(), otherFormatter); 219 reverseFormatterTable.Add(otherFormatter, otherFormatter.GetType().VersionInvariantName()); 220 formatterName = formatter.GetType().VersionInvariantName(); 221 } 222 simpleFormatterTable[formatter.GetType().Name] = true; 223 formatterTable.Add(formatterName, formatter); 224 reverseFormatterTable.Add(formatter, formatterName); 225 226 string typeName = formatter.SourceType.IsGenericType ? 227 formatter.SourceType.SimpleFullName() : 228 formatter.SourceType.Name; 229 if (typeNameTable.ContainsKey(typeName)) { 230 Type otherType = typeNameTable[typeName]; 231 if (otherType != formatter.SourceType) { 232 typeNameTable.Remove(typeName); 233 reverseTypeNameTable.Remove(otherType); 234 typeNameTable.Add(otherType.VersionInvariantName(), otherType); 235 reverseTypeNameTable.Add(otherType, otherType.VersionInvariantName()); 236 typeName = formatter.SourceType.VersionInvariantName(); 237 typeNameTable.Add(typeName, formatter.SourceType); 238 reverseTypeNameTable.Add(formatter.SourceType, typeName); 239 } 240 } else { 241 typeNameTable.Add(typeName, formatter.SourceType); 242 reverseTypeNameTable.Add(formatter.SourceType, typeName); 243 } 216 244 } 217 formatterTable.Add(formatterName, formatter);218 reverseFormatterTable.Add(formatter, formatterName);219 220 string typeName = formatter.Type.IsGenericType ?221 formatter.Type.SimpleFullName() :222 formatter.Type.Name;223 if (typeNameTable.ContainsKey(typeName)) {224 Type otherType = typeNameTable[typeName];225 if (otherType != formatter.Type) {226 typeNameTable.Remove(typeName);227 reverseTypeNameTable.Remove(otherType);228 typeNameTable.Add(otherType.VersionInvariantName(), otherType);229 reverseTypeNameTable.Add(otherType, otherType.VersionInvariantName());230 typeName = formatter.Type.VersionInvariantName();231 typeNameTable.Add(typeName, formatter.Type);232 reverseTypeNameTable.Add(formatter.Type, typeName);233 }234 } else {235 typeNameTable.Add(typeName, formatter.Type);236 reverseTypeNameTable.Add(formatter.Type, typeName);237 }238 245 } 239 246 } … … 321 328 } 322 329 323 private Configuration GenerateConfiguration( DataGridView formatterGrid, ListView decomposerList) {330 private Configuration GenerateConfiguration(IFormat format, DataGridView formatterGrid, ListView decomposerList) { 324 331 if (formatterGrid == null || decomposerList == null) 325 332 return null; … … 340 347 decomposers.Add((IDecomposer)item.Tag); 341 348 } 342 return new Configuration(formatters, decomposers); 343 } 344 345 private Configuration GetActiveConfiguration() { 346 return GenerateConfiguration( 349 return new Configuration(format, formatters, decomposers); 350 } 351 352 private Configuration GetActiveConfiguration() { 353 IFormat format = (IFormat)configurationTabs.SelectedTab.Tag; 354 return GenerateConfiguration(format, 347 355 (DataGridView)GetActiveControl("GridView"), 348 356 (ListView)GetActiveControl("DecomposerList")); … … 350 358 351 359 private Configuration GetConfiguration(IFormat format) { 352 return GenerateConfiguration( 360 return GenerateConfiguration(format, 353 361 (DataGridView)GetControlsOnPage(format.Name, "GridView"), 354 362 (ListView)GetControlsOnPage(format.Name, "DecomposerList")); … … 359 367 if (format != null) 360 368 ConfigurationService.Instance.DefineConfiguration( 361 format,362 369 GetActiveConfiguration()); 363 370 } … … 365 372 } 366 373 374 public class Empty : ISerialData { } 375 367 376 [EmptyStorableClass] 368 public class EmptyFormat : FormatBase {377 public class EmptyFormat : FormatBase<Empty> { 369 378 public override string Name { get { return "Empty"; } } 370 public static EmptyFormat Instance = new EmptyFormat();371 379 } 372 380 373 381 [EmptyStorableClass] 374 public class EmptyFormatter : IFormatter { 375 376 public Type Type { get { return typeof(Type); } } 377 public IFormat Format { get { return EmptyFormat.Instance; } } 378 379 public object DoFormat(object o) { 382 public class EmptyFormatter : FormatterBase<Type, Empty> { 383 384 public override Empty Format(Type o) { 380 385 return null; 381 386 } 382 387 383 public o bject Parse(objecto) {388 public override Type Parse(Empty o) { 384 389 return null; 385 390 } … … 387 392 388 393 [EmptyStorableClass] 389 public class FakeBoolean2XmlFormatter : IFormatter { 390 391 public Type Type { get { return typeof (Boolean); } } 392 393 public IFormat Format { get { return XmlFormat.Instance; } } 394 395 public object DoFormat(object o) { 394 public class FakeBoolean2XmlFormatter : FormatterBase<bool, Empty> { 395 396 public override Empty Format(bool o) { 396 397 return null; 397 398 } 398 399 399 public object Parse(object o) { 400 public override bool Parse(Empty o) { 401 return false; 402 } 403 } 404 405 [EmptyStorableClass] 406 public class Int2XmlFormatter : FormatterBase<int, Empty> { 407 408 public override Empty Format(int o) { 400 409 return null; 401 } 402 } 403 404 [EmptyStorableClass] 405 public class Int2XmlFormatter: IFormatter { 406 public Type Type { get { return typeof (int); } } 407 public IFormat Format { get { return XmlFormat.Instance; } } 408 public object DoFormat(object o) { 409 return null; 410 } 411 public object Parse(object o) { 412 return null; 413 } 410 } 411 412 public override int Parse(Empty o) { 413 return 0; 414 } 415 414 416 } 415 417 … … 424 426 private static void SimpleFullName(Type type, StringBuilder sb) { 425 427 if (type.IsGenericType) { 426 sb.Append(type.Name, 0, type.Name.LastIndexOf('`')); 428 sb.Append(type.Name, 0, type.Name.LastIndexOf('`')); 427 429 sb.Append("<"); 428 430 foreach (Type t in type.GetGenericArguments()) { 429 SimpleFullName(t, sb); 431 SimpleFullName(t, sb); 430 432 sb.Append(", "); 431 433 } -
trunk/sources/HeuristicLab.Persistence.Test/NewSerializationTest.cs
r1554 r1565 6 6 using HeuristicLab.Persistence.Default.Xml; 7 7 using HeuristicLab.Persistence.Interfaces; 8 using HeuristicLab.Persistence.Default.ViewOnly;9 8 using HeuristicLab.Tracing; 10 9 using log4net; 11 10 using log4net.Config; 11 using HeuristicLab.Persistence.Default.ViewOnly; 12 12 13 13 namespace HeuristicLab.Persistence.Test { … … 273 273 Console.WriteLine(ViewOnlyGenerator.Serialize(o)); 274 274 } 275 276 public static void Test9() { 277 Root r = new Root(); 278 //BinaryGenerator.Serialize(r, "test.bin"); 279 } 275 280 276 281 class Float { … … 279 284 } 280 285 281 public static void Test 9() {286 public static void Test10() { 282 287 XmlGenerator.Serialize(12.3f, "test9.zip"); 283 288 object o = XmlParser.DeSerialize("test9.zip"); … … 299 304 Test8(); 300 305 Test9(); 306 Test10(); 301 307 //SpeedTest(); 302 308 //SpeedTest2();
Note: See TracChangeset
for help on using the changeset viewer.