Example #1
0
        /// <summary>
        /// Gets a list of the tuples <path, chunk index, chunk size> for each input (virtual) file chunk.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="fileIndices">The file indices.</param>
        public List <Tuple <string, int, int> > GetChunkIndices(string filePath, int[] fileIndices)
        {
            logger.DebugFormat("Going to get chunks indices for file indices {0} for file {1}.", string.Join(",",
                                                                                                             System.Array.ConvertAll <int, string>(fileIndices, x => x.ToString())), filePath);
            var sessionProvider = new NHSessionProvider(_sessionFactory);

            using (sessionProvider) {
                var         helper      = new ChunkDbHelper(sessionProvider.CurrentSession);
                var         txnProvider = new NHTransactionProvider(sessionProvider);
                ManagedFile file;
                using (var transaction = txnProvider.BeginTransaction()) {
                    file = helper.GetManagedFile(filePath);
                }
                var chunkMap = file.ChunkMap;
                var eofChunk = chunkMap.EofChunk;
                var ret      = new List <Tuple <string, int, int> >();
                foreach (int fileIndex in fileIndices)
                {
                    var entry = chunkMap.GetByFileIndex(fileIndex);
                    logger.DebugFormat("File index {0} maps to chunk index {1}",
                                       fileIndex, entry.ChunkIndex);
                    var fileTuple = Tuple.Create <string, int, int>(
                        filePath,
                        entry.ChunkIndex,
                        entry.ChunkSize);
                    ret.Add(fileTuple);
                }
                return(ret);
            }
        }
Example #2
0
        /// <summary>
        /// Gets a list of the tuples <path, chunk index, chunk size> for each input chunk.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        /// <param name="chunkIndices">The chunk indices.</param>
        public List <Tuple <string, int, int> > GetChunkLocations(string filePath, int[] chunkIndices)
        {
            logger.DebugFormat("Going to get deduplicated locations of data chunks {0} for file {1}.", string.Join(",",
                                                                                                                   System.Array.ConvertAll <int, string>(chunkIndices, x => x.ToString())), filePath);

            var sessionProvider = new NHSessionProvider(_sessionFactory);

            using (sessionProvider) {
                var         helper      = new ChunkDbHelper(sessionProvider.CurrentSession);
                var         txnProvider = new NHTransactionProvider(sessionProvider);
                ManagedFile file;
                using (var transaction = txnProvider.BeginTransaction()) {
                    file = helper.GetManagedFile(filePath);
                }
                var chunkMap = file.ChunkMap;
                var eofChunk = chunkMap.EofChunk;
                var ret      = new List <Tuple <string, int, int> >();
                using (var transaction = txnProvider.BeginTransaction()) {
                    var dao = new Dao <DataChunk>(sessionProvider.CurrentSession);
                    foreach (int chunkIndex in chunkIndices)
                    {
                        byte[] chunkHash = chunkMap.HashAt(chunkIndex);
                        int    chunkSize = chunkIndex == eofChunk.ChunkIndex ?
                                           eofChunk.ChunkSize : DataChunk.ChunkSize;
                        var chunkInfo = dao.UniqueResultByExample(new
                                                                  DataChunk {
                            Hash = chunkHash
                        });

                        if (chunkInfo == null)
                        {
                            throw new ChunkNotInDbException(string.Format(
                                                                "Chunk {0} in the file hasn't been added yet.",
                                                                chunkIndex))
                                  {
                                      File       = filePath,
                                      ChunkIndex = chunkIndex
                                  };
                        }

                        logger.DebugFormat("Chunk index {0} maps to chunk {1} in file {2}.",
                                           chunkIndex, chunkInfo.ChunkIndex, chunkInfo.File.Path);
                        var fileTuple = Tuple.Create <string, int, int>(
                            chunkInfo.File.Path,
                            chunkInfo.ChunkIndex,
                            chunkSize);
                        ret.Add(fileTuple);
                    }
                }
                return(ret);
            }
        }
 public NHTransactionProvider(NHSessionProvider sessionProvider)
 {
     _sessionProvider = sessionProvider;
 }
Example #4
0
 public NHTransactionProvider(NHSessionProvider sessionProvider)
 {
     _sessionProvider = sessionProvider;
 }