/// <summary> /// Create Sub Folder on Folder Node. /// </summary> /// <param name="node"></param> /// <param name="folderName"></param> /// <returns></returns> public Node CreateFolder(Node node, string folderName) { if (!this.ValidateNode(node)) { return(null); } if (string.IsNullOrEmpty(folderName)) { this.AddError("CreateFolder", "Required folderName"); return(null); } if (node.Type != NodeType.Folder) { this.AddError("CreateFolder", $"Invalid Operation: NodeType.{node.Type}"); return(null); } var newFullPath = $@"{node.FullPath}\{folderName}"; PathSet newPathSet; try { newPathSet = PathSet.Parse(newFullPath); } catch (Exception ex) { this.AddError("CreateFolder", $"Invalid Path: {newFullPath}", ex); return(null); } if (!this.ValidatePathSet(newPathSet)) { return(null); } var path = this.FormatPath(newPathSet.ElementsPath); using (var hdr = this.GetHandler(path, HandleType.Write, NodeType.Folder)) { if (!hdr.Succeeded) { this.AddError("CreateFolder", $"Create Handle Failed: {node.FullPath}"); return(null); } // The creation handle cannot be used to get node information. //return this.CreateNode(hdr, NodeType.Folder, newPathSet, node.ParamSet); } using (var hdr = this.GetHandler(path, HandleType.Read, NodeType.Folder)) { return(this.CreateNode(hdr, NodeType.Folder, newPathSet, node.ParamSet)); } }
/// <summary> /// Get Node from only Path. /// </summary> /// <param name="fullPath"></param> /// <param name="nodeType"></param> /// <param name="paramSet"></param> /// <returns></returns> public static Node Get( string fullPath, NodeType nodeType, FixedParamSet paramSet ) { var pathSet = PathSet.Parse(fullPath); return(NodeFactory.InnerGet(nodeType, pathSet, paramSet)); }
/// <summary> /// Get Node from Path and SMB-FileInfomation /// </summary> /// <param name="fullPath"></param> /// <param name="paramSet"></param> /// <param name="basicInfo"></param> /// <param name="stdInfo"></param> /// <returns></returns> public static Node Get( string fullPath, FixedParamSet paramSet, FileBasicInformation basicInfo, FileStandardInformation stdInfo = null ) { if (paramSet == null) { throw new ArgumentException("Required paramSet."); } if (basicInfo == null) { throw new ArgumentException("Required info."); } var pathSet = PathSet.Parse(fullPath); if (basicInfo.FileAttributes.HasFlag(SMBLibrary.FileAttributes.Directory)) { // Folder var result = NodeFactory.InnerGet( NodeType.Folder, pathSet, paramSet ); result.Created = basicInfo.CreationTime; result.Updated = basicInfo.LastWriteTime; result.LastAccessed = basicInfo.LastAccessTime; return(result); } else { // File var result = NodeFactory.InnerGet( NodeType.File, pathSet, paramSet ); result.Size = stdInfo?.EndOfFile; result.Created = basicInfo.CreationTime; result.Updated = basicInfo.LastWriteTime; result.LastAccessed = basicInfo.LastAccessTime; return(result); } }
/// <summary> /// Get Child Node from Path and Smb1-Result. /// </summary> /// <param name="parentNode"></param> /// <param name="info"></param> /// <returns></returns> public static Node GetChild( Node parentNode, FindFileDirectoryInfo info ) { if (parentNode == null) { throw new ArgumentException("Required parentNode."); } if (info == null) { throw new ArgumentException("Required info."); } var pathSet = PathSet.Parse($@"{parentNode.FullPath}\{info.FileName}"); if (info.ExtFileAttributes.HasFlag(ExtendedFileAttributes.Directory)) { // Folder var result = NodeFactory.InnerGet( NodeType.Folder, pathSet, parentNode.ParamSet ); result.Created = info.CreationTime; result.Updated = info.LastWriteTime; result.LastAccessed = info.LastAccessTime; return(result); } else { // File var result = NodeFactory.InnerGet( NodeType.File, pathSet, parentNode.ParamSet ); result.Size = info.EndOfFile; result.Created = info.CreationTime; result.Updated = info.LastWriteTime; result.LastAccessed = info.LastAccessTime; return(result); } }
/// <summary> /// Get Parent Node from Node. /// </summary> /// <param name="node"></param> /// <returns></returns> public static Node GetParent(Node node) { if (node == null) { throw new ArgumentException("Required node."); } if (node.Type == NodeType.Server) { return(null); } if (string.IsNullOrEmpty(node.PathSet.Share)) { throw new IOException($"Invalid FullPath String. : {node.FullPath}"); } var paths = new List <string>() { node.PathSet.IpAddressString }; if (1 <= node.PathSet.Elements.Length) { paths.Add(node.PathSet.Share); } if (2 <= node.PathSet.Elements.Length) { paths.AddRange(node.PathSet.Elements.Take(node.PathSet.Elements.Length - 1)); } var pathSet = PathSet.Parse(string.Join(@"\", paths)); var nodeType = (string.IsNullOrEmpty(pathSet.Share)) ? NodeType.Server : NodeType.Folder; return(NodeFactory.InnerGet(nodeType, pathSet, node.ParamSet)); }
/// <summary> /// Get Node Instance. /// </summary> /// <param name="path"></param> /// <param name="paramSet"></param> /// <param name="throwException"></param> /// <returns></returns> /// <remarks> /// /// ** Warning ** /// SMB1 with Windows Domain (= Active Directory) is NOT Supoorted. /// /// </remarks> public static async Task <Node> GetNode( string path, ParamSet paramSet = null, bool throwException = false ) { PathSet pathSet; try { pathSet = PathSet.Parse(path); } catch (Exception ex) { var message = Node.GetErrorMessage( "GetNode", $"Invalid Format fullPath: {path}" ); if (throwException) { throw new ArgumentException(message, ex); } Debug.WriteLine(message); return(null); } return(await Task.Run(() => { using (var conn = new Connection(pathSet, paramSet)) { if (conn.HasError) { if (throwException) { throw new IOException(Node.GetErrorMessage(conn)); } Node.DebugWrite(conn); return null; } var result = conn.GetNode(); if (result == null) { if (throwException) { throw new IOException(Node.GetErrorMessage(conn)); } Node.DebugWrite(conn); return null; } return result; } }).ConfigureAwait(false)); }