示例#1
0
 public static void SerializeToXml(string filePath, ChunkMap chunkMap)
 {
     var serializer = new XmlSerializer(typeof(ChunkMap));
     using (var stream = File.OpenWrite(filePath)) {
         serializer.Serialize(stream, chunkMap);
     }
 }
示例#2
0
        public static void SerializeToXml(string filePath, ChunkMap chunkMap)
        {
            var serializer = new XmlSerializer(typeof(ChunkMap));

            using (var stream = File.OpenWrite(filePath)) {
                serializer.Serialize(stream, chunkMap);
            }
        }
        public static void ReverseChunkMap(string chunkMap, string newChunkMap)
        {
            logger.DebugFormat("ChunkMap: {0}", chunkMap);
            var dto = ChunkMapSerializer.Deserialize(chunkMap);
            var cm = new ChunkMap(dto);
            cm.FileIndices = dto.FileIndices.Reverse().ToArray();
            var l = cm.CopyHashesAsList();
            l.Reverse();
            cm.SetHashesAsList(l);
            cm.EofChunkIndex = 0;
            cm.GenerateChunkIndices();

            var newDto = cm.ConvertToDto();

            logger.DebugFormat("New ChunkMap: {0}", cm);
            ChunkMapSerializer.Serialize(newChunkMap, newDto);
            ChunkMapSerializer.SerializeToXml(newChunkMap + ".xml", cm);
        }
示例#4
0
        public void AddFile(string path, byte[] chunkMapDto)
        {
            var txnProvider = new NHTransactionProvider(
                new NHSessionProvider(_sessionFactory));

            using (txnProvider) {
                using (var transaction = txnProvider.BeginTransaction()) {
                    var         cm          = ChunkMap.Create(chunkMapDto);
                    ManagedFile managedFile =
                        new ManagedFile {
                        Path     = path,
                        ChunkMap = cm,
                        Size     = cm.FileSize
                    };
                    var session = txnProvider.SessionProvider.CurrentSession;
                    session.Save(managedFile);
                    transaction.Commit();
                }
            }
        }
示例#5
0
        public void AddFileToDownload(string path, byte[] chunkMap,
                                      byte[] torrent, long fileSize)
        {
            var txnProvider = new NHTransactionProvider(
                new NHSessionProvider(_sessionFactory));

            using (txnProvider) {
                using (var transaction = txnProvider.BeginTransaction()) {
                    ManagedFile managedFile =
                        new ManagedFile {
                        Path        = path,
                        ChunkMap    = ChunkMap.Create(chunkMap),
                        TorrentFile = torrent,
                        Size        = fileSize
                    };
                    var session = txnProvider.SessionProvider.CurrentSession;
                    session.Save(managedFile);
                    transaction.Commit();
                }
            }
            logger.DebugFormat("ChunkMap is added for file {0}", path);
        }