Ejemplo n.º 1
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);
        }