- Timestamp:
- 06/25/19 23:14:06 (6 years ago)
- Location:
- branches/2435-alglib_3_15
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2435-alglib_3_15
- Property svn:mergeinfo changed
-
branches/2435-alglib_3_15/HeuristicLab.Common/3.3/Content/ContentManager.cs
r16565 r17034 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)) {
Note: See TracChangeset
for help on using the changeset viewer.