/* ======================================================================== * Copyright (c) 2005-2025 The OPC Foundation, Inc. All rights reserved. * * OPC Foundation MIT License 1.00 * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the "Software"), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * The complete license agreement can be found here: * http://opcfoundation.org/License/MIT/1.00/ * ======================================================================*/ using System; using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; namespace Opc.Ua.Client.FileSystem { /// /// Common base for and /// ; mirrors /// . /// public abstract class UaFileSystemInfo { internal UaFileSystemInfo( FileSystemClient owner, UaDirectoryInfo? parent, NodeId nodeId, QualifiedName browseName, IReadOnlyList segments) { Owner = owner ?? throw new ArgumentNullException(nameof(owner)); Parent = parent; if (nodeId.IsNull) { throw new ArgumentNullException(nameof(nodeId)); } NodeId = nodeId; BrowseName = browseName; Segments = segments; } /// /// The that produced this info /// object. All operations that need to call back to the server /// route through this owner. /// public FileSystemClient Owner { get; } /// /// The parent directory; null only for the root. /// public UaDirectoryInfo? Parent { get; } /// /// The OPC UA of the underlying object. /// public NodeId NodeId { get; } /// /// The OPC UA of the underlying /// object. /// public QualifiedName BrowseName { get; } /// /// The unqualified leaf name of this file or directory. /// /// /// This property mirrors /// : it discards the /// namespace prefix. Use when round-trip /// fidelity matters. /// public string Name => BrowseName.Name ?? string.Empty; /// /// The canonical, namespace-aware path of this object relative /// to the root, in /// form (always begins with '/'). /// public string FullPath => UaPath.Format(Segments); /// /// The path segments leading to this object. /// public IReadOnlyList Segments { get; } /// /// true for ; false /// for . /// public abstract bool IsDirectory { get; } /// /// Re-reads metadata from the server. Subclasses populate type- /// specific properties. /// public abstract ValueTask RefreshAsync(CancellationToken ct = default); /// /// Deletes this file or empty directory. For non-empty /// directories, use /// with recursive: true. /// public virtual ValueTask DeleteAsync(CancellationToken ct = default) { return Owner.DeleteCoreAsync(this, recursive: false, ct); } /// /// Moves this object to . The /// destination's parent directory must exist. /// public ValueTask MoveToAsync( string destPath, CancellationToken ct = default) { return Owner.MoveOrCopyAsync(this, destPath, copy: false, ct); } /// /// Moves this object into , /// optionally renaming it via . /// public ValueTask MoveToAsync( UaDirectoryInfo destinationDirectory, string? newName = null, CancellationToken ct = default) { return Owner.MoveOrCopyAsync( this, destinationDirectory, newName ?? Name, copy: false, ct); } /// /// Copies this object to . /// public ValueTask CopyToAsync( string destPath, CancellationToken ct = default) { return Owner.MoveOrCopyAsync(this, destPath, copy: true, ct); } /// /// Copies this object into /// , optionally renaming /// it via . /// public ValueTask CopyToAsync( UaDirectoryInfo destinationDirectory, string? newName = null, CancellationToken ct = default) { return Owner.MoveOrCopyAsync( this, destinationDirectory, newName ?? Name, copy: true, ct); } /// public override string ToString() { return FullPath; } } }