Beispiel #1
0
 public ControlBodyGlyph(Rectangle bounds, Cursor?cursor, IComponent?relatedComponent, ControlDesigner?designer)
     : base(relatedComponent, new ControlDesigner.TransparentBehavior(designer))
 {
     _bounds        = bounds;
     _hitTestCursor = cursor;
     _component     = relatedComponent;
 }
Beispiel #2
0
 public ControlBodyGlyph(Rectangle bounds, Cursor?cursor, IComponent?relatedComponent, Behavior?behavior)
     : base(relatedComponent, behavior)
 {
     _bounds        = bounds;
     _hitTestCursor = cursor;
     _component     = relatedComponent;
 }
Beispiel #3
0
        /// <summary>
        /// Creates a new instance for the specified control.
        /// </summary>
        /// <param name="control">The control whose Cursor property should be changed.</param>
        public WaitCursor(Control?control)
        {
            this.control = control;

            // Try to find the highest-level control (i.e., Form) that we can.
            if (this.control != null)
            {
                Form frm = this.control.FindForm();
                if (frm == null)
                {
                    frm = Form.ActiveForm;
                }

                if (frm != null)
                {
                    this.control = frm;
                }
            }
            else
            {
                this.control = Form.ActiveForm;
            }

            if (this.control == null)
            {
                this.previous = Cursor.Current;
            }
            else
            {
                this.previous = this.control.Cursor;
            }

            this.Refresh();
        }
        public static Connection <T> ToConnection <T>(
            this IEnumerable <Edge <T> > edges,
            bool hasNextPage,
            bool hasPreviousPage        = false,
            int?totalCount              = null,
            Cursor?defaultCursorIfEmpty = null)
        {
            var edgeList = edges.ToList();

            if (!defaultCursorIfEmpty.HasValue)
            {
                defaultCursorIfEmpty = Cursor.New <T>(0);
            }
            return(new Connection <T>
            {
                Edges = edgeList,
                TotalCount = totalCount,
                PageInfo = new PageInfo
                {
                    StartCursor = edgeList.Any()
                        ? edgeList.Min(edge => edge.Cursor)
                        : defaultCursorIfEmpty.Value,
                    EndCursor = edgeList.Any()
                        ? edgeList.Max(edge => edge.Cursor)
                        : defaultCursorIfEmpty.Value,
                    HasNextPage = hasNextPage,
                    HasPreviousPage = hasPreviousPage,
                },
            });
        }
Beispiel #5
0
 private Connection <int> GenerateInfiniteConnection(
     int count, int throwExceptionAboveThisNumber,
     int?first = null, int?last = null, Cursor?after = null, Cursor?before = null)
 {
     return(InfiniteCollection(throwExceptionAboveThisNumber)
            .ToConnection(first, after, last, before));
 }
Beispiel #6
0
        /// <summary>
        /// Starts a new scope, recording <see cref="Cursor.Current"/> and setting the mouse cursor to <see cref="Cursors.WaitCursor"/>.
        /// </summary>
        public static WaitCursorScope Enter(Cursor?cursor = null)
        {
            var cursorAtStartOfScope = Cursor.Current;

            Cursor.Current = cursor ?? Cursors.WaitCursor;

            return(new WaitCursorScope(cursorAtStartOfScope));
        }
Beispiel #7
0
 public void SetCursor(Form?f, Cursor?z)
 {
     if (f != null)
     {
         f.Cursor = z;
     }
     Info.Cursor = z;
 }
Beispiel #8
0
        void ExportButtonClick(object?sender, EventArgs e)
        {
            if (Session is null)
            {
                return;
            }

            string filename = Session.SenderCompId + "-" + Session.TargetCompId + ".txt";

            using SaveFileDialog dlg = new();
            dlg.Filter           = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
            dlg.FilterIndex      = 2;
            dlg.RestoreDirectory = true;
            dlg.FileName         = filename;
            dlg.Title            = "Export";

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Cursor?original = Cursor.Current;
                Cursor.Current = Cursors.WaitCursor;

                try
                {
                    using FileStream stream   = new(dlg.FileName, FileMode.Create);
                    using StreamWriter writer = new(stream);

                    foreach (Fix.Message message in Session.Messages)
                    {
                        string timestamp = "Unknown";

                        Fix.Field?field = message.Fields.Find(FIX_5_0SP2.Fields.SendingTime.Tag);

                        if (field is not null)
                        {
                            timestamp = field.Value;
                        }

                        string direction = message.Incoming ? "received" : "sent";

                        if (Session.Version.Messages[message.MsgType] is Fix.Dictionary.Message definition)
                        {
                            writer.WriteLine("{0} ({1}) ({2})",
                                             timestamp,
                                             direction,
                                             definition.Name);

                            writer.WriteLine("{");
                            writer.WriteLine(message.ToString());
                            writer.WriteLine("}");
                        }
                    }
                }
                finally
                {
                    Cursor.Current = original;
                }
            }
        }
Beispiel #9
0
            public ParseError(Cursor?cursor, string message)
            {
                message = message
                          .Replace("\r", "\\r")
                          .Replace("\n", "\\n");

                Cursor  = cursor;
                Message = message;
            }
        private void PlatformDispose()
        {
            if (_needsDisposing)
            {
                Cursor?.Dispose();
                Cursor = null;

                _needsDisposing = false;
            }
        }
Beispiel #11
0
        private void ThumbPreviewMouseMove(object sender, MouseEventArgs e)
        {
            var thumb = sender as Thumb;

            if (thumb is null)
            {
                return;
            }
            var gridViewColumn = FindParentColumn(thumb);

            if (gridViewColumn is null)
            {
                return;
            }

            // suppress column resizing for proportional, fixed and range fill columns
            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
            {
                thumb.SetCurrentValue(FrameworkElement.CursorProperty, null);
                return;
            }

            // check range column bounds
            if (thumb.IsMouseCaptured && RangeColumn.IsRangeColumn(gridViewColumn))
            {
                var minWidth = RangeColumn.GetRangeMinWidth(gridViewColumn);
                var maxWidth = RangeColumn.GetRangeMaxWidth(gridViewColumn);

                if (minWidth.HasValue && maxWidth.HasValue && (minWidth > maxWidth))
                {
                    return; // invalid case
                }

                if (_resizeCursor is null)
                {
                    _resizeCursor = thumb.Cursor; // save the resize cursor
                }

                if (minWidth.HasValue && gridViewColumn.Width <= minWidth.Value)
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, Cursors.No);
                }
                else if (maxWidth.HasValue && gridViewColumn.Width >= maxWidth.Value)
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, Cursors.No);
                }
                else
                {
                    thumb.SetCurrentValue(FrameworkElement.CursorProperty, _resizeCursor); // between valid min/max
                }
            }
        }
Beispiel #12
0
 public Connection <SearchResult> Search(
     UserContext context,
     [Description("Title or last name.")] NonNull <string> forString,
     [Description("Only return search results after given cursor.")] Cursor?after,
     [Description("Return the first N results.")] int?first)
 {
     return(context
            .Search(forString.Value)
            .Select(node => new SearchResult {
         Instance = node
     })
            .ToConnection(first ?? 5, after));
 }
Beispiel #13
0
        private void SetCursor(Cursor?newCursor)
        {
            bool useWaitCursor = newCursor is not null && newCursor == Cursors.WaitCursor;

            if (this.control != null)
            {
                this.control.Cursor        = newCursor;
                this.control.UseWaitCursor = useWaitCursor;
            }

            Application.UseWaitCursor = useWaitCursor;
            Cursor.Current            = newCursor;
        }
        private Connection <Foo> GenerateConnection(
            int count, int?first = null, int?last = null, Cursor?after = null, Cursor?before = null)
        {
            var items = new List <Foo>();

            for (var i = 1; i <= count; i++)
            {
                items.Add(new Foo {
                    Value = i
                });
            }

            return(items.ToConnection(first, after, last, before, count));
        }
Beispiel #15
0
        private WaitCursorScope(Func <bool>?showWhen = null)
        {
            s_current.Value?.Dispose();
            s_current.Value = this;

            _stopwatch.Start();
            _oldCursor = Cursor.Current;
            _showWhen  = showWhen;
            _timer     = new System.Windows.Forms.Timer {
                Interval = 250
            };
            _timer.Tick += OnIdle;
            _timer.Start();
            Application.Idle += OnIdle;
        }
        } // ListViewUnloaded

        // ----------------------------------------------------------------------
        private void ThumbPreviewMouseMove(object sender, MouseEventArgs e)
        {
            if (!(sender is Thumb thumb))
            {
                return;
            }
            var gridViewColumn = FindParentColumn(thumb);

            if (gridViewColumn == null)
            {
                return;
            }

            // suppress column resizing for proportional, fixed and range fill columns
            if (ProportionalColumn.IsProportionalColumn(gridViewColumn) || FixedColumn.IsFixedColumn(gridViewColumn) || IsFillColumn(gridViewColumn))
            {
                thumb.Cursor = null;
                return;
            }

            // check range column bounds
            if (thumb.IsMouseCaptured && RangeColumn.IsRangeColumn(gridViewColumn))
            {
                var minWidth = RangeColumn.GetRangeMinWidth(gridViewColumn);
                var maxWidth = RangeColumn.GetRangeMaxWidth(gridViewColumn);

                if (minWidth.HasValue && maxWidth.HasValue && minWidth > maxWidth)
                {
                    return;                                                                // invalid case
                }
                if (_resizeCursor == null)
                {
                    _resizeCursor = thumb.Cursor;                        // save the resize cursor
                }
                if (minWidth.HasValue && gridViewColumn.Width <= minWidth.Value)
                {
                    thumb.Cursor = Cursors.No;
                }
                else if (maxWidth.HasValue && gridViewColumn.Width >= maxWidth.Value)
                {
                    thumb.Cursor = Cursors.No;
                }
                else
                {
                    thumb.Cursor = _resizeCursor; // between valid min/max
                }
            }
        } // ThumbPreviewMouseMove
        public static Connection <T> ToConnection <T>(
            this IEnumerable <T> enumerable,
            int?first      = null,
            Cursor?after   = null,
            int?last       = null,
            Cursor?before  = null,
            int?totalCount = null)
        {
            ValidateParameters(first, after, last, before);
            var connection = new ConnectionImpl <T>(enumerable, first, after, last, before);

            return(new Connection <T>
            {
                Edges = connection.Edges,
                PageInfo = connection.PageInfo,
                TotalCount = totalCount,
            });
        }
Beispiel #18
0
        void LoadClientMessagesButtonClick(object?sender, EventArgs e)
        {
            using OpenFileDialog dlg = new();

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Cursor?original = Cursor.Current;

            Cursor.Current = Cursors.WaitCursor;

            try
            {
                Fix.MessageCollection messages = Fix.MessageCollection.Parse(dlg.FileName);

                if (messages == null)
                {
                    MessageBox.Show(this,
                                    "The file could not be parsed",
                                    Application.ProductName,
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Information);
                    return;
                }

                Messages = messages;
            }
            catch (Exception ex)
            {
                MessageBox.Show(this,
                                ex.Message,
                                Application.ProductName,
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
            finally
            {
                Cursor.Current = original;
            }
        }
Beispiel #19
0
        private static void ValidateParameters(int?first, Cursor?after, int?last, Cursor?before)
        {
            if (first.HasValue && last.HasValue)
            {
                throw new ArgumentException("Cannot use `first` in conjunction with `last`.");
            }

            if (after.HasValue && before.HasValue)
            {
                throw new ArgumentException("Cannot use `after` in conjunction with `before`.");
            }

            if (first.HasValue && before.HasValue)
            {
                throw new ArgumentException("Cannot use `first` in conjunction with `before`.");
            }

            if (last.HasValue && after.HasValue)
            {
                throw new ArgumentException("Cannot use `last` in conjunction with `after`.");
            }
        }
        // ReSharper disable ParameterOnlyUsedForPreconditionCheck.Local
        private static void ValidateParameters(int?first, Cursor?after, int?last, Cursor?before)
        // ReSharper restore ParameterOnlyUsedForPreconditionCheck.Local
        {
            if (first.HasValue && last.HasValue)
            {
                throw new ArgumentException("Cannot use `first` in conjunction with `last`.");
            }

            if (after.HasValue && before.HasValue)
            {
                throw new ArgumentException("Cannot use `after` in conjunction with `before`.");
            }

            if (first.HasValue && before.HasValue)
            {
                throw new ArgumentException("Cannot use `first` in conjunction with `before`.");
            }

            if (last.HasValue && after.HasValue)
            {
                throw new ArgumentException("Cannot use `last` in conjunction with `after`.");
            }
        }
Beispiel #21
0
        /// <summary>
        ///  Converts the given object to another type.  The most common types to convert
        ///  are to and from a string object.  The default implementation will make a call
        ///  to ToString on the object if the object is valid and if the destination
        ///  type is string.  If this cannot convert to the destination type, this will
        ///  throw a NotSupportedException.
        /// </summary>
        public override object?ConvertTo(ITypeDescriptorContext?context, CultureInfo?culture, object?value, Type destinationType)
        {
            if (value is Cursor cursor)
            {
                if (destinationType == typeof(string))
                {
                    PropertyInfo[] props     = GetProperties();
                    int            bestMatch = -1;

                    for (int i = 0; i < props.Length; i++)
                    {
                        PropertyInfo prop = props[i];
                        object[]? tempIndex = null;
                        Cursor?c = (Cursor?)prop.GetValue(null, tempIndex);
                        if (c == cursor)
                        {
                            if (ReferenceEquals(c, value))
                            {
                                return(prop.Name);
                            }
                            else
                            {
                                bestMatch = i;
                            }
                        }
                    }

                    if (bestMatch != -1)
                    {
                        return(props[bestMatch].Name);
                    }

                    // We throw here because we cannot meaningfully convert a custom
                    // cursor into a string. In fact, the ResXResourceWriter will use
                    // this exception to indicate to itself that this object should
                    // be serialized through ISerializable instead of a string.

                    throw new FormatException(SR.CursorCannotCovertToString);
                }
                else if (destinationType == typeof(InstanceDescriptor))
                {
                    PropertyInfo[] props = GetProperties();
                    foreach (PropertyInfo prop in props)
                    {
                        if (prop.GetValue(null, null) == value)
                        {
                            return(new InstanceDescriptor(prop, null));
                        }
                    }
                }
                else if (destinationType == typeof(byte[]))
                {
                    return(cursor.GetData());
                }
            }
            else if (destinationType == typeof(byte[]) && value is null)
            {
                return(Array.Empty <byte>());
            }

            return(base.ConvertTo(context, culture, value, destinationType));
        }
Beispiel #22
0
        private void ListDragSource_MouseMove(object?sender, MouseEventArgs e)
        {
            testOutputHelper.WriteLine($"Mouse move on drag source to position ({e.X},{e.Y}) with buttons {e.Button}.");
            if ((e.Button & MouseButtons.Left) == MouseButtons.Left)
            {
                // If the mouse moves outside the rectangle, start the drag.
                if (dragBoxFromMouseDown != Rectangle.Empty &&
                    !dragBoxFromMouseDown.Contains(e.X, e.Y))
                {
                    // Create custom cursors for the drag-and-drop operation.
                    try
                    {
                        MyNormalCursor = new Cursor("3dwarro.cur");
                        MyNoDropCursor = new Cursor("3dwno.cur");
                    }
                    catch
                    {
                        // An error occurred while attempting to load the cursors, so use
                        // standard cursors.
                        UseCustomCursorsCheck.Checked = false;
                    }
                    finally
                    {
                        // The screenOffset is used to account for any desktop bands
                        // that may be at the top or left side of the screen when
                        // determining when to cancel the drag drop operation.
                        screenOffset = SystemInformation.WorkingArea.Location;

                        // Proceed with the drag-and-drop, passing in the list item.
                        DragDropEffects dropEffect = ListDragSource.DoDragDrop(ListDragSource.Items[indexOfItemUnderMouseToDrag], DragDropEffects.All | DragDropEffects.Link);

                        // If the drag operation was a move then remove the item.
                        if (dropEffect == DragDropEffects.Move)
                        {
                            ListDragSource.Items.RemoveAt(indexOfItemUnderMouseToDrag);

                            // Selects the previous item in the list as long as the list has an item.
                            if (indexOfItemUnderMouseToDrag > 0)
                            {
                                ListDragSource.SelectedIndex = indexOfItemUnderMouseToDrag - 1;
                            }

                            else if (ListDragSource.Items.Count > 0)
                            {
                                // Selects the first item.
                                ListDragSource.SelectedIndex = 0;
                            }
                        }

                        // Dispose of the cursors since they are no longer needed.
                        if (MyNormalCursor != null)
                        {
                            MyNormalCursor.Dispose();
                        }

                        if (MyNoDropCursor != null)
                        {
                            MyNoDropCursor.Dispose();
                        }
                    }
                }
            }
        }
 public ConnectionImpl(IEnumerable <TNode> collection, int?first, Cursor?after, int?last, Cursor?before)
     : this(collection.Select((item, index) => Tuple.Create($"{index + 1}", item)), first, after, last, before)
 {
 }
            public ConnectionImpl(IEnumerable <Tuple <string, TNode> > collection, int?first, Cursor?after, int?last, Cursor?before)
            {
                Cursor?minCursor = null;
                Cursor?maxCursor = null;

                _collection = collection ?? new List <Tuple <string, TNode> >();

                var edges = _collection
                            .Select(t => new Edge <TNode>
                {
                    Cursor = Cursor.New <TNode>(t.Item1),
                    Node   = t.Item2,
                });

                if (after.HasValue)
                {
                    // ReSharper disable PossibleMultipleEnumeration
                    var lastEntryBefore = edges
                                          .TakeWhile(edge => edge.Cursor <= after.Value)
                                          .LastOrDefault();

                    if (lastEntryBefore != null)
                    {
                        minCursor = lastEntryBefore.Cursor;
                    }

                    edges = edges.SkipWhile(edge => edge.Cursor <= after.Value);
                    // ReSharper restore PossibleMultipleEnumeration
                }

                if (before.HasValue)
                {
                    var beforeEdges = edges
                                      .TakeWhile(edge => edge.Cursor <= before.Value)
                                      .ToList();

                    maxCursor = beforeEdges.LastOrDefault()?.Cursor;
                    edges     = beforeEdges.TakeWhile(edge => edge.Cursor < before.Value);
                }

                if (first.HasValue)
                {
                    var edgesList = edges.Take(first.Value + 1).ToList();
                    maxCursor = edgesList.LastOrDefault()?.Cursor;
                    edgesList = edgesList.Take(first.Value).ToList();
                    edges     = edgesList;
                }

                if (last.HasValue)
                {
                    var edgesList = edges.ToList();
                    var count     = edgesList.Count;
                    if (last.Value < count)
                    {
                        minCursor = edgesList
                                    .Skip(Math.Max(0, count - last.Value - 2))
                                    .FirstOrDefault()?
                                    .Cursor ?? Cursor.New <TNode>(0);
                        edges = edgesList.Skip(count - last.Value);
                    }
                    else
                    {
                        edges     = edgesList;
                        minCursor = edgesList.FirstOrDefault()?.Cursor;
                    }
                }

                var paginatedEdges = edges.ToList();

                Edges = paginatedEdges;

                if (minCursor == null)
                {
                    minCursor = paginatedEdges.FirstOrDefault()?.Cursor ?? Cursor.New <TNode>(0);
                }
                if (maxCursor == null)
                {
                    maxCursor = paginatedEdges.Any() ? paginatedEdges.Max(n => n.Cursor) : Cursor.New <TNode>(0);
                }

                if (paginatedEdges.Any())
                {
                    var minPageCursor = paginatedEdges.Min(edge => edge.Cursor);
                    var maxPageCursor = paginatedEdges.Max(edge => edge.Cursor);

                    PageInfo = new PageInfo
                    {
                        StartCursor = minPageCursor,
                        EndCursor   = maxPageCursor,
                        HasNextPage = maxPageCursor <maxCursor,
                                                     HasPreviousPage = minPageCursor> minCursor,
                    };
                }
                else
                {
                    PageInfo = new PageInfo
                    {
                        StartCursor = after ?? before ?? (Cursor)minCursor,
                        EndCursor   = before ?? after ?? (Cursor)maxCursor,
                    };

                    var startValue = PageInfo.Value.StartCursor.IntegerForCursor <TNode>() ?? 0;
                    var endValue   = PageInfo.Value.EndCursor.IntegerForCursor <TNode>() ?? 0;

                    if (before.HasValue)
                    {
                        var cursorValue = Cursor.New <TNode>(Math.Max(0, Math.Min(startValue - 1, endValue - 1)));
                        PageInfo.Value.StartCursor = PageInfo.Value.EndCursor = cursorValue;
                    }
                    else if (after.HasValue)
                    {
                        var cursorValue = Cursor.New <TNode>(Math.Max(0, Math.Max(startValue + 1, endValue + 1)));
                        PageInfo.Value.StartCursor = PageInfo.Value.EndCursor = cursorValue;
                    }
                    else if (first.HasValue)
                    {
                        var cursorValue = Cursor.New <TNode>(Math.Max(0, Math.Min(startValue - 1, endValue - 1)));
                        PageInfo.Value.StartCursor = PageInfo.Value.EndCursor = cursorValue;
                    }
                    else if (last.HasValue)
                    {
                        var cursorValue = Cursor.New <TNode>(Math.Max(0, Math.Max(startValue + 1, endValue + 1)));
                        PageInfo.Value.StartCursor = PageInfo.Value.EndCursor = cursorValue;
                    }

                    PageInfo.Value.HasNextPage =
                        (first.GetValueOrDefault(-1) == 0)
                        ? PageInfo.Value.EndCursor <= maxCursor
                        : PageInfo.Value.EndCursor < maxCursor;

                    PageInfo.Value.HasPreviousPage =
                        PageInfo.Value.StartCursor > minCursor;
                }
            }
 private void PlatformSetCursor(MouseCursor cursor)
 {
     _cursor = cursor.Cursor;
     UpdateCursor();
 }
Beispiel #26
0
 public void RenderCursor(int row, int col, bool on)
 {
     _cursor = on ? new Cursor {
         Row = row, Col = col
     } : null;
 }
#pragma warning disable CS0612 // 型またはメンバーが旧型式です
    protected override async Task WriteRandomImplAsync(long position, ReadOnlyMemory <byte> data, CancellationToken cancel = default)
    {
        checked
        {
            if (data.Length == 0)
            {
                return;
            }

            List <Cursor> cursorList = GenerateCursorList(position, data.Length, true);

            if (cursorList.Count >= 1 && lastWriteCursor != null)
            {
                if (cursorList[0].PhysicalFileNumber != lastWriteCursor.PhysicalFileNumber)
                {
                    await using (var handle = await GetUnderlayRandomAccessHandle(lastWriteCursor.LogicalPosition, cancel))
                    {
                        await handle.FlushAsync();
                    }

                    lastWriteCursor = null;
                }
            }

            if (this.FileParams.Flags.Bit(FileFlags.LargeFs_ProhibitWriteWithCrossBorder) && cursorList.Count >= 2)
            {
                if (cursorList.Count >= 3)
                {
                    // Write fails because it beyonds two borders
                    throw new FileException(this.FileParams.Path, $"LargeFileSystemDoNotAppendBeyondBorder error: pos = {position}, data = {data.Length}");
                }
                else
                {
                    Debug.Assert(data.Length <= this.LargeFileSystem.Params.MaxSinglePhysicalFileSize);

                    var firstCursor  = cursorList[0];
                    var secondCursor = cursorList[1];

                    Debug.Assert(firstCursor.LogicalPosition == position);
                    Debug.Assert(secondCursor.LogicalPosition == (firstCursor.LogicalPosition + firstCursor.PhysicalRemainingLength));

                    long requiredPaddingSize = firstCursor.PhysicalRemainingLength;

                    throw new LargeFsWriteWithCrossBorderException($"LargeFs_ProhibitWriteWithCrossBorder. pos = {position}, data = {data.Length}, requiredPaddingSize = {requiredPaddingSize}", requiredPaddingSize);
                }
            }

            if (this.FileParams.Flags.BitAny(FileFlags.LargeFs_AppendWithoutCrossBorder | FileFlags.LargeFs_AppendNewLineForCrossBorder) &&
                position == this.CurrentFileSize && cursorList.Count >= 2)
            {
                // Crossing the border when the LargeFileSystemAppendWithCrossBorder flag is set
                if (cursorList.Count >= 3)
                {
                    // Write fails because it beyonds two borders
                    throw new FileException(this.FileParams.Path, $"LargeFileSystemDoNotAppendBeyondBorder error: pos = {position}, data = {data.Length}");
                }
                else
                {
                    Debug.Assert(data.Length <= this.LargeFileSystem.Params.MaxSinglePhysicalFileSize);

                    var firstCursor  = cursorList[0];
                    var secondCursor = cursorList[1];

                    Debug.Assert(firstCursor.LogicalPosition == position);
                    Debug.Assert(secondCursor.LogicalPosition == (firstCursor.LogicalPosition + firstCursor.PhysicalRemainingLength));

                    await using (var handle = await GetUnderlayRandomAccessHandle(position, cancel))
                    {
                        // Write the zero-cleared block toward the end of the first physical file
                        byte[] appendBytes = new byte[firstCursor.PhysicalRemainingLength];
                        if (this.FileParams.Flags.Bit(FileFlags.LargeFs_AppendNewLineForCrossBorder))
                        {
                            if (appendBytes.Length >= 2)
                            {
                                appendBytes[0] = 13;
                                appendBytes[1] = 10;
                            }
                            else if (appendBytes.Length >= 1)
                            {
                                appendBytes[0] = 10;
                            }
                        }

                        await handle.WriteRandomAsync(firstCursor.PhysicalPosition, appendBytes, cancel);

                        await handle.FlushAsync(cancel); // Complete write the first file

                        this.CurrentFileSize += firstCursor.PhysicalRemainingLength;
                    }

                    await using (var handle = await GetUnderlayRandomAccessHandle(secondCursor.LogicalPosition, cancel))
                    {
                        // Write the data from the beginning of the second physical file
                        await handle.WriteRandomAsync(0, data, cancel);

                        this.CurrentFileSize += data.Length;
                    }

                    this.lastWriteCursor = secondCursor;
                }
            }
            else
            {
                // Normal write
                for (int i = 0; i < cursorList.Count; i++)
                {
                    Cursor cursor     = cursorList[i];
                    bool   isPastFile = (i != cursorList.Count - 1);

                    await using (var handle = await GetUnderlayRandomAccessHandle(cursor.LogicalPosition, cancel))
                    {
                        await handle.WriteRandomAsync(cursor.PhysicalPosition, data.Slice((int)(cursor.LogicalPosition - position), (int)cursor.PhysicalDataLength), cancel);

                        if (isPastFile)
                        {
                            await handle.FlushAsync(cancel);
                        }
                    }

                    this.lastWriteCursor = cursor;
                }

                this.CurrentFileSize = Math.Max(this.CurrentFileSize, position + data.Length);
            }
        }
    }
 private MouseCursor(Cursor cursor, bool needsDisposing = false)
 {
     Cursor          = cursor;
     _needsDisposing = needsDisposing;
 }