Exemplo n.º 1
0
        private PagerState.AllocationInfo RemapViewOfFileAtAddress(long allocationSize, ulong offsetInFile, byte *baseAddress)
        {
            var offset = new SplitValue {
                Value = offsetInFile
            };

            var mmf = MemoryMappedFile.CreateFromFile(_fileStream, null, _fileStream.Length,
                                                      _memoryMappedFileAccess,
                                                      null, HandleInheritability.None, true);

            var newMappingBaseAddress = Win32MemoryMapNativeMethods.MapViewOfFileEx(mmf.SafeMemoryMappedFileHandle.DangerousGetHandle(),
                                                                                    Win32MemoryMapNativeMethods.NativeFileMapAccessType.Read | Win32MemoryMapNativeMethods.NativeFileMapAccessType.Write,
                                                                                    offset.High, offset.Low,
                                                                                    new UIntPtr((ulong)allocationSize),
                                                                                    baseAddress);

            var hasMappingSucceeded = newMappingBaseAddress != null && newMappingBaseAddress != (byte *)0;

            if (!hasMappingSucceeded)
            {
                mmf.Dispose();
                return(null);
            }

            return(new PagerState.AllocationInfo
            {
                BaseAddress = newMappingBaseAddress,
                Size = allocationSize,
                MappedFile = mmf
            });
        }
        /// <summary>
        /// Returns true if PdfSplitParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of PdfSplitParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PdfSplitParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     FileId == input.FileId ||
                     (FileId != null &&
                      FileId.Equals(input.FileId))
                     ) &&
                 (
                     SplitMethod == input.SplitMethod ||
                     SplitMethod.Equals(input.SplitMethod)
                 ) &&
                 (
                     SplitValue == input.SplitValue ||
                     SplitValue.Equals(input.SplitValue)
                 ) &&
                 (
                     ImmediateDownload == input.ImmediateDownload ||
                     ImmediateDownload.Equals(input.ImmediateDownload)
                 ));
        }
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (FileId != null)
         {
             hashCode = hashCode * 59 + FileId.GetHashCode();
         }
         hashCode = hashCode * 59 + SplitMethod.GetHashCode();
         hashCode = hashCode * 59 + SplitValue.GetHashCode();
         hashCode = hashCode * 59 + ImmediateDownload.GetHashCode();
         return(hashCode);
     }
 }
		private PagerState.AllocationInfo RemapViewOfFileAtAddress(long allocationSize, ulong offsetInFile, byte* baseAddress)
		{
			var offset = new SplitValue { Value = offsetInFile };

			var mmf = MemoryMappedFile.CreateFromFile(_fileStream, null, _fileStream.Length,
				_memoryMappedFileAccess,
				null, HandleInheritability.None, true);

			var newMappingBaseAddress = Win32MemoryMapNativeMethods.MapViewOfFileEx(mmf.SafeMemoryMappedFileHandle.DangerousGetHandle(),
				Win32MemoryMapNativeMethods.NativeFileMapAccessType.Read | Win32MemoryMapNativeMethods.NativeFileMapAccessType.Write,
				offset.High, offset.Low,
				new UIntPtr((ulong)allocationSize), 
				baseAddress);

			var hasMappingSucceeded = newMappingBaseAddress != null && newMappingBaseAddress != (byte*)0;
			if (!hasMappingSucceeded)
			{
				mmf.Dispose();
				return null;
			}

			return new PagerState.AllocationInfo
			{
				BaseAddress = newMappingBaseAddress,
				Size = allocationSize,
				MappedFile = mmf
			};
		}