Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Persistence
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 12 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Persistence
- Property svn:mergeinfo changed
-
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs
r5445 r6760 42 42 43 43 private static ConfigurationService instance; 44 private static object locker = new object(); 44 45 private readonly Dictionary<IFormat, Configuration> customConfigurations; 45 46 … … 65 66 public static ConfigurationService Instance { 66 67 get { 67 if (instance == null) 68 instance = new ConfigurationService(); 69 return instance; 68 lock (locker) { 69 if (instance == null) 70 instance = new ConfigurationService(); 71 return instance; 72 } 70 73 } 71 74 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Core/Serializer.cs
r6737 r6760 210 210 } 211 211 ICompositeSerializer compositeSerializer = configuration.GetCompositeSerializer(type); 212 typeCache.SetSerializer(typeId, compositeSerializer.GetType());213 if (compositeSerializer != null)212 if (compositeSerializer != null) { 213 typeCache.SetSerializer(typeId, compositeSerializer.GetType()); 214 214 return CompositeEnumerator( 215 215 name, … … 218 218 typeId, 219 219 compositeSerializer.CreateMetaInfo(value)); 220 throw CreatePersistenceException(type, "Could not determine how to serialize a value.", null); 221 } catch (Exception x) { 220 } 221 throw CreatePersistenceException(type, "Could not determine how to serialize a value.", true); 222 } 223 catch (Exception x) { 222 224 if (isTestRun) { 223 225 exceptions.Add(x); … … 226 228 throw; 227 229 } else { 228 throw CreatePersistenceException(type, "Uncaught exception during serialization: ", x); 230 throw CreatePersistenceException( 231 type, 232 string.Format("Uncaught exception during serialization:{0}{1}", Environment.NewLine, x), 233 false); 229 234 } 230 235 } finally { … … 233 238 } 234 239 235 private PersistenceException CreatePersistenceException(Type type, string message, Exception x) {240 private PersistenceException CreatePersistenceException(Type type, string message, bool appendConfig) { 236 241 StringBuilder sb = new StringBuilder(); 237 242 sb.Append(message) … … 240 245 .AppendLine("\"") 241 246 .Append("object graph location: ") 242 .AppendLine(string.Join(".", objectGraphTrace.ToArray())) 243 .AppendLine("No registered primitive serializer for this type:"); 244 foreach (var ps in configuration.PrimitiveSerializers) 245 sb.Append(ps.SourceType.VersionInvariantName()) 246 .Append(" ---- (") 247 .Append(ps.GetType().VersionInvariantName()) 248 .AppendLine(")"); 249 sb.AppendLine("Rejected by all composite serializers:"); 250 foreach (var cs in configuration.CompositeSerializers) 251 sb.Append("\"") 252 .Append(cs.JustifyRejection(type)) 253 .Append("\" ---- (") 254 .Append(cs.GetType().VersionInvariantName()) 255 .AppendLine(")"); 247 .AppendLine(string.Join(".", objectGraphTrace.ToArray())); 248 if (appendConfig) { 249 sb.AppendLine("No registered primitive serializer for this type:"); 250 foreach (var ps in configuration.PrimitiveSerializers) 251 sb.Append(ps.SourceType.VersionInvariantName()) 252 .Append(" ---- (") 253 .Append(ps.GetType().VersionInvariantName()) 254 .AppendLine(")"); 255 sb.AppendLine("Rejected by all composite serializers:"); 256 foreach (var cs in configuration.CompositeSerializers) 257 sb.Append("\"") 258 .Append(cs.JustifyRejection(type)) 259 .Append("\" ---- (") 260 .Append(cs.GetType().VersionInvariantName()) 261 .AppendLine(")"); 262 } 256 263 return new PersistenceException(sb.ToString()); 257 264 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/NumberEnumerable2StringSerializer.cs
r5445 r6760 46 46 47 47 private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>(); 48 private static readonly object locker = new object(); 48 49 49 50 public Type GetGenericEnumerableInterface(Type type) { 50 if (interfaceCache.ContainsKey(type)) 51 return interfaceCache[type]; 52 foreach (Type iface in type.GetInterfaces()) { 53 if (iface.IsGenericType && 54 iface.GetGenericTypeDefinition() == typeof(IEnumerable<>) && 55 numberConverter.CanSerialize(iface.GetGenericArguments()[0])) { 56 interfaceCache.Add(type, iface); 57 return iface; 51 lock (locker) { 52 if (interfaceCache.ContainsKey(type)) 53 return interfaceCache[type]; 54 foreach (Type iface in type.GetInterfaces()) { 55 if (iface.IsGenericType && 56 iface.GetGenericTypeDefinition() == typeof(IEnumerable<>) && 57 numberConverter.CanSerialize(iface.GetGenericArguments()[0])) { 58 interfaceCache.Add(type, iface); 59 return iface; 60 } 58 61 } 62 interfaceCache.Add(type, null); 59 63 } 60 interfaceCache.Add(type, null);61 64 return null; 62 65 } -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Bitmap2XmlSerializer.cs
r5445 r6760 30 30 public override XmlString Format(Bitmap o) { 31 31 MemoryStream stream = new MemoryStream(); 32 o.Save(stream, ImageFormat.Png); 32 lock (o) 33 o.Save(stream, ImageFormat.Png); 33 34 byte[] array = stream.ToArray(); 34 35 Byte1DArray2XmlSerializer serializer = new Byte1DArray2XmlSerializer(); -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj
r6737 r6760 211 211 <Compile Include="Default\Xml\Primitive\SimpleNumber2XmlSerializerBase.cs" /> 212 212 <Compile Include="Default\Xml\Primitive\String2XmlSerializer.cs" /> 213 <Compile Include="Default\Xml\Primitive\System.Drawing\Font2XmlSerializer.cs" /> 213 214 <Compile Include="Default\Xml\Primitive\TimeSpan2XmlSerializer.cs" /> 214 215 <Compile Include="Default\Xml\Primitive\UInt2XmlSerializer.cs" /> -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/HeuristicLabPersistencePlugin.cs.frame
r6099 r6760 27 27 /// The plugin for HeuriticLab.Persistence 28 28 /// </summary> 29 [Plugin("HeuristicLab.Persistence", "3.3. 4.$WCREV$")]29 [Plugin("HeuristicLab.Persistence", "3.3.5.$WCREV$")] 30 30 [PluginFile("HeuristicLab.Persistence-3.3.dll", PluginFileType.Assembly)] 31 31 [PluginDependency("HeuristicLab.Tracing", "3.3")] -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Properties/AssemblyInfo.frame
r6099 r6760 52 52 // 53 53 [assembly: AssemblyVersion("3.3.0.0")] 54 [assembly: AssemblyFileVersion("3.3. 4.$WCREV$")]54 [assembly: AssemblyFileVersion("3.3.5.$WCREV$")] -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Tests/HeuristicLab.Persistence-3.3.Tests.csproj
r4065 r6760 107 107 </ItemGroup> 108 108 <ItemGroup> 109 <ProjectReference Include="..\..\..\HeuristicLab.Algorithms.GeneticAlgorithm\3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj"> 110 <Project>{A51DA44F-CB35-4F6F-99F5-2A2E904AB93B}</Project> 111 <Name>HeuristicLab.Algorithms.GeneticAlgorithm-3.3</Name> 112 </ProjectReference> 109 113 <ProjectReference Include="..\HeuristicLab.Persistence-3.3.csproj"> 110 114 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project> -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Tests/Properties/AssemblyInfo.cs
r5446 r6760 53 53 // by using the '*' as shown below: 54 54 [assembly: AssemblyVersion("3.3.0.0")] 55 [assembly: AssemblyFileVersion("3.3. 3.0")]55 [assembly: AssemblyFileVersion("3.3.5.0")] -
branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Tests/UseCases.cs
r6737 r6760 39 39 using HeuristicLab.Persistence.Interfaces; 40 40 using Microsoft.VisualStudio.TestTools.UnitTesting; 41 using System.Threading.Tasks; 42 using HeuristicLab.Algorithms.GeneticAlgorithm; 41 43 42 44 namespace HeuristicLab.Persistence_33.Tests { … … 1111 1113 public OneWayTest() { this.value = "default"; } 1112 1114 public string value; 1113 [Storable(AllowOneWay =true)]1115 [Storable(AllowOneWay = true)] 1114 1116 public string ReadOnly { 1115 1117 get { return "ReadOnly"; } 1116 1118 } 1117 [Storable(AllowOneWay =true)]1119 [Storable(AllowOneWay = true)] 1118 1120 public string WriteOnly { 1119 1121 set { this.value = value; } … … 1183 1185 } 1184 1186 1185 1187 [TestMethod] 1188 public void FontTest() { 1189 List<Font> fonts = new List<Font>() { 1190 new Font(FontFamily.GenericSansSerif, 12), 1191 new Font("Times New Roman", 21, FontStyle.Bold, GraphicsUnit.Pixel), 1192 new Font("Courier New", 10, FontStyle.Underline, GraphicsUnit.Document), 1193 new Font("Helvetica", 21, FontStyle.Strikeout, GraphicsUnit.Inch, 0, true), 1194 }; 1195 XmlGenerator.Serialize(fonts, tempFile); 1196 var newFonts = XmlParser.Deserialize<List<Font>>(tempFile); 1197 Assert.AreEqual(fonts[0], newFonts[0]); 1198 Assert.AreEqual(fonts[1], newFonts[1]); 1199 Assert.AreEqual(fonts[2], newFonts[2]); 1200 Assert.AreEqual(fonts[3], newFonts[3]); 1201 } 1202 1203 [TestMethod] 1204 public void ConcurrencyTest() { 1205 int n = 20; 1206 Task[] tasks = new Task[n]; 1207 for (int i = 0; i < n; i++) { 1208 tasks[i] = Task.Factory.StartNew((idx) => { 1209 byte[] data; 1210 using(var stream = new MemoryStream()) { 1211 XmlGenerator.Serialize(new GeneticAlgorithm(), stream); 1212 data = stream.ToArray(); 1213 } 1214 }, i); 1215 } 1216 Task.WaitAll(tasks); 1217 } 1218 1219 [TestMethod] 1220 public void ConcurrentBitmapTest() { 1221 Bitmap b = new Bitmap(300, 300); 1222 Random r = new Random(); 1223 for (int x = 0; x<b.Height; x++) { 1224 for (int y = 0; y<b.Width; y++) { 1225 b.SetPixel(x, y, Color.FromArgb(r.Next())); 1226 } 1227 } 1228 Task[] tasks = new Task[20]; 1229 byte[][] datas = new byte[tasks.Length][]; 1230 for (int i = 0; i<tasks.Length; i++) { 1231 tasks[i] = Task.Factory.StartNew((idx) => { 1232 using (var stream = new MemoryStream()) { 1233 XmlGenerator.Serialize(b, stream); 1234 datas[(int)idx] = stream.ToArray(); 1235 } 1236 }, i); 1237 } 1238 Task.WaitAll(tasks); 1239 } 1186 1240 1187 1241 [ClassInitialize]
Note: See TracChangeset
for help on using the changeset viewer.