Changeset 17000
- Timestamp:
- 05/31/19 13:56:47 (5 years ago)
- Location:
- branches/2925_AutoDiffForDynamicalModels
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2925_AutoDiffForDynamicalModels
- Property svn:mergeinfo changed
/trunk merged: 16992,16997
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Common/3.3/Content/ContentManager.cs
r16662 r17000 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using System.Threading; 26 using System.Threading.Tasks; 27 using HEAL.Attic; 24 28 25 29 namespace HeuristicLab.Common { 26 30 public abstract class ContentManager { 31 public class Info { 32 public Info() { } 33 34 public Info(string filename, TimeSpan duration) { 35 Filename = filename; 36 Duration = duration; 37 } 38 39 public Info(string filename, SerializationInfo serInfo) { 40 Filename = filename; 41 Duration = serInfo.Duration; 42 UnknownTypeGuids = serInfo.UnknownTypeGuids; 43 NumberOfSerializedObjects = serInfo.NumberOfSerializedObjects; 44 SerializedTypes = serInfo.SerializedTypes; 45 } 46 47 public TimeSpan Duration { get; internal set; } 48 public IEnumerable<Guid> UnknownTypeGuids { get; internal set; } = Enumerable.Empty<Guid>(); 49 public int NumberOfSerializedObjects { get; internal set; } 50 public IEnumerable<Type> SerializedTypes { get; internal set; } = Enumerable.Empty<Type>(); 51 public string Filename { get; internal set; } = string.Empty; 52 } 53 27 54 private static ContentManager instance; 28 55 … … 36 63 37 64 public static IStorableContent Load(string filename) { 65 return Load(filename, out var _); 66 } 67 68 public static IStorableContent Load(string filename, out Info serializationInfo) { 38 69 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 39 IStorableContent content = instance.LoadContent(filename); 40 content.Filename = filename; 70 IStorableContent content = instance.LoadContent(filename, out serializationInfo); 71 72 if (content != null) content.Filename = filename; 41 73 return content; 42 74 } 43 public static void LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) { 75 76 77 public static Task LoadAsync(string filename, Action<IStorableContent, Exception> loadingCompletedCallback) { 78 return LoadAsync(filename, (content, error, info) => loadingCompletedCallback(content, error)); // drop info 79 } 80 81 public static async Task LoadAsync(string filename, Action<IStorableContent, Exception, Info> loadingCompletedCallback) { 44 82 if (instance == null) throw new InvalidOperationException("ContentManager is not initialized."); 45 var func = new Func<string, IStorableContent>(instance.LoadContent); 46 func.BeginInvoke(filename, delegate (IAsyncResult result) { 47 Exception error = null; 48 IStorableContent content = null; 49 try { 50 content = func.EndInvoke(result); 51 content.Filename = filename; 52 } catch (Exception ex) { 53 error = ex; 54 } 55 loadingCompletedCallback(content, error); 56 }, null); 83 84 Exception error = null; 85 IStorableContent result = null; 86 Info serializationInfo = null; 87 try { 88 result = await Task.Run(() => { 89 var content = instance.LoadContent(filename, out serializationInfo); 90 if(content!=null) content.Filename = filename; 91 return content; 92 }); 93 } catch(Exception ex) { 94 error = ex; 95 } 96 loadingCompletedCallback(result, error, serializationInfo); 57 97 } 58 protected abstract IStorableContent LoadContent(string filename); 98 99 protected abstract IStorableContent LoadContent(string filename, out Info serializationInfo); 59 100 60 101 public static void Save(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken = default(CancellationToken)) { -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Core merged: 16992
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core.Views
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Core.Views merged: 16992,16997
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core.Views/3.3/Clipboard.cs
r16662 r17000 24 24 using System.Collections.Generic; 25 25 using System.IO; 26 using System.IO.Compression;27 26 using System.Linq; 28 27 using System.Threading; … … 31 30 using HeuristicLab.Common; 32 31 using HeuristicLab.MainForm; 33 using HeuristicLab.Persistence.Default.Xml;34 32 using HeuristicLab.PluginInfrastructure; 35 33 … … 157 155 foreach (string filename in items) { 158 156 try { 159 var ser = new ProtoBufSerializer(); 160 T item = (T)ser.Deserialize(filename); 157 T item = (T)ContentManager.Load(filename); 161 158 OnItemLoaded(item, progressBar.Maximum / items.Length); 162 } catch (Exception) { 163 try { 164 // try old format if protobuf deserialization fails 165 T item = XmlParser.Deserialize<T>(filename); 166 OnItemLoaded(item, progressBar.Maximum / items.Length); 167 } catch (Exception) { } 159 } catch(Exception) { 160 // ignore if loading a clipboad item fails. 168 161 } 169 162 } -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core.Views/3.3/HeuristicLab.Core.Views-3.3.csproj
r16662 r17000 375 375 <Private>False</Private> 376 376 </ProjectReference> 377 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">378 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>379 <Name>HeuristicLab.Persistence-3.3</Name>380 <Private>False</Private>381 </ProjectReference>382 377 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 383 378 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core.Views/3.3/Plugin.cs.frame
r16662 r17000 35 35 [PluginDependency("HeuristicLab.MainForm", "3.3")] 36 36 [PluginDependency("HeuristicLab.MainForm.WindowsForms", "3.3")] 37 [PluginDependency("HeuristicLab.Persistence", "3.3")]38 37 public class HeuristicLabCoreViewsPlugin : PluginBase { 39 38 } -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Core/3.3/PersistenceContentManager.cs
r16988 r17000 25 25 using HEAL.Attic; 26 26 using System; 27 using System.Diagnostics; 27 28 28 29 namespace HeuristicLab.Core { … … 30 31 public PersistenceContentManager() : base() { } 31 32 32 protected override IStorableContent LoadContent(string filename ) {33 protected override IStorableContent LoadContent(string filename, out Info info) { 33 34 bool useOldPersistence = XmlParser.CanOpen(filename); 34 if (useOldPersistence) return XmlParser.Deserialize<IStorableContent>(filename); 35 IStorableContent content = null; 36 if (useOldPersistence) { 37 var sw = new Stopwatch(); 38 sw.Start(); 39 content = XmlParser.Deserialize<IStorableContent>(filename); 40 sw.Stop(); 41 info = new Info(filename, sw.Elapsed); 42 } else { 43 var ser = new ProtoBufSerializer(); 44 content = (IStorableContent)ser.Deserialize(filename, out SerializationInfo serInfo); 45 info = new Info(filename, serInfo); 46 } 47 if (content == null) throw new PersistenceException($"Cannot deserialize root element of {filename}"); 48 return content; 49 } 35 50 36 var ser = new ProtoBufSerializer();37 return (IStorableContent)ser.Deserialize(filename, out SerializationInfo info);38 }39 51 40 52 protected override void SaveContent(IStorableContent content, string filename, bool compressed, CancellationToken cancellationToken) { -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimizer
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Optimizer merged: 16992,16997
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimizer/3.3/FileManager.cs
r16662 r17000 23 23 using System.Collections.Generic; 24 24 using System.IO; 25 using System.Linq; 25 26 using System.Threading; 26 27 using System.Windows.Forms; … … 73 74 } 74 75 75 private static void LoadingCompleted(IStorableContent content, Exception error ) {76 private static void LoadingCompleted(IStorableContent content, Exception error, ContentManager.Info info) { 76 77 try { 77 78 if (error != null) throw error; 79 if (info!=null && info.UnknownTypeGuids.Any()) { 80 var message = "Unknown type guids: " + string.Join(Environment.NewLine, info.UnknownTypeGuids); 81 MessageBox.Show((Control)MainFormManager.MainForm, message, $"File {info.Filename} not restored completely", MessageBoxButtons.OK, MessageBoxIcon.Information); 82 } 78 83 IView view = MainFormManager.MainForm.ShowContent(content); 79 84 if (view == null) -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimizer/3.3/HeuristicLab.Optimizer-3.3.csproj
r16662 r17000 312 312 <Private>False</Private> 313 313 </ProjectReference> 314 <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">315 <Project>{102BC7D3-0EF9-439C-8F6D-96FF0FDB8E1B}</Project>316 <Name>HeuristicLab.Persistence-3.3</Name>317 <Private>False</Private>318 </ProjectReference>319 314 <ProjectReference Include="..\..\HeuristicLab.PluginInfrastructure\3.3\HeuristicLab.PluginInfrastructure-3.3.csproj"> 320 315 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimizer/3.3/Plugin.cs.frame
r16662 r17000 43 43 [PluginDependency("HeuristicLab.Optimization", "3.3")] 44 44 [PluginDependency("HeuristicLab.Parameters", "3.3")] 45 [PluginDependency("HeuristicLab.Persistence", "3.3")]46 45 [PluginDependency("HeuristicLab.Problems.Instances", "3.3")] 47 46 public class HeuristicLabOptimizerPlugin : PluginBase { -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Optimizer/3.3/StartPage.cs
r16662 r17000 30 30 using HeuristicLab.Core; 31 31 using HeuristicLab.MainForm; 32 using HeuristicLab.Persistence.Default.Xml;33 32 34 33 namespace HeuristicLab.Optimizer { … … 121 120 using (var stream = assembly.GetManifestResourceStream(name)) { 122 121 WriteStreamToTempFile(stream, path); // create a file in a temporary folder (persistence cannot load these files directly from the stream) 123 var item = XmlParser.Deserialize<INamedItem>(path);122 var item = (INamedItem)ContentManager.Load(path); 124 123 OnSampleLoaded(item, group, 1.0 / count); 125 124 } -
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Tests merged: 16997
- Property svn:mergeinfo changed
-
branches/2925_AutoDiffForDynamicalModels/HeuristicLab.Tests/HeuristicLab.Persistence.Attic/PersistenceConsistencyChecks.cs
r16988 r17000 18 18 var dict = new Dictionary<Guid, string>(); 19 19 var duplicates = new Dictionary<string, string>(); 20 //get all non-generic and instantiable classes which implement IContentView21 20 foreach (Type type in ApplicationManager.Manager.GetTypes(typeof(object))) { 22 21 var attr = StorableTypeAttribute.GetStorableTypeAttribute(type);
Note: See TracChangeset
for help on using the changeset viewer.