Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        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();
            }
        }
Esempio n. 3
0
        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();
            }
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
        public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options)
        {
            ValidateWriteParams(source, offset);

            BaseStorage.Write(source, offset);

            if ((options & WriteOption.Flush) != 0)
            {
                Flush();
            }
        }
Esempio n. 7
0
        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));
        }
Esempio n. 8
0
        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);
        }
Esempio n. 9
0
        // 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);
        }
Esempio n. 10
0
        /// <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));
        }
Esempio n. 12
0
        // 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;
        }
Esempio n. 13
0
        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));
        }
Esempio n. 14
0
        /// <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);
        }
Esempio n. 15
0
        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);
        }
Esempio n. 16
0
        // 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);
        }
Esempio n. 17
0
        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);
        }
Esempio n. 18
0
        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);
        }
Esempio n. 19
0
        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);
        }
Esempio n. 20
0
        // 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);
        }
Esempio n. 21
0
 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;
 }
Esempio n. 24
0
        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);
            }
        }
Esempio n. 25
0
        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;
            }
        }
Esempio n. 26
0
 public abstract void Write(ReadOnlySpan <byte> source, long offset, WriteOption options);
Esempio n. 27
0
 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
Esempio n. 28
0
 public static extern nn.Result Write(
     FileHandle handle, long offset, byte[] buffer, long size, WriteOption option);
Esempio n. 29
0
 public override void Write(ReadOnlySpan <byte> source, long offset, WriteOption options) =>
 ThrowHelper.ThrowResult(ResultFs.UnsupportedOperationModifyReadOnlyFile);
Esempio n. 30
0
 protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options)
 {
     return(BaseFile.Write(offset, source, options));
 }
Esempio n. 31
0
 protected override Result WriteImpl(long offset, ReadOnlySpan <byte> source, WriteOption options)
 {
     return(ResultFs.InvalidOpenModeForWrite.Log());
 }