Ejemplo n.º 1
0
        public static void OverwriteSequenceNumbers(File file,
                                                    long position,
                                                    IDictionary <uint, int> shiftTable)
        {
            bool done = true;

            foreach (KeyValuePair <uint, int> pair in shiftTable)
            {
                if (pair.Value != 0)
                {
                    done = false;
                    break;
                }
            }

            if (done)
            {
                return;
            }

            while (position < file.Length)
            {
                PageHeader header = new PageHeader(file, position);
                int        size   = (int)(header.Size + header.DataSize);

                if (shiftTable.ContainsKey(header.StreamSerialNumber) &&
                    shiftTable [header.StreamSerialNumber] != 0)
                {
                    file.Seek(position);
                    ByteVector page_data = file.ReadBlock(size);

                    ByteVector new_data = ByteVector.FromUInt(
                        (uint)(header.PageSequenceNumber +
                               shiftTable [header.StreamSerialNumber]),
                        false);

                    for (int i = 18; i < 22; i++)
                    {
                        page_data [i] = new_data [i - 18];
                    }
                    for (int i = 22; i < 26; i++)
                    {
                        page_data [i] = 0;
                    }

                    new_data.Add(ByteVector.FromUInt(
                                     page_data.Checksum, false));
                    file.Seek(position + 18);
                    file.WriteBlock(new_data);
                }
                position += size;
            }
        }
Ejemplo n.º 2
0
		public static void OverwriteSequenceNumbers (File file,
		                                             long position,
		                                             IDictionary<uint, int> shiftTable)
		{
			bool done = true;
			foreach (KeyValuePair<uint, int> pair in shiftTable)
				if (pair.Value != 0) {
					done = false;
					break;
				}
			
			if (done)
				return;
			
			while (position < file.Length) {
				PageHeader header = new PageHeader (file, position);
				int size = (int) (header.Size + header.DataSize);
				
				if (shiftTable.ContainsKey (header.StreamSerialNumber)
					&& shiftTable [header.StreamSerialNumber] != 0) {
					file.Seek (position);
					ByteVector page_data = file.ReadBlock (size);
					
					ByteVector new_data = ByteVector.FromUInt (
						(uint)(header.PageSequenceNumber +
						shiftTable [header.StreamSerialNumber]),
						false);
					
					for (int i = 18; i < 22; i ++)
						page_data [i] = new_data [i - 18];
					for (int i = 22; i < 26; i++)
						page_data [i] = 0;
					
					new_data.Add (ByteVector.FromUInt (
						page_data.Checksum, false));
					file.Seek (position + 18);
					file.WriteBlock (new_data);
				}
				position += size;
			}
		}
Ejemplo n.º 3
0
        /// <summary>
        ///    Overwrites all page headers in a file starting at a
        ///    specified position, shifting the page sequence numbers
        ///    a set amount.
        /// </summary>
        /// <param name="file">
        ///    A <see cref="File" /> object containing the file to
        ///    update.
        /// </param>
        /// <param name="position">
        ///    A <see cref="long" /> value specify at what position to
        ///    start updating.
        /// </param>
        /// <param name="shiftTable">
        ///    A <see cref="T:System.Collections.Generic.IDictionary`2"
        ///    /> object where the key is the serial number of the
        ///    stream to update and the value is the amount to offset
        ///    the page sequence numbers in the stream.
        /// </param>
        /// <exception cref="ArgumentNullException">
        ///    <paramref name="file" /> or <paramref name="shiftTable"
        ///    /> is <see langword="null" />.
        /// </exception>
        /// <remarks>
        ///    When the number of pages in a stream changes, all
        ///    subsequent pages in the stream need to have their page
        ///    sequence number update in order to remain valid.
        ///    Additionally, when the page sequence number changes, the
        ///    page needs to have its checksum recomputed. This makes
        ///    for a costly recalculation if large comment data is
        ///    added.
        /// </remarks>
        public static void OverwriteSequenceNumbers(File file,
                                                    long position,
                                                    IDictionary <uint, int> shiftTable)
        {
            if (file == null)
            {
                throw new ArgumentNullException("file");
            }

            if (shiftTable == null)
            {
                throw new ArgumentNullException("shiftTable");
            }

            // Check to see if there are no changes to be made.
            bool done = true;

            foreach (KeyValuePair <uint, int> pair in shiftTable)
            {
                if (pair.Value != 0)
                {
                    done = false;
                    break;
                }
            }

            // If the file is fine, quit.
            if (done)
            {
                return;
            }

            while (position < file.Length - 27)
            {
                PageHeader header = new PageHeader(file, position);
                int        size   = (int)(header.Size + header.DataSize);

                if (shiftTable.ContainsKey(header.StreamSerialNumber) &&
                    shiftTable [header.StreamSerialNumber] != 0)
                {
                    file.Seek(position);
                    ByteVector page_data = file.ReadBlock(size);

                    ByteVector new_data = ByteVector.FromUInt(
                        (uint)(header.PageSequenceNumber +
                               shiftTable [header.StreamSerialNumber]),
                        false);

                    for (int i = 18; i < 22; i++)
                    {
                        page_data [i] = new_data [i - 18];
                    }
                    for (int i = 22; i < 26; i++)
                    {
                        page_data [i] = 0;
                    }

                    new_data.Add(ByteVector.FromUInt(
                                     page_data.Checksum, false));
                    file.Seek(position + 18);
                    file.WriteBlock(new_data);
                }
                position += size;
            }
        }
Ejemplo n.º 4
0
		/// <summary>
		///    Overwrites all page headers in a file starting at a
		///    specified position, shifting the page sequence numbers
		///    a set amount.
		/// </summary>
		/// <param name="file">
		///    A <see cref="File" /> object containing the file to
		///    update.
		/// </param>
		/// <param name="position">
		///    A <see cref="long" /> value specify at what position to
		///    start updating.
		/// </param>
		/// <param name="shiftTable">
		///    A <see cref="T:System.Collections.Generic.IDictionary`2"
		///    /> object where the key is the serial number of the
		///    stream to update and the value is the amount to offset
		///    the page sequence numbers in the stream.
		/// </param>
		/// <exception cref="ArgumentNullException">
		///    <paramref name="file" /> or <paramref name="shiftTable"
		///    /> is <see langword="null" />.
		/// </exception>
		/// <remarks>
		///    When the number of pages in a stream changes, all
		///    subsequent pages in the stream need to have their page
		///    sequence number update in order to remain valid.
		///    Additionally, when the page sequence number changes, the
		///    page needs to have its checksum recomputed. This makes
		///    for a costly recalculation if large comment data is
		///    added.
		/// </remarks>
		public static void OverwriteSequenceNumbers (File file,
		                                             long position,
		                                             IDictionary<uint, int> shiftTable)
		{
			if (file == null)
				throw new ArgumentNullException ("file");
			
			if (shiftTable == null)
				throw new ArgumentNullException ("shiftTable");
			
			// Check to see if there are no changes to be made.
			bool done = true;
			foreach (KeyValuePair<uint, int> pair in shiftTable)
				if (pair.Value != 0) {
					done = false;
					break;
				}
			
			// If the file is fine, quit.
			if (done)
				return;
			
			while (position < file.Length - 27) {
				PageHeader header = new PageHeader (file, position);
				int size = (int) (header.Size + header.DataSize);
				
				if (shiftTable.ContainsKey (header.StreamSerialNumber)
					&& shiftTable [header.StreamSerialNumber] != 0) {
					file.Seek (position);
					ByteVector page_data = file.ReadBlock (size);
					
					ByteVector new_data = ByteVector.FromUInt (
						(uint)(header.PageSequenceNumber +
						shiftTable [header.StreamSerialNumber]),
						false);
					
					for (int i = 18; i < 22; i ++)
						page_data [i] = new_data [i - 18];
					for (int i = 22; i < 26; i++)
						page_data [i] = 0;
					
					new_data.Add (ByteVector.FromUInt (
						page_data.Checksum, false));
					file.Seek (position + 18);
					file.WriteBlock (new_data);
				}
				position += size;
			}
		}