Exemplo n.º 1
0
        /// <summary>
        /// Add an object map to an existing object.
        /// </summary>
        /// <param name="key">Object key.</param>
        /// <param name="chunkKey">Chunk key.</param>
        /// <param name="chunkLength">Chunk length.</param>
        /// <param name="chunkPosition">Ordinal position of the chunk, i.e. 1, 2, ..., n.</param>
        /// <param name="chunkAddress">Byte address of the chunk within the original object.</param>
        public override void AddObjectMap(string key, string chunkKey, int chunkLength, int chunkPosition, long chunkAddress)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (String.IsNullOrEmpty(chunkKey))
            {
                throw new ArgumentNullException(nameof(chunkKey));
            }
            if (chunkLength < 1)
            {
                throw new ArgumentException("Chunk length must be greater than zero.");
            }
            if (chunkPosition < 0)
            {
                throw new ArgumentException("Position must be zero or greater.");
            }
            if (chunkAddress < 0)
            {
                throw new ArgumentException("Address must be zero or greater.");
            }

            DedupeObjectMap map = new DedupeObjectMap(key, chunkKey, chunkLength, chunkPosition, chunkAddress);

            _ORM.Insert <DedupeObjectMap>(map);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Retrieve the object map containing the metadata for a given address within the original object.
        /// </summary>
        /// <param name="key">Object key.</param>
        /// <param name="position">Starting byte position.</param>
        /// <returns>Dedupe object map.</returns>
        public override DedupeObjectMap GetObjectMapForPosition(string key, long position)
        {
            if (String.IsNullOrEmpty(key))
            {
                throw new ArgumentNullException(nameof(key));
            }
            if (position < 0)
            {
                throw new ArgumentOutOfRangeException("Start of range must be zero or greater.");
            }

            key = DedupeCommon.SanitizeString(key);

            DedupeObject obj = GetObjectMetadata(key);

            if (obj == null)
            {
                return(null);
            }

            string objMapTable  = _ORM.GetTableName(typeof(DedupeObjectMap));
            string objKeyCol    = _ORM.GetColumnName <DedupeObjectMap>(nameof(DedupeObjectMap.ObjectKey));
            string chunkAddrCol = _ORM.GetColumnName <DedupeObjectMap>(nameof(DedupeObjectMap.ChunkAddress));
            string chunkLenCol  = _ORM.GetColumnName <DedupeObjectMap>(nameof(DedupeObjectMap.ChunkLength));

            string query =
                "SELECT * FROM " + objMapTable + " " +
                "WHERE " +
                "  " + objKeyCol + " = '" + obj.Key + "' " +
                "  AND " + chunkAddrCol + " <= " + position + " AND " + chunkAddrCol + " + " + chunkLenCol + " > " + position + " ";

            DedupeObjectMap map    = null;
            DataTable       result = _ORM.Query(query);

            if (result != null && result.Rows.Count > 0)
            {
                map = _ORM.DataRowToObject <DedupeObjectMap>(result.Rows[0]);
            }

            return(map);
        }