private IEnumerable<CompletionPort> CreateParentLocator(AsyncMachine<ParentLocator> machine) { var locator = new ParentLocator(); BeginReadPlatformCode(attributeHelper.GetAttribute(() => locator.PlatformCode), machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.PlatformCode = EndReadPlatformCode(machine.CompletionResult); BeginReadPlatformDataSpace(attributeHelper.GetAttribute(() => locator.PlatformDataSpace), machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.PlatformDataSpace = EndReadPlatformDataSpace(machine.CompletionResult); BeginReadPlatformDataLength(attributeHelper.GetAttribute(() => locator.PlatformDataLength), machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.PlatformDataLength = EndReadPlatformDataLength(machine.CompletionResult); BeginReadReserved(attributeHelper.GetAttribute(() => locator.Reserved), machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.Reserved = EndReadReserved(machine.CompletionResult); BeginReadPlatformDataOffset(attributeHelper.GetAttribute(() => locator.PlatformDataOffset), machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.PlatformDataOffset = EndReadPlatformDataOffset(machine.CompletionResult); BeginReadFileLocator(locator, machine.CompletionCallback, null); yield return CompletionPort.SingleOperation; locator.PlatformSpecificFileLocator = EndReadFileLocator(machine.CompletionResult); machine.ParameterValue = locator; }
public ParentLocator(ParentLocator toCopy) { PlatformCode = toCopy.PlatformCode; PlatformDataSpace = toCopy.PlatformDataSpace; PlatformDataLength = toCopy.PlatformDataLength; PlatformDataOffset = toCopy.PlatformDataOffset; }
public ParentLocator(ParentLocator toCopy) { PlatformCode = toCopy.PlatformCode; PlatformDataSpace = toCopy.PlatformDataSpace; PlatformDataLength = toCopy.PlatformDataLength; PlatformDataOffset = toCopy.PlatformDataOffset; }
private string CreateFileLocator(ParentLocator locator, byte[] fileLocator) { switch (locator.PlatformCode) { case PlatformCode.None: return(String.Empty); case PlatformCode.Wi2R: case PlatformCode.Wi2K: throw new VhdParsingException(String.Format("Deprecated PlatformCode:{0}", locator.PlatformCode)); case PlatformCode.W2Ru: //TODO: Add differencing disks path name, this is relative path return(Encoding.Unicode.GetString(fileLocator)); case PlatformCode.W2Ku: return(Encoding.Unicode.GetString(fileLocator)); case PlatformCode.Mac: //TODO: Mac OS alias stored as a blob? throw new NotImplementedException(String.Format("PlatformCode: {0}", locator.PlatformCode)); case PlatformCode.MacX: return(Encoding.UTF8.GetString(fileLocator)); } return(Encoding.BigEndianUnicode.GetString(fileLocator).TrimEnd('\0')); }
public static ParentLocator FromBytes(byte[] data, int offset) { ParentLocator result = new ParentLocator(); result.PlatformCode = Utilities.BytesToString(data, offset, 4); result.PlatformDataSpace = Utilities.ToInt32BigEndian(data, offset + 4); result.PlatformDataLength = Utilities.ToInt32BigEndian(data, offset + 8); result.PlatformDataOffset = Utilities.ToInt64BigEndian(data, offset + 16); return result; }
public static ParentLocator FromBytes(byte[] data, int offset) { ParentLocator result = new ParentLocator(); result.PlatformCode = Utilities.BytesToString(data, offset, 4); result.PlatformDataSpace = Utilities.ToInt32BigEndian(data, offset + 4); result.PlatformDataLength = Utilities.ToInt32BigEndian(data, offset + 8); result.PlatformDataOffset = Utilities.ToInt64BigEndian(data, offset + 16); return(result); }
public ParentLocator Create() { var locator = new ParentLocator(); locator.PlatformCode = ReadPlaformCode(attributeHelper.GetAttribute(() => locator.PlatformCode)); locator.PlatformDataSpace = ReadPlatformDataSpace(attributeHelper.GetAttribute(() => locator.PlatformDataSpace)); locator.PlatformDataLength = ReadPlatformDataLength(attributeHelper.GetAttribute(() => locator.PlatformDataLength)); locator.Reserved = ReadReserved(attributeHelper.GetAttribute(() => locator.Reserved)); locator.PlatformDataOffset = ReadPlatformDataOffset(attributeHelper.GetAttribute(() => locator.PlatformDataOffset)); locator.PlatformSpecificFileLocator = ReadFileLocator(locator); return locator; }
public ParentLocator Create() { var locator = new ParentLocator(); locator.PlatformCode = ReadPlaformCode(attributeHelper.GetAttribute(() => locator.PlatformCode)); locator.PlatformDataSpace = ReadPlatformDataSpace(attributeHelper.GetAttribute(() => locator.PlatformDataSpace)); locator.PlatformDataLength = ReadPlatformDataLength(attributeHelper.GetAttribute(() => locator.PlatformDataLength)); locator.Reserved = ReadReserved(attributeHelper.GetAttribute(() => locator.Reserved)); locator.PlatformDataOffset = ReadPlatformDataOffset(attributeHelper.GetAttribute(() => locator.PlatformDataOffset)); locator.PlatformSpecificFileLocator = ReadFileLocator(locator); return(locator); }
/// <summary> /// Determine if the locator contains an object for the given key. /// </summary> /// <param name="key">The key to check.</param> /// <returns> /// true if the locator contains an object for the key; returns /// false otherwise. /// </returns> public override bool Contains(object key) { Guard.ArgumentNotNull(key, "key"); if (references.ContainsKey(key)) { return(true); } if (ParentLocator != null) { return(ParentLocator.Contains(key)); } return(false); }
public override object Get(object key) { if (key == null) { throw new ArgumentNullException("key"); } if (references.ContainsKey(key)) { return(references[key]); } if (ParentLocator != null) { return(ParentLocator.Get(key)); } return(null); }
/// <summary> /// Gets an object from the locator, registered with the given key. /// </summary> /// <param name="key">The key that the object is registered with.</param> /// <returns>The object, if found; null otherwise.</returns> /// <exception cref="ArgumentNullException">Key is null.</exception> public override object Get(object key) { if (key == null) { throw new ArgumentNullException("key"); } object value; if (references.TryGet(key, out value)) { return(value); } if (ParentLocator != null) { return(ParentLocator.Get(key)); } return(null); }
private IEnumerable <CompletionPort> CreateParentLocators(AsyncMachine <IList <ParentLocator> > machine, VhdPropertyAttribute attribute) { var parentLocators = new List <ParentLocator>(); var attributeHelper = new AttributeHelper <ParentLocator>(); var entityAttribute = attributeHelper.GetEntityAttribute(); long baseOffset = headerOffset + attribute.Offset; for (int i = 0; i < attribute.Count; i++) { var parentLocatorFactory = new VhdParentLocatorFactory(dataReader, baseOffset); parentLocatorFactory.BeginReadCreate(machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); ParentLocator parentLocator = parentLocatorFactory.EndReadCreate(machine.CompletionResult); parentLocators.Add(parentLocator); baseOffset += entityAttribute.Size; } machine.ParameterValue = parentLocators; }
/// <summary> /// See <see cref="IReadableLocator.Get(object, SearchMode)"/> for more information. /// </summary> public override object Get(object key, SearchMode options) { if (key == null) { throw new ArgumentNullException("key"); } if (!Enum.IsDefined(typeof(SearchMode), options)) { throw new ArgumentException(Properties.Resources.InvalidEnumerationValue, "options"); } if (references.ContainsKey(key)) { return(references[key]); } if (options == SearchMode.Up && ParentLocator != null) { return(ParentLocator.Get(key, options)); } return(null); }
/// <summary> /// See <see cref="IReadableLocator.Contains(object, SearchMode)"/> for more information. /// </summary> public override bool Contains(object key, SearchMode options) { if (key == null) { throw new ArgumentNullException("key"); } if (!Enum.IsDefined(typeof(SearchMode), options)) { throw new ArgumentException(); } if (references.ContainsKey(key)) { return(true); } if (options == SearchMode.Up && ParentLocator != null) { return(ParentLocator.Contains(key, options)); } return(false); }
private IEnumerable <CompletionPort> CreateParentLocator(AsyncMachine <ParentLocator> machine) { var locator = new ParentLocator(); BeginReadPlatformCode(attributeHelper.GetAttribute(() => locator.PlatformCode), machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.PlatformCode = EndReadPlatformCode(machine.CompletionResult); BeginReadPlatformDataSpace(attributeHelper.GetAttribute(() => locator.PlatformDataSpace), machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.PlatformDataSpace = EndReadPlatformDataSpace(machine.CompletionResult); BeginReadPlatformDataLength(attributeHelper.GetAttribute(() => locator.PlatformDataLength), machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.PlatformDataLength = EndReadPlatformDataLength(machine.CompletionResult); BeginReadReserved(attributeHelper.GetAttribute(() => locator.Reserved), machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.Reserved = EndReadReserved(machine.CompletionResult); BeginReadPlatformDataOffset(attributeHelper.GetAttribute(() => locator.PlatformDataOffset), machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.PlatformDataOffset = EndReadPlatformDataOffset(machine.CompletionResult); BeginReadFileLocator(locator, machine.CompletionCallback, null); yield return(CompletionPort.SingleOperation); locator.PlatformSpecificFileLocator = EndReadFileLocator(machine.CompletionResult); machine.ParameterValue = locator; }
private string ReadFileLocator(ParentLocator locator) { var fileLocator = dataReader.ReadBytes(locator.PlatformDataOffset, locator.PlatformDataLength); return(CreateFileLocator(locator, fileLocator)); }
private IAsyncResult BeginReadFileLocator(ParentLocator locator, AsyncCallback callback, object state) { return(dataReader.BeginReadBytes(locator.PlatformDataOffset, locator.PlatformDataLength, callback, locator)); }
private string CreateFileLocator(ParentLocator locator, byte[] fileLocator) { switch (locator.PlatformCode) { case PlatformCode.None: return String.Empty; case PlatformCode.Wi2R: case PlatformCode.Wi2K: throw new VhdParsingException(String.Format("Deprecated PlatformCode:{0}", locator.PlatformCode)); case PlatformCode.W2Ru: //TODO: Add differencing disks path name, this is relative path return Encoding.Unicode.GetString(fileLocator); case PlatformCode.W2Ku: return Encoding.Unicode.GetString(fileLocator); case PlatformCode.Mac: //TODO: Mac OS alias stored as a blob? throw new NotImplementedException(String.Format("PlatformCode: {0}", locator.PlatformCode)); case PlatformCode.MacX: return Encoding.UTF8.GetString(fileLocator); } return Encoding.BigEndianUnicode.GetString(fileLocator).TrimEnd('\0'); }
private string ReadFileLocator(ParentLocator locator) { var fileLocator = dataReader.ReadBytes(locator.PlatformDataOffset, locator.PlatformDataLength); return CreateFileLocator(locator, fileLocator); }
private IAsyncResult BeginReadFileLocator(ParentLocator locator, AsyncCallback callback, object state) { return dataReader.BeginReadBytes(locator.PlatformDataOffset, locator.PlatformDataLength, callback, locator); }