コード例 #1
0
    protected override async Task <FileObject> CreateFileImplAsync(FileParameters option, CancellationToken cancel = default)
    {
        string fileName = this.PathParser.GetFileName(option.Path);

        if (fileName.IndexOf(Params.SplitStr) != -1)
        {
            throw new ApplicationException($"The original filename '{fileName}' contains '{Params.SplitStr}'.");
        }

        await using (CreatePerTaskCancellationToken(out CancellationToken operationCancel, cancel))
        {
            using (await AsyncLockObj.LockWithAwait(operationCancel))
            {
                cancel.ThrowIfCancellationRequested();

                bool isSimplePhysicalFileExists = await UnderlayFileSystem.IsFileExistsAsync(option.Path);

                if (isSimplePhysicalFileExists)
                {
                    // If there is a simple physical file, open it.
                    return(await UnderlayFileSystem.CreateFileAsync(option, cancel));
                }

                ParsedPath[] relatedFiles = await GetPhysicalFileStateInternal(option.Path, operationCancel);

                return(await LargeFileObject.CreateFileAsync(this, option, relatedFiles, operationCancel));
            }
        }
    }
コード例 #2
0
        public Cursor(LargeFileObject o, long logicalPosision, long dataLength = 0)
        {
            checked
            {
                Lfo = o;

                if (logicalPosision < 0)
                {
                    throw new ArgumentOutOfRangeException("logicalPosision < 0");
                }

                if (dataLength < 0)
                {
                    throw new ArgumentOutOfRangeException("dataLength < 0");
                }

                var p = Lfo.LargeFileSystem.Params;
                if (logicalPosision > p.MaxLogicalFileSize)
                {
                    throw new ArgumentOutOfRangeException("logicalPosision > MaxLogicalFileSize");
                }

                this.LogicalPosition    = logicalPosision;
                this.PhysicalFileNumber = this.LogicalPosition / p.MaxSinglePhysicalFileSize;

                if (this.PhysicalFileNumber > p.MaxFileNumber)
                {
                    throw new ArgumentOutOfRangeException($"this.PhysicalFileNumber ({this.PhysicalFileNumber}) > p.MaxFileNumber ({p.MaxFileNumber})");
                }

                this.PhysicalPosition        = this.LogicalPosition % p.MaxSinglePhysicalFileSize;
                this.PhysicalRemainingLength = p.MaxSinglePhysicalFileSize - this.PhysicalPosition;
                this.PhysicalDataLength      = Math.Min(this.PhysicalRemainingLength, dataLength);
            }
        }
コード例 #3
0
    public static async Task <FileObject> CreateFileAsync(LargeFileSystem fileSystem, FileParameters fileParams, LargeFileSystem.ParsedPath[] relatedFiles, CancellationToken cancel = default)
    {
        cancel.ThrowIfCancellationRequested();

        LargeFileObject f = new LargeFileObject(fileSystem, fileParams, relatedFiles);

        try
        {
            await f.InternalInitAsync(cancel);
        }
        catch
        {
            f._DisposeSafe();
            throw;
        }

        return(f);
    }