Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/14/11 13:59:25 (13 years ago)
Author:
epitzer
Message:

#1530 integrate changes from trunk

Location:
branches/PersistenceSpeedUp
Files:
12 edited
1 copied

Legend:

Unmodified
Added
Removed
  • branches/PersistenceSpeedUp

  • branches/PersistenceSpeedUp/HeuristicLab.Persistence

  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Core/ConfigurationService.cs

    r5445 r6760  
    4242
    4343    private static ConfigurationService instance;
     44    private static object locker = new object();
    4445    private readonly Dictionary<IFormat, Configuration> customConfigurations;
    4546
     
    6566    public static ConfigurationService Instance {
    6667      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        }
    7073      }
    7174    }
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Core/Serializer.cs

    r6737 r6760  
    210210        }
    211211        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());
    214214          return CompositeEnumerator(
    215215            name,
     
    218218            typeId,
    219219            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) {
    222224        if (isTestRun) {
    223225          exceptions.Add(x);
     
    226228          throw;
    227229        } 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);
    229234        }
    230235      } finally {
     
    233238    }
    234239
    235     private PersistenceException CreatePersistenceException(Type type, string message, Exception x) {
     240    private PersistenceException CreatePersistenceException(Type type, string message, bool appendConfig) {
    236241      StringBuilder sb = new StringBuilder();
    237242      sb.Append(message)
     
    240245        .AppendLine("\"")
    241246        .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      }
    256263      return new PersistenceException(sb.ToString());
    257264    }
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/NumberEnumerable2StringSerializer.cs

    r5445 r6760  
    4646
    4747    private static readonly Dictionary<Type, Type> interfaceCache = new Dictionary<Type, Type>();
     48    private static readonly object locker = new object();
    4849
    4950    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          }
    5861        }
     62        interfaceCache.Add(type, null);
    5963      }
    60       interfaceCache.Add(type, null);
    6164      return null;
    6265    }
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Default/Xml/Primitive/System.Drawing/Bitmap2XmlSerializer.cs

    r5445 r6760  
    3030    public override XmlString Format(Bitmap o) {
    3131      MemoryStream stream = new MemoryStream();
    32       o.Save(stream, ImageFormat.Png);
     32      lock (o)
     33        o.Save(stream, ImageFormat.Png);
    3334      byte[] array = stream.ToArray();
    3435      Byte1DArray2XmlSerializer serializer = new Byte1DArray2XmlSerializer();
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/HeuristicLab.Persistence-3.3.csproj

    r6737 r6760  
    211211    <Compile Include="Default\Xml\Primitive\SimpleNumber2XmlSerializerBase.cs" />
    212212    <Compile Include="Default\Xml\Primitive\String2XmlSerializer.cs" />
     213    <Compile Include="Default\Xml\Primitive\System.Drawing\Font2XmlSerializer.cs" />
    213214    <Compile Include="Default\Xml\Primitive\TimeSpan2XmlSerializer.cs" />
    214215    <Compile Include="Default\Xml\Primitive\UInt2XmlSerializer.cs" />
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/HeuristicLabPersistencePlugin.cs.frame

    r6099 r6760  
    2727  /// The plugin for HeuriticLab.Persistence
    2828  /// </summary>
    29   [Plugin("HeuristicLab.Persistence", "3.3.4.$WCREV$")]
     29  [Plugin("HeuristicLab.Persistence", "3.3.5.$WCREV$")]
    3030  [PluginFile("HeuristicLab.Persistence-3.3.dll", PluginFileType.Assembly)]
    3131  [PluginDependency("HeuristicLab.Tracing", "3.3")]
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Properties/AssemblyInfo.frame

    r6099 r6760  
    5252//
    5353[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  
    107107  </ItemGroup>
    108108  <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>
    109113    <ProjectReference Include="..\HeuristicLab.Persistence-3.3.csproj">
    110114      <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>
  • branches/PersistenceSpeedUp/HeuristicLab.Persistence/3.3/Tests/Properties/AssemblyInfo.cs

    r5446 r6760  
    5353// by using the '*' as shown below:
    5454[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  
    3939using HeuristicLab.Persistence.Interfaces;
    4040using Microsoft.VisualStudio.TestTools.UnitTesting;
     41using System.Threading.Tasks;
     42using HeuristicLab.Algorithms.GeneticAlgorithm;
    4143
    4244namespace HeuristicLab.Persistence_33.Tests {
     
    11111113      public OneWayTest() { this.value = "default"; }
    11121114      public string value;
    1113       [Storable(AllowOneWay=true)]
     1115      [Storable(AllowOneWay = true)]
    11141116      public string ReadOnly {
    11151117        get { return "ReadOnly"; }
    11161118      }
    1117       [Storable(AllowOneWay=true)]
     1119      [Storable(AllowOneWay = true)]
    11181120      public string WriteOnly {
    11191121        set { this.value = value; }
     
    11831185    }
    11841186
    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    }
    11861240
    11871241    [ClassInitialize]
Note: See TracChangeset for help on using the changeset viewer.