/// <summary> /// Initializes a new instance of the LocalFileReferenceInfo class. /// </summary> /// <param name="file">The file item.</param> /// <param name="parent">The parent folder.</param> public LocalFileReferenceInfo(FileInfo file, LocalDirectoryReferenceInfo parent = null) : base(file, parent) { if (file == null) { return; } try { Extension = file.Extension; Creation = file.CreationTime; Attributes = file.Attributes; } catch (IOException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } catch (ExternalException) { } }
/// <summary> /// Initializes a new instance of the LocalDirectoryReferenceInfo class. /// </summary> /// <param name="directory">The directory instance.</param> /// <param name="parent">The parent folder.</param> public LocalDirectoryReferenceInfo(DirectoryInfo directory, LocalDirectoryReferenceInfo parent = null) : base(directory) { this.parent = parent; if (directory == null) { return; } try { Creation = directory.CreationTime; } catch (IOException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } catch (ExternalException) { } }
private static LocalFileReferenceInfo CreateFileReferenceInfo(FileInfo ele, LocalDirectoryReferenceInfo parent) { #if !NETFRAMEWORK if (ele.Extension?.Equals(".zip", StringComparison.OrdinalIgnoreCase) == true) { return(new ZipFileReferenceInfo(ele, parent)); } else #endif return(new LocalFileReferenceInfo(ele, parent)); }
/// <summary> /// Initializes a new instance of the BaseFileReferenceInfo class. /// </summary> /// <param name="file">The file item.</param> /// <param name="parent">The parent folder.</param> public BaseFileReferenceInfo(FileInfo file, LocalDirectoryReferenceInfo parent = null) : base() { Source = file; if (file == null) { return; } if (!file.Exists) { try { Name = file.Name; } catch (IOException) { } catch (ArgumentException) { } catch (NotSupportedException) { } catch (NullReferenceException) { } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } catch (ExternalException) { } Exists = false; return; } Name = file.Name; try { LastModification = file.LastWriteTime; Size = file.Length; } catch (IOException) { return; } catch (NotSupportedException) { return; } catch (InvalidOperationException) { return; } catch (UnauthorizedAccessException) { return; } catch (SecurityException) { return; } catch (ExternalException) { return; } Exists = true; if (parent != null) { SetParent(parent); return; } try { var dir = file.Directory; if (dir == null || !dir.Exists) { return; } SetParent(new LocalDirectoryReferenceInfo(dir)); } catch (IOException) { } catch (NotSupportedException) { } catch (InvalidOperationException) { } catch (UnauthorizedAccessException) { } catch (SecurityException) { } catch (ExternalException) { } }
/// <summary> /// Initializes a new instance of the LocalPackageFileReferenceInfo class. /// </summary> /// <param name="file">The file item.</param> /// <param name="parent">The parent folder.</param> public LocalPackageFileReferenceInfo(FileInfo file, LocalDirectoryReferenceInfo parent = null) : base(file, parent) { }
internal static Task <IReadOnlyList <IFileReferenceInfo> > GetFilesAsync(DirectoryInfo dir, LocalDirectoryReferenceInfo parent) { if (dir == null) { return(Task.FromResult <IReadOnlyList <IFileReferenceInfo> >(new List <IFileReferenceInfo>())); } if (parent == null) { parent = new LocalDirectoryReferenceInfo(dir); } var col = dir.EnumerateFiles()?.Where(ele => !ele.Attributes.HasFlag(FileAttributes.Hidden))?.Select(ele => CreateFileReferenceInfo(ele, parent) as IFileReferenceInfo)?.ToList() ?? new List <IFileReferenceInfo>(); return(Task.FromResult <IReadOnlyList <IFileReferenceInfo> >(col)); }