protected override long MeasureItemOverride() { var streamKeeper = new StreamKeeper(new BitStream(new NullStream())); var serializableChildren = GetSerializableChildren(); var childLengths = serializableChildren.Select(child => { streamKeeper.RelativePosition = 0; child.Serialize(streamKeeper.Stream, null); return(streamKeeper.RelativePosition); }).ToList(); if (!childLengths.Any()) { return(0); } var childLengthGroups = childLengths.GroupBy(childLength => childLength); var childLengthGroup = childLengthGroups.SingleOrDefault(); if (childLengthGroup == null) { throw new InvalidOperationException("Unable to update binding source because not all items have equal lengths."); } return(childLengthGroup.Key); }
protected virtual long MeasureOverride() { var streamKeeper = new StreamKeeper(new BitStream(new NullStream())); Serialize(streamKeeper.Stream, null); return(streamKeeper.RelativePosition); }
public override void Write(Stream stream) { // 0x10 ignored bytes stream.Write(new byte[0x10], 0, 0x10); // optimization: Check if we have the data from the original file, and we don't need to encrypt and compress it again if (this.Data.GetType() == typeof(CompressedFileStreamCreator) && (this.Data as CompressedFileStreamCreator).Encrypted == IsResourceEncrypted(this.Type)) { (this.Data as CompressedFileStreamCreator).WriteRaw(stream); } else { // we need to create it.. Stream baseStream = new StreamKeeper(stream); using (Stream input = this.Data.GetStream()) { using (Stream output = IsResourceEncrypted(this.Type) ? Platform.GetCompressStream(AES.EncryptStream(baseStream)) : Platform.GetCompressStream(baseStream)) { input.CopyTo(output); } } } }
public override void Write(Stream stream) { FileStreamCreator originalStream = this.TryGetOriginalFileStreamCreator(); // optimization: Check if we have the data from the original file, and we don't need to encrypt and compress it again if (originalStream != null) { originalStream.WriteRaw(stream); } else { // we need to create it.. Stream baseStream = new StreamKeeper(stream); using (Stream input = this.Data.GetStream()) { using (Stream output = this.Compressed ? Platform.GetCompressStream(AES.EncryptStream(baseStream)) : baseStream) { input.CopyTo(output); } } } }
public override void Write(Stream stream) { // optimization: Check if we have the data from the original file, and we don't need to encrypt and compress it again if (this.Compressed && this.Data.GetType() == typeof(CompressedFileStreamCreator)) { (this.Data as CompressedFileStreamCreator).WriteRaw(stream); } else if (!this.Compressed && this.Data.GetType() == typeof(FileStreamCreator)) { (this.Data as FileStreamCreator).WriteRaw(stream); } else { // we need to create it.. Stream baseStream = new StreamKeeper(stream); using (Stream input = this.Data.GetStream()) { using (Stream output = this.Compressed ? Platform.GetCompressStream(AES.EncryptStream(baseStream)) : baseStream) { input.CopyTo(output); } } } }