示例#1
0
 public byte[] ToPersistentByteArray()
 {
     D("Generating persistent byte array...");
     return(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(
                                       new InnerCheckPoint()
     {
         Tasks = Tasks.Select(task => new KeyValuePair
                              <string, DownloadTask>(task.Key, task)).ToArray(),
         Downloaders = Downloaders.Where(downloader =>
                                         downloader.Status != DownloaderStatus.Completed &&
                                         downloader.Status != DownloaderStatus.Disposed)
                       .Select(downloader =>
         {
             byte[] val = null;
             if (downloader is IPersistable per)
             {
                 try { val = per.ToPersistentByteArray(); } catch (Exception) { }
             }
             return new KeyValuePair <string, byte[]>(
                 downloader.DownloadTask.Key, val);
         }).ToArray(),
         Histories = Histories.ToArray(),
         CacheManagerCheckPoint = coreCacheManager.ToPersistentByteArray(),
         TorrentEngineCheckPoint = torrentProvider.ToPersistentByteArray()
     }, new JsonSerializerSettings()
示例#2
0
 /// <summary>
 /// Construct a CollectionBind from a source collection which
 /// should be an ISyncableCollection to a destination collection.
 /// It uses the caster when new object is required to be created
 /// and uses the comparer to match existence objects in two
 /// collections when resyncing.
 /// </summary>
 /// <param name="source">The source collection.</param>
 /// <param name="destination">The destination collection.</param>
 /// <param name="caster">The caster creates an object of type
 /// <typeparamref name="T"/> from an object of type <typeparamref name="S"/>.
 /// </param>
 /// <param name="comparer">The comparer compares an object of type
 /// <typeparamref name="T"/> with an object of type <typeparamref name="S"/>
 /// and returns true if they are corresponding.</param>
 public CollectionBind(
     ISyncableEnumerable <S> source,
     ICollection <T> destination,
     Func <S, T> caster,
     Func <S, T, bool> comparer)
 {
     Ensure.That(source, nameof(source)).IsNotNull();
     Ensure.That(destination, nameof(destination)).IsNotNull();
     Ensure.That(caster, nameof(caster)).IsNotNull();
     Ensure.That(comparer, nameof(comparer)).IsNotNull();
     Source      = source;
     Destination = destination;
     Caster      = caster;
     Comparer    = comparer;
 }