/// <summary> /// Read data for simulating purposes. Returns a list of byte[] of data. /// </summary> /// <param name="filePath"></param> /// <param name="ergoOrHeartRate"></param> /// <returns></returns> public List <byte[]> ReadData(string filePath, WriteOption ergoOrHeartRate) { filePath = GetErgoHeartRatePath(filePath, ergoOrHeartRate); List <byte[]> deSerializedObject = ReadToFileBinary <List <byte[]> >(filePath); return(deSerializedObject); }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { #if STREAM_SPAN lock (Locker) { BaseStream.Position = offset; BaseStream.Write(source); } #else byte[] buffer = ArrayPool <byte> .Shared.Rent(source.Length); try { source.CopyTo(buffer); lock (Locker) { BaseStream.Position = offset; BaseStream.Write(buffer, 0, source.Length); } } finally { ArrayPool <byte> .Shared.Return(buffer); } #endif if ((options & WriteOption.Flush) != 0) { Flush(); } }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { ValidateWriteParams(source, offset); int inPos = 0; long outPos = offset; int remaining = source.Length; while (remaining > 0) { int fileIndex = GetSubFileIndexFromOffset(outPos); IFile file = Sources[fileIndex]; long fileOffset = outPos - fileIndex * SubFileSize; long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, GetSize()); int bytesToWrite = (int)Math.Min(fileEndOffset - outPos, remaining); file.Write(source.Slice(inPos, bytesToWrite), fileOffset, options); outPos += bytesToWrite; inPos += bytesToWrite; remaining -= bytesToWrite; } if ((options & WriteOption.Flush) != 0) { Flush(); } }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded); if (rc.IsFailure()) { return(rc); } if (isResizeNeeded) { rc = SetSizeImpl(offset + source.Length); if (rc.IsFailure()) { return(rc); } } BaseStorage.Write(offset, source); if ((options & WriteOption.Flush) != 0) { return(Flush()); } return(Result.Success); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out bool isResizeNeeded); if (rc.IsFailure()) { return(rc); } if (isResizeNeeded) { return(ResultFs.UnsupportedOperationInPartitionFileSetSize.Log()); } if (offset > Size) { return(ResultFs.ValueOutOfRange.Log()); } rc = BaseStorage.Write(offset, source); if (rc.IsFailure()) { return(rc); } // N doesn't flush if the flag is set if (options.HasFlag(WriteOption.Flush)) { return(BaseStorage.Flush()); } return(Result.Success); }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { ValidateWriteParams(source, offset); BaseStorage.Write(source, offset); if ((options & WriteOption.Flush) != 0) { Flush(); } }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out _); if (rc.IsFailure()) { return(rc); } return(File.Write(offset, source, options)); }
public void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { CheckIfDisposed(); if (source.Length == 0) { WriteState = (WriteState)(~options & WriteOption.Flush); return; } File.Write(source, offset, options); WriteState = (WriteState)(~options & WriteOption.Flush); }
// Write(u32 writeOption, u64 offset, u64 size, buffer<u8, 0x45, 0>) public ResultCode Write(ServiceCtx context) { long position = context.Request.SendBuff[0].Position; WriteOption writeOption = (WriteOption)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = context.Memory.ReadBytes(position, size); return((ResultCode)_baseFile.Write(offset, data, writeOption).Value); }
/// <summary> /// Receive the Ergometer or Heart rate data path. /// </summary> /// <param name="pathToFile"></param> /// <param name="ergoOrHeartRate"></param> /// <returns></returns> private static string GetErgoHeartRatePath(string pathToFile, WriteOption ergoOrHeartRate) { string newPath = pathToFile; switch (ergoOrHeartRate) { case WriteOption.Ergo: newPath += "_Ergometer"; break; case WriteOption.Heartrate: newPath += "_HRMonitor"; break; } return(newPath); }
public Result Write(long offset, ReadOnlySpan <byte> source, WriteOption option) { if (offset < 0) { return(ResultFs.InvalidOffset.Log()); } if (source.Length < 0) { return(ResultFs.InvalidSize.Log()); } // Note: Thread priority is temporarily when writing in FS return(BaseFile.Write(offset, source, option)); }
// Write(u32 writeOption, u64 offset, u64 size, buffer<u8, 0x45, 0>) public ResultCode Write(ServiceCtx context) { long position = context.Request.SendBuff[0].Position; WriteOption writeOption = new WriteOption(context.RequestData.ReadInt32()); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[size]; context.Memory.Read((ulong)position, data); return (ResultCode)_baseFile.Write(offset, data, writeOption).Value; }
public Result Write(long offset, InBuffer source, long size, WriteOption option) { if (offset < 0) { return(ResultFs.InvalidOffset.Log()); } if (source.Size < 0) { return(ResultFs.InvalidSize.Log()); } // Note: Thread priority is temporarily increased when writing in FS return(BaseFile.Write(offset, source.Buffer.Slice(0, (int)size), option)); }
/// <summary> /// Write to file, writeOption is needed to define the path. /// </summary> /// <param name="writeOption"></param> public void WriteData(WriteOption writeOption) { string pathToFile = GetErgoHeartRatePath(ApplicationSettings.GetReadWritePath(this._ergoID), writeOption); List <byte[]> dataToWrite = new List <byte[]>(); switch (writeOption) { case WriteOption.Ergo: dataToWrite = this._bytesErgo; break; case WriteOption.Heartrate: dataToWrite = this._bytesHeartRate; break; } WriteToFileBinary(pathToFile, dataToWrite); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out _); if (rc.IsFailure()) { return(rc); } int inPos = 0; long outPos = offset; int remaining = source.Length; rc = GetSize(out long fileSize); if (rc.IsFailure()) { return(rc); } while (remaining > 0) { int fileIndex = GetSubFileIndexFromOffset(outPos); IFile file = Sources[fileIndex]; long fileOffset = outPos - fileIndex * SubFileSize; long fileEndOffset = Math.Min((fileIndex + 1) * SubFileSize, fileSize); int bytesToWrite = (int)Math.Min(fileEndOffset - outPos, remaining); rc = file.Write(fileOffset, source.Slice(inPos, bytesToWrite), options); if (rc.IsFailure()) { return(rc); } outPos += bytesToWrite; inPos += bytesToWrite; remaining -= bytesToWrite; } if (options.HasFlag(WriteOption.Flush)) { return(Flush()); } return(Result.Success); }
// Write(u32 writeOption, u64 offset, u64 size, buffer<u8, 0x45, 0>) public ResultCode Write(ServiceCtx context) { ulong position = context.Request.SendBuff[0].Position; WriteOption writeOption = context.RequestData.ReadStruct <WriteOption>(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = new byte[context.Request.SendBuff[0].Size]; context.Memory.Read(position, data); return((ResultCode)_baseFile.Get.Write(offset, new InBuffer(data), size, writeOption).Value); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { CheckIfDisposed(); if (source.Length == 0) { WriteState = (WriteState)(~options & WriteOption.Flush); return(Result.Success); } Result rc = File.Write(offset, source, options); if (rc.IsSuccess()) { WriteState = (WriteState)(~options & WriteOption.Flush); } return(rc); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out _); if (rc.IsFailure()) { return(rc); } lock (Locker) { BaseStream.Position = offset; BaseStream.Write(source); } if (options.HasFlag(WriteOption.Flush)) { return(Flush()); } return(Result.Success); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { Result rc = ValidateWriteParams(offset, source.Length, Mode, out _); if (rc.IsFailure()) { return(rc); } #if STREAM_SPAN lock (Locker) { BaseStream.Position = offset; BaseStream.Write(source); } #else byte[] buffer = ArrayPool <byte> .Shared.Rent(source.Length); try { source.CopyTo(buffer); lock (Locker) { BaseStream.Position = offset; BaseStream.Write(buffer, 0, source.Length); } } finally { ArrayPool <byte> .Shared.Return(buffer); } #endif if (options.HasFlag(WriteOption.Flush)) { return(Flush()); } return(Result.Success); }
// Write(u32 writeOption, u64 offset, u64 size, buffer<u8, 0x45, 0>) public ResultCode Write(ServiceCtx context) { long position = context.Request.SendBuff[0].Position; WriteOption writeOption = (WriteOption)context.RequestData.ReadInt32(); context.RequestData.BaseStream.Position += 4; long offset = context.RequestData.ReadInt64(); long size = context.RequestData.ReadInt64(); byte[] data = context.Memory.ReadBytes(position, size); try { _baseFile.Write(data, offset, writeOption); } catch (HorizonResultException ex) { return((ResultCode)ex.ResultValue.Value); } return(ResultCode.Success); }
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) { BaseFile.Write(source, offset, options); }
public PersonChoiceHandler(WriteOption writeOption) { this.writeOption = writeOption; }
public PersonChoiceHandler() { this.writeOption = WriteOption.Both; }
public void WriteFile(FileHandle handle, ReadOnlySpan <byte> source, long offset, WriteOption option) { if (IsEnabledAccessLog() && IsEnabledHandleAccessLog(handle)) { TimeSpan startTime = Time.GetCurrent(); handle.File.Write(source, offset, option); TimeSpan endTime = Time.GetCurrent(); string optionString = (option & WriteOption.Flush) == 0 ? "" : $", write_option: {option}"; OutputAccessLog(startTime, endTime, handle, $", offset: {offset}, size: {source.Length}{optionString}"); } else { handle.File.Write(source, offset, option); } }
public void SaveToImage(string filePath, string function, WriteOption option = WriteOption.None) { switch (option) { default: case WriteOption.SaveSeperate: SaveToImage(filePath, function, false); break; case WriteOption.Overwrite: SaveToImage(filePath, function, true); break; case WriteOption.None: SingleMap(filePath, function); break; } }
public abstract void Write(ReadOnlySpan <byte> source, long offset, WriteOption options);
public static extern Result Read(ref long outValue, FileHandle handle, long offset, byte[] buffer, long size); // 0x00A15960-0x00A15990 public static extern Result Write(FileHandle handle, long offset, byte[] buffer, long size, WriteOption option); // 0x00A15990-0x00A159C0
public static extern nn.Result Write( FileHandle handle, long offset, byte[] buffer, long size, WriteOption option);
public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) => ThrowHelper.ThrowResult(ResultFs.UnsupportedOperationModifyReadOnlyFile);
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { return(BaseFile.Write(offset, source, options)); }
protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options) { return(ResultFs.InvalidOpenModeForWrite.Log()); }